Skip to content

Commit 61cec43

Browse files
committed
sweep: add a new event TxUnknownSpend
1 parent 8c9ba32 commit 61cec43

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

sweep/fee_bumper.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ const (
9595
// TxConfirmed is sent when the tx is confirmed.
9696
TxConfirmed
9797

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+
98109
// TxFatal is sent when the inputs in this tx cannot be retried. Txns
99110
// will end up in this state if they have encountered a non-fee related
100111
// error, which means they cannot be retried with increased budget.
@@ -115,6 +126,8 @@ func (e BumpEvent) String() string {
115126
return "Replaced"
116127
case TxConfirmed:
117128
return "Confirmed"
129+
case TxUnknownSpend:
130+
return "UnknownSpend"
118131
case TxFatal:
119132
return "Fatal"
120133
default:
@@ -280,7 +293,8 @@ func (b *BumpResult) String() string {
280293

281294
// Validate validates the BumpResult so it's safe to use.
282295
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
284298

285299
// Every result must have a tx except the fatal or failed case.
286300
if b.Tx == nil && !isFailureEvent {
@@ -754,6 +768,11 @@ func (t *TxPublisher) removeResult(result *BumpResult) {
754768
log.Debugf("Removing monitor record=%v due to fatal err: %v",
755769
id, result.Err)
756770

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+
757776
// Do nothing if it's neither failed or confirmed.
758777
default:
759778
log.Tracef("Skipping record removal for id=%v, event=%v", id,
@@ -1120,12 +1139,8 @@ func (t *TxPublisher) handleThirdPartySpent(r *monitorRecord) {
11201139

11211140
// Create a result that will be sent to the resultChan which is
11221141
// 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.
11271142
result := &BumpResult{
1128-
Event: TxFailed,
1143+
Event: TxUnknownSpend,
11291144
Tx: r.tx,
11301145
requestID: r.requestID,
11311146
Err: ErrThirdPartySpent,

0 commit comments

Comments
 (0)