2020-09-15 05:16:32 +03:00
|
|
|
// +build rpctest
|
|
|
|
|
|
|
|
package itest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcutil"
|
2020-11-17 02:28:56 +03:00
|
|
|
"github.com/lightningnetwork/lnd/funding"
|
2020-09-15 05:16:32 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lntest"
|
|
|
|
)
|
|
|
|
|
|
|
|
// testMaxChannelSize tests that lnd handles --maxchansize parameter
|
|
|
|
// correctly. Wumbo nodes should enforce a default soft limit of 10 BTC by
|
|
|
|
// default. This limit can be adjusted with --maxchansize config option
|
|
|
|
func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
|
|
|
|
// We'll make two new nodes, both wumbo but with the default
|
|
|
|
// limit on maximum channel size (10 BTC)
|
2021-06-07 23:05:12 +03:00
|
|
|
wumboNode := net.NewNode(
|
|
|
|
t.t, "wumbo", []string{"--protocol.wumbo-channels"},
|
2020-09-15 05:16:32 +03:00
|
|
|
)
|
|
|
|
defer shutdownAndAssert(net, t, wumboNode)
|
|
|
|
|
2021-06-07 23:05:12 +03:00
|
|
|
wumboNode2 := net.NewNode(
|
|
|
|
t.t, "wumbo2", []string{"--protocol.wumbo-channels"},
|
2020-09-15 05:16:32 +03:00
|
|
|
)
|
|
|
|
defer shutdownAndAssert(net, t, wumboNode2)
|
|
|
|
|
|
|
|
// We'll send 11 BTC to the wumbo node so it can test the wumbo soft limit.
|
|
|
|
ctxb := context.Background()
|
2021-06-09 20:29:22 +03:00
|
|
|
net.SendCoins(ctxb, t.t, 11*btcutil.SatoshiPerBitcoin, wumboNode)
|
2020-09-15 05:16:32 +03:00
|
|
|
|
|
|
|
// Next we'll connect both nodes, then attempt to make a wumbo channel
|
|
|
|
// funding request, which should fail as it exceeds the default wumbo
|
|
|
|
// soft limit of 10 BTC.
|
2021-06-09 20:29:22 +03:00
|
|
|
err := net.EnsureConnected(ctxb, wumboNode, wumboNode2)
|
2020-09-15 05:16:32 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to connect peers: %v", err)
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:28:56 +03:00
|
|
|
chanAmt := funding.MaxBtcFundingAmountWumbo + 1
|
2020-09-15 05:16:32 +03:00
|
|
|
_, err = net.OpenChannel(
|
|
|
|
ctxb, wumboNode, wumboNode2, lntest.OpenChannelParams{
|
|
|
|
Amt: chanAmt,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected channel funding to fail as it exceeds 10 BTC limit")
|
|
|
|
}
|
|
|
|
|
|
|
|
// The test should show failure due to the channel exceeding our max size.
|
|
|
|
if !strings.Contains(err.Error(), "exceeds maximum chan size") {
|
|
|
|
t.Fatalf("channel should be rejected due to size, instead "+
|
|
|
|
"error was: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next we'll create a non-wumbo node to verify that it enforces the
|
|
|
|
// BOLT-02 channel size limit and rejects our funding request.
|
2021-06-07 23:05:12 +03:00
|
|
|
miniNode := net.NewNode(t.t, "mini", nil)
|
2020-09-15 05:16:32 +03:00
|
|
|
defer shutdownAndAssert(net, t, miniNode)
|
|
|
|
|
|
|
|
err = net.EnsureConnected(ctxb, wumboNode, miniNode)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to connect peers: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = net.OpenChannel(
|
|
|
|
ctxb, wumboNode, miniNode, lntest.OpenChannelParams{
|
|
|
|
Amt: chanAmt,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected channel funding to fail as it exceeds 0.16 BTC limit")
|
|
|
|
}
|
|
|
|
|
|
|
|
// The test should show failure due to the channel exceeding our max size.
|
|
|
|
if !strings.Contains(err.Error(), "exceeds maximum chan size") {
|
|
|
|
t.Fatalf("channel should be rejected due to size, instead "+
|
|
|
|
"error was: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll now make another wumbo node with appropriate maximum channel size
|
|
|
|
// to accept our wumbo channel funding.
|
2021-06-07 23:05:12 +03:00
|
|
|
wumboNode3 := net.NewNode(
|
|
|
|
t.t, "wumbo3", []string{
|
|
|
|
"--protocol.wumbo-channels",
|
|
|
|
fmt.Sprintf(
|
|
|
|
"--maxchansize=%v",
|
|
|
|
int64(funding.MaxBtcFundingAmountWumbo+1),
|
|
|
|
),
|
|
|
|
},
|
2020-09-15 05:16:32 +03:00
|
|
|
)
|
|
|
|
defer shutdownAndAssert(net, t, wumboNode3)
|
|
|
|
|
|
|
|
// Creating a wumbo channel between these two nodes should succeed.
|
|
|
|
err = net.EnsureConnected(ctxb, wumboNode, wumboNode3)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to connect peers: %v", err)
|
|
|
|
}
|
|
|
|
chanPoint := openChannelAndAssert(
|
|
|
|
ctxb, t, net, wumboNode, wumboNode3,
|
|
|
|
lntest.OpenChannelParams{
|
|
|
|
Amt: chanAmt,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
closeChannelAndAssert(ctxb, t, net, wumboNode, chanPoint, false)
|
|
|
|
|
|
|
|
}
|