lnwallet+sweep: introduce TxPublisher to handle fee bump

This commit adds `TxPublisher` which implements `Bumper` interface. This
is part one of the implementation that focuses on implementing the
`Broadcast` method which guarantees a tx can be published with
RBF-compliant. It does so by leveraging the `testmempoolaccept` API,
keep increasing the fee rate until an RBF-compliant tx is made and
broadcasts it.

This tx will then be monitored by the `TxPublisher` and in the following
commit, the monitoring process will be added.
This commit is contained in:
yyforyongyu
2024-02-29 13:18:59 +08:00
parent ecd471ac75
commit 11f7e455d1
6 changed files with 1548 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package chainntnfs
import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn"
"github.com/stretchr/testify/mock"
@@ -50,3 +51,73 @@ func (m *MockMempoolWatcher) LookupInputMempoolSpend(
return args.Get(0).(fn.Option[wire.MsgTx])
}
// MockNotifier is a mock implementation of the ChainNotifier interface.
type MockChainNotifier struct {
mock.Mock
}
// Compile-time check to ensure MockChainNotifier implements ChainNotifier.
var _ ChainNotifier = (*MockChainNotifier)(nil)
// RegisterConfirmationsNtfn registers an intent to be notified once txid
// reaches numConfs confirmations.
func (m *MockChainNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
pkScript []byte, numConfs, heightHint uint32,
opts ...NotifierOption) (*ConfirmationEvent, error) {
args := m.Called(txid, pkScript, numConfs, heightHint)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*ConfirmationEvent), args.Error(1)
}
// RegisterSpendNtfn registers an intent to be notified once the target
// outpoint is successfully spent within a transaction.
func (m *MockChainNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
pkScript []byte, heightHint uint32) (*SpendEvent, error) {
args := m.Called(outpoint, pkScript, heightHint)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*SpendEvent), args.Error(1)
}
// RegisterBlockEpochNtfn registers an intent to be notified of each new block
// connected to the tip of the main chain.
func (m *MockChainNotifier) RegisterBlockEpochNtfn(epoch *BlockEpoch) (
*BlockEpochEvent, error) {
args := m.Called(epoch)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*BlockEpochEvent), args.Error(1)
}
// Start the ChainNotifier. Once started, the implementation should be ready,
// and able to receive notification registrations from clients.
func (m *MockChainNotifier) Start() error {
args := m.Called()
return args.Error(0)
}
// Started returns true if this instance has been started, and false otherwise.
func (m *MockChainNotifier) Started() bool {
args := m.Called()
return args.Bool(0)
}
// Stops the concrete ChainNotifier.
func (m *MockChainNotifier) Stop() error {
args := m.Called()
return args.Error(0)
}