Skip to content

Commit c68b8e8

Browse files
committed
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.
1 parent 6bf895a commit c68b8e8

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

sweep/sweeper.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ const (
119119
// sweeping transactions confirmed, the remaining two will be excluded.
120120
Excluded
121121

122-
// Failed is the state when a pending input has too many failed publish
123-
// atttempts or unknown broadcast error is returned.
124-
Failed
122+
// Fatal is the final state of a pending input. Inputs ending in this
123+
// state won't be retried. This could happen,
124+
// - when a pending input has too many failed publish attempts;
125+
// - the input has been spent by another party;
126+
// - unknown broadcast error is returned.
127+
Fatal
125128
)
126129

127130
// String gives a human readable text for the sweep states.
@@ -145,8 +148,8 @@ func (s SweepState) String() string {
145148
case Excluded:
146149
return "Excluded"
147150

148-
case Failed:
149-
return "Failed"
151+
case Fatal:
152+
return "Fatal"
150153

151154
default:
152155
return "Unknown"
@@ -215,7 +218,7 @@ func (p *SweeperInput) terminated() bool {
215218
// If the input has reached a final state, that it's either
216219
// been swept, or failed, or excluded, we will remove it from
217220
// our sweeper.
218-
case Failed, Swept, Excluded:
221+
case Fatal, Swept, Excluded:
219222
return true
220223

221224
default:
@@ -1264,7 +1267,7 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
12641267
)
12651268
if err != nil {
12661269
err := fmt.Errorf("wait for spend: %w", err)
1267-
s.markInputFailed(pi, err)
1270+
s.markInputFatal(pi, err)
12681271

12691272
return err
12701273
}
@@ -1477,12 +1480,12 @@ func (s *UtxoSweeper) markInputsSwept(tx *wire.MsgTx, isOurTx bool) {
14771480
}
14781481
}
14791482

1480-
// markInputFailed marks the given input as failed and won't be retried. It
1483+
// markInputFatal marks the given input as fatal and won't be retried. It
14811484
// will also notify all the subscribers of this input.
1482-
func (s *UtxoSweeper) markInputFailed(pi *SweeperInput, err error) {
1485+
func (s *UtxoSweeper) markInputFatal(pi *SweeperInput, err error) {
14831486
log.Errorf("Failed to sweep input: %v, error: %v", pi, err)
14841487

1485-
pi.state = Failed
1488+
pi.state = Fatal
14861489

14871490
s.signalResult(pi, Result{Err: err})
14881491
}
@@ -1784,15 +1787,15 @@ func (s *UtxoSweeper) handleBumpEventTxFatal(resp *bumpResp) error {
17841787
}
17851788
}
17861789

1787-
// Mark the inputs as failed.
1788-
s.markInputsFailed(resp.set, r.Err)
1790+
// Mark the inputs as fatal.
1791+
s.markInputsFatal(resp.set, r.Err)
17891792

17901793
return nil
17911794
}
17921795

1793-
// markInputsFailed marks all inputs found in the tx as failed. It will also
1796+
// markInputsFatal marks all inputs in the input set as failed. It will also
17941797
// notify all the subscribers of these inputs.
1795-
func (s *UtxoSweeper) markInputsFailed(set InputSet, err error) {
1798+
func (s *UtxoSweeper) markInputsFatal(set InputSet, err error) {
17961799
for _, inp := range set.Inputs() {
17971800
outpoint := inp.OutPoint()
17981801

@@ -1816,7 +1819,7 @@ func (s *UtxoSweeper) markInputsFailed(set InputSet, err error) {
18161819
continue
18171820
}
18181821

1819-
s.markInputFailed(input, err)
1822+
s.markInputFatal(input, err)
18201823
}
18211824
}
18221825

sweep/sweeper_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,21 @@ func TestMarkInputsPublishFailed(t *testing.T) {
215215
// published.
216216
// - inputSwept specifies an input that's swept.
217217
// - inputExcluded specifies an input that's excluded.
218-
// - inputFailed specifies an input that's failed.
218+
// - inputFatal specifies an input that's fatal.
219219
var (
220220
inputInit = createMockInput(t, s, Init)
221221
inputPendingPublish = createMockInput(t, s, PendingPublish)
222222
inputPublished = createMockInput(t, s, Published)
223223
inputPublishFailed = createMockInput(t, s, PublishFailed)
224224
inputSwept = createMockInput(t, s, Swept)
225225
inputExcluded = createMockInput(t, s, Excluded)
226-
inputFailed = createMockInput(t, s, Failed)
226+
inputFatal = createMockInput(t, s, Fatal)
227227
)
228228

229229
// Gather all inputs.
230230
set.On("Inputs").Return([]input.Input{
231231
inputInit, inputPendingPublish, inputPublished,
232-
inputPublishFailed, inputSwept, inputExcluded, inputFailed,
232+
inputPublishFailed, inputSwept, inputExcluded, inputFatal,
233233
})
234234

235235
// Mark the test inputs. We expect the non-exist input and the
@@ -264,7 +264,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
264264
require.Equal(Excluded, s.inputs[inputExcluded.OutPoint()].state)
265265

266266
// We expect the failed input to stay unchanged.
267-
require.Equal(Failed, s.inputs[inputFailed.OutPoint()].state)
267+
require.Equal(Fatal, s.inputs[inputFatal.OutPoint()].state)
268268

269269
// Assert mocked statements are executed as expected.
270270
mockStore.AssertExpectations(t)
@@ -437,7 +437,7 @@ func TestUpdateSweeperInputs(t *testing.T) {
437437
// These inputs won't hit RequiredLockTime so we won't mock.
438438
input4 := &SweeperInput{state: Swept, Input: inp1}
439439
input5 := &SweeperInput{state: Excluded, Input: inp1}
440-
input6 := &SweeperInput{state: Failed, Input: inp1}
440+
input6 := &SweeperInput{state: Fatal, Input: inp1}
441441

442442
// Mock the input to have a locktime in the future so it will NOT be
443443
// returned.
@@ -575,7 +575,7 @@ func TestDecideStateAndRBFInfo(t *testing.T) {
575575
require.Equal(Published, state)
576576
}
577577

578-
// TestMarkInputFailed checks that the input is marked as failed as expected.
578+
// TestMarkInputFatal checks that the input is marked as expected.
579579
func TestMarkInputFailed(t *testing.T) {
580580
t.Parallel()
581581

@@ -596,10 +596,10 @@ func TestMarkInputFailed(t *testing.T) {
596596
}
597597

598598
// Call the method under test.
599-
s.markInputFailed(pi, errors.New("dummy error"))
599+
s.markInputFatal(pi, errors.New("dummy error"))
600600

601601
// Assert the state is updated.
602-
require.Equal(t, Failed, pi.state)
602+
require.Equal(t, Fatal, pi.state)
603603
}
604604

605605
// TestSweepPendingInputs checks that `sweepPendingInputs` correctly executes
@@ -1102,41 +1102,41 @@ func TestMarkInputsFailed(t *testing.T) {
11021102
// published.
11031103
// - inputSwept specifies an input that's swept.
11041104
// - inputExcluded specifies an input that's excluded.
1105-
// - inputFailed specifies an input that's failed.
1105+
// - inputFatal specifies an input that's fatal.
11061106
var (
11071107
inputInit = createMockInput(t, s, Init)
11081108
inputPendingPublish = createMockInput(t, s, PendingPublish)
11091109
inputPublished = createMockInput(t, s, Published)
11101110
inputPublishFailed = createMockInput(t, s, PublishFailed)
11111111
inputSwept = createMockInput(t, s, Swept)
11121112
inputExcluded = createMockInput(t, s, Excluded)
1113-
inputFailed = createMockInput(t, s, Failed)
1113+
inputFatal = createMockInput(t, s, Fatal)
11141114
)
11151115

11161116
// Gather all inputs.
11171117
set.On("Inputs").Return([]input.Input{
11181118
inputInit, inputPendingPublish, inputPublished,
1119-
inputPublishFailed, inputSwept, inputExcluded, inputFailed,
1119+
inputPublishFailed, inputSwept, inputExcluded, inputFatal,
11201120
})
11211121

11221122
// Mark the test inputs. We expect the non-exist input and
1123-
// inputSwept/inputExcluded/inputFailed to be skipped.
1124-
s.markInputsFailed(set, errDummy)
1123+
// inputSwept/inputExcluded/inputFatal to be skipped.
1124+
s.markInputsFatal(set, errDummy)
11251125

11261126
// We expect unchanged number of pending inputs.
11271127
require.Len(s.inputs, 7)
11281128

1129-
// We expect the init input's to be marked as failed.
1130-
require.Equal(Failed, s.inputs[inputInit.OutPoint()].state)
1129+
// We expect the init input's to be marked as fatal.
1130+
require.Equal(Fatal, s.inputs[inputInit.OutPoint()].state)
11311131

11321132
// We expect the pending-publish input to be marked as failed.
1133-
require.Equal(Failed, s.inputs[inputPendingPublish.OutPoint()].state)
1133+
require.Equal(Fatal, s.inputs[inputPendingPublish.OutPoint()].state)
11341134

1135-
// We expect the published input to be marked as failed.
1136-
require.Equal(Failed, s.inputs[inputPublished.OutPoint()].state)
1135+
// We expect the published input to be marked as fatal.
1136+
require.Equal(Fatal, s.inputs[inputPublished.OutPoint()].state)
11371137

11381138
// We expect the publish failed input to be markd as failed.
1139-
require.Equal(Failed, s.inputs[inputPublishFailed.OutPoint()].state)
1139+
require.Equal(Fatal, s.inputs[inputPublishFailed.OutPoint()].state)
11401140

11411141
// We expect the swept input to stay unchanged.
11421142
require.Equal(Swept, s.inputs[inputSwept.OutPoint()].state)
@@ -1145,7 +1145,7 @@ func TestMarkInputsFailed(t *testing.T) {
11451145
require.Equal(Excluded, s.inputs[inputExcluded.OutPoint()].state)
11461146

11471147
// We expect the failed input to stay unchanged.
1148-
require.Equal(Failed, s.inputs[inputFailed.OutPoint()].state)
1148+
require.Equal(Fatal, s.inputs[inputFatal.OutPoint()].state)
11491149
}
11501150

11511151
// TestHandleBumpEventTxFatal checks that `handleBumpEventTxFatal` correctly

0 commit comments

Comments
 (0)