Merge pull request #4567 from calvinrzachman/max-wumbo

add new max channel size config option
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2020-09-15 15:31:47 -07:00
commit fa342a1230
10 files changed
+272 -7

No files matched your search

+120
View File
@@ -0,0 +1,120 @@
// +build rpctest
package itest
import (
"context"
"fmt"
"strings"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd"
"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)
wumboNode, err := net.NewNode(
"wumbo", []string{"--protocol.wumbo-channels"},
)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
defer shutdownAndAssert(net, t, wumboNode)
wumboNode2, err := net.NewNode(
"wumbo2", []string{"--protocol.wumbo-channels"},
)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
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()
err = net.SendCoins(ctxb, 11*btcutil.SatoshiPerBitcoin, wumboNode)
if err != nil {
t.Fatalf("unable to send coins to wumbo node: %v", err)
}
// 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.
err = net.EnsureConnected(ctxb, wumboNode, wumboNode2)
if err != nil {
t.Fatalf("unable to connect peers: %v", err)
}
chanAmt := lnd.MaxBtcFundingAmountWumbo + 1
_, 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.
miniNode, err := net.NewNode("mini", nil)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
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.
wumboNode3, err := net.NewNode(
"wumbo3", []string{"--protocol.wumbo-channels",
fmt.Sprintf("--maxchansize=%v", int64(lnd.MaxBtcFundingAmountWumbo+1))},
)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
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)
}
+4
View File
@@ -14374,6 +14374,10 @@ var testsCases = []*testCase{
name: "wumbo channels",
test: testWumboChannels,
},
{
name: "maximum channel size",
test: testMaxChannelSize,
},
}
// TestLightningNetworkDaemon performs a series of integration tests amongst a
+1 -1
View File
@@ -62,7 +62,7 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) {
// The test should indicate a failure due to the channel being too
// large.
if !strings.Contains(err.Error(), "channel too large") {
if !strings.Contains(err.Error(), "exceeds maximum chan size") {
t.Fatalf("channel should be rejected due to size, instead "+
"error was: %v", err)
}
+9
View File
@@ -203,6 +203,15 @@
<time> [ERR] FNDG: received funding error from <hex>: chan_id=<hex>, err=channel too large
<time> [ERR] RPCS: [/lnrpc.Lightning/OpenChannel]: received funding error from <hex>: chan_id=<hex>, err=channel too large
<time> [ERR] RPCS: unable to open channel to NodeKey(<hex>): received funding error from <hex>: chan_id=<hex>, err=channel too large
<time> [ERR] FNDG: received funding error from <hex>: chan_id=<hex>, err=chan size of 0.16777216 BTC exceeds maximum chan size of 0.16777215 BTC
<time> [ERR] RPCS: [/lnrpc.Lightning/OpenChannel]: received funding error from <hex>: chan_id=<hex>, err=chan size of 0.16777216 BTC exceeds maximum chan size of 0.16777215 BTC
<time> [ERR] RPCS: unable to open channel to NodeKey(<hex>): received funding error from <hex>: chan_id=<hex>, err=chan size of 0.16777216 BTC exceeds maximum chan size of 0.16777215 BTC
<time> [ERR] FNDG: received funding error from <hex>: chan_id=<hex>, err=chan size of 10.00000001 BTC exceeds maximum chan size of 10 BTC
<time> [ERR] RPCS: [/lnrpc.Lightning/OpenChannel]: received funding error from <hex>: chan_id=<hex>, err=chan size of 10.00000001 BTC exceeds maximum chan size of 10 BTC
<time> [ERR] RPCS: unable to open channel to NodeKey(<hex>): received funding error from <hex>: chan_id=<hex>, err=chan size of 10.00000001 BTC exceeds maximum chan size of 10 BTC
<time> [ERR] FNDG: received funding error from <hex>: chan_id=<hex>, err=chan size of 10.00000001 BTC exceeds maximum chan size of 0.16777215 BTC
<time> [ERR] RPCS: [/lnrpc.Lightning/OpenChannel]: received funding error from <hex>: chan_id=<hex>, err=chan size of 10.00000001 BTC exceeds maximum chan size of 0.16777215 BTC
<time> [ERR] RPCS: unable to open channel to NodeKey(<hex>): received funding error from <hex>: chan_id=<hex>, err=chan size of 10.00000001 BTC exceeds maximum chan size of 0.16777215 BTC
<time> [ERR] NTNF: unable to get hash from block with height <height>
<time> [ERR] FNDG: Unable to add new channel <chan_point> with peer <hex>: canceled adding new channel
<time> [ERR] RPCS: WS: error closing upgraded conn: write tcp4 <ip>-><ip>: write: connection reset by peer