diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 88404e52a..8f74a6da9 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -119,9 +119,12 @@ const ( // sweeping transactions confirmed, the remaining two will be excluded. Excluded - // Failed is the state when a pending input has too many failed publish - // atttempts or unknown broadcast error is returned. - Failed + // Fatal is the final state of a pending input. Inputs ending in this + // state won't be retried. This could happen, + // - 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. @@ -145,8 +148,8 @@ func (s SweepState) String() string { case Excluded: return "Excluded" - case Failed: - return "Failed" + case Fatal: + return "Fatal" default: return "Unknown" @@ -215,7 +218,7 @@ func (p *SweeperInput) terminated() bool { // If the input has reached a final state, that it's either // been swept, or failed, or excluded, we will remove it from // our sweeper. - case Failed, Swept, Excluded: + case Fatal, Swept, Excluded: return true default: @@ -1264,7 +1267,7 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error { ) if err != nil { err := fmt.Errorf("wait for spend: %w", err) - s.markInputFailed(pi, err) + s.markInputFatal(pi, 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. -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) - pi.state = Failed + pi.state = Fatal s.signalResult(pi, Result{Err: err}) } @@ -1784,15 +1787,15 @@ func (s *UtxoSweeper) handleBumpEventTxFatal(resp *bumpResp) error { } } - // Mark the inputs as failed. - s.markInputsFailed(resp.set, r.Err) + // Mark the inputs as fatal. + s.markInputsFatal(resp.set, r.Err) 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. -func (s *UtxoSweeper) markInputsFailed(set InputSet, err error) { +func (s *UtxoSweeper) markInputsFatal(set InputSet, err error) { for _, inp := range set.Inputs() { outpoint := inp.OutPoint() @@ -1816,7 +1819,7 @@ func (s *UtxoSweeper) markInputsFailed(set InputSet, err error) { continue } - s.markInputFailed(input, err) + s.markInputFatal(input, err) } } diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 16a4a46fb..40b25425d 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -215,7 +215,7 @@ func TestMarkInputsPublishFailed(t *testing.T) { // published. // - inputSwept specifies an input that's swept. // - inputExcluded specifies an input that's excluded. - // - inputFailed specifies an input that's failed. + // - inputFatal specifies an input that's fatal. var ( inputInit = createMockInput(t, s, Init) inputPendingPublish = createMockInput(t, s, PendingPublish) @@ -223,13 +223,13 @@ func TestMarkInputsPublishFailed(t *testing.T) { inputPublishFailed = createMockInput(t, s, PublishFailed) inputSwept = createMockInput(t, s, Swept) inputExcluded = createMockInput(t, s, Excluded) - inputFailed = createMockInput(t, s, Failed) + inputFatal = createMockInput(t, s, Fatal) ) // Gather all inputs. set.On("Inputs").Return([]input.Input{ inputInit, inputPendingPublish, inputPublished, - inputPublishFailed, inputSwept, inputExcluded, inputFailed, + inputPublishFailed, inputSwept, inputExcluded, inputFatal, }) // 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) // 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. mockStore.AssertExpectations(t) @@ -437,7 +437,7 @@ func TestUpdateSweeperInputs(t *testing.T) { // These inputs won't hit RequiredLockTime so we won't mock. input4 := &SweeperInput{state: Swept, 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 // returned. @@ -575,7 +575,7 @@ func TestDecideStateAndRBFInfo(t *testing.T) { 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) { t.Parallel() @@ -596,10 +596,10 @@ func TestMarkInputFailed(t *testing.T) { } // Call the method under test. - s.markInputFailed(pi, errors.New("dummy error")) + s.markInputFatal(pi, errors.New("dummy error")) // Assert the state is updated. - require.Equal(t, Failed, pi.state) + require.Equal(t, Fatal, pi.state) } // TestSweepPendingInputs checks that `sweepPendingInputs` correctly executes @@ -1102,7 +1102,7 @@ func TestMarkInputsFailed(t *testing.T) { // published. // - inputSwept specifies an input that's swept. // - inputExcluded specifies an input that's excluded. - // - inputFailed specifies an input that's failed. + // - inputFatal specifies an input that's fatal. var ( inputInit = createMockInput(t, s, Init) inputPendingPublish = createMockInput(t, s, PendingPublish) @@ -1110,33 +1110,33 @@ func TestMarkInputsFailed(t *testing.T) { inputPublishFailed = createMockInput(t, s, PublishFailed) inputSwept = createMockInput(t, s, Swept) inputExcluded = createMockInput(t, s, Excluded) - inputFailed = createMockInput(t, s, Failed) + inputFatal = createMockInput(t, s, Fatal) ) // Gather all inputs. set.On("Inputs").Return([]input.Input{ inputInit, inputPendingPublish, inputPublished, - inputPublishFailed, inputSwept, inputExcluded, inputFailed, + inputPublishFailed, inputSwept, inputExcluded, inputFatal, }) // Mark the test inputs. We expect the non-exist input and - // inputSwept/inputExcluded/inputFailed to be skipped. - s.markInputsFailed(set, errDummy) + // inputSwept/inputExcluded/inputFatal to be skipped. + s.markInputsFatal(set, errDummy) // We expect unchanged number of pending inputs. require.Len(s.inputs, 7) - // We expect the init input's to be marked as failed. - require.Equal(Failed, s.inputs[inputInit.OutPoint()].state) + // We expect the init input's to be marked as fatal. + require.Equal(Fatal, s.inputs[inputInit.OutPoint()].state) // 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. - require.Equal(Failed, s.inputs[inputPublished.OutPoint()].state) + // We expect the published input to be marked as fatal. + require.Equal(Fatal, s.inputs[inputPublished.OutPoint()].state) // 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. 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) // 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