github.com/decred/dcrlnd@v0.7.6/lntest/itest/lnd_max_channel_size_test.go (about) 1 package itest 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/decred/dcrd/dcrutil/v4" 8 "github.com/decred/dcrlnd/funding" 9 "github.com/decred/dcrlnd/lntest" 10 "github.com/stretchr/testify/require" 11 ) 12 13 // testMaxChannelSize tests that lnd handles --maxchansize parameter 14 // correctly. Wumbo nodes should enforce a default soft limit of 10 BTC by 15 // default. This limit can be adjusted with --maxchansize config option 16 func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) { 17 18 // Mine blocks until the miner wallet has enough funds to start the test. 19 var blockCount int 20 for net.Miner.ConfirmedBalance() < 520e8 { 21 _, err := net.Generate(5) 22 require.NoError(t.t, err) 23 blockCount += 5 24 if blockCount > 1000 { 25 t.Fatalf("mined too many blocks") 26 } 27 } 28 29 // We'll make two new nodes, both wumbo but with the default limit on 30 // maximum channel size (500 DCR) 31 wumboNode := net.NewNode( 32 t.t, "wumbo", []string{"--protocol.wumbo-channels"}, 33 ) 34 defer shutdownAndAssert(net, t, wumboNode) 35 36 wumboNode2 := net.NewNode( 37 t.t, "wumbo2", []string{"--protocol.wumbo-channels"}, 38 ) 39 defer shutdownAndAssert(net, t, wumboNode2) 40 41 // We'll send 501 DCR to the wumbo node so it can test the wumbo soft 42 // limit. 43 net.SendCoins(t.t, 501*dcrutil.AtomsPerCoin, wumboNode) 44 45 // Next we'll connect both nodes, then attempt to make a wumbo channel 46 // funding request, which should fail as it exceeds the default wumbo 47 // soft limit of 500 DCR. 48 net.EnsureConnected(t.t, wumboNode, wumboNode2) 49 50 chanAmt := funding.MaxDecredFundingAmountWumbo + 1 51 _, err := net.OpenChannel( 52 wumboNode, wumboNode2, lntest.OpenChannelParams{ 53 Amt: chanAmt, 54 }, 55 ) 56 if err == nil { 57 t.Fatalf("expected channel funding to fail as it exceeds 10 BTC limit") 58 } 59 60 // The test should show failure due to the channel exceeding our max size. 61 if !strings.Contains(err.Error(), "exceeds maximum chan size") { 62 t.Fatalf("channel should be rejected due to size, instead "+ 63 "error was: %v", err) 64 } 65 66 // Next we'll create a non-wumbo node to verify that it enforces the 67 // BOLT-02 channel size limit and rejects our funding request. 68 miniNode := net.NewNode(t.t, "mini", nil) 69 defer shutdownAndAssert(net, t, miniNode) 70 71 net.EnsureConnected(t.t, wumboNode, miniNode) 72 73 _, err = net.OpenChannel( 74 wumboNode, miniNode, lntest.OpenChannelParams{ 75 Amt: chanAmt, 76 }, 77 ) 78 if err == nil { 79 t.Fatalf("expected channel funding to fail as it exceeds 10.7 DCR limit") 80 } 81 82 // The test should show failure due to the channel exceeding our max size. 83 if !strings.Contains(err.Error(), "exceeds maximum chan size") { 84 t.Fatalf("channel should be rejected due to size, instead "+ 85 "error was: %v", err) 86 } 87 88 // We'll now make another wumbo node with appropriate maximum channel size 89 // to accept our wumbo channel funding. 90 wumboNode3 := net.NewNode( 91 t.t, "wumbo3", []string{"--protocol.wumbo-channels", 92 fmt.Sprintf("--maxchansize=%v", int64(funding.MaxDecredFundingAmountWumbo+1))}, 93 ) 94 defer shutdownAndAssert(net, t, wumboNode3) 95 96 // Creating a wumbo channel between these two nodes should succeed. 97 net.EnsureConnected(t.t, wumboNode, wumboNode3) 98 chanPoint := openChannelAndAssert( 99 t, net, wumboNode, wumboNode3, 100 lntest.OpenChannelParams{ 101 Amt: chanAmt, 102 }, 103 ) 104 closeChannelAndAssert(t, net, wumboNode, chanPoint, false) 105 106 }