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,
r.Tx.TxHash())
// Cancel the rebroadcasting of the failed tx.
s.cfg.Wallet.CancelRebroadcast(r.Tx.TxHash())
return
}
@ -1673,6 +1676,9 @@ func (s *UtxoSweeper) handleBumpEventTxReplaced(r *BumpResult) error {
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 "+
"tx=%v(fee=%v, "+"feerate=%v)", record.Txid, record.Fee,
record.FeeRate, tr.Txid, tr.Fee, tr.FeeRate)

View file

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