mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
sweep: add new AuxSweeper interface
In this commit, we add a new AuxSweeper interface. This'll take a set of inputs, and a change addr for the sweep transaction, then optionally return a new sweep output to be added to the sweep transaction. We also add a new NotifyBroadcast method. This'll be used to notify that we're _about_ to broadcast a sweeping transaction. The set of inputs is passed in, which allows the caller to prepare for the ultimate broadcast of the sweeping transaction. We also add ExtraTxOut to BumpRequest pass fees to NotifyBroadcast. This allows the callee to know the total fee of the sweeping transaction.
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcwallet/chain"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
@@ -21,12 +22,14 @@ import (
|
||||
|
||||
var (
|
||||
// Create a taproot change script.
|
||||
changePkScript = []byte{
|
||||
0x51, 0x20,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
changePkScript = lnwallet.AddrWithKey{
|
||||
DeliveryAddress: []byte{
|
||||
0x51, 0x20,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
},
|
||||
}
|
||||
|
||||
testInputCount atomic.Uint64
|
||||
@@ -117,7 +120,9 @@ func TestCalcSweepTxWeight(t *testing.T) {
|
||||
require.Zero(t, weight)
|
||||
|
||||
// Use a correct change script to test the success case.
|
||||
weight, err = calcSweepTxWeight([]input.Input{&inp}, changePkScript)
|
||||
weight, err = calcSweepTxWeight(
|
||||
[]input.Input{&inp}, changePkScript.DeliveryAddress,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// BaseTxSize 8 bytes
|
||||
@@ -137,7 +142,9 @@ func TestBumpRequestMaxFeeRateAllowed(t *testing.T) {
|
||||
inp := createTestInput(100, input.WitnessKeyHash)
|
||||
|
||||
// The weight is 487.
|
||||
weight, err := calcSweepTxWeight([]input.Input{&inp}, changePkScript)
|
||||
weight, err := calcSweepTxWeight(
|
||||
[]input.Input{&inp}, changePkScript.DeliveryAddress,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Define a test budget and calculates its fee rate.
|
||||
@@ -154,7 +161,9 @@ func TestBumpRequestMaxFeeRateAllowed(t *testing.T) {
|
||||
// Use a wrong change script to test the error case.
|
||||
name: "error calc weight",
|
||||
req: &BumpRequest{
|
||||
DeliveryAddress: []byte{1},
|
||||
DeliveryAddress: lnwallet.AddrWithKey{
|
||||
DeliveryAddress: []byte{1},
|
||||
},
|
||||
},
|
||||
expectedMaxFeeRate: 0,
|
||||
expectedErr: true,
|
||||
@@ -239,7 +248,8 @@ func TestInitializeFeeFunction(t *testing.T) {
|
||||
|
||||
// Create a publisher using the mocks.
|
||||
tp := NewTxPublisher(TxPublisherConfig{
|
||||
Estimator: estimator,
|
||||
Estimator: estimator,
|
||||
AuxSweeper: fn.Some[AuxSweeper](&MockAuxSweeper{}),
|
||||
})
|
||||
|
||||
// Create a test feerate.
|
||||
@@ -304,7 +314,9 @@ func TestStoreRecord(t *testing.T) {
|
||||
tx := &wire.MsgTx{}
|
||||
|
||||
// Create a publisher using the mocks.
|
||||
tp := NewTxPublisher(TxPublisherConfig{})
|
||||
tp := NewTxPublisher(TxPublisherConfig{
|
||||
AuxSweeper: fn.Some[AuxSweeper](&MockAuxSweeper{}),
|
||||
})
|
||||
|
||||
// Get the current counter and check it's increased later.
|
||||
initialCounter := tp.requestCounter.Load()
|
||||
@@ -369,10 +381,11 @@ func createTestPublisher(t *testing.T) (*TxPublisher, *mockers) {
|
||||
|
||||
// Create a publisher using the mocks.
|
||||
tp := NewTxPublisher(TxPublisherConfig{
|
||||
Estimator: m.estimator,
|
||||
Signer: m.signer,
|
||||
Wallet: m.wallet,
|
||||
Notifier: m.notifier,
|
||||
Estimator: m.estimator,
|
||||
Signer: m.signer,
|
||||
Wallet: m.wallet,
|
||||
Notifier: m.notifier,
|
||||
AuxSweeper: fn.Some[AuxSweeper](&MockAuxSweeper{}),
|
||||
})
|
||||
|
||||
return tp, m
|
||||
@@ -451,7 +464,7 @@ func TestCreateAndCheckTx(t *testing.T) {
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// Call the method under test.
|
||||
_, _, err := tp.createAndCheckTx(tc.req, m.feeFunc)
|
||||
_, err := tp.createAndCheckTx(tc.req, m.feeFunc)
|
||||
|
||||
// Check the result is as expected.
|
||||
require.ErrorIs(t, err, tc.expectedErr)
|
||||
|
Reference in New Issue
Block a user