Merge pull request #7820 from hieblmi/sync-batch-chan-open-params

lnrpc: sync BatchOpenChannel and OpenChannel params
This commit is contained in:
Oliver Gugger 2023-07-26 11:31:05 +02:00 committed by GitHub
commit 1d3796a6d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 2415 additions and 2036 deletions

View File

@ -113,6 +113,10 @@ on the old value of 10000](https://github.com/lightningnetwork/lnd/pull/7780).
UTXOs [as a basis for funding a channel
opening.](https://github.com/lightningnetwork/lnd/pull/7516)
* The [BatchOpenChannel](https://github.com/lightningnetwork/lnd/pull/7820)
message now supports all fields that are present in the `OpenChannel` message,
except for the `funding_shim` and `fundmax` fields.
## Misc
* [Generate default macaroons

View File

@ -230,19 +230,31 @@ func (b *Batcher) BatchFund(ctx context.Context,
err)
}
//nolint:lll
fundingReq, err := b.cfg.RequestParser(&lnrpc.OpenChannelRequest{
SatPerVbyte: uint64(req.SatPerVbyte),
NodePubkey: rpcChannel.NodePubkey,
LocalFundingAmount: rpcChannel.LocalFundingAmount,
PushSat: rpcChannel.PushSat,
TargetConf: req.TargetConf,
Private: rpcChannel.Private,
MinHtlcMsat: rpcChannel.MinHtlcMsat,
RemoteCsvDelay: rpcChannel.RemoteCsvDelay,
MinConfs: req.MinConfs,
SpendUnconfirmed: req.SpendUnconfirmed,
CloseAddress: rpcChannel.CloseAddress,
CommitmentType: rpcChannel.CommitmentType,
SatPerVbyte: uint64(req.SatPerVbyte),
TargetConf: req.TargetConf,
MinConfs: req.MinConfs,
SpendUnconfirmed: req.SpendUnconfirmed,
NodePubkey: rpcChannel.NodePubkey,
LocalFundingAmount: rpcChannel.LocalFundingAmount,
PushSat: rpcChannel.PushSat,
Private: rpcChannel.Private,
MinHtlcMsat: rpcChannel.MinHtlcMsat,
RemoteCsvDelay: rpcChannel.RemoteCsvDelay,
CloseAddress: rpcChannel.CloseAddress,
RemoteMaxValueInFlightMsat: rpcChannel.RemoteMaxValueInFlightMsat,
RemoteMaxHtlcs: rpcChannel.RemoteMaxHtlcs,
MaxLocalCsv: rpcChannel.MaxLocalCsv,
CommitmentType: rpcChannel.CommitmentType,
ZeroConf: rpcChannel.ZeroConf,
ScidAlias: rpcChannel.ScidAlias,
BaseFee: rpcChannel.BaseFee,
FeeRate: rpcChannel.FeeRate,
UseBaseFee: rpcChannel.UseBaseFee,
UseFeeRate: rpcChannel.UseFeeRate,
RemoteChanReserveSat: rpcChannel.RemoteChanReserveSat,
Memo: rpcChannel.Memo,
FundingShim: &lnrpc.FundingShim{
Shim: &lnrpc.FundingShim_PsbtShim{
PsbtShim: &lnrpc.PsbtShim{

View File

@ -1,6 +1,7 @@
package itest
import (
"context"
"fmt"
"testing"
"time"
@ -9,6 +10,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/labels"
@ -717,13 +719,24 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
carol := ht.NewNode("carol", []string{"--minchansize=200000"})
dave := ht.NewNode("dave", nil)
// Next we create a node that will receive a zero-conf channel open from
// Alice. We'll create the node with the required parameters.
scidAliasArgs := []string{
"--protocol.option-scid-alias",
"--protocol.zero-conf",
"--protocol.anchors",
}
eve := ht.NewNode("eve", scidAliasArgs)
alice, bob := ht.Alice, ht.Bob
ht.RestartNodeWithExtraArgs(alice, scidAliasArgs)
// Before we start the test, we'll ensure Alice is connected to Carol
// and Dave so she can open channels to both of them (and Bob).
// and Dave, so she can open channels to both of them (and Bob).
ht.EnsureConnected(alice, bob)
ht.EnsureConnected(alice, carol)
ht.EnsureConnected(alice, dave)
ht.EnsureConnected(alice, eve)
// Let's create our batch TX request. This first one should fail as we
// open a channel to Carol that is too small for her min chan size.
@ -733,26 +746,51 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
Channels: []*lnrpc.BatchOpenChannel{{
NodePubkey: bob.PubKey[:],
LocalFundingAmount: 100_000,
BaseFee: 1337,
UseBaseFee: true,
}, {
NodePubkey: carol.PubKey[:],
LocalFundingAmount: 100_000,
FeeRate: 1337,
UseFeeRate: true,
}, {
NodePubkey: dave.PubKey[:],
LocalFundingAmount: 100_000,
BaseFee: 1337,
UseBaseFee: true,
FeeRate: 1337,
UseFeeRate: true,
}, {
NodePubkey: eve.PubKey[:],
LocalFundingAmount: 100_000,
Private: true,
ZeroConf: true,
CommitmentType: lnrpc.CommitmentType_ANCHORS,
}},
}
// Check that batch opening fails due to the minchansize requirement.
err := alice.RPC.BatchOpenChannelAssertErr(batchReq)
require.Contains(ht, err.Error(), "initial negotiation failed")
// Let's fix the minimum amount for Alice now and try again.
batchReq.Channels[1].LocalFundingAmount = 200_000
// Set up a ChannelAcceptor for Eve to accept a zero-conf opening from
// Alice.
acceptStream, cancel := eve.RPC.ChannelAcceptor()
go acceptChannel(ht.T, true, acceptStream)
// Batch-open all channels.
batchResp := alice.RPC.BatchOpenChannel(batchReq)
require.Len(ht, batchResp.PendingChannels, 3)
require.Len(ht, batchResp.PendingChannels, 4)
txHash, err := chainhash.NewHash(batchResp.PendingChannels[0].Txid)
require.NoError(ht, err)
// Remove the ChannelAcceptor.
cancel()
chanPoint1 := &lnrpc.ChannelPoint{
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
FundingTxidBytes: batchResp.PendingChannels[0].Txid,
@ -771,7 +809,26 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
},
OutputIndex: batchResp.PendingChannels[2].OutputIndex,
}
chanPoint4 := &lnrpc.ChannelPoint{
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
FundingTxidBytes: batchResp.PendingChannels[3].Txid,
},
OutputIndex: batchResp.PendingChannels[3].OutputIndex,
}
// Ensure that Alice can send funds to Eve via the zero-conf channel
// before the batch transaction was mined.
ht.AssertTopologyChannelOpen(alice, chanPoint4)
eveInvoiceParams := &lnrpc.Invoice{
Value: int64(10_000),
Private: true,
}
eveInvoiceResp := eve.RPC.AddInvoice(eveInvoiceParams)
ht.CompletePaymentRequests(
alice, []string{eveInvoiceResp.PaymentRequest},
)
// Mine the batch transaction and check the network topology.
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.Miner.AssertTxInBlock(block, txHash)
ht.AssertTopologyChannelOpen(alice, chanPoint1)
@ -780,15 +837,18 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
// 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)
require.Len(ht, rawTx.MsgTx().TxOut, 5)
// 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)
// Example: Batch outputs = 4, sum_consecutive_ints(4) = 10
// Subtract all other output indices to get the change index:
// 10 - 0 - 1 - 2 - 3 = 4
changeIndex := uint32(10) - (chanPoint1.OutputIndex +
chanPoint2.OutputIndex + chanPoint3.OutputIndex +
chanPoint4.OutputIndex)
ht.AssertOutputScriptClass(
rawTx, changeIndex, txscript.WitnessV1TaprootTy,
)
@ -808,6 +868,28 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
resp := carol.RPC.AddInvoice(invoice)
ht.CompletePaymentRequests(alice, []string{resp.PaymentRequest})
// Confirm that Alice's channel partners see here initial fee settings.
ensurePolicy(
ht, alice, bob, chanPoint1,
lnwire.MilliSatoshi(batchReq.Channels[0].BaseFee),
chainreg.DefaultBitcoinFeeRate,
)
ensurePolicy(
ht, alice, carol, chanPoint2,
chainreg.DefaultBitcoinBaseFeeMSat,
lnwire.MilliSatoshi(batchReq.Channels[1].FeeRate),
)
ensurePolicy(
ht, alice, dave, chanPoint3,
lnwire.MilliSatoshi(batchReq.Channels[2].BaseFee),
lnwire.MilliSatoshi(batchReq.Channels[2].FeeRate),
)
ensurePolicy(
ht, alice, eve, chanPoint4,
chainreg.DefaultBitcoinBaseFeeMSat,
chainreg.DefaultBitcoinFeeRate,
)
// To conclude, we'll close the newly created channel between Carol and
// Dave. This function will also block until the channel is closed and
// will additionally assert the relevant channel closing post
@ -815,6 +897,27 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
ht.CloseChannel(alice, chanPoint1)
ht.CloseChannel(alice, chanPoint2)
ht.CloseChannel(alice, chanPoint3)
ht.CloseChannel(alice, chanPoint4)
}
// ensurePolicy ensures that the peer sees alice's channel fee settings.
func ensurePolicy(ht *lntest.HarnessTest, alice, peer *node.HarnessNode,
chanPoint *lnrpc.ChannelPoint, expectedBaseFee lnwire.MilliSatoshi,
expectedFeeRate lnwire.MilliSatoshi) {
channel := ht.AssertChannelExists(peer, chanPoint)
policy, err := peer.RPC.LN.GetChanInfo(
context.Background(), &lnrpc.ChanInfoRequest{
ChanId: channel.ChanId,
},
)
require.NoError(ht, err)
alicePolicy := policy.Node1Policy
if alice.PubKeyStr == policy.Node2Pub {
alicePolicy = policy.Node2Policy
}
require.EqualValues(ht, expectedBaseFee, alicePolicy.FeeBaseMsat)
require.EqualValues(ht, expectedFeeRate, alicePolicy.FeeRateMilliMsat)
}
// deriveFundingShim creates a channel funding shim by deriving the necessary

File diff suppressed because it is too large Load Diff

View File

@ -2128,6 +2128,76 @@ message BatchOpenChannel {
the remote peer supports explicit channel negotiation.
*/
CommitmentType commitment_type = 9;
/*
The maximum amount of coins in millisatoshi that can be pending within
the channel. It only applies to the remote party.
*/
uint64 remote_max_value_in_flight_msat = 10;
/*
The maximum number of concurrent HTLCs we will allow the remote party to add
to the commitment transaction.
*/
uint32 remote_max_htlcs = 11;
/*
Max local csv is the maximum csv delay we will allow for our own commitment
transaction.
*/
uint32 max_local_csv = 12;
/*
If this is true, then a zero-conf channel open will be attempted.
*/
bool zero_conf = 13;
/*
If this is true, then an option-scid-alias channel-type open will be
attempted.
*/
bool scid_alias = 14;
/*
The base fee charged regardless of the number of milli-satoshis sent.
*/
uint64 base_fee = 15;
/*
The fee rate in ppm (parts per million) that will be charged in
proportion of the value of each forwarded HTLC.
*/
uint64 fee_rate = 16;
/*
If use_base_fee is true the open channel announcement will update the
channel base fee with the value specified in base_fee. In the case of
a base_fee of 0 use_base_fee is needed downstream to distinguish whether
to use the default base fee value specified in the config or 0.
*/
bool use_base_fee = 17;
/*
If use_fee_rate is true the open channel announcement will update the
channel fee rate with the value specified in fee_rate. In the case of
a fee_rate of 0 use_fee_rate is needed downstream to distinguish whether
to use the default fee rate value specified in the config or 0.
*/
bool use_fee_rate = 18;
/*
The number of satoshis we require the remote peer to reserve. This value,
if specified, must be above the dust limit and below 20% of the channel
capacity.
*/
uint64 remote_chan_reserve_sat = 19;
/*
An optional note-to-self to go along with the channel containing some
useful information. This is only ever stored locally and in no way impacts
the channel's operation.
*/
string memo = 20;
}
message BatchOpenChannelResponse {

View File

@ -3305,6 +3305,56 @@
"commitment_type": {
"$ref": "#/definitions/lnrpcCommitmentType",
"description": "The explicit commitment type to use. Note this field will only be used if\nthe remote peer supports explicit channel negotiation."
},
"remote_max_value_in_flight_msat": {
"type": "string",
"format": "uint64",
"description": "The maximum amount of coins in millisatoshi that can be pending within\nthe channel. It only applies to the remote party."
},
"remote_max_htlcs": {
"type": "integer",
"format": "int64",
"description": "The maximum number of concurrent HTLCs we will allow the remote party to add\nto the commitment transaction."
},
"max_local_csv": {
"type": "integer",
"format": "int64",
"description": "Max local csv is the maximum csv delay we will allow for our own commitment\ntransaction."
},
"zero_conf": {
"type": "boolean",
"description": "If this is true, then a zero-conf channel open will be attempted."
},
"scid_alias": {
"type": "boolean",
"description": "If this is true, then an option-scid-alias channel-type open will be\nattempted."
},
"base_fee": {
"type": "string",
"format": "uint64",
"description": "The base fee charged regardless of the number of milli-satoshis sent."
},
"fee_rate": {
"type": "string",
"format": "uint64",
"description": "The fee rate in ppm (parts per million) that will be charged in\nproportion of the value of each forwarded HTLC."
},
"use_base_fee": {
"type": "boolean",
"description": "If use_base_fee is true the open channel announcement will update the\nchannel base fee with the value specified in base_fee. In the case of\na base_fee of 0 use_base_fee is needed downstream to distinguish whether\nto use the default base fee value specified in the config or 0."
},
"use_fee_rate": {
"type": "boolean",
"description": "If use_fee_rate is true the open channel announcement will update the\nchannel fee rate with the value specified in fee_rate. In the case of\na fee_rate of 0 use_fee_rate is needed downstream to distinguish whether\nto use the default fee rate value specified in the config or 0."
},
"remote_chan_reserve_sat": {
"type": "string",
"format": "uint64",
"description": "The number of satoshis we require the remote peer to reserve. This value,\nif specified, must be above the dust limit and below 20% of the channel\ncapacity."
},
"memo": {
"type": "string",
"description": "An optional note-to-self to go along with the channel containing some\nuseful information. This is only ever stored locally and in no way impacts\nthe channel's operation."
}
}
},

View File

@ -388,7 +388,7 @@ func (h *HarnessTest) AssertOutputScriptClass(tx *btcutil.Tx,
pkScript, err := txscript.ParsePkScript(txOut.PkScript)
require.NoError(h, err)
require.Equal(h, pkScript.Class(), scriptClass)
require.Equal(h, scriptClass, pkScript.Class())
}
// findChannel tries to find a target channel in the node using the given