mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
sweep: cancel rebroadcasting of failed/replaced/confirmed txns
This commit is contained in:
parent
106b97ce33
commit
fce86f9b22
2 changed files with 34 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
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,
|
||||
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,
|
||||
|
|
Loading…
Add table
Reference in a new issue