From a2b8f4e19c1bb56f11941a98387e4e13c235b566 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 8 Apr 2024 17:46:18 +0800 Subject: [PATCH] sweep: allow published input to be marked as `PublishFailed` If anything happens during the fee bumping process, and causes the input to be failed, we should be able to mark it as `PublishFailed`. --- sweep/sweeper.go | 2 +- sweep/sweeper_test.go | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 982d9ad84..090cea717 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -961,7 +961,7 @@ func (s *UtxoSweeper) markInputsPublishFailed(outpoints []wire.OutPoint) { } // Valdiate that the input is in an expected state. - if pi.state != PendingPublish { + if pi.state != PendingPublish && pi.state != Published { log.Errorf("Expect input %v to have %v, instead it "+ "has %v", op, PendingPublish, pi.state) diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 450e434e7..2c6326c04 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -2274,8 +2274,8 @@ func TestMarkInputsPublished(t *testing.T) { } // TestMarkInputsPublishFailed checks that given a list of inputs with -// different states, only the state `PendingPublish` will be marked as -// `PublishFailed`. +// different states, only the state `PendingPublish` and `Published` will be +// marked as `PublishFailed`. func TestMarkInputsPublishFailed(t *testing.T) { t.Parallel() @@ -2315,6 +2315,14 @@ func TestMarkInputsPublishFailed(t *testing.T) { state: PendingPublish, } + // inputPublished specifies an input that's published. + inputPublished := &wire.TxIn{ + PreviousOutPoint: wire.OutPoint{Index: 4}, + } + s.inputs[inputPublished.PreviousOutPoint] = &SweeperInput{ + state: Published, + } + // Mark the test inputs. We expect the non-exist input and the // inputInit to be skipped, and the final input to be marked as // published. @@ -2322,10 +2330,11 @@ func TestMarkInputsPublishFailed(t *testing.T) { inputNotExist.PreviousOutPoint, inputInit.PreviousOutPoint, inputPendingPublish.PreviousOutPoint, + inputPublished.PreviousOutPoint, }) // We expect unchanged number of pending inputs. - require.Len(s.inputs, 2) + require.Len(s.inputs, 3) // We expect the init input's state to stay unchanged. require.Equal(Init, @@ -2336,6 +2345,10 @@ func TestMarkInputsPublishFailed(t *testing.T) { require.Equal(PublishFailed, s.inputs[inputPendingPublish.PreviousOutPoint].state) + // We expect the published input's is now marked as publish failed. + require.Equal(PublishFailed, + s.inputs[inputPublished.PreviousOutPoint].state) + // Assert mocked statements are executed as expected. mockStore.AssertExpectations(t) }