From 7edbfeadd8a31ebe070ccca2468b708ea9b78356 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Tue, 8 Apr 2025 20:42:14 -0300 Subject: [PATCH] sweepbatcher: store batch status before monitoring If monitorConfirmations fails, we still want to persist the state to DB. --- sweepbatcher/sweep_batch.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sweepbatcher/sweep_batch.go b/sweepbatcher/sweep_batch.go index ee623659..25c58ba3 100644 --- a/sweepbatcher/sweep_batch.go +++ b/sweepbatcher/sweep_batch.go @@ -2099,16 +2099,19 @@ func (b *batch) handleSpend(ctx context.Context, spendTx *wire.MsgTx) error { "purged swaps: %v, purged groups: %v", confirmedSweeps, purgedSweeps, purgedSwaps, len(purgeList)) - err = b.monitorConfirmations(ctx) - if err != nil { - return err - } - // We are no longer able to accept new sweeps, so we mark the batch as // closed and persist on storage. b.state = Closed - return b.persist(ctx) + if err = b.persist(ctx); err != nil { + return fmt.Errorf("saving batch failed: %w", err) + } + + if err = b.monitorConfirmations(ctx); err != nil { + return fmt.Errorf("monitorConfirmations failed: %w", err) + } + + return nil } // handleConf handles a confirmation notification. This is the final step of the