diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 24ed52782..1a7a8b94f 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -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) diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 3921cf7d0..51f21ce98 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -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,