sweep: cancel rebroadcasting of failed/replaced/confirmed txns

This commit is contained in:
yyforyongyu 2024-03-21 20:34:43 +08:00
parent 106b97ce33
commit fce86f9b22
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
2 changed files with 34 additions and 2 deletions

View File

@ -1622,6 +1622,9 @@ func (s *UtxoSweeper) monitorFeeBumpResult(resultChan <-chan *BumpResult) {
"fee bump monitor", r.Event, "fee bump monitor", r.Event,
r.Tx.TxHash()) r.Tx.TxHash())
// Cancel the rebroadcasting of the failed tx.
s.cfg.Wallet.CancelRebroadcast(r.Tx.TxHash())
return return
} }
@ -1673,6 +1676,9 @@ func (s *UtxoSweeper) handleBumpEventTxReplaced(r *BumpResult) error {
return err return err
} }
// Cancel the rebroadcasting of the replaced tx.
s.cfg.Wallet.CancelRebroadcast(oldTxid)
log.Infof("RBFed tx=%v(fee=%v sats, feerate=%v sats/kw) with new "+ log.Infof("RBFed tx=%v(fee=%v sats, feerate=%v sats/kw) with new "+
"tx=%v(fee=%v, "+"feerate=%v)", record.Txid, record.Fee, "tx=%v(fee=%v, "+"feerate=%v)", record.Txid, record.Fee,
record.FeeRate, tr.Txid, tr.Fee, tr.FeeRate) record.FeeRate, tr.Txid, tr.Fee, tr.FeeRate)

View File

@ -2802,9 +2802,14 @@ func TestHandleBumpEventTxReplaced(t *testing.T) {
store := &MockSweeperStore{} store := &MockSweeperStore{}
defer store.AssertExpectations(t) defer store.AssertExpectations(t)
// Create a mock wallet.
wallet := &MockWallet{}
defer wallet.AssertExpectations(t)
// Create a test sweeper. // Create a test sweeper.
s := New(&UtxoSweeperConfig{ s := New(&UtxoSweeperConfig{
Store: store, Store: store,
Wallet: wallet,
}) })
// Create a testing outpoint. // Create a testing outpoint.
@ -2855,6 +2860,9 @@ func TestHandleBumpEventTxReplaced(t *testing.T) {
Txid: tx.TxHash(), Txid: tx.TxHash(),
}, nil).Once() }, nil).Once()
// We expect to cancel rebroadcasting the replaced tx.
wallet.On("CancelRebroadcast", tx.TxHash()).Once()
// Mock an error returned when deleting the old tx record. // Mock an error returned when deleting the old tx record.
store.On("DeleteTx", tx.TxHash()).Return(dummyErr).Once() store.On("DeleteTx", tx.TxHash()).Return(dummyErr).Once()
@ -2875,6 +2883,9 @@ func TestHandleBumpEventTxReplaced(t *testing.T) {
Published: true, Published: true,
}).Return(nil).Once() }).Return(nil).Once()
// We expect to cancel rebroadcasting the replaced tx.
wallet.On("CancelRebroadcast", tx.TxHash()).Once()
// Call the method under test. // Call the method under test.
err = s.handleBumpEventTxReplaced(br) err = s.handleBumpEventTxReplaced(br)
require.NoError(t, err) require.NoError(t, err)
@ -2944,9 +2955,14 @@ func TestMonitorFeeBumpResult(t *testing.T) {
store := &MockSweeperStore{} store := &MockSweeperStore{}
defer store.AssertExpectations(t) defer store.AssertExpectations(t)
// Create a mock wallet.
wallet := &MockWallet{}
defer wallet.AssertExpectations(t)
// Create a test sweeper. // Create a test sweeper.
s := New(&UtxoSweeperConfig{ s := New(&UtxoSweeperConfig{
Store: store, Store: store,
Wallet: wallet,
}) })
// Create a testing outpoint. // Create a testing outpoint.
@ -2990,6 +3006,11 @@ func TestMonitorFeeBumpResult(t *testing.T) {
FeeRate: 100, FeeRate: 100,
} }
// We expect to cancel rebroadcasting the tx
// once confirmed.
wallet.On("CancelRebroadcast",
tx.TxHash()).Once()
return resultChan return resultChan
}, },
shouldExit: true, shouldExit: true,
@ -3009,6 +3030,11 @@ func TestMonitorFeeBumpResult(t *testing.T) {
Err: errDummy, Err: errDummy,
} }
// We expect to cancel rebroadcasting the tx
// once failed.
wallet.On("CancelRebroadcast",
tx.TxHash()).Once()
return resultChan return resultChan
}, },
shouldExit: true, shouldExit: true,