sweep: rename Failed to Fatal

This commit renames `Failed` to `Fatal` as it sounds too close to
`PublishFailed`. We also wanna emphasize that inputs in this state won't
be retried.
This commit is contained in:
yyforyongyu
2025-01-20 23:33:03 +08:00
parent 6bf895aeb9
commit c68b8e8c1e
2 changed files with 38 additions and 35 deletions

View File

@@ -119,9 +119,12 @@ const (
// sweeping transactions confirmed, the remaining two will be excluded. // sweeping transactions confirmed, the remaining two will be excluded.
Excluded Excluded
// Failed is the state when a pending input has too many failed publish // Fatal is the final state of a pending input. Inputs ending in this
// atttempts or unknown broadcast error is returned. // state won't be retried. This could happen,
Failed // - when a pending input has too many failed publish attempts;
// - the input has been spent by another party;
// - unknown broadcast error is returned.
Fatal
) )
// String gives a human readable text for the sweep states. // String gives a human readable text for the sweep states.
@@ -145,8 +148,8 @@ func (s SweepState) String() string {
case Excluded: case Excluded:
return "Excluded" return "Excluded"
case Failed: case Fatal:
return "Failed" return "Fatal"
default: default:
return "Unknown" return "Unknown"
@@ -215,7 +218,7 @@ func (p *SweeperInput) terminated() bool {
// If the input has reached a final state, that it's either // If the input has reached a final state, that it's either
// been swept, or failed, or excluded, we will remove it from // been swept, or failed, or excluded, we will remove it from
// our sweeper. // our sweeper.
case Failed, Swept, Excluded: case Fatal, Swept, Excluded:
return true return true
default: default:
@@ -1264,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.markInputFailed(pi, err) s.markInputFatal(pi, err)
return err return err
} }
@@ -1477,12 +1480,12 @@ func (s *UtxoSweeper) markInputsSwept(tx *wire.MsgTx, isOurTx bool) {
} }
} }
// markInputFailed marks the given input as failed 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) markInputFailed(pi *SweeperInput, err error) { func (s *UtxoSweeper) markInputFatal(pi *SweeperInput, 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 = Failed pi.state = Fatal
s.signalResult(pi, Result{Err: err}) s.signalResult(pi, Result{Err: err})
} }
@@ -1784,15 +1787,15 @@ func (s *UtxoSweeper) handleBumpEventTxFatal(resp *bumpResp) error {
} }
} }
// Mark the inputs as failed. // Mark the inputs as fatal.
s.markInputsFailed(resp.set, r.Err) s.markInputsFatal(resp.set, r.Err)
return nil return nil
} }
// markInputsFailed marks all inputs found in the tx as failed. It will also // markInputsFatal marks all inputs in the input set as failed. It will also
// notify all the subscribers of these inputs. // notify all the subscribers of these inputs.
func (s *UtxoSweeper) markInputsFailed(set InputSet, err error) { func (s *UtxoSweeper) markInputsFatal(set InputSet, err error) {
for _, inp := range set.Inputs() { for _, inp := range set.Inputs() {
outpoint := inp.OutPoint() outpoint := inp.OutPoint()
@@ -1816,7 +1819,7 @@ func (s *UtxoSweeper) markInputsFailed(set InputSet, err error) {
continue continue
} }
s.markInputFailed(input, err) s.markInputFatal(input, err)
} }
} }

View File

@@ -215,7 +215,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
// published. // published.
// - inputSwept specifies an input that's swept. // - inputSwept specifies an input that's swept.
// - inputExcluded specifies an input that's excluded. // - inputExcluded specifies an input that's excluded.
// - inputFailed specifies an input that's failed. // - inputFatal specifies an input that's fatal.
var ( var (
inputInit = createMockInput(t, s, Init) inputInit = createMockInput(t, s, Init)
inputPendingPublish = createMockInput(t, s, PendingPublish) inputPendingPublish = createMockInput(t, s, PendingPublish)
@@ -223,13 +223,13 @@ func TestMarkInputsPublishFailed(t *testing.T) {
inputPublishFailed = createMockInput(t, s, PublishFailed) inputPublishFailed = createMockInput(t, s, PublishFailed)
inputSwept = createMockInput(t, s, Swept) inputSwept = createMockInput(t, s, Swept)
inputExcluded = createMockInput(t, s, Excluded) inputExcluded = createMockInput(t, s, Excluded)
inputFailed = createMockInput(t, s, Failed) inputFatal = createMockInput(t, s, Fatal)
) )
// Gather all inputs. // Gather all inputs.
set.On("Inputs").Return([]input.Input{ set.On("Inputs").Return([]input.Input{
inputInit, inputPendingPublish, inputPublished, inputInit, inputPendingPublish, inputPublished,
inputPublishFailed, inputSwept, inputExcluded, inputFailed, inputPublishFailed, inputSwept, inputExcluded, inputFatal,
}) })
// Mark the test inputs. We expect the non-exist input and the // Mark the test inputs. We expect the non-exist input and the
@@ -264,7 +264,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
require.Equal(Excluded, s.inputs[inputExcluded.OutPoint()].state) require.Equal(Excluded, s.inputs[inputExcluded.OutPoint()].state)
// We expect the failed input to stay unchanged. // We expect the failed input to stay unchanged.
require.Equal(Failed, s.inputs[inputFailed.OutPoint()].state) require.Equal(Fatal, s.inputs[inputFatal.OutPoint()].state)
// Assert mocked statements are executed as expected. // Assert mocked statements are executed as expected.
mockStore.AssertExpectations(t) mockStore.AssertExpectations(t)
@@ -437,7 +437,7 @@ func TestUpdateSweeperInputs(t *testing.T) {
// These inputs won't hit RequiredLockTime so we won't mock. // These inputs won't hit RequiredLockTime so we won't mock.
input4 := &SweeperInput{state: Swept, Input: inp1} input4 := &SweeperInput{state: Swept, Input: inp1}
input5 := &SweeperInput{state: Excluded, Input: inp1} input5 := &SweeperInput{state: Excluded, Input: inp1}
input6 := &SweeperInput{state: Failed, Input: inp1} input6 := &SweeperInput{state: Fatal, Input: inp1}
// Mock the input to have a locktime in the future so it will NOT be // Mock the input to have a locktime in the future so it will NOT be
// returned. // returned.
@@ -575,7 +575,7 @@ func TestDecideStateAndRBFInfo(t *testing.T) {
require.Equal(Published, state) require.Equal(Published, state)
} }
// TestMarkInputFailed checks that the input is marked as failed as expected. // TestMarkInputFatal checks that the input is marked as expected.
func TestMarkInputFailed(t *testing.T) { func TestMarkInputFailed(t *testing.T) {
t.Parallel() t.Parallel()
@@ -596,10 +596,10 @@ func TestMarkInputFailed(t *testing.T) {
} }
// Call the method under test. // Call the method under test.
s.markInputFailed(pi, errors.New("dummy error")) s.markInputFatal(pi, errors.New("dummy error"))
// Assert the state is updated. // Assert the state is updated.
require.Equal(t, Failed, pi.state) require.Equal(t, Fatal, pi.state)
} }
// TestSweepPendingInputs checks that `sweepPendingInputs` correctly executes // TestSweepPendingInputs checks that `sweepPendingInputs` correctly executes
@@ -1102,7 +1102,7 @@ func TestMarkInputsFailed(t *testing.T) {
// published. // published.
// - inputSwept specifies an input that's swept. // - inputSwept specifies an input that's swept.
// - inputExcluded specifies an input that's excluded. // - inputExcluded specifies an input that's excluded.
// - inputFailed specifies an input that's failed. // - inputFatal specifies an input that's fatal.
var ( var (
inputInit = createMockInput(t, s, Init) inputInit = createMockInput(t, s, Init)
inputPendingPublish = createMockInput(t, s, PendingPublish) inputPendingPublish = createMockInput(t, s, PendingPublish)
@@ -1110,33 +1110,33 @@ func TestMarkInputsFailed(t *testing.T) {
inputPublishFailed = createMockInput(t, s, PublishFailed) inputPublishFailed = createMockInput(t, s, PublishFailed)
inputSwept = createMockInput(t, s, Swept) inputSwept = createMockInput(t, s, Swept)
inputExcluded = createMockInput(t, s, Excluded) inputExcluded = createMockInput(t, s, Excluded)
inputFailed = createMockInput(t, s, Failed) inputFatal = createMockInput(t, s, Fatal)
) )
// Gather all inputs. // Gather all inputs.
set.On("Inputs").Return([]input.Input{ set.On("Inputs").Return([]input.Input{
inputInit, inputPendingPublish, inputPublished, inputInit, inputPendingPublish, inputPublished,
inputPublishFailed, inputSwept, inputExcluded, inputFailed, inputPublishFailed, inputSwept, inputExcluded, inputFatal,
}) })
// Mark the test inputs. We expect the non-exist input and // Mark the test inputs. We expect the non-exist input and
// inputSwept/inputExcluded/inputFailed to be skipped. // inputSwept/inputExcluded/inputFatal to be skipped.
s.markInputsFailed(set, errDummy) s.markInputsFatal(set, errDummy)
// We expect unchanged number of pending inputs. // We expect unchanged number of pending inputs.
require.Len(s.inputs, 7) require.Len(s.inputs, 7)
// We expect the init input's to be marked as failed. // We expect the init input's to be marked as fatal.
require.Equal(Failed, s.inputs[inputInit.OutPoint()].state) require.Equal(Fatal, s.inputs[inputInit.OutPoint()].state)
// We expect the pending-publish input to be marked as failed. // We expect the pending-publish input to be marked as failed.
require.Equal(Failed, s.inputs[inputPendingPublish.OutPoint()].state) require.Equal(Fatal, s.inputs[inputPendingPublish.OutPoint()].state)
// We expect the published input to be marked as failed. // We expect the published input to be marked as fatal.
require.Equal(Failed, s.inputs[inputPublished.OutPoint()].state) require.Equal(Fatal, s.inputs[inputPublished.OutPoint()].state)
// We expect the publish failed input to be markd as failed. // We expect the publish failed input to be markd as failed.
require.Equal(Failed, s.inputs[inputPublishFailed.OutPoint()].state) require.Equal(Fatal, s.inputs[inputPublishFailed.OutPoint()].state)
// We expect the swept input to stay unchanged. // We expect the swept input to stay unchanged.
require.Equal(Swept, s.inputs[inputSwept.OutPoint()].state) require.Equal(Swept, s.inputs[inputSwept.OutPoint()].state)
@@ -1145,7 +1145,7 @@ func TestMarkInputsFailed(t *testing.T) {
require.Equal(Excluded, s.inputs[inputExcluded.OutPoint()].state) require.Equal(Excluded, s.inputs[inputExcluded.OutPoint()].state)
// We expect the failed input to stay unchanged. // We expect the failed input to stay unchanged.
require.Equal(Failed, s.inputs[inputFailed.OutPoint()].state) require.Equal(Fatal, s.inputs[inputFatal.OutPoint()].state)
} }
// TestHandleBumpEventTxFatal checks that `handleBumpEventTxFatal` correctly // TestHandleBumpEventTxFatal checks that `handleBumpEventTxFatal` correctly