address more errors

increase room for fees (Jeremy says just pay more)
add code to wait for daemon startup
This commit is contained in:
Niko Storni 2018-05-07 16:26:46 -04:00
parent c5c66eac14
commit 42deb1d29d
No known key found for this signature in database
GPG key ID: F37FE63398800368
2 changed files with 23 additions and 5 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/lbryio/lbry.go/jsonrpc" "github.com/lbryio/lbry.go/jsonrpc"
"github.com/lbryio/lbry.go/lbrycrd" "github.com/lbryio/lbry.go/lbrycrd"
"github.com/lbryio/lbry.go/util"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -45,8 +46,12 @@ func (s *Sync) walletSetup() error {
log.Debugf("We already published %d videos", numPublished) log.Debugf("We already published %d videos", numPublished)
minBalance := (float64(numOnSource)-float64(numPublished))*publishAmount + channelClaimAmount minBalance := (float64(numOnSource)-float64(numPublished))*publishAmount + channelClaimAmount
if numPublished > numOnSource {
util.SendToSlackError("something is going on as we published more videos than those available on source: %d/%d", numPublished, numOnSource)
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 *= 2 // add 100% margin for fees, future publishes, etc 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 {
@ -155,14 +160,15 @@ func (s *Sync) waitUntilUTXOsConfirmed() error {
if allUTXOsConfirmed(r) { if allUTXOsConfirmed(r) {
return nil return nil
} }
if time.Now().After(origin.Add(10 * time.Minute)) { if time.Now().After(origin.Add(15 * time.Minute)) {
//lbryum is messing with us or something. restart the daemon //lbryum is messing with us or something. restart the daemon
//this could also be a very long block
err := stopDaemonViaSystemd() err := stopDaemonViaSystemd()
if err != nil { if err != nil {
logShutdownError(err) logShutdownError(err)
return err return err
} }
var waitTimeout time.Duration = 60 * 6 var waitTimeout time.Duration = 60 * 8
err = waitForDaemonProcess(waitTimeout) err = waitForDaemonProcess(waitTimeout)
if err != nil { if err != nil {
logShutdownError(err) logShutdownError(err)
@ -172,6 +178,17 @@ func (s *Sync) waitUntilUTXOsConfirmed() error {
if err != nil { if err != nil {
return err return err
} }
log.Infoln("Waiting for daemon to finish starting...")
s.daemon = jsonrpc.NewClient("")
s.daemon.SetRPCTimeout(5 * time.Minute)
for {
_, err := s.daemon.WalletBalance()
if err == nil {
break
}
time.Sleep(5 * time.Second)
}
} }
wait := 30 * time.Second wait := 30 * time.Second
log.Println("Waiting " + wait.String() + "...") log.Println("Waiting " + wait.String() + "...")

View file

@ -110,7 +110,7 @@ func (s *Sync) FullCycle() error {
} else { } else {
// the cli will return long before the daemon effectively stops. we must observe the processes running // the cli will return long before the daemon effectively stops. we must observe the processes running
// before moving the wallet // before moving the wallet
var waitTimeout time.Duration = 60 * 6 var waitTimeout time.Duration = 60 * 8
processDeathError := waitForDaemonProcess(waitTimeout) processDeathError := waitForDaemonProcess(waitTimeout)
if processDeathError != nil { if processDeathError != nil {
logShutdownError(processDeathError) logShutdownError(processDeathError)
@ -257,6 +257,7 @@ func (s *Sync) startWorker(workerNum int) {
"download error: AccessDenied: Access Denied", "download error: AccessDenied: Access Denied",
"Playback on other websites has been disabled by the video owner", "Playback on other websites has been disabled by the video owner",
"Error in daemon: Cannot publish empty file", "Error in daemon: Cannot publish empty file",
"Error extracting sts from embedded url response",
} }
if util.InSlice(err.Error(), errorsNoRetry) { if util.InSlice(err.Error(), errorsNoRetry) {
log.Println("This error should not be retried at all") log.Println("This error should not be retried at all")
@ -275,7 +276,7 @@ func (s *Sync) startWorker(workerNum int) {
log.Println("Retrying") log.Println("Retrying")
continue continue
} }
util.SendToSlackInfo("Video failed after %d retries, skipping. Stack: %s", s.MaxTries, logMsg) util.SendToSlackError("Video failed after %d retries, skipping. Stack: %s", s.MaxTries, logMsg)
} }
} }
break break