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.
This commit is contained in:
yyforyongyu 2025-01-24 19:28:08 +08:00
parent 81987f050d
commit e8a37e1414
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
2 changed files with 11 additions and 6 deletions

View file

@ -1267,7 +1267,7 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
) )
if err != nil { if err != nil {
err := fmt.Errorf("wait for spend: %w", err) err := fmt.Errorf("wait for spend: %w", err)
s.markInputFatal(pi, err) s.markInputFatal(pi, nil, err)
return 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 // markInputFatal marks the given input as fatal and won't be retried. It
// will also notify all the subscribers of this input. // 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) log.Errorf("Failed to sweep input: %v, error: %v", pi, err)
pi.state = Fatal 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 // updateSweeperInputs updates the sweeper's internal state and returns a map
@ -1819,7 +1824,7 @@ func (s *UtxoSweeper) markInputsFatal(set InputSet, err error) {
continue 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 // Since the input is spent by others, we now mark it as fatal and won't
// be retried. // be retried.
s.markInputFatal(inp, ErrRemoteSpend) s.markInputFatal(inp, tx, ErrRemoteSpend)
log.Debugf("Removing descendant txns invalidated by (txid=%v): %v", log.Debugf("Removing descendant txns invalidated by (txid=%v): %v",
txid, lnutils.SpewLogClosure(tx)) txid, lnutils.SpewLogClosure(tx))

View file

@ -596,7 +596,7 @@ func TestMarkInputFailed(t *testing.T) {
} }
// Call the method under test. // 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. // Assert the state is updated.
require.Equal(t, Fatal, pi.state) require.Equal(t, Fatal, pi.state)