Skip to content

Commit cb67094

Browse files
committedFeb 7, 2025
sweep: rename methods for clarity
We now rename "third party" to "unknown" as the inputs can be spent via an older sweeping tx, a third party (anchor), or a remote party (pin). In fee bumper we don't have the info to distinguish the above cases, and leave them to be further handled by the sweeper as it has more context.
1 parent bce9814 commit cb67094

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed
 

‎sweep/fee_bumper.go

+19-22
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ var (
4040
// preparation, usually due to the output being dust.
4141
ErrTxNoOutput = errors.New("tx has no output")
4242

43-
// ErrThirdPartySpent is returned when a third party has spent the
44-
// input in the sweeping tx.
45-
ErrThirdPartySpent = errors.New("third party spent the output")
43+
// ErrUnknownSpent is returned when an unknown tx has spent an input in
44+
// the sweeping tx.
45+
ErrUnknownSpent = errors.New("unknown spend of input")
4646
)
4747

4848
var (
@@ -81,10 +81,6 @@ const (
8181
// bumper. In either case the inputs in this tx should be retried with
8282
// either a different grouping strategy or an increased budget.
8383
//
84-
// NOTE: We also send this event when there's a third party spend
85-
// event, and the sweeper will handle cleaning this up once it's
86-
// confirmed.
87-
//
8884
// TODO(yy): Remove the above usage once we remove sweeping non-CPFP
8985
// anchors.
9086
TxFailed
@@ -929,7 +925,7 @@ func (t *TxPublisher) processRecords() {
929925

930926
// Check whether the inputs has been spent by a unknown
931927
// tx.
932-
if t.isThirdPartySpent(r, spends) {
928+
if t.isUnknownSpent(r, spends) {
933929
failedRecords[requestID] = r
934930

935931
// Move to the next record.
@@ -989,7 +985,7 @@ func (t *TxPublisher) processRecords() {
989985
// result.
990986
for _, r := range failedRecords {
991987
t.wg.Add(1)
992-
go t.handleThirdPartySpent(r)
988+
go t.handleUnknownSpent(r)
993989
}
994990
}
995991

@@ -1151,12 +1147,12 @@ func (t *TxPublisher) handleFeeBumpTx(r *monitorRecord, currentHeight int32) {
11511147
})
11521148
}
11531149

1154-
// handleThirdPartySpent is called when the inputs in an unconfirmed tx is
1155-
// spent. It will notify the subscriber then remove the record from the maps
1156-
// and send a TxFailed event to the subscriber.
1150+
// handleUnknownSpent is called when the inputs are spent by a unknown tx. It
1151+
// will notify the subscriber then remove the record from the maps and send a
1152+
// TxUnknownSpend event to the subscriber.
11571153
//
11581154
// NOTE: Must be run as a goroutine to avoid blocking on sending the result.
1159-
func (t *TxPublisher) handleThirdPartySpent(r *monitorRecord) {
1155+
func (t *TxPublisher) handleUnknownSpent(r *monitorRecord) {
11601156
defer t.wg.Done()
11611157

11621158
log.Debugf("Record %v has inputs spent by a tx unknown to the fee "+
@@ -1169,7 +1165,7 @@ func (t *TxPublisher) handleThirdPartySpent(r *monitorRecord) {
11691165
Event: TxUnknownSpend,
11701166
Tx: r.tx,
11711167
requestID: r.requestID,
1172-
Err: ErrThirdPartySpent,
1168+
Err: ErrUnknownSpent,
11731169
}
11741170

11751171
// Notify that this tx is confirmed and remove the record from the map.
@@ -1277,10 +1273,11 @@ func (t *TxPublisher) createAndPublishTx(
12771273
return fn.Some(*result)
12781274
}
12791275

1280-
// isThirdPartySpent checks whether the inputs of the tx has already been spent
1281-
// by a third party. When a tx is not confirmed, yet its inputs has been spent,
1282-
// then it must be spent by a different tx other than the sweeping tx here.
1283-
func (t *TxPublisher) isThirdPartySpent(r *monitorRecord,
1276+
// isUnknownSpent checks whether the inputs of the tx has already been spent by
1277+
// a tx not known to us. When a tx is not confirmed, yet its inputs has been
1278+
// spent, then it must be spent by a different tx other than the sweeping tx
1279+
// here.
1280+
func (t *TxPublisher) isUnknownSpent(r *monitorRecord,
12841281
spends map[wire.OutPoint]*wire.MsgTx) bool {
12851282

12861283
txid := r.tx.TxHash()
@@ -1290,14 +1287,14 @@ func (t *TxPublisher) isThirdPartySpent(r *monitorRecord,
12901287
for op, spendingTx := range spends {
12911288
spendingTxID := spendingTx.TxHash()
12921289

1293-
// If the spending tx is the same as the sweeping tx
1294-
// then we are good.
1290+
// If the spending tx is the same as the sweeping tx then we are
1291+
// good.
12951292
if spendingTxID == txid {
12961293
continue
12971294
}
12981295

1299-
log.Warnf("Detected third party spent of output=%v "+
1300-
"in tx=%v", op, spendingTx.TxHash())
1296+
log.Warnf("Detected unknown spend of input=%v in tx=%v", op,
1297+
spendingTx.TxHash())
13011298

13021299
return true
13031300
}

‎sweep/fee_bumper_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ func TestProcessRecordsInitialSpent(t *testing.T) {
15971597
require.Nil(t, result.ReplacedTx)
15981598

15991599
// The error should be set.
1600-
require.ErrorIs(t, result.Err, ErrThirdPartySpent)
1600+
require.ErrorIs(t, result.Err, ErrUnknownSpent)
16011601
require.Equal(t, requestID, result.requestID)
16021602
}
16031603
}
@@ -1786,7 +1786,7 @@ func TestProcessRecordsSpent(t *testing.T) {
17861786
require.Equal(t, tx, result.Tx)
17871787

17881788
// No error should be set.
1789-
require.ErrorIs(t, result.Err, ErrThirdPartySpent)
1789+
require.ErrorIs(t, result.Err, ErrUnknownSpent)
17901790
require.Equal(t, requestID, result.requestID)
17911791
}
17921792
}

0 commit comments

Comments
 (0)