Merge pull request #6956 from ellemouton/configureChanReserve

multi: configurable remote chan reserve
This commit is contained in:
Oliver Gugger authored and GitHub committed 2022-10-13 15:39:40 +02:00
commit d2d3cf3408
9 files changed
+2212 -2034

No files matched your search

+103 -13
View File
@@ -2795,6 +2795,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
const minHtlcIn = 1234
const maxValueInFlight = 50000
const fundingAmt = 5000000
const chanReserve = 100000
// Use custom channel fees.
// These will show up in the channel reservation context
@@ -2815,19 +2816,20 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
// workflow.
errChan := make(chan error, 1)
initReq := &InitFundingMsg{
Peer: bob,
TargetPubkey: bob.privKey.PubKey(),
ChainHash: *fundingNetParams.GenesisHash,
LocalFundingAmt: localAmt,
PushAmt: lnwire.NewMSatFromSatoshis(pushAmt),
Private: false,
MaxValueInFlight: maxValueInFlight,
MinHtlcIn: minHtlcIn,
RemoteCsvDelay: csvDelay,
Updates: updateChan,
Err: errChan,
BaseFee: &baseFee,
FeeRate: &feeRate,
Peer: bob,
TargetPubkey: bob.privKey.PubKey(),
ChainHash: *fundingNetParams.GenesisHash,
LocalFundingAmt: localAmt,
PushAmt: lnwire.NewMSatFromSatoshis(pushAmt),
Private: false,
MaxValueInFlight: maxValueInFlight,
MinHtlcIn: minHtlcIn,
RemoteCsvDelay: csvDelay,
RemoteChanReserve: chanReserve,
Updates: updateChan,
Err: errChan,
BaseFee: &baseFee,
FeeRate: &feeRate,
}
alice.fundingMgr.InitFundingWorkflow(initReq)
@@ -2872,6 +2874,12 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
maxValueInFlight, openChannelReq.MaxValueInFlight)
}
// Check that the custom remoteChanReserve value is sent.
if openChannelReq.ChannelReserve != chanReserve {
t.Fatalf("expected OpenChannel to have chanReserve %v, got %v",
chanReserve, openChannelReq.ChannelReserve)
}
chanID := openChannelReq.PendingChannelID
// Let Bob handle the init message.
@@ -3163,6 +3171,88 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
}
}
// TestFundingManagerInvalidChanReserve ensures proper validation is done on
// remoteChanReserve parameter sent to open channel.
func TestFundingManagerInvalidChanReserve(t *testing.T) {
t.Parallel()
var (
fundingAmt = btcutil.Amount(500000)
pushAmt = lnwire.NewMSatFromSatoshis(10)
genesisHash = *fundingNetParams.GenesisHash
)
tests := []struct {
name string
chanReserve btcutil.Amount
expectErr bool
errorContains string
}{
{
name: "Use default chan reserve",
chanReserve: 0,
},
{
name: "Above dust but below 1% of the capacity",
chanReserve: 400,
},
{
name: "Channel reserve below dust",
chanReserve: 300,
expectErr: true,
errorContains: "channel reserve of 300 sat is too " +
"small",
},
{
name: "Channel reserve more than 20% of the " +
"channel capacity",
chanReserve: fundingAmt,
expectErr: true,
errorContains: "channel reserve is too large",
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
alice, bob := setupFundingManagers(t)
defer tearDownFundingManagers(t, alice, bob)
// Create a funding request and start the workflow.
updateChan := make(chan *lnrpc.OpenStatusUpdate)
errChan := make(chan error, 1)
initReq := &InitFundingMsg{
Peer: bob,
TargetPubkey: bob.privKey.PubKey(),
ChainHash: genesisHash,
LocalFundingAmt: fundingAmt,
PushAmt: pushAmt,
Updates: updateChan,
RemoteChanReserve: test.chanReserve,
Err: errChan,
}
alice.fundingMgr.InitFundingWorkflow(initReq)
var err error
select {
case <-alice.msgChan:
case err = <-initReq.Err:
case <-time.After(time.Second * 5):
t.Fatalf("no message or error received")
}
if !test.expectErr {
require.NoError(t, err)
return
}
require.ErrorContains(t, err, test.errorContains)
})
}
}
// TestFundingManagerMaxPendingChannels checks that trying to open another
// channel with the same peer when MaxPending channels are pending fails.
func TestFundingManagerMaxPendingChannels(t *testing.T) {