From 4f8bc816643bf400228cacc84e384e90a7f27dc0 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Sat, 5 May 2018 10:15:02 -0400 Subject: [PATCH] added timeout to utxo waiting added more error handling --- setup.go | 25 +++++++++++++++++++++++-- ytsync.go | 4 +++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/setup.go b/setup.go index 42aa935..276a980 100644 --- a/setup.go +++ b/setup.go @@ -92,7 +92,10 @@ func (s *Sync) ensureEnoughUTXOs() error { if !allUTXOsConfirmed(utxolist) { log.Println("Waiting for previous txns to confirm") // happens if you restarted the daemon soon after a previous publish run - s.waitUntilUTXOsConfirmed() + err := s.waitUntilUTXOsConfirmed() + if err != nil { + return err + } } target := 60 @@ -140,6 +143,7 @@ func (s *Sync) ensureEnoughUTXOs() error { } func (s *Sync) waitUntilUTXOsConfirmed() error { + origin := time.Now() for { r, err := s.daemon.UTXOList() if err != nil { @@ -151,7 +155,24 @@ func (s *Sync) waitUntilUTXOsConfirmed() error { if allUTXOsConfirmed(r) { return nil } - + if time.Now().After(origin.Add(10 * time.Minute)) { + //lbryum is messing with us or something. restart the daemon + err := stopDaemonViaSystemd() + if err != nil { + logShutdownError(err) + return err + } + var waitTimeout time.Duration = 60 * 6 + err = waitForDaemonProcess(waitTimeout) + if err != nil { + logShutdownError(err) + return err + } + err = startDaemonViaSystemd() + if err != nil { + return err + } + } wait := 30 * time.Second log.Println("Waiting " + wait.String() + "...") time.Sleep(wait) diff --git a/ytsync.go b/ytsync.go index 28d76a9..911b6a9 100644 --- a/ytsync.go +++ b/ytsync.go @@ -267,7 +267,9 @@ func (s *Sync) startWorker(workerNum int) { log.Println("waiting for a block and refilling addresses before retrying") err = s.walletSetup() if err != nil { - log.Println(err.Error()) + s.stop.Stop() + util.SendToSlackError("Failed to setup the wallet for a refill: %v", err) + break } } log.Println("Retrying")