From 15588355b33dc55dfe3f27702c694df149c6f3bc Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 27 Mar 2024 17:51:45 +0800 Subject: [PATCH] sweep: exit when `handleNewInput` fails When `handleNewInput` fails, it means there's something terribly wrong with the chain backend, which means we need to stop the current process and let user handle it. --- sweep/sweeper.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 37817361b..1bb4afb2b 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -657,7 +657,13 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) { // we are already trying to sweep this input and if not, set up // a listener to spend and schedule a sweep. case input := <-s.newInputs: - s.handleNewInput(input) + err := s.handleNewInput(input) + if err != nil { + log.Criticalf("Unable to handle new input: %v", + err) + + return + } // If this input is forced, we perform an sweep // immediately. @@ -1221,7 +1227,7 @@ func (s *UtxoSweeper) mempoolLookup(op wire.OutPoint) fn.Option[wire.MsgTx] { // handleNewInput processes a new input by registering spend notification and // scheduling sweeping for it. -func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) { +func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error { outpoint := input.input.OutPoint() pi, pending := s.inputs[outpoint] if pending { @@ -1229,7 +1235,7 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) { s.handleExistingInput(input, pi) - return + return nil } // This is a new input, and we want to query the mempool to see if this @@ -1261,10 +1267,12 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) { err := fmt.Errorf("wait for spend: %w", err) s.markInputFailed(pi, err) - return + return err } pi.ntfnRegCancel = cancel + + return nil } // decideStateAndRBFInfo queries the mempool to see whether the given input has