From ba5c1c65191a0aaa00042386575b0d91e8330a39 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Mon, 4 Jun 2018 10:35:35 -0400 Subject: [PATCH] fix selfsync issues with the queue remove margin for fees handle non latin names adjusted error handling --- setup.go | 1 - sources/shared.go | 10 ++++++++++ sources/youtubeVideo.go | 10 ++++------ ytsync.go | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/setup.go b/setup.go index 59aff8b..97f180e 100644 --- a/setup.go +++ b/setup.go @@ -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 } 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 amountToAdd < 0 { diff --git a/sources/shared.go b/sources/shared.go index f70ebbc..fc128cb 100644 --- a/sources/shared.go +++ b/sources/shared.go @@ -1,11 +1,15 @@ package sources import ( + "fmt" "regexp" "strconv" "strings" "sync" + "crypto/md5" + "encoding/hex" + "github.com/lbryio/lbry.go/jsonrpc" 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) 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) if err == nil || strings.Contains(err.Error(), "failed: Multiple claims (") { diff --git a/sources/youtubeVideo.go b/sources/youtubeVideo.go index fbe02dc..bb1db6b 100644 --- a/sources/youtubeVideo.go +++ b/sources/youtubeVideo.go @@ -59,10 +59,6 @@ func (v YoutubeVideo) PublishedAt() time.Time { } func (v YoutubeVideo) getFilename() string { - return v.dir + "/" + v.getClaimName() + ".mp4" -} - -func (v YoutubeVideo) getClaimName() string { maxLen := 30 reg := regexp.MustCompile(`[^a-zA-Z0-9]+`) @@ -83,8 +79,10 @@ func (v YoutubeVideo) getClaimName() string { } name = tmpName } - - return name + if len(name) < 1 { + name = v.id + } + return v.dir + "/" + name + ".mp4" } func (v YoutubeVideo) getAbbrevDescription() string { diff --git a/ytsync.go b/ytsync.go index dbdddbc..4d58a74 100644 --- a/ytsync.go +++ b/ytsync.go @@ -272,10 +272,10 @@ func (s *Sync) startWorker(workerNum int) { if util.InSliceContains(err.Error(), errorsNoRetry) { log.Println("This error should not be retried at all") } 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(), "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") err = s.walletSetup() if err != nil {