fix selfsync issues with the queue

remove margin for fees
handle non latin names
adjusted error handling
This commit is contained in:
Niko Storni 2018-06-04 10:35:35 -04:00
parent 3bbf46e139
commit ba5c1c6519
4 changed files with 16 additions and 9 deletions

View file

@ -51,7 +51,6 @@ func (s *Sync) walletSetup() error {
minBalance = 1 //since we ended up in this function it means some juice is still needed minBalance = 1 //since we ended up in this function it means some juice is still needed
} }
amountToAdd, _ := decimal.NewFromFloat(minBalance).Sub(balance).Float64() amountToAdd, _ := decimal.NewFromFloat(minBalance).Sub(balance).Float64()
amountToAdd *= 6 // add 600% margin for fees, future publishes, etc (insane i know)
if s.Refill > 0 { if s.Refill > 0 {
if amountToAdd < 0 { if amountToAdd < 0 {

View file

@ -1,11 +1,15 @@
package sources package sources
import ( import (
"fmt"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"crypto/md5"
"encoding/hex"
"github.com/lbryio/lbry.go/jsonrpc" "github.com/lbryio/lbry.go/jsonrpc"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -56,6 +60,12 @@ func publishAndRetryExistingNames(daemon *jsonrpc.Client, title, filename string
log.Printf("name exists, retrying (%d attempts so far)\n", attempt) log.Printf("name exists, retrying (%d attempts so far)\n", attempt)
continue continue
} }
//if for some reasons the title can't be converted in a valid claim name (too short or not latin) then we use a hash
if len(name) < 2 {
hasher := md5.New()
hasher.Write([]byte(title))
name = fmt.Sprintf("%s-%d", hex.EncodeToString(hasher.Sum(nil))[:15], attempt)
}
_, err := daemon.Publish(name, filename, amount, options) _, err := daemon.Publish(name, filename, amount, options)
if err == nil || strings.Contains(err.Error(), "failed: Multiple claims (") { if err == nil || strings.Contains(err.Error(), "failed: Multiple claims (") {

View file

@ -59,10 +59,6 @@ func (v YoutubeVideo) PublishedAt() time.Time {
} }
func (v YoutubeVideo) getFilename() string { func (v YoutubeVideo) getFilename() string {
return v.dir + "/" + v.getClaimName() + ".mp4"
}
func (v YoutubeVideo) getClaimName() string {
maxLen := 30 maxLen := 30
reg := regexp.MustCompile(`[^a-zA-Z0-9]+`) reg := regexp.MustCompile(`[^a-zA-Z0-9]+`)
@ -83,8 +79,10 @@ func (v YoutubeVideo) getClaimName() string {
} }
name = tmpName name = tmpName
} }
if len(name) < 1 {
return name name = v.id
}
return v.dir + "/" + name + ".mp4"
} }
func (v YoutubeVideo) getAbbrevDescription() string { func (v YoutubeVideo) getAbbrevDescription() string {

View file

@ -272,10 +272,10 @@ func (s *Sync) startWorker(workerNum int) {
if util.InSliceContains(err.Error(), errorsNoRetry) { if util.InSliceContains(err.Error(), errorsNoRetry) {
log.Println("This error should not be retried at all") log.Println("This error should not be retried at all")
} else if tryCount < s.MaxTries { } else if tryCount < s.MaxTries {
if strings.Contains(err.Error(), "The transaction was rejected by network rules.(258: txn-mempool-conflict)") || if strings.Contains(err.Error(), "258: txn-mempool-conflict") ||
strings.Contains(err.Error(), "failed: Not enough funds") || strings.Contains(err.Error(), "failed: Not enough funds") ||
strings.Contains(err.Error(), "Error in daemon: Insufficient funds, please deposit additional LBC") || strings.Contains(err.Error(), "Error in daemon: Insufficient funds, please deposit additional LBC") ||
strings.Contains(err.Error(), "The transaction was rejected by network rules.(64: too-long-mempool-chain)") { strings.Contains(err.Error(), "64: too-long-mempool-chain") {
log.Println("waiting for a block and refilling addresses before retrying") log.Println("waiting for a block and refilling addresses before retrying")
err = s.walletSetup() err = s.walletSetup()
if err != nil { if err != nil {