mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-12 18:52:14 +01:00
funding: use p2tr by default for batch_open_channel
In LND v0.15.1, batch_open_channel used p2tr by default for change output. However, in a later version, a breaking change has been fixed in FundPSBT to make the change type configurable (default to p2wkh). As batch_open_channel uses FundPsbt, we need to put back p2tr as default for change output
This commit is contained in:
parent
239fda1894
commit
02be618935
3 changed files with 32 additions and 0 deletions
|
@ -320,6 +320,7 @@ func (b *Batcher) BatchFund(ctx context.Context,
|
||||||
// anyway.
|
// anyway.
|
||||||
firstReq := b.channels[0].fundingReq
|
firstReq := b.channels[0].fundingReq
|
||||||
feeRateSatPerKVByte := firstReq.FundingFeePerKw.FeePerKVByte()
|
feeRateSatPerKVByte := firstReq.FundingFeePerKw.FeePerKVByte()
|
||||||
|
changeType := walletrpc.ChangeAddressType_CHANGE_ADDRESS_TYPE_P2TR
|
||||||
fundPsbtReq := &walletrpc.FundPsbtRequest{
|
fundPsbtReq := &walletrpc.FundPsbtRequest{
|
||||||
Template: &walletrpc.FundPsbtRequest_Raw{
|
Template: &walletrpc.FundPsbtRequest_Raw{
|
||||||
Raw: txTemplate,
|
Raw: txTemplate,
|
||||||
|
@ -329,6 +330,7 @@ func (b *Batcher) BatchFund(ctx context.Context,
|
||||||
},
|
},
|
||||||
MinConfs: firstReq.MinConfs,
|
MinConfs: firstReq.MinConfs,
|
||||||
SpendUnconfirmed: firstReq.MinConfs == 0,
|
SpendUnconfirmed: firstReq.MinConfs == 0,
|
||||||
|
ChangeType: changeType,
|
||||||
}
|
}
|
||||||
fundPsbtResp, err := b.cfg.WalletKitServer.FundPsbt(ctx, fundPsbtReq)
|
fundPsbtResp, err := b.cfg.WalletKitServer.FundPsbt(ctx, fundPsbtReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/funding"
|
"github.com/lightningnetwork/lnd/funding"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
|
@ -777,6 +778,21 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
|
||||||
ht.AssertTopologyChannelOpen(alice, chanPoint2)
|
ht.AssertTopologyChannelOpen(alice, chanPoint2)
|
||||||
ht.AssertTopologyChannelOpen(alice, chanPoint3)
|
ht.AssertTopologyChannelOpen(alice, chanPoint3)
|
||||||
|
|
||||||
|
// Check if the change type from the batch_open_channel funding is P2TR.
|
||||||
|
rawTx := ht.Miner.GetRawTransaction(txHash)
|
||||||
|
require.Len(ht, rawTx.MsgTx().TxOut, 4)
|
||||||
|
|
||||||
|
// For calculating the change output index we use the formula for the
|
||||||
|
// sum of consecutive of integers (n(n+1)/2). All the channel point
|
||||||
|
// indexes are known, so we just calculate the difference to get the
|
||||||
|
// change output index.
|
||||||
|
changeIndex := uint32(6) - (chanPoint1.OutputIndex +
|
||||||
|
chanPoint2.OutputIndex + chanPoint3.OutputIndex)
|
||||||
|
|
||||||
|
ht.AssertOutputScriptClass(
|
||||||
|
rawTx, changeIndex, txscript.WitnessV1TaprootTy,
|
||||||
|
)
|
||||||
|
|
||||||
// With the channel open, ensure that it is counted towards Alice's
|
// With the channel open, ensure that it is counted towards Alice's
|
||||||
// total channel balance.
|
// total channel balance.
|
||||||
balRes := alice.RPC.ChannelBalance()
|
balRes := alice.RPC.ChannelBalance()
|
||||||
|
|
|
@ -377,6 +377,20 @@ func (h *HarnessTest) AssertChannelExists(hn *node.HarnessNode,
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssertOutputScriptClass checks that the specified transaction output has the
|
||||||
|
// expected script class.
|
||||||
|
func (h *HarnessTest) AssertOutputScriptClass(tx *btcutil.Tx,
|
||||||
|
outputIndex uint32, scriptClass txscript.ScriptClass) {
|
||||||
|
|
||||||
|
require.Greater(h, len(tx.MsgTx().TxOut), int(outputIndex))
|
||||||
|
|
||||||
|
txOut := tx.MsgTx().TxOut[outputIndex]
|
||||||
|
|
||||||
|
pkScript, err := txscript.ParsePkScript(txOut.PkScript)
|
||||||
|
require.NoError(h, err)
|
||||||
|
require.Equal(h, pkScript.Class(), scriptClass)
|
||||||
|
}
|
||||||
|
|
||||||
// findChannel tries to find a target channel in the node using the given
|
// findChannel tries to find a target channel in the node using the given
|
||||||
// channel point.
|
// channel point.
|
||||||
func (h *HarnessTest) findChannel(hn *node.HarnessNode,
|
func (h *HarnessTest) findChannel(hn *node.HarnessNode,
|
||||||
|
|
Loading…
Add table
Reference in a new issue