sweep: remove conflicted sweep txns from the rebroadcaster

In this commit, we an existing gap in our rebroadcast handling logic. As
is, if we're trying to sweep a transaction and a conflicting transaction
is mined (timeout lands on chain, anchor swept), then we'll continue to
try to rebroadcast the tx in the background.

To resolve this, we give the sweeper a new closure function that it can
use to mark conflicted transactions as no longer requiring rebroadcast.
This commit is contained in:
Olaoluwa Osuntokun committed 2023-04-21 11:53:08 -07:00
1 parent d908becf73
commit 3d2daeefd8
7 files changed
+49 -2

No files matched your search

+3
View File
@@ -159,3 +159,6 @@ func (b *mockBackend) RemoveDescendants(*wire.MsgTx) error {
func (b *mockBackend) FetchTx(chainhash.Hash) (*wire.MsgTx, error) {
return nil, nil
}
func (b *mockBackend) CancelRebroadcast(tx chainhash.Hash) {
}
+6
View File
@@ -35,4 +35,10 @@ type Wallet interface {
// hash passed in. If the transaction can't be found then a nil
// transaction pointer is returned.
FetchTx(chainhash.Hash) (*wire.MsgTx, error)
// CancelRebroadcast is used to inform the rebroadcaster sub-system
// that it no longer needs to try to rebroadcast a transaction. This is
// used to ensure that invalid transactions (inputs spent) aren't
// retried in the background.
CancelRebroadcast(tx chainhash.Hash)
}
+7
View File
@@ -555,6 +555,9 @@ func (s *UtxoSweeper) removeLastSweepDescendants(spendingTx *wire.MsgTx) error {
// Transaction wasn't found in the wallet, may have already
// been replaced/removed.
if sweepTx == nil {
// If it was removed, then we'll play it safe and mark
// it as no longer need to be rebroadcasted.
s.cfg.Wallet.CancelRebroadcast(sweepHash)
continue
}
@@ -579,6 +582,10 @@ func (s *UtxoSweeper) removeLastSweepDescendants(spendingTx *wire.MsgTx) error {
if err != nil {
log.Warnf("unable to remove descendants: %v", err)
}
// If this transaction was conflicting, then we'll stop
// rebroadcasting it in the background.
s.cfg.Wallet.CancelRebroadcast(sweepHash)
}
}