From dca20d80a717edd6a6350e1989914b0549390766 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 19 Aug 2021 20:12:50 +0800 Subject: [PATCH] itest: fix context leak in openChannelAndAssert In this commit, we put the context initialization inside openChannelAndAssert, thus saving us a few lines and making sure the context is always properly handled. --- lntest/itest/assertions.go | 8 +- lntest/itest/lnd_channel_backup_test.go | 17 +--- lntest/itest/lnd_channel_balance_test.go | 6 +- lntest/itest/lnd_channel_force_close.go | 8 +- lntest/itest/lnd_channel_graph_test.go | 12 +-- lntest/itest/lnd_channel_policy_test.go | 11 +-- lntest/itest/lnd_etcd_failover_test.go | 3 +- lntest/itest/lnd_forward_interceptor_test.go | 3 +- lntest/itest/lnd_funding_test.go | 5 +- lntest/itest/lnd_hold_invoice_force_test.go | 6 +- lntest/itest/lnd_hold_persistence_test.go | 3 +- lntest/itest/lnd_max_channel_size_test.go | 2 +- lntest/itest/lnd_max_htlcs_test.go | 5 +- lntest/itest/lnd_misc_test.go | 52 ++++------- lntest/itest/lnd_mpp_test.go | 7 +- .../lnd_multi-hop-error-propagation_test.go | 8 +- lntest/itest/lnd_multi-hop-payments_test.go | 11 +-- lntest/itest/lnd_multi-hop_test.go | 6 +- lntest/itest/lnd_onchain_test.go | 8 +- lntest/itest/lnd_open_channel_test.go | 3 +- lntest/itest/lnd_payment_test.go | 18 ++-- lntest/itest/lnd_rest_api_test.go | 6 +- lntest/itest/lnd_revocation_test.go | 12 +-- lntest/itest/lnd_routing_test.go | 91 +++++++------------ lntest/itest/lnd_single_hop_invoice_test.go | 5 +- lntest/itest/lnd_switch_test.go | 44 ++++----- lntest/itest/lnd_wumbo_channels_test.go | 2 +- 27 files changed, 133 insertions(+), 229 deletions(-) diff --git a/lntest/itest/assertions.go b/lntest/itest/assertions.go index 2cc0e4986..357d82a6c 100644 --- a/lntest/itest/assertions.go +++ b/lntest/itest/assertions.go @@ -62,12 +62,16 @@ func openChannelStream(ctx context.Context, t *harnessTest, // after the channel is considered open: the funding transaction should be // found within a block, and that Alice can report the status of the new // channel. -func openChannelAndAssert(ctx context.Context, t *harnessTest, - net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode, +func openChannelAndAssert(t *harnessTest, net *lntest.NetworkHarness, + alice, bob *lntest.HarnessNode, p lntest.OpenChannelParams) *lnrpc.ChannelPoint { t.t.Helper() + ctxb := context.Background() + ctx, cancel := context.WithTimeout(ctxb, channelOpenTimeout) + defer cancel() + chanOpenUpdate := openChannelStream(ctx, t, net, alice, bob, p) // Mine 6 blocks, then wait for Alice's node to notify us that the diff --git a/lntest/itest/lnd_channel_backup_test.go b/lntest/itest/lnd_channel_backup_test.go index 7e273b602..14dea02ac 100644 --- a/lntest/itest/lnd_channel_backup_test.go +++ b/lntest/itest/lnd_channel_backup_test.go @@ -513,12 +513,9 @@ func testChannelBackupUpdates(net *lntest.NetworkHarness, t *harnessTest) { numChans := 2 chanAmt := btcutil.Amount(1000000) for i := 0; i < numChans; i++ { - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, - lntest.OpenChannelParams{ - Amt: chanAmt, - }, + t, net, net.Alice, carol, + lntest.OpenChannelParams{Amt: chanAmt}, ) chanPoints = append(chanPoints, chanPoint) @@ -652,12 +649,9 @@ func testExportChannelBackup(net *lntest.NetworkHarness, t *harnessTest) { numChans := 2 chanAmt := btcutil.Amount(1000000) for i := 0; i < numChans; i++ { - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, - lntest.OpenChannelParams{ - Amt: chanAmt, - }, + t, net, net.Alice, carol, + lntest.OpenChannelParams{Amt: chanAmt}, ) chanPoints = append(chanPoints, chanPoint) @@ -943,9 +937,8 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness, ) default: - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint = openChannelAndAssert( - ctxt, t, net, from, to, + t, net, from, to, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, diff --git a/lntest/itest/lnd_channel_balance_test.go b/lntest/itest/lnd_channel_balance_test.go index b9b98a1b5..4c88dad57 100644 --- a/lntest/itest/lnd_channel_balance_test.go +++ b/lntest/itest/lnd_channel_balance_test.go @@ -54,9 +54,8 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(ctxt, t.t, net.Alice, net.Bob) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: amount, }, @@ -149,9 +148,8 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) { net.ConnectNodes(ctxb, t.t, net.Alice, carol) // Open a channel between Alice and Carol. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_channel_force_close.go b/lntest/itest/lnd_channel_force_close.go index 0fbd4aca3..65b8c7150 100644 --- a/lntest/itest/lnd_channel_force_close.go +++ b/lntest/itest/lnd_channel_force_close.go @@ -109,7 +109,7 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness, // Open a channel between Alice and Bob. chanPoint := openChannelAndAssert( - ctxt, t, net, alice, bob, lntest.OpenChannelParams{ + t, net, alice, bob, lntest.OpenChannelParams{ Amt: 10e6, PushAmt: 5e6, }, @@ -335,9 +335,8 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, carolStartingBalance := carolBalResp.ConfirmedBalance - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, alice, carol, + t, net, alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -1421,9 +1420,8 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) { // Let Alice connect and open a channel to Carol, ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Alice, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_channel_graph_test.go b/lntest/itest/lnd_channel_graph_test.go index 84411212d..858aad262 100644 --- a/lntest/itest/lnd_channel_graph_test.go +++ b/lntest/itest/lnd_channel_graph_test.go @@ -54,9 +54,8 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. chanAmt := btcutil.Amount(100000) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, alice, bob, + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -472,9 +471,8 @@ func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned b defer close(graphSub.quit) // Open a new channel between Alice and Bob. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, alice, bob, + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -605,9 +603,8 @@ out: ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, bob, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint = openChannelAndAssert( - ctxt, t, net, bob, carol, + t, net, bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -716,9 +713,8 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) { // We'll then go ahead and open a channel between Bob and Dave. This // ensures that Alice receives the node announcement from Bob as part of // the announcement broadcast. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Bob, dave, + t, net, net.Bob, dave, lntest.OpenChannelParams{ Amt: 1000000, }, diff --git a/lntest/itest/lnd_channel_policy_test.go b/lntest/itest/lnd_channel_policy_test.go index 2b8a84f1d..e0f7a5f29 100644 --- a/lntest/itest/lnd_channel_policy_test.go +++ b/lntest/itest/lnd_channel_policy_test.go @@ -37,9 +37,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { pushAmt := chanAmt / 2 // Create a channel Alice->Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -81,7 +80,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { ) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) if err != nil { t.Fatalf("alice didn't report channel: %v", err) @@ -120,9 +119,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { // HTLCs smaller than this value, and hence he should advertise it as // part of his ChannelUpdate. const customMinHtlc = 5000 - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint2 := openChannelAndAssert( - ctxt, t, net, carol, net.Bob, + t, net, carol, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -391,9 +389,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { // We'll now open a channel from Alice directly to Carol. net.ConnectNodes(ctxb, t.t, net.Alice, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint3 := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, diff --git a/lntest/itest/lnd_etcd_failover_test.go b/lntest/itest/lnd_etcd_failover_test.go index 367bbf225..21542aad8 100644 --- a/lntest/itest/lnd_etcd_failover_test.go +++ b/lntest/itest/lnd_etcd_failover_test.go @@ -106,9 +106,8 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest, // Open a channel with 100k satoshis between Carol and Alice with Alice // being the sole funder of the channel. chanAmt := btcutil.Amount(100000) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) _ = openChannelAndAssert( - ctxt, ht, net, net.Alice, carol1, + ht, net, net.Alice, carol1, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_forward_interceptor_test.go b/lntest/itest/lnd_forward_interceptor_test.go index 843e14372..0f788dd4e 100644 --- a/lntest/itest/lnd_forward_interceptor_test.go +++ b/lntest/itest/lnd_forward_interceptor_test.go @@ -359,9 +359,8 @@ func (c *interceptorTestContext) openChannel(from, to *lntest.HarnessNode, ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) c.net.SendCoins(ctxt, c.t.t, btcutil.SatoshiPerBitcoin, from) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, c.t, c.net, from, to, + c.t, c.net, from, to, lntest.OpenChannelParams{ Amt: chanSize, }, diff --git a/lntest/itest/lnd_funding_test.go b/lntest/itest/lnd_funding_test.go index ce530081e..38512947f 100644 --- a/lntest/itest/lnd_funding_test.go +++ b/lntest/itest/lnd_funding_test.go @@ -202,9 +202,8 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness, // assertions will be executed to ensure the funding process completed // successfully. ctxb := context.Background() - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, alice, bob, + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -213,7 +212,7 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) require.NoError(t.t, err, "alice didn't report channel") diff --git a/lntest/itest/lnd_hold_invoice_force_test.go b/lntest/itest/lnd_hold_invoice_force_test.go index 0f770e64f..81afce5f0 100644 --- a/lntest/itest/lnd_hold_invoice_force_test.go +++ b/lntest/itest/lnd_hold_invoice_force_test.go @@ -25,10 +25,8 @@ func testHoldInvoiceForceClose(net *lntest.NetworkHarness, t *harnessTest) { Amt: 300000, } - ctxt, cancel := context.WithTimeout(ctxb, channelOpenTimeout) - defer cancel() chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, chanReq, + t, net, net.Alice, net.Bob, chanReq, ) // Create a non-dust hold invoice for bob. @@ -42,7 +40,7 @@ func testHoldInvoiceForceClose(net *lntest.NetworkHarness, t *harnessTest) { Hash: payHash[:], } - ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) + ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) defer cancel() bobInvoice, err := net.Bob.AddHoldInvoice(ctxt, invoiceReq) require.NoError(t.t, err) diff --git a/lntest/itest/lnd_hold_persistence_test.go b/lntest/itest/lnd_hold_persistence_test.go index bcab29eac..cc6c9c415 100644 --- a/lntest/itest/lnd_hold_persistence_test.go +++ b/lntest/itest/lnd_hold_persistence_test.go @@ -39,9 +39,8 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel between Alice and Carol which is private so that we // cover the addition of hop hints for hold invoices. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, Private: true, diff --git a/lntest/itest/lnd_max_channel_size_test.go b/lntest/itest/lnd_max_channel_size_test.go index 625cf6255..fc7a32bdc 100644 --- a/lntest/itest/lnd_max_channel_size_test.go +++ b/lntest/itest/lnd_max_channel_size_test.go @@ -91,7 +91,7 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) { // Creating a wumbo channel between these two nodes should succeed. net.EnsureConnected(ctxb, t.t, wumboNode, wumboNode3) chanPoint := openChannelAndAssert( - ctxb, t, net, wumboNode, wumboNode3, + t, net, wumboNode, wumboNode3, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_max_htlcs_test.go b/lntest/itest/lnd_max_htlcs_test.go index b697582f8..a6dff646e 100644 --- a/lntest/itest/lnd_max_htlcs_test.go +++ b/lntest/itest/lnd_max_htlcs_test.go @@ -23,9 +23,8 @@ func testMaxHtlcPathfind(net *lntest.NetworkHarness, t *harnessTest) { // Bob to add a maximum of 5 htlcs to her commitment. maxHtlcs := 5 - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: 1000000, PushAmt: 800000, @@ -35,7 +34,7 @@ func testMaxHtlcPathfind(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice and Bob to receive the channel edge from the // funding manager. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) require.NoError(t.t, err, "alice does not have open channel") diff --git a/lntest/itest/lnd_misc_test.go b/lntest/itest/lnd_misc_test.go index 1b20eae2f..aeca05041 100644 --- a/lntest/itest/lnd_misc_test.go +++ b/lntest/itest/lnd_misc_test.go @@ -207,9 +207,8 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -228,9 +227,8 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, fred) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointFC := openChannelAndAssert( - ctxt, t, net, fred, carol, + t, net, fred, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -393,9 +391,8 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { const customizedMinHtlc = 4200 chanAmt := btcutil.Amount(100000) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, alice, bob, + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt, MinHtlc: customizedMinHtlc, @@ -618,9 +615,8 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel between Alice and Bob which will later be // cooperatively closed. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) coopChanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, ) @@ -628,14 +624,13 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) { // Create Carol's node and connect Alice to her. carol := net.NewNode(t.t, "Carol", nil) defer shutdownAndAssert(net, t, carol) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Alice, carol) // Open a channel between Alice and Carol which will later be force // closed. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) forceCloseChanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, lntest.OpenChannelParams{ + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, ) @@ -647,9 +642,8 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) { defer shutdownAndAssert(net, t, dave) net.ConnectNodes(ctxt, t.t, net.Alice, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) persistentChanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, dave, lntest.OpenChannelParams{ + t, net, net.Alice, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, ) @@ -887,9 +881,8 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) { // We'll first open up a channel between them with a 0.5 BTC // value. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, carol, node, + t, net, carol, node, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1174,18 +1167,16 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) { net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcent, net.Alice) // Open a channel between Alice and Carol. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, ) // Open a channel between Carol and Bob. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, net.Bob, + t, net, carol, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1223,7 +1214,7 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) { } // Alice pays Carols invoice. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err = completePaymentRequests( ctxt, net.Alice, net.Alice.RouterClient, []string{resp.PaymentRequest}, true, @@ -1303,9 +1294,8 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) { pushAmt := btcutil.Amount(100000) // Create a channel between alice and bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) aliceBobCh := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -1316,7 +1306,7 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) { // alice signs "alice msg" and sends her signature to bob. sigReq := &lnrpc.SignMessageRequest{Msg: aliceMsg} - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) sigResp, err := net.Alice.SignMessage(ctxt, sigReq) if err != nil { t.Fatalf("SignMessage rpc call failed: %v", err) @@ -1384,9 +1374,8 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel between Alice and Bob and Alice and Carol. These will // be closed later on in order to trigger channel update messages // marking the channels as disabled. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAliceBob := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1401,11 +1390,10 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) { }) defer shutdownAndAssert(net, t, carol) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Alice, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointAliceCarol := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1433,9 +1421,8 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, eve, net.Bob) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointEveCarol := openChannelAndAssert( - ctxt, t, net, eve, carol, + t, net, eve, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1602,16 +1589,15 @@ func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) { PushAmt: btcutil.Amount(100000), } - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, channelParam, + t, net, net.Alice, net.Bob, channelParam, ) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) require.NoError(t.t, err, "alice bob get channel funding txid") chanPointStr := fmt.Sprintf("%v:%v", txid, chanPoint.OutputIndex) // Wait for channel to be confirmed open. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) require.NoError(t.t, err, "alice wait for network channel open") err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) diff --git a/lntest/itest/lnd_mpp_test.go b/lntest/itest/lnd_mpp_test.go index f9c1821e6..9ab978515 100644 --- a/lntest/itest/lnd_mpp_test.go +++ b/lntest/itest/lnd_mpp_test.go @@ -296,12 +296,9 @@ func (c *mppTestContext) openChannel(from, to *lntest.HarnessNode, chanSize btcu ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) c.net.SendCoins(ctxt, c.t.t, btcutil.SatoshiPerBitcoin, from) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, c.t, c.net, from, to, - lntest.OpenChannelParams{ - Amt: chanSize, - }, + c.t, c.net, from, to, + lntest.OpenChannelParams{Amt: chanSize}, ) c.closeChannelFuncs = append(c.closeChannelFuncs, func() { diff --git a/lntest/itest/lnd_multi-hop-error-propagation_test.go b/lntest/itest/lnd_multi-hop-error-propagation_test.go index 6d8ea998c..d893b128d 100644 --- a/lntest/itest/lnd_multi-hop-error-propagation_test.go +++ b/lntest/itest/lnd_multi-hop-error-propagation_test.go @@ -23,14 +23,13 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) { // First establish a channel with a capacity of 0.5 BTC between Alice // and Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) if err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice); err != nil { t.Fatalf("channel not seen by alice before timeout: %v", err) } @@ -96,10 +95,9 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) { // above. ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Bob, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) const bobChanAmt = funding.MaxBtcFundingAmount chanPointBob := openChannelAndAssert( - ctxt, t, net, net.Bob, carol, + t, net, net.Bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_multi-hop-payments_test.go b/lntest/itest/lnd_multi-hop-payments_test.go index bcf34ad12..59e96fb8d 100644 --- a/lntest/itest/lnd_multi-hop-payments_test.go +++ b/lntest/itest/lnd_multi-hop-payments_test.go @@ -20,9 +20,8 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -50,14 +49,13 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { dave := net.NewNode(t.t, "Dave", daveArgs) defer shutdownAndAssert(net, t, dave) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, dave, net.Alice) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointDave := openChannelAndAssert( - ctxt, t, net, dave, net.Alice, + t, net, dave, net.Alice, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -82,9 +80,8 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_multi-hop_test.go b/lntest/itest/lnd_multi-hop_test.go index 536cc6310..34db606d0 100644 --- a/lntest/itest/lnd_multi-hop_test.go +++ b/lntest/itest/lnd_multi-hop_test.go @@ -223,9 +223,8 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness, // We'll start the test by creating a channel between Alice and Bob, // which will act as the first leg for out multi-hop HTLC. const chanAmt = 1000000 - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) aliceChanPoint := openChannelAndAssert( - ctxt, t, net, alice, bob, + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -266,9 +265,8 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness, // We'll then create a channel from Bob to Carol. After this channel is // open, our topology looks like: A -> B -> C. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) bobChanPoint := openChannelAndAssert( - ctxt, t, net, bob, carol, + t, net, bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_onchain_test.go b/lntest/itest/lnd_onchain_test.go index b3dce7745..7bace73d0 100644 --- a/lntest/itest/lnd_onchain_test.go +++ b/lntest/itest/lnd_onchain_test.go @@ -205,9 +205,8 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) { // Alice opens a smaller channel. This works since it will have a // change output. - ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout) aliceChanPoint1 := openChannelAndAssert( - ctxt, t, net, alice, bob, + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt / 4, }, @@ -216,7 +215,7 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) { // If Alice tries to open another anchor channel to Bob, Bob should not // reject it as he is not contributing any funds. aliceChanPoint2 := openChannelAndAssert( - ctxt, t, net, alice, bob, lntest.OpenChannelParams{ + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt / 4, }, ) @@ -226,9 +225,8 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) { // to remove his support for anchors. err = net.RestartNode(bob, nil) require.NoError(t.t, err) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) aliceChanPoint3 := openChannelAndAssert( - ctxt, t, net, alice, bob, lntest.OpenChannelParams{ + t, net, alice, bob, lntest.OpenChannelParams{ Amt: chanAmt / 4, }, ) diff --git a/lntest/itest/lnd_open_channel_test.go b/lntest/itest/lnd_open_channel_test.go index 00ed0fc54..5ca3fc9a5 100644 --- a/lntest/itest/lnd_open_channel_test.go +++ b/lntest/itest/lnd_open_channel_test.go @@ -280,9 +280,8 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe // have been properly opened on-chain. chanPoints := make([]*lnrpc.ChannelPoint, numChannels) for i := 0; i < numChannels; i++ { - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoints[i] = openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: amount, }, diff --git a/lntest/itest/lnd_payment_test.go b/lntest/itest/lnd_payment_test.go index 62796e3dd..1980abffd 100644 --- a/lntest/itest/lnd_payment_test.go +++ b/lntest/itest/lnd_payment_test.go @@ -44,9 +44,8 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. chanAmt := btcutil.Amount(100000) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -263,16 +262,15 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) { // First establish a channel with a capacity equals to the overall // amount of payments, between Alice and Bob, at the end of the test // Alice should send all money from her side to Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) channelCapacity := btcutil.Amount(paymentAmt * 2000) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: channelCapacity, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) info, err := getChanInfo(ctxt, net.Alice) if err != nil { t.Fatalf("unable to get alice channel info: %v", err) @@ -429,16 +427,15 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) // First establish a channel with a capacity equals to the overall // amount of payments, between Alice and Bob, at the end of the test // Alice should send all money from her side to Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: paymentAmt * 2000, PushAmt: paymentAmt * 1000, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) info, err := getChanInfo(ctxt, net.Alice) if err != nil { t.Fatalf("unable to get alice channel info: %v", err) @@ -619,9 +616,8 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 500k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -636,7 +632,7 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) { RPreimage: makeFakePayHash(t), Value: paymentAmt, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) invoiceResp, err := net.Bob.AddInvoice(ctxt, invoice) if err != nil { t.Fatalf("unable to add invoice: %v", err) diff --git a/lntest/itest/lnd_rest_api_test.go b/lntest/itest/lnd_rest_api_test.go index 3f162de20..ad009c941 100644 --- a/lntest/itest/lnd_rest_api_test.go +++ b/lntest/itest/lnd_rest_api_test.go @@ -506,10 +506,8 @@ func wsTestCaseBiDirectionalSubscription(ht *harnessTest, const numChannels = 3 for i := 0; i < numChannels; i++ { openChannelAndAssert( - context.Background(), ht, net, net.Bob, net.Alice, - lntest.OpenChannelParams{ - Amt: 500000, - }, + ht, net, net.Bob, net.Alice, + lntest.OpenChannelParams{Amt: 500000}, ) select { diff --git a/lntest/itest/lnd_revocation_test.go b/lntest/itest/lnd_revocation_test.go index ed036b5f7..ea2375811 100644 --- a/lntest/itest/lnd_revocation_test.go +++ b/lntest/itest/lnd_revocation_test.go @@ -55,9 +55,8 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) { // In order to test Carol's response to an uncooperative channel // closure by Bob, we'll first open up a channel between them with a // 0.5 BTC value. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, carol, net.Bob, + t, net, carol, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -313,9 +312,8 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness // In order to test Dave's response to an uncooperative channel // closure by Carol, we'll first open up a channel between them with a // 0.5 BTC value. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, dave, carol, + t, net, dave, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -546,9 +544,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, // In order to test Dave's response to an uncooperative channel closure // by Carol, we'll first open up a channel between them with a // funding.MaxBtcFundingAmount (2^24) satoshis value. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, dave, carol, + t, net, dave, carol, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -1041,9 +1038,8 @@ func testRevokedCloseRetributionAltruistWatchtowerCase( // In order to test Dave's response to an uncooperative channel // closure by Carol, we'll first open up a channel between them with a // 0.5 BTC value. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPoint := openChannelAndAssert( - ctxt, t, net, dave, carol, + t, net, dave, carol, lntest.OpenChannelParams{ Amt: 3 * (chanAmt / 4), PushAmt: chanAmt / 4, diff --git a/lntest/itest/lnd_routing_test.go b/lntest/itest/lnd_routing_test.go index 8adc4def5..df94f50a1 100644 --- a/lntest/itest/lnd_routing_test.go +++ b/lntest/itest/lnd_routing_test.go @@ -110,9 +110,8 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest, // Open a channel with 100k satoshis between Carol and Dave with Carol // being the sole funder of the channel. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -445,9 +444,8 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -469,14 +467,13 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) { carol := net.NewNode(t.t, "Carol", nil) defer shutdownAndAssert(net, t, carol) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, carol, net.Bob) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointBob := openChannelAndAssert( - ctxt, t, net, net.Bob, carol, + t, net, net.Bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -618,15 +615,14 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) if err != nil { t.Fatalf("alice didn't advertise her channel: %v", err) @@ -654,9 +650,8 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, carol, charlie) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, charlie, + t, net, carol, charlie, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -745,9 +740,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { // where the 100k channel between Carol and Alice is private. // Open a channel with 200k satoshis between Alice and Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt * 2, }, @@ -767,14 +761,13 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { dave := net.NewNode(t.t, "Dave", nil) defer shutdownAndAssert(net, t, dave) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, dave, net.Alice) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointDave := openChannelAndAssert( - ctxt, t, net, dave, net.Alice, + t, net, dave, net.Alice, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -799,9 +792,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1066,9 +1058,8 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness, const chanAmt = btcutil.Amount(100000) // Open a channel with 100k satoshis between Alice and Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAliceBob := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1088,13 +1079,12 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness, defer shutdownAndAssert(net, t, carol) // Connect Carol to Bob. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, carol, net.Bob) // Open a channel with 100k satoshis between Bob and Carol. - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointBobCarol := openChannelAndAssert( - ctxt, t, net, net.Bob, carol, + t, net, net.Bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, Private: true, @@ -1205,9 +1195,8 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { // throughout this test. We'll include a push amount since we currently // require channels to have enough remote balance to cover the invoice's // payment. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointBob := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: chanAmt / 2, @@ -1221,11 +1210,10 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { carol := net.NewNode(t.t, "Carol", nil) defer shutdownAndAssert(net, t, carol) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Alice, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: chanAmt / 2, @@ -1239,9 +1227,8 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { // that wish to stay unadvertised. ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Bob, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointBobCarol := openChannelAndAssert( - ctxt, t, net, net.Bob, carol, + t, net, net.Bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: chanAmt / 2, @@ -1257,9 +1244,8 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Alice, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointDave := openChannelAndAssert( - ctxt, t, net, net.Alice, dave, + t, net, net.Alice, dave, lntest.OpenChannelParams{ Amt: chanAmt, Private: true, @@ -1273,9 +1259,8 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { eve := net.NewNode(t.t, "Eve", nil) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Alice, eve) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointEve := openChannelAndAssert( - ctxt, t, net, net.Alice, eve, + t, net, net.Alice, eve, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: chanAmt / 2, @@ -1406,16 +1391,15 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) // First, we'll open a private channel between Alice and Bob with Alice // being the funder. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, Private: true, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) if err != nil { t.Fatalf("alice didn't see the channel alice <-> bob before "+ @@ -1445,9 +1429,8 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, net.Bob, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointBob := openChannelAndAssert( - ctxt, t, net, net.Bob, carol, + t, net, net.Bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1492,9 +1475,8 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, Private: true, @@ -1612,9 +1594,8 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) { var networkChans []*lnrpc.ChannelPoint // Open a channel between Alice and Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1625,14 +1606,13 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) { carol := net.NewNode(t.t, "Carol", nil) defer shutdownAndAssert(net, t, carol) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, carol, net.Bob) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointBob := openChannelAndAssert( - ctxt, t, net, net.Bob, carol, + t, net, net.Bob, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1648,9 +1628,8 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1904,9 +1883,8 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) { const chanAmt = btcutil.Amount(100000) // Open a channel between Alice and Bob. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAliceBob := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1917,14 +1895,13 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) { carol := net.NewNode(t.t, "Carol", nil) defer shutdownAndAssert(net, t, carol) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, carol, net.Alice) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointAliceCarol := openChannelAndAssert( - ctxt, t, net, net.Alice, carol, + t, net, net.Alice, carol, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1937,9 +1914,8 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, dave, net.Bob) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointBobDave := openChannelAndAssert( - ctxt, t, net, net.Bob, dave, + t, net, net.Bob, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -1948,9 +1924,8 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel between Carol and Dave. ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, carol, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarolDave := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, }, diff --git a/lntest/itest/lnd_single_hop_invoice_test.go b/lntest/itest/lnd_single_hop_invoice_test.go index 1602c832a..8e8c79d01 100644 --- a/lntest/itest/lnd_single_hop_invoice_test.go +++ b/lntest/itest/lnd_single_hop_invoice_test.go @@ -23,10 +23,9 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 100k satoshis between Alice and Bob with Alice being // the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanAmt := btcutil.Amount(100000) chanPoint := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, }, @@ -49,7 +48,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice to recognize and advertise the new channel generated // above. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) if err != nil { t.Fatalf("alice didn't advertise channel before "+ diff --git a/lntest/itest/lnd_switch_test.go b/lntest/itest/lnd_switch_test.go index f2038af12..a7e556dca 100644 --- a/lntest/itest/lnd_switch_test.go +++ b/lntest/itest/lnd_switch_test.go @@ -29,9 +29,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -58,14 +57,13 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { dave := net.NewNode(t.t, "Dave", nil) defer shutdownAndAssert(net, t, dave) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, dave, net.Alice) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointDave := openChannelAndAssert( - ctxt, t, net, dave, net.Alice, + t, net, dave, net.Alice, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -92,9 +90,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -320,9 +317,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -349,14 +345,13 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { dave := net.NewNode(t.t, "Dave", nil) defer shutdownAndAssert(net, t, dave) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, dave, net.Alice) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointDave := openChannelAndAssert( - ctxt, t, net, dave, net.Alice, + t, net, dave, net.Alice, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -383,9 +378,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -638,9 +632,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -667,14 +660,13 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness dave := net.NewNode(t.t, "Dave", nil) defer shutdownAndAssert(net, t, dave) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, dave, net.Alice) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointDave := openChannelAndAssert( - ctxt, t, net, dave, net.Alice, + t, net, dave, net.Alice, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -702,9 +694,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -942,9 +933,8 @@ func testSwitchOfflineDeliveryOutgoingOffline( // Open a channel with 100k satoshis between Alice and Bob with Alice // being the sole funder of the channel. - ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) chanPointAlice := openChannelAndAssert( - ctxt, t, net, net.Alice, net.Bob, + t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -971,14 +961,13 @@ func testSwitchOfflineDeliveryOutgoingOffline( dave := net.NewNode(t.t, "Dave", nil) defer shutdownAndAssert(net, t, dave) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ctxt, t.t, dave, net.Alice) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointDave := openChannelAndAssert( - ctxt, t, net, dave, net.Alice, + t, net, dave, net.Alice, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, @@ -1003,9 +992,8 @@ func testSwitchOfflineDeliveryOutgoingOffline( ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) - ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) chanPointCarol := openChannelAndAssert( - ctxt, t, net, carol, dave, + t, net, carol, dave, lntest.OpenChannelParams{ Amt: chanAmt, PushAmt: pushAmt, diff --git a/lntest/itest/lnd_wumbo_channels_test.go b/lntest/itest/lnd_wumbo_channels_test.go index c926ab001..61902d621 100644 --- a/lntest/itest/lnd_wumbo_channels_test.go +++ b/lntest/itest/lnd_wumbo_channels_test.go @@ -63,7 +63,7 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) { // Creating a wumbo channel between these two nodes should succeed. net.EnsureConnected(ctxb, t.t, wumboNode, wumboNode2) chanPoint := openChannelAndAssert( - ctxb, t, net, wumboNode, wumboNode2, + t, net, wumboNode, wumboNode2, lntest.OpenChannelParams{ Amt: chanAmt, },