@@ -95,6 +95,17 @@ const (
95
95
// TxConfirmed is sent when the tx is confirmed.
96
96
TxConfirmed
97
97
98
+ // TxUnknownSpend is sent when at least one of the inputs is spent but
99
+ // not by the current sweeping tx, this can happen when,
100
+ // - a remote party has replaced our sweeping tx by spending the
101
+ // input(s), e.g., via the direct preimage spend on our outgoing HTLC.
102
+ // - a third party has replaced our sweeping tx, e.g., the anchor output
103
+ // after 16 blocks.
104
+ // - A previous sweeping tx has confirmed but the fee bumper is not
105
+ // aware of it, e.g., a restart happens right after the sweeping tx is
106
+ // broadcast and confirmed.
107
+ TxUnknownSpend
108
+
98
109
// TxFatal is sent when the inputs in this tx cannot be retried. Txns
99
110
// will end up in this state if they have encountered a non-fee related
100
111
// error, which means they cannot be retried with increased budget.
@@ -115,6 +126,8 @@ func (e BumpEvent) String() string {
115
126
return "Replaced"
116
127
case TxConfirmed :
117
128
return "Confirmed"
129
+ case TxUnknownSpend :
130
+ return "UnknownSpend"
118
131
case TxFatal :
119
132
return "Fatal"
120
133
default :
@@ -280,7 +293,8 @@ func (b *BumpResult) String() string {
280
293
281
294
// Validate validates the BumpResult so it's safe to use.
282
295
func (b * BumpResult ) Validate () error {
283
- isFailureEvent := b .Event == TxFailed || b .Event == TxFatal
296
+ isFailureEvent := b .Event == TxFailed || b .Event == TxFatal ||
297
+ b .Event == TxUnknownSpend
284
298
285
299
// Every result must have a tx except the fatal or failed case.
286
300
if b .Tx == nil && ! isFailureEvent {
@@ -754,6 +768,11 @@ func (t *TxPublisher) removeResult(result *BumpResult) {
754
768
log .Debugf ("Removing monitor record=%v due to fatal err: %v" ,
755
769
id , result .Err )
756
770
771
+ case TxUnknownSpend :
772
+ // Remove the record if there's an unknown spend.
773
+ log .Debugf ("Removing monitor record=%v due unknown spent: " +
774
+ "%v" , id , result .Err )
775
+
757
776
// Do nothing if it's neither failed or confirmed.
758
777
default :
759
778
log .Tracef ("Skipping record removal for id=%v, event=%v" , id ,
@@ -1120,12 +1139,8 @@ func (t *TxPublisher) handleThirdPartySpent(r *monitorRecord) {
1120
1139
1121
1140
// Create a result that will be sent to the resultChan which is
1122
1141
// listened by the caller.
1123
- //
1124
- // TODO(yy): create a new state `TxThirdPartySpent` to notify the
1125
- // sweeper to remove the input, hence moving the monitoring of inputs
1126
- // spent inside the fee bumper.
1127
1142
result := & BumpResult {
1128
- Event : TxFailed ,
1143
+ Event : TxUnknownSpend ,
1129
1144
Tx : r .tx ,
1130
1145
requestID : r .requestID ,
1131
1146
Err : ErrThirdPartySpent ,
0 commit comments