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.
This commit is contained in:
2 files changed
+21
-24
No files matched your search
+19
-22
@@ -40,9 +40,9 @@ var (
|
|||||||
// preparation, usually due to the output being dust.
|
// preparation, usually due to the output being dust.
|
||||||
ErrTxNoOutput = errors.New("tx has no output")
|
ErrTxNoOutput = errors.New("tx has no output")
|
||||||
|
|
||||||
// ErrThirdPartySpent is returned when a third party has spent the
|
// ErrUnknownSpent is returned when an unknown tx has spent an input in
|
||||||
// input in the sweeping tx.
|
// the sweeping tx.
|
||||||
ErrThirdPartySpent = errors.New("third party spent the output")
|
ErrUnknownSpent = errors.New("unknown spend of input")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -81,10 +81,6 @@ const (
|
|||||||
// bumper. In either case the inputs in this tx should be retried with
|
// bumper. In either case the inputs in this tx should be retried with
|
||||||
// either a different grouping strategy or an increased budget.
|
// either a different grouping strategy or an increased budget.
|
||||||
//
|
//
|
||||||
// NOTE: We also send this event when there's a third party spend
|
|
||||||
// event, and the sweeper will handle cleaning this up once it's
|
|
||||||
// confirmed.
|
|
||||||
//
|
|
||||||
// TODO(yy): Remove the above usage once we remove sweeping non-CPFP
|
// TODO(yy): Remove the above usage once we remove sweeping non-CPFP
|
||||||
// anchors.
|
// anchors.
|
||||||
TxFailed
|
TxFailed
|
||||||
@@ -929,7 +925,7 @@ func (t *TxPublisher) processRecords() {
|
|||||||
|
|
||||||
// Check whether the inputs has been spent by a unknown
|
// Check whether the inputs has been spent by a unknown
|
||||||
// tx.
|
// tx.
|
||||||
if t.isThirdPartySpent(r, spends) {
|
if t.isUnknownSpent(r, spends) {
|
||||||
failedRecords[requestID] = r
|
failedRecords[requestID] = r
|
||||||
|
|
||||||
// Move to the next record.
|
// Move to the next record.
|
||||||
@@ -989,7 +985,7 @@ func (t *TxPublisher) processRecords() {
|
|||||||
// result.
|
// result.
|
||||||
for _, r := range failedRecords {
|
for _, r := range failedRecords {
|
||||||
t.wg.Add(1)
|
t.wg.Add(1)
|
||||||
go t.handleThirdPartySpent(r)
|
go t.handleUnknownSpent(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1151,12 +1147,12 @@ func (t *TxPublisher) handleFeeBumpTx(r *monitorRecord, currentHeight int32) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleThirdPartySpent is called when the inputs in an unconfirmed tx is
|
// handleUnknownSpent is called when the inputs are spent by a unknown tx. It
|
||||||
// spent. It will notify the subscriber then remove the record from the maps
|
// will notify the subscriber then remove the record from the maps and send a
|
||||||
// and send a TxFailed event to the subscriber.
|
// TxUnknownSpend event to the subscriber.
|
||||||
//
|
//
|
||||||
// NOTE: Must be run as a goroutine to avoid blocking on sending the result.
|
// NOTE: Must be run as a goroutine to avoid blocking on sending the result.
|
||||||
func (t *TxPublisher) handleThirdPartySpent(r *monitorRecord) {
|
func (t *TxPublisher) handleUnknownSpent(r *monitorRecord) {
|
||||||
defer t.wg.Done()
|
defer t.wg.Done()
|
||||||
|
|
||||||
log.Debugf("Record %v has inputs spent by a tx unknown to the fee "+
|
log.Debugf("Record %v has inputs spent by a tx unknown to the fee "+
|
||||||
@@ -1169,7 +1165,7 @@ func (t *TxPublisher) handleThirdPartySpent(r *monitorRecord) {
|
|||||||
Event: TxUnknownSpend,
|
Event: TxUnknownSpend,
|
||||||
Tx: r.tx,
|
Tx: r.tx,
|
||||||
requestID: r.requestID,
|
requestID: r.requestID,
|
||||||
Err: ErrThirdPartySpent,
|
Err: ErrUnknownSpent,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify that this tx is confirmed and remove the record from the map.
|
// Notify that this tx is confirmed and remove the record from the map.
|
||||||
@@ -1277,10 +1273,11 @@ func (t *TxPublisher) createAndPublishTx(
|
|||||||
return fn.Some(*result)
|
return fn.Some(*result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// isThirdPartySpent checks whether the inputs of the tx has already been spent
|
// isUnknownSpent checks whether the inputs of the tx has already been spent by
|
||||||
// by a third party. When a tx is not confirmed, yet its inputs has been spent,
|
// a tx not known to us. When a tx is not confirmed, yet its inputs has been
|
||||||
// then it must be spent by a different tx other than the sweeping tx here.
|
// spent, then it must be spent by a different tx other than the sweeping tx
|
||||||
func (t *TxPublisher) isThirdPartySpent(r *monitorRecord,
|
// here.
|
||||||
|
func (t *TxPublisher) isUnknownSpent(r *monitorRecord,
|
||||||
spends map[wire.OutPoint]*wire.MsgTx) bool {
|
spends map[wire.OutPoint]*wire.MsgTx) bool {
|
||||||
|
|
||||||
txid := r.tx.TxHash()
|
txid := r.tx.TxHash()
|
||||||
@@ -1290,14 +1287,14 @@ func (t *TxPublisher) isThirdPartySpent(r *monitorRecord,
|
|||||||
for op, spendingTx := range spends {
|
for op, spendingTx := range spends {
|
||||||
spendingTxID := spendingTx.TxHash()
|
spendingTxID := spendingTx.TxHash()
|
||||||
|
|
||||||
// If the spending tx is the same as the sweeping tx
|
// If the spending tx is the same as the sweeping tx then we are
|
||||||
// then we are good.
|
// good.
|
||||||
if spendingTxID == txid {
|
if spendingTxID == txid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warnf("Detected third party spent of output=%v "+
|
log.Warnf("Detected unknown spend of input=%v in tx=%v", op,
|
||||||
"in tx=%v", op, spendingTx.TxHash())
|
spendingTx.TxHash())
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1597,7 +1597,7 @@ func TestProcessRecordsInitialSpent(t *testing.T) {
|
|||||||
require.Nil(t, result.ReplacedTx)
|
require.Nil(t, result.ReplacedTx)
|
||||||
|
|
||||||
// The error should be set.
|
// The error should be set.
|
||||||
require.ErrorIs(t, result.Err, ErrThirdPartySpent)
|
require.ErrorIs(t, result.Err, ErrUnknownSpent)
|
||||||
require.Equal(t, requestID, result.requestID)
|
require.Equal(t, requestID, result.requestID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1786,7 +1786,7 @@ func TestProcessRecordsSpent(t *testing.T) {
|
|||||||
require.Equal(t, tx, result.Tx)
|
require.Equal(t, tx, result.Tx)
|
||||||
|
|
||||||
// No error should be set.
|
// No error should be set.
|
||||||
require.ErrorIs(t, result.Err, ErrThirdPartySpent)
|
require.ErrorIs(t, result.Err, ErrUnknownSpent)
|
||||||
require.Equal(t, requestID, result.requestID)
|
require.Equal(t, requestID, result.requestID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user