From 4bd1a344b95c1c42079cbc1d8223b6cea1d96d68 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 24 Jan 2025 19:28:08 +0800 Subject: [PATCH] sweep: signal tx in `markInputFatal` This commit adds the failed tx to the result when marking the input as fatal, which is used in the commit resolver when handling revoked outputs. --- sweep/sweeper.go | 15 ++++++++++----- sweep/sweeper_test.go | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sweep/sweeper.go b/sweep/sweeper.go index e1e870828..5b0601b14 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -1267,7 +1267,7 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error { ) if err != nil { err := fmt.Errorf("wait for spend: %w", err) - s.markInputFatal(pi, err) + s.markInputFatal(pi, nil, err) return err } @@ -1482,12 +1482,17 @@ func (s *UtxoSweeper) markInputsSwept(tx *wire.MsgTx, isOurTx bool) { // markInputFatal marks the given input as fatal and won't be retried. It // will also notify all the subscribers of this input. -func (s *UtxoSweeper) markInputFatal(pi *SweeperInput, err error) { +func (s *UtxoSweeper) markInputFatal(pi *SweeperInput, tx *wire.MsgTx, + err error) { + log.Errorf("Failed to sweep input: %v, error: %v", pi, err) pi.state = Fatal - s.signalResult(pi, Result{Err: err}) + s.signalResult(pi, Result{ + Tx: tx, + Err: err, + }) } // updateSweeperInputs updates the sweeper's internal state and returns a map @@ -1819,7 +1824,7 @@ func (s *UtxoSweeper) markInputsFatal(set InputSet, err error) { continue } - s.markInputFatal(input, err) + s.markInputFatal(input, nil, err) } } @@ -1932,7 +1937,7 @@ func (s *UtxoSweeper) handleUnknownSpendTx(inp *SweeperInput, tx *wire.MsgTx) { // Since the input is spent by others, we now mark it as fatal and won't // be retried. - s.markInputFatal(inp, ErrRemoteSpend) + s.markInputFatal(inp, tx, ErrRemoteSpend) log.Debugf("Removing descendant txns invalidated by (txid=%v): %v", txid, lnutils.SpewLogClosure(tx)) diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index da49c601e..450654473 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -596,7 +596,7 @@ func TestMarkInputFailed(t *testing.T) { } // Call the method under test. - s.markInputFatal(pi, errors.New("dummy error")) + s.markInputFatal(pi, nil, errors.New("dummy error")) // Assert the state is updated. require.Equal(t, Fatal, pi.state)