From 5e4aaab0ceeed6359a7866ae76cf903d24851339 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 29 Feb 2024 09:58:08 +0100 Subject: [PATCH 1/3] autopilot: reduce logger noise --- autopilot/autopilot.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/autopilot/autopilot.go b/autopilot/autopilot.go index e5ddd8411..f0d81f434 100644 --- a/autopilot/autopilot.go +++ b/autopilot/autopilot.go @@ -202,6 +202,13 @@ func (ap *Autopilot) Run() error { var forceScan bool var launchAccountRefillsOnce sync.Once for { + // check for shutdown right before starting a new iteration + select { + case <-ap.shutdownCtx.Done(): + return nil + default: + } + ap.logger.Info("autopilot iteration starting") tickerFired := make(chan struct{}) ap.workers.withWorker(func(w Worker) { @@ -220,7 +227,7 @@ func (ap *Autopilot) Run() error { close(tickerFired) return } - ap.logger.Error("autopilot stopped before consensus was synced") + ap.logger.Info("autopilot stopped before consensus was synced") return } else if blocked { if scanning, _ := ap.s.Status(); !scanning { @@ -234,7 +241,7 @@ func (ap *Autopilot) Run() error { close(tickerFired) return } - ap.logger.Error("autopilot stopped before it was able to confirm it was configured in the bus") + ap.logger.Info("autopilot stopped before it was able to confirm it was configured in the bus") return } @@ -463,11 +470,17 @@ func (ap *Autopilot) blockUntilSynced(interrupt <-chan time.Time) (synced, block } func (ap *Autopilot) tryScheduleTriggerWhenFunded() error { - ctx, cancel := context.WithTimeout(ap.shutdownCtx, 30*time.Second) - wallet, err := ap.bus.Wallet(ctx) - cancel() + // no need to schedule a trigger if we're stopped + if ap.isStopped() { + return nil + } + + // apply sane timeout + ctx, cancel := context.WithTimeout(ap.shutdownCtx, time.Minute) + defer cancel() // no need to schedule a trigger if the wallet is already funded + wallet, err := ap.bus.Wallet(ctx) if err != nil { return err } else if !wallet.Confirmed.Add(wallet.Unconfirmed).IsZero() { From 54cd3f928742c2fa011693be52e4234f59cc5662 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 29 Feb 2024 10:42:29 +0100 Subject: [PATCH 2/3] autoilot: implement MR remarks --- autopilot/autopilot.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/autopilot/autopilot.go b/autopilot/autopilot.go index f0d81f434..da7105d06 100644 --- a/autopilot/autopilot.go +++ b/autopilot/autopilot.go @@ -194,21 +194,14 @@ func (ap *Autopilot) Run() error { } // schedule a trigger when the wallet receives its first deposit - if err := ap.tryScheduleTriggerWhenFunded(); err != nil { + if err := ap.tryScheduleTriggerWhenFunded(); err != nil && !isErr(err, context.Canceled) { ap.logger.Error(err) return nil } var forceScan bool var launchAccountRefillsOnce sync.Once - for { - // check for shutdown right before starting a new iteration - select { - case <-ap.shutdownCtx.Done(): - return nil - default: - } - + for !ap.isStopped() { ap.logger.Info("autopilot iteration starting") tickerFired := make(chan struct{}) ap.workers.withWorker(func(w Worker) { @@ -315,6 +308,7 @@ func (ap *Autopilot) Run() error { case <-tickerFired: } } + return nil } // Shutdown shuts down the autopilot. @@ -470,11 +464,6 @@ func (ap *Autopilot) blockUntilSynced(interrupt <-chan time.Time) (synced, block } func (ap *Autopilot) tryScheduleTriggerWhenFunded() error { - // no need to schedule a trigger if we're stopped - if ap.isStopped() { - return nil - } - // apply sane timeout ctx, cancel := context.WithTimeout(ap.shutdownCtx, time.Minute) defer cancel() From 96bb6ef800fa4b56ab62d54b5d93488dfcd7614e Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 29 Feb 2024 10:44:09 +0100 Subject: [PATCH 3/3] autopilot: fix error check --- autopilot/autopilot.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autopilot/autopilot.go b/autopilot/autopilot.go index da7105d06..a7cb225ba 100644 --- a/autopilot/autopilot.go +++ b/autopilot/autopilot.go @@ -194,8 +194,10 @@ func (ap *Autopilot) Run() error { } // schedule a trigger when the wallet receives its first deposit - if err := ap.tryScheduleTriggerWhenFunded(); err != nil && !isErr(err, context.Canceled) { - ap.logger.Error(err) + if err := ap.tryScheduleTriggerWhenFunded(); err != nil { + if !errors.Is(err, context.Canceled) { + ap.logger.Error(err) + } return nil }