From 26ed64fa521fe40d76dff18308c4d31fe7a888bb Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 14 Sep 2021 18:40:02 +0800 Subject: [PATCH] itest: manage context within HarnessNode This commit removes the context as a param needed when calling methods of HarnessNode. This change moves the context management inside HarnessNode, aside from saving us a few lines, it makes the context creation/timeout less error-prone. --- lntest/harness.go | 32 ++++------ lntest/itest/assertions.go | 6 +- lntest/itest/lnd_amp_test.go | 6 +- lntest/itest/lnd_channel_backup_test.go | 11 ++-- lntest/itest/lnd_channel_balance_test.go | 16 ++--- lntest/itest/lnd_channel_force_close_test.go | 8 +-- lntest/itest/lnd_channel_graph_test.go | 11 +--- lntest/itest/lnd_channel_policy_test.go | 29 +++------ lntest/itest/lnd_etcd_failover_test.go | 3 +- lntest/itest/lnd_forward_interceptor_test.go | 5 +- lntest/itest/lnd_funding_test.go | 15 ++--- lntest/itest/lnd_hold_invoice_force_test.go | 8 +-- lntest/itest/lnd_hold_persistence_test.go | 14 ++--- lntest/itest/lnd_macaroons_test.go | 3 +- lntest/itest/lnd_max_htlcs_test.go | 8 +-- lntest/itest/lnd_misc_test.go | 35 ++++------- lntest/itest/lnd_mpp_test.go | 5 +- .../lnd_multi-hop-error-propagation_test.go | 10 ++-- lntest/itest/lnd_multi-hop-payments_test.go | 9 +-- lntest/itest/lnd_multi-hop_test.go | 17 ++---- lntest/itest/lnd_onchain_test.go | 6 +- lntest/itest/lnd_open_channel_test.go | 8 +-- lntest/itest/lnd_payment_test.go | 20 +++---- lntest/itest/lnd_psbt_test.go | 16 ++--- lntest/itest/lnd_revocation_test.go | 16 ++--- lntest/itest/lnd_routing_test.go | 55 ++++++----------- lntest/itest/lnd_single_hop_invoice_test.go | 7 +-- lntest/itest/lnd_switch_test.go | 51 ++++++---------- lntest/itest/lnd_wallet_import_test.go | 6 +- lntest/node.go | 59 +++++++++++-------- 30 files changed, 186 insertions(+), 309 deletions(-) diff --git a/lntest/harness.go b/lntest/harness.go index 84f61d271..a67383b6e 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -218,12 +218,10 @@ func (n *NetworkHarness) SetUp(t *testing.T, } // Now we want to wait for the nodes to catch up. - ctxt, cancel := context.WithTimeout(ctxb, DefaultTimeout) - defer cancel() - if err := n.Alice.WaitForBlockchainSync(ctxt); err != nil { + if err := n.Alice.WaitForBlockchainSync(); err != nil { return err } - if err := n.Bob.WaitForBlockchainSync(ctxt); err != nil { + if err := n.Bob.WaitForBlockchainSync(); err != nil { return err } @@ -403,7 +401,7 @@ func (n *NetworkHarness) newNodeWithSeed(name string, extraArgs []string, // Pass the init request via rpc to finish unlocking the node. This will // also initialize the macaroon-authenticated LightningClient. - response, err := node.Init(ctxb, initReq) + response, err := node.Init(initReq) if err != nil { return nil, nil, nil, err } @@ -429,8 +427,6 @@ func (n *NetworkHarness) NewNodeRemoteSigner(name string, extraArgs []string, return nil, err } - ctxb := context.Background() - // With the seed created, construct the init request to the node, // including the newly generated seed. initReq := &lnrpc.InitWalletRequest{ @@ -440,7 +436,7 @@ func (n *NetworkHarness) NewNodeRemoteSigner(name string, extraArgs []string, // Pass the init request via rpc to finish unlocking the node. This will // also initialize the macaroon-authenticated LightningClient. - _, err = node.Init(ctxb, initReq) + _, err = node.Init(initReq) if err != nil { return nil, err } @@ -478,7 +474,7 @@ func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string, ChannelBackups: chanBackups, } - _, err = node.Init(context.Background(), initReq) + _, err = node.Init(initReq) if err != nil { return nil, err } @@ -828,15 +824,13 @@ func (n *NetworkHarness) RestartNode(node *HarnessNode, callback func() error, unlockReq.RecoveryWindow = 1000 } - if err := node.Unlock(context.Background(), unlockReq); err != nil { + if err := node.Unlock(unlockReq); err != nil { return err } - // Give the node some time to catch up with the chain before we continue - // with the tests. - ctxc, done := context.WithTimeout(context.Background(), DefaultTimeout) - defer done() - return node.WaitForBlockchainSync(ctxc) + // Give the node some time to catch up with the chain before we + // continue with the tests. + return node.WaitForBlockchainSync() } // RestartNodeNoUnlock attempts to restart a lightning node by shutting it down @@ -1057,10 +1051,10 @@ func (n *NetworkHarness) OpenChannel(srcNode, destNode *HarnessNode, // Otherwise, we may run into a check within the funding manager that // prevents any funding workflows from being kicked off if the chain // isn't yet synced. - if err := srcNode.WaitForBlockchainSync(ctx); err != nil { + if err := srcNode.WaitForBlockchainSync(); err != nil { return nil, fmt.Errorf("unable to sync srcNode chain: %v", err) } - if err := destNode.WaitForBlockchainSync(ctx); err != nil { + if err := destNode.WaitForBlockchainSync(); err != nil { return nil, fmt.Errorf("unable to sync destNode chain: %v", err) } @@ -1133,10 +1127,10 @@ func (n *NetworkHarness) OpenPendingChannel(srcNode, destNode *HarnessNode, defer cancel() // Wait until srcNode and destNode have blockchain synced - if err := srcNode.WaitForBlockchainSync(ctx); err != nil { + if err := srcNode.WaitForBlockchainSync(); err != nil { return nil, fmt.Errorf("unable to sync srcNode chain: %v", err) } - if err := destNode.WaitForBlockchainSync(ctx); err != nil { + if err := destNode.WaitForBlockchainSync(); err != nil { return nil, fmt.Errorf("unable to sync destNode chain: %v", err) } diff --git a/lntest/itest/assertions.go b/lntest/itest/assertions.go index 071b07c48..822508d5a 100644 --- a/lntest/itest/assertions.go +++ b/lntest/itest/assertions.go @@ -1783,13 +1783,9 @@ func assertChannelPolicyUpdate(t *testing.T, node *lntest.HarnessNode, advertisingNode string, policy *lnrpc.RoutingPolicy, chanPoint *lnrpc.ChannelPoint, includeUnannounced bool) { - ctxb := context.Background() - ctxt, cancel := context.WithTimeout(ctxb, lntest.DefaultTimeout) - defer cancel() - require.NoError( t, node.WaitForChannelPolicyUpdate( - ctxt, advertisingNode, policy, + advertisingNode, policy, chanPoint, includeUnannounced, ), "error while waiting for channel update", ) diff --git a/lntest/itest/lnd_amp_test.go b/lntest/itest/lnd_amp_test.go index 756819182..e5bbea0fc 100644 --- a/lntest/itest/lnd_amp_test.go +++ b/lntest/itest/lnd_amp_test.go @@ -245,11 +245,9 @@ func testSendPaymentAMPInvoiceRepeat(net *lntest.NetworkHarness, Amt: chanAmt, }, ) - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "carol didn't report channel") - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = dave.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "dave didn't report channel") // Create an AMP invoice of a trivial amount, that we'll pay repeatedly diff --git a/lntest/itest/lnd_channel_backup_test.go b/lntest/itest/lnd_channel_backup_test.go index 3aa355b2c..e9a7414a9 100644 --- a/lntest/itest/lnd_channel_backup_test.go +++ b/lntest/itest/lnd_channel_backup_test.go @@ -982,12 +982,11 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness, ) // Wait for both sides to see the opened channel. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = dave.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("dave didn't report channel: %v", err) } - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("carol didn't report channel: %v", err) } @@ -1327,11 +1326,9 @@ func createLegacyRevocationChannel(net *lntest.NetworkHarness, t *harnessTest, } _ = mineBlocks(t, net, 6, 1) - ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - err = from.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = from.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) - err = to.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = to.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) } diff --git a/lntest/itest/lnd_channel_balance_test.go b/lntest/itest/lnd_channel_balance_test.go index d49a27609..8f3f95254 100644 --- a/lntest/itest/lnd_channel_balance_test.go +++ b/lntest/itest/lnd_channel_balance_test.go @@ -18,8 +18,6 @@ import ( // testChannelBalance creates a new channel between Alice and Bob, then checks // channel balance to be equal amount specified while creation of channel. func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) { - ctxb := context.Background() - // Open a channel with 0.16 BTC between Alice and Bob, ensuring the // channel has been opened properly. amount := funding.MaxBtcFundingAmount @@ -61,14 +59,12 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) { ) // Wait for both Alice and Bob to recognize this new channel. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err := net.Alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't advertise channel before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Bob.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("bob didn't advertise channel before "+ "timeout: %v", err) @@ -155,15 +151,13 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice and Carol to receive the channel edge from the // funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) + err := net.Alice.WaitForNetworkChannelOpen(chanPointAlice) if err != nil { t.Fatalf("alice didn't see the alice->carol channel before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointAlice) + err = carol.WaitForNetworkChannelOpen(chanPointAlice) if err != nil { t.Fatalf("alice didn't see the alice->carol channel before "+ "timeout: %v", err) @@ -191,7 +185,7 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) { errChan := make(chan error) for i := 0; i < numInvoices; i++ { go func() { - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) _, err := net.Alice.RouterClient.SendPaymentV2(ctxt, &routerrpc.SendPaymentRequest{ Dest: carolPubKey, diff --git a/lntest/itest/lnd_channel_force_close_test.go b/lntest/itest/lnd_channel_force_close_test.go index 7225c4a2c..9c0069e18 100644 --- a/lntest/itest/lnd_channel_force_close_test.go +++ b/lntest/itest/lnd_channel_force_close_test.go @@ -335,13 +335,12 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, // Wait for Alice and Carol to receive the channel edge from the // funding manager. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't see the alice->carol channel before "+ "timeout: %v", err) } - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't see the alice->carol channel before "+ "timeout: %v", err) @@ -1430,8 +1429,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) { carolPayReqs := []string{resp.PaymentRequest} // Wait for Alice to receive the channel edge from the funding manager. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't see the alice->carol channel before "+ "timeout: %v", err) diff --git a/lntest/itest/lnd_channel_graph_test.go b/lntest/itest/lnd_channel_graph_test.go index 747f018fd..3df424ce6 100644 --- a/lntest/itest/lnd_channel_graph_test.go +++ b/lntest/itest/lnd_channel_graph_test.go @@ -58,12 +58,10 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice and Bob to receive the channel edge from the // funding manager. - ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err := alice.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "alice didn't see the alice->bob channel") - err = bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = bob.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "bob didn't see the alice->bob channel") // Launch a node for Carol which will connect to Alice and Bob in order @@ -83,12 +81,9 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) { assertChannelUpdate := func(node *lntest.HarnessNode, policy *lnrpc.RoutingPolicy) { - ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - require.NoError( t.t, carol.WaitForChannelPolicyUpdate( - ctxt, node.PubKeyStr, policy, chanPoint, false, + node.PubKeyStr, policy, chanPoint, false, ), "error while waiting for channel update", ) } diff --git a/lntest/itest/lnd_channel_policy_test.go b/lntest/itest/lnd_channel_policy_test.go index 3bdadf86c..b716ade25 100644 --- a/lntest/itest/lnd_channel_policy_test.go +++ b/lntest/itest/lnd_channel_policy_test.go @@ -85,12 +85,11 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { ) } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err := net.Alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't report channel: %v", err) } - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Bob.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("bob didn't report channel: %v", err) } @@ -163,18 +162,15 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { ) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint2) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint2) if err != nil { t.Fatalf("alice didn't report channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint2) + err = net.Bob.WaitForNetworkChannelOpen(chanPoint2) if err != nil { t.Fatalf("bob didn't report channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint2) + err = carol.WaitForNetworkChannelOpen(chanPoint2) if err != nil { t.Fatalf("carol didn't report channel: %v", err) } @@ -187,7 +183,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { Memo: "testing", Value: int64(payAmt), } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) resp, err := carol.AddInvoice(ctxt, invoice) if err != nil { t.Fatalf("unable to add invoice: %v", err) @@ -387,13 +383,11 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { ) defer closeChannelAndAssert(t, net, net.Alice, chanPoint3, false) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint3) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint3) if err != nil { t.Fatalf("alice didn't report channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint3) + err = carol.WaitForNetworkChannelOpen(chanPoint3) if err != nil { t.Fatalf("bob didn't report channel: %v", err) } @@ -505,8 +499,6 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { // flag set is sent once a channel has been either unilaterally or cooperatively // closed. func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) { - ctxb := context.Background() - const ( chanAmt = 100000 ) @@ -588,12 +580,9 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) { assertPolicyUpdate := func(node *lntest.HarnessNode, policy *lnrpc.RoutingPolicy, chanPoint *lnrpc.ChannelPoint) { - ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - require.NoError( t.t, dave.WaitForChannelPolicyUpdate( - ctxt, node.PubKeyStr, policy, chanPoint, false, + node.PubKeyStr, policy, chanPoint, false, ), "error while waiting for channel update", ) } diff --git a/lntest/itest/lnd_etcd_failover_test.go b/lntest/itest/lnd_etcd_failover_test.go index 9d6caceb7..53718aa13 100644 --- a/lntest/itest/lnd_etcd_failover_test.go +++ b/lntest/itest/lnd_etcd_failover_test.go @@ -161,8 +161,7 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest, assertLeader(ht, observer, "Carol-2") - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol2.Unlock(ctxt, &lnrpc.UnlockWalletRequest{ + err = carol2.Unlock(&lnrpc.UnlockWalletRequest{ WalletPassword: password, }) if err != nil { diff --git a/lntest/itest/lnd_forward_interceptor_test.go b/lntest/itest/lnd_forward_interceptor_test.go index 035576594..c24c25ac2 100644 --- a/lntest/itest/lnd_forward_interceptor_test.go +++ b/lntest/itest/lnd_forward_interceptor_test.go @@ -534,8 +534,6 @@ func (c *interceptorTestContext) closeChannels() { } func (c *interceptorTestContext) waitForChannels() { - ctxb := context.Background() - // Wait for all nodes to have seen all channels. for _, chanPoint := range c.networkChans { for _, node := range c.nodes { @@ -547,8 +545,7 @@ func (c *interceptorTestContext) waitForChannels() { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) require.NoError(c.t.t, err, fmt.Sprintf("(%d): timeout "+ "waiting for channel(%s) open", node.NodeID, point)) diff --git a/lntest/itest/lnd_funding_test.go b/lntest/itest/lnd_funding_test.go index 8c8cda653..49dae9246 100644 --- a/lntest/itest/lnd_funding_test.go +++ b/lntest/itest/lnd_funding_test.go @@ -196,7 +196,6 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness, // open or an error occurs in the funding process. A series of // assertions will be executed to ensure the funding process completed // successfully. - ctxb := context.Background() chanPoint := openChannelAndAssert( t, net, alice, bob, lntest.OpenChannelParams{ @@ -207,12 +206,10 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness, }, ) - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - - err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err := alice.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "alice didn't report channel") - err = bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = bob.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "bob didn't report channel") cType, err := channelCommitType(alice, chanPoint) @@ -816,13 +813,11 @@ func testBatchChanFunding(net *lntest.NetworkHarness, t *harnessTest) { block := mineBlocks(t, net, 6, 1)[0] assertTxInBlock(t, block, txHash) - ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint1) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint1) require.NoError(t.t, err) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint2) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint2) require.NoError(t.t, err) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint3) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint3) require.NoError(t.t, err) // With the channel open, ensure that it is counted towards Carol's diff --git a/lntest/itest/lnd_hold_invoice_force_test.go b/lntest/itest/lnd_hold_invoice_force_test.go index 78b5bde5c..b8b176246 100644 --- a/lntest/itest/lnd_hold_invoice_force_test.go +++ b/lntest/itest/lnd_hold_invoice_force_test.go @@ -74,8 +74,8 @@ func testHoldInvoiceForceClose(net *lntest.NetworkHarness, t *harnessTest) { require.Len(t.t, chans.Channels[0].PendingHtlcs, 1) activeHtlc := chans.Channels[0].PendingHtlcs[0] - require.NoError(t.t, net.Alice.WaitForBlockchainSync(ctxb)) - require.NoError(t.t, net.Bob.WaitForBlockchainSync(ctxb)) + require.NoError(t.t, net.Alice.WaitForBlockchainSync()) + require.NoError(t.t, net.Bob.WaitForBlockchainSync()) info, err := net.Alice.GetInfo(ctxb, &lnrpc.GetInfoRequest{}) require.NoError(t.t, err) @@ -99,8 +99,8 @@ func testHoldInvoiceForceClose(net *lntest.NetworkHarness, t *harnessTest) { mineBlocksSlow(t, net, blocksTillForce, 0) - require.NoError(t.t, net.Alice.WaitForBlockchainSync(ctxb)) - require.NoError(t.t, net.Bob.WaitForBlockchainSync(ctxb)) + require.NoError(t.t, net.Alice.WaitForBlockchainSync()) + require.NoError(t.t, net.Bob.WaitForBlockchainSync()) // Our channel should not have been force closed, instead we expect our // channel to still be open and our invoice to have been canceled before diff --git a/lntest/itest/lnd_hold_persistence_test.go b/lntest/itest/lnd_hold_persistence_test.go index a9b570a03..e92086ca5 100644 --- a/lntest/itest/lnd_hold_persistence_test.go +++ b/lntest/itest/lnd_hold_persistence_test.go @@ -48,15 +48,13 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice and Carol to receive the channel edge from the // funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) + err := net.Alice.WaitForNetworkChannelOpen(chanPointAlice) if err != nil { t.Fatalf("alice didn't see the alice->carol channel before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointAlice) + err = carol.WaitForNetworkChannelOpen(chanPointAlice) if err != nil { t.Fatalf("carol didn't see the carol->alice channel before "+ "timeout: %v", err) @@ -92,7 +90,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { Hash: payHash[:], Private: true, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) resp, err := carol.AddHoldInvoice(ctxt, invoiceReq) if err != nil { t.Fatalf("unable to add invoice: %v", err) @@ -165,7 +163,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { req := &lnrpc.ListPaymentsRequest{ IncludeIncomplete: true, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) paymentsResp, err := net.Alice.ListPayments(ctxt, req) if err != nil { return fmt.Errorf("error when obtaining payments: %v", @@ -299,7 +297,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { for i, preimage := range preimages { var expectedState lnrpc.Invoice_InvoiceState - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) if i%2 == 0 { settle := &invoicesrpc.SettleInvoiceMsg{ Preimage: preimage[:], @@ -368,7 +366,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { req := &lnrpc.ListPaymentsRequest{ IncludeIncomplete: true, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) paymentsResp, err := net.Alice.ListPayments(ctxt, req) if err != nil { t.Fatalf("error when obtaining Alice payments: %v", err) diff --git a/lntest/itest/lnd_macaroons_test.go b/lntest/itest/lnd_macaroons_test.go index 9ea4552ae..22ae852ba 100644 --- a/lntest/itest/lnd_macaroons_test.go +++ b/lntest/itest/lnd_macaroons_test.go @@ -665,8 +665,7 @@ func testStatelessInit(net *lntest.NetworkHarness, t *harnessTest) { NewPassword: newPw, StatelessInit: true, } - ctxb := context.Background() - response, err := carol.InitChangePassword(ctxb, changePwReq) + response, err := carol.InitChangePassword(changePwReq) require.NoError(t.t, err) // Again, make sure no macaroon files have been created by the node diff --git a/lntest/itest/lnd_max_htlcs_test.go b/lntest/itest/lnd_max_htlcs_test.go index a6dff646e..9f5218cac 100644 --- a/lntest/itest/lnd_max_htlcs_test.go +++ b/lntest/itest/lnd_max_htlcs_test.go @@ -34,12 +34,10 @@ 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) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err := net.Alice.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "alice does not have open channel") - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Bob.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "bob does not have open channel") // Alice and bob should have one channel open with each other now. @@ -87,7 +85,7 @@ func testMaxHtlcPathfind(net *lntest.NetworkHarness, t *harnessTest) { // Now, we're going to try to send another payment from Bob -> Alice. // We've hit our max remote htlcs, so we expect this payment to spin // out dramatically with pathfinding. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) payment, err := net.Bob.RouterClient.SendPaymentV2( ctxt, &routerrpc.SendPaymentRequest{ Amt: 1000, diff --git a/lntest/itest/lnd_misc_test.go b/lntest/itest/lnd_misc_test.go index d90e64b40..1f3873125 100644 --- a/lntest/itest/lnd_misc_test.go +++ b/lntest/itest/lnd_misc_test.go @@ -236,23 +236,22 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) { } // Wait for all channels to be recognized and advertized. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't advertise channel before "+ "timeout: %v", err) } - err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = dave.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("bob didn't advertise channel before "+ "timeout: %v", err) } - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointFC) + err = carol.WaitForNetworkChannelOpen(chanPointFC) if err != nil { t.Fatalf("alice didn't advertise channel before "+ "timeout: %v", err) } - err = fred.WaitForNetworkChannelOpen(ctxt, chanPointFC) + err = fred.WaitForNetworkChannelOpen(chanPointFC) if err != nil { t.Fatalf("bob didn't advertise channel before "+ "timeout: %v", err) @@ -386,15 +385,13 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice and Bob to receive the channel edge from the // funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err := alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't see the alice->bob channel before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = bob.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("bob didn't see the bob->alice channel before "+ "timeout: %v", err) @@ -407,8 +404,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { // Get the ListChannel response from Alice. listReq := &lnrpc.ListChannelsRequest{} - ctxb = context.Background() - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) resp, err := alice.ListChannels(ctxt, listReq) if err != nil { t.Fatalf("unable to query for %s's channel list: %v", @@ -484,8 +480,6 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { // max pending channel number was exceeded and that '--maxpendingchannels' flag // exists and works properly. func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) { - ctxb := context.Background() - maxPendingChannels := lncfg.DefaultMaxPendingChannels + 1 amount := funding.MaxBtcFundingAmount @@ -557,8 +551,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) { // Ensure that the funding transaction enters a block, and is // properly advertised by Alice. assertTxInBlock(t, block, fundingTxID) - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, fundingChanPoint) + err = net.Alice.WaitForNetworkChannelOpen(fundingChanPoint) if err != nil { t.Fatalf("channel not seen on network before "+ "timeout: %v", err) @@ -878,8 +871,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Carol to receive the channel edge from the funding // manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("carol didn't see the carol->%s channel "+ "before timeout: %v", node.Name(), err) @@ -975,7 +967,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) { } balReq := &lnrpc.WalletBalanceRequest{} - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) balResp, err := node.WalletBalance(ctxt, balReq) if err != nil { t.Fatalf("unable to get dave's balance: %v", err) @@ -1352,16 +1344,15 @@ func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) { chanPointStr := fmt.Sprintf("%v:%v", txid, chanPoint.OutputIndex) // Wait for channel to be confirmed open. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "alice wait for network channel open") - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Bob.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err, "bob wait for network channel open") // Now that the channel is open, we'll obtain its channel ID real quick // so we can use it to query the graph below. listReq := &lnrpc.ListChannelsRequest{} - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) aliceChannelList, err := net.Alice.ListChannels(ctxt, listReq) require.NoError(t.t, err) var chanID uint64 diff --git a/lntest/itest/lnd_mpp_test.go b/lntest/itest/lnd_mpp_test.go index 7c51e66f2..80ddaedd7 100644 --- a/lntest/itest/lnd_mpp_test.go +++ b/lntest/itest/lnd_mpp_test.go @@ -319,8 +319,6 @@ func (c *mppTestContext) shutdownNodes() { } func (c *mppTestContext) waitForChannels() { - ctxb := context.Background() - // Wait for all nodes to have seen all channels. for _, chanPoint := range c.networkChans { for _, node := range c.nodes { @@ -333,8 +331,7 @@ func (c *mppTestContext) waitForChannels() { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { c.t.Fatalf("(%v:%d): timeout waiting for "+ "channel(%s) open: %v", diff --git a/lntest/itest/lnd_multi-hop-error-propagation_test.go b/lntest/itest/lnd_multi-hop-error-propagation_test.go index 3e01628fd..64951753f 100644 --- a/lntest/itest/lnd_multi-hop-error-propagation_test.go +++ b/lntest/itest/lnd_multi-hop-error-propagation_test.go @@ -29,8 +29,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) { Amt: chanAmt, }, ) - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - if err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice); err != nil { + if err := net.Alice.WaitForNetworkChannelOpen(chanPointAlice); err != nil { t.Fatalf("channel not seen by alice before timeout: %v", err) } @@ -115,7 +114,7 @@ out: for { select { case <-checkTableTicker.C: - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) _, err := net.Alice.GetNodeInfo(ctxt, nodeInfoReq) if err != nil && strings.Contains(err.Error(), "unable to find") { @@ -138,7 +137,7 @@ out: Memo: "kek99", Value: payAmt, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) carolInvoice, err := carol.AddInvoice(ctxt, invoiceReq) if err != nil { t.Fatalf("unable to generate carol invoice: %v", err) @@ -154,8 +153,7 @@ out: // Before we send the payment, ensure that the announcement of the new // channel has been processed by Alice. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - if err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointBob); err != nil { + if err := net.Alice.WaitForNetworkChannelOpen(chanPointBob); err != nil { t.Fatalf("channel not seen by alice before timeout: %v", err) } diff --git a/lntest/itest/lnd_multi-hop-payments_test.go b/lntest/itest/lnd_multi-hop-payments_test.go index d1b578dc4..f282d9d95 100644 --- a/lntest/itest/lnd_multi-hop-payments_test.go +++ b/lntest/itest/lnd_multi-hop-payments_test.go @@ -107,8 +107,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -130,13 +129,11 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { // We'll wait for all parties to recognize the new channels within the // network. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) + err = dave.WaitForNetworkChannelOpen(chanPointDave) if err != nil { t.Fatalf("dave didn't advertise his channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = carol.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("carol didn't advertise her channel in time: %v", err) diff --git a/lntest/itest/lnd_multi-hop_test.go b/lntest/itest/lnd_multi-hop_test.go index a2b11ab8a..416f1d5ad 100644 --- a/lntest/itest/lnd_multi-hop_test.go +++ b/lntest/itest/lnd_multi-hop_test.go @@ -210,8 +210,6 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode, carolHodl bool, c lnrpc.CommitmentType) ( *lnrpc.ChannelPoint, *lnrpc.ChannelPoint, *lntest.HarnessNode) { - ctxb := context.Background() - net.EnsureConnected(t.t, alice, bob) // Make sure there are enough utxos for anchoring. @@ -242,14 +240,12 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness, }, ) - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := alice.WaitForNetworkChannelOpen(ctxt, aliceChanPoint) + err := alice.WaitForNetworkChannelOpen(aliceChanPoint) if err != nil { t.Fatalf("alice didn't report channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = bob.WaitForNetworkChannelOpen(ctxt, aliceChanPoint) + err = bob.WaitForNetworkChannelOpen(aliceChanPoint) if err != nil { t.Fatalf("bob didn't report channel: %v", err) } @@ -289,18 +285,15 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness, FundingShim: bobFundingShim, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = bob.WaitForNetworkChannelOpen(ctxt, bobChanPoint) + err = bob.WaitForNetworkChannelOpen(bobChanPoint) if err != nil { t.Fatalf("alice didn't report channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, bobChanPoint) + err = carol.WaitForNetworkChannelOpen(bobChanPoint) if err != nil { t.Fatalf("bob didn't report channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = alice.WaitForNetworkChannelOpen(ctxt, bobChanPoint) + err = alice.WaitForNetworkChannelOpen(bobChanPoint) if err != nil { t.Fatalf("bob didn't report channel: %v", err) } diff --git a/lntest/itest/lnd_onchain_test.go b/lntest/itest/lnd_onchain_test.go index cfae6921d..1e6f3cb63 100644 --- a/lntest/itest/lnd_onchain_test.go +++ b/lntest/itest/lnd_onchain_test.go @@ -237,12 +237,10 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) { aliceChanPoint1, aliceChanPoint2, aliceChanPoint3, } for _, chanPoint := range chanPoints { - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = alice.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = bob.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) } diff --git a/lntest/itest/lnd_open_channel_test.go b/lntest/itest/lnd_open_channel_test.go index 2864558c2..52ae84a00 100644 --- a/lntest/itest/lnd_open_channel_test.go +++ b/lntest/itest/lnd_open_channel_test.go @@ -142,14 +142,12 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice and Bob to recognize and advertise the new channel // generated above. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't advertise channel before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Bob.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("bob didn't advertise channel before "+ "timeout: %v", err) @@ -159,7 +157,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) { req := &lnrpc.ChannelGraphRequest{ IncludeUnannounced: true, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) chanGraph, err := net.Alice.DescribeGraph(ctxt, req) if err != nil { t.Fatalf("unable to query for alice's routing table: %v", err) diff --git a/lntest/itest/lnd_payment_test.go b/lntest/itest/lnd_payment_test.go index aef6158c0..74afab2b4 100644 --- a/lntest/itest/lnd_payment_test.go +++ b/lntest/itest/lnd_payment_test.go @@ -69,12 +69,11 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice to recognize and advertise the new channel generated // above. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - if err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint); err != nil { + if err = net.Alice.WaitForNetworkChannelOpen(chanPoint); err != nil { t.Fatalf("alice didn't advertise channel before "+ "timeout: %v", err) } - if err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint); err != nil { + if err = net.Bob.WaitForNetworkChannelOpen(chanPoint); err != nil { t.Fatalf("bob didn't advertise channel before "+ "timeout: %v", err) } @@ -292,8 +291,7 @@ func runAsyncPayments(net *lntest.NetworkHarness, t *harnessTest, alice, } // Wait for Alice to receive the channel edge from the funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't see the alice->bob channel before "+ "timeout: %v", err) @@ -307,7 +305,7 @@ func runAsyncPayments(net *lntest.NetworkHarness, t *harnessTest, alice, for i := 0; i < numInvoices; i++ { payReq := bobPayReqs[i] go func() { - ctxt, _ = context.WithTimeout(ctxb, lntest.AsyncBenchmarkTimeout) + ctxt, _ := context.WithTimeout(ctxb, lntest.AsyncBenchmarkTimeout) stream, err := alice.RouterClient.SendPaymentV2( ctxt, &routerrpc.SendPaymentRequest{ @@ -465,12 +463,11 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) } // Wait for Alice to receive the channel edge from the funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - if err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint); err != nil { + if err = net.Alice.WaitForNetworkChannelOpen(chanPoint); err != nil { t.Fatalf("alice didn't see the alice->bob channel before "+ "timeout: %v", err) } - if err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint); err != nil { + if err = net.Bob.WaitForNetworkChannelOpen(chanPoint); err != nil { t.Fatalf("bob didn't see the bob->alice channel before "+ "timeout: %v", err) } @@ -478,7 +475,7 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) // Reset mission control to prevent previous payment results from // interfering with this test. A new channel has been opened, but // mission control operates on node pairs. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) _, err = net.Alice.RouterClient.ResetMissionControl( ctxt, &routerrpc.ResetMissionControlRequest{}, ) @@ -680,8 +677,7 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) { // Wait for the channel to be recognized by both Alice and Bob before // continuing the rest of the test. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { // TODO(roasbeef): will need to make num blocks to advertise a // node param diff --git a/lntest/itest/lnd_psbt_test.go b/lntest/itest/lnd_psbt_test.go index afdef552a..22ab54a5d 100644 --- a/lntest/itest/lnd_psbt_test.go +++ b/lntest/itest/lnd_psbt_test.go @@ -215,11 +215,9 @@ func runPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest, carol, txHash := finalTx.TxHash() block := mineBlocks(t, net, 6, 1)[0] assertTxInBlock(t, block, &txHash) - ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint2) + err = carol.WaitForNetworkChannelOpen(chanPoint2) require.NoError(t.t, err) // With the channel open, ensure that it is counted towards Carol's @@ -431,11 +429,9 @@ func testPsbtChanFundingExternal(net *lntest.NetworkHarness, t *harnessTest) { // for the new channel to be propagated through the network. block := mineBlocks(t, net, 6, 1)[0] assertTxInBlock(t, block, &txHash) - ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint2) + err = carol.WaitForNetworkChannelOpen(chanPoint2) require.NoError(t.t, err) // With the channel open, ensure that it is counted towards Carol's @@ -483,11 +479,11 @@ func openChannelPsbt(ctx context.Context, srcNode, destNode *lntest.HarnessNode, // Otherwise, we may run into a check within the funding manager that // prevents any funding workflows from being kicked off if the chain // isn't yet synced. - if err := srcNode.WaitForBlockchainSync(ctx); err != nil { + if err := srcNode.WaitForBlockchainSync(); err != nil { return nil, nil, fmt.Errorf("unable to sync srcNode chain: %v", err) } - if err := destNode.WaitForBlockchainSync(ctx); err != nil { + if err := destNode.WaitForBlockchainSync(); err != nil { return nil, nil, fmt.Errorf("unable to sync destNode chain: %v", err) } diff --git a/lntest/itest/lnd_revocation_test.go b/lntest/itest/lnd_revocation_test.go index 4846850b7..4de83d436 100644 --- a/lntest/itest/lnd_revocation_test.go +++ b/lntest/itest/lnd_revocation_test.go @@ -24,8 +24,6 @@ import ( // retribution in the event that she fails immediately after detecting Bob's // breach txn in the mempool. func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) { - ctxb := context.Background() - const ( chanAmt = funding.MaxBtcFundingAmount paymentAmt = 10000 @@ -71,8 +69,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) { } // Wait for Carol to receive the channel edge from the funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = carol.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("carol didn't see the carol->bob channel before "+ "timeout: %v", err) @@ -260,7 +257,6 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) { // commitment output has zero-value. func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness, t *harnessTest) { - ctxb := context.Background() const ( chanAmt = funding.MaxBtcFundingAmount @@ -312,8 +308,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness } // Wait for Dave to receive the channel edge from the funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = dave.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("dave didn't see the dave->carol channel before "+ "timeout: %v", err) @@ -475,7 +470,6 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness // remote party breaches before settling extended HTLCs. func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, t *harnessTest) { - ctxb := context.Background() const ( chanAmt = funding.MaxBtcFundingAmount @@ -559,8 +553,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, } // Wait for Dave to receive the channel edge from the funding manager. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = dave.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("dave didn't see the dave->carol channel before "+ "timeout: %v", err) @@ -1017,8 +1010,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase( } // Wait for Dave to receive the channel edge from the funding manager. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = dave.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("dave didn't see the dave->carol channel before "+ "timeout: %v", err) diff --git a/lntest/itest/lnd_routing_test.go b/lntest/itest/lnd_routing_test.go index 8a6d40e6c..99ba3c322 100644 --- a/lntest/itest/lnd_routing_test.go +++ b/lntest/itest/lnd_routing_test.go @@ -138,8 +138,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest, Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", node.Name(), @@ -527,8 +526,7 @@ func runMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest, Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -567,8 +565,7 @@ func runMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest, // We'll wait for all parties to recognize the new channels within the // network. - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointBob) + err = carol.WaitForNetworkChannelOpen(chanPointBob) if err != nil { t.Fatalf("bob didn't advertise his channel in time: %v", err) } @@ -647,8 +644,7 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) }, ) - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) + err := net.Alice.WaitForNetworkChannelOpen(chanPointAlice) if err != nil { t.Fatalf("alice didn't advertise her channel: %v", err) } @@ -678,8 +674,7 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) Amt: chanAmt, }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = carol.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("carol didn't advertise her channel: %v", err) } @@ -690,7 +685,7 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) PubKey: charlie.PubKeyStr, Amt: int64(1), } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) fakeRoute, err := carol.QueryRoutes(ctxt, fakeReq) if err != nil { t.Fatalf("unable get fake route: %v", err) @@ -842,8 +837,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -1142,8 +1136,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { chanPointEve, } for i, chanPoint := range aliceChans { - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err := net.Alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("timed out waiting for channel open %s: %v", chanNames[i], err) @@ -1263,14 +1256,12 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) }, ) - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) + err := net.Alice.WaitForNetworkChannelOpen(chanPointAlice) if err != nil { t.Fatalf("alice didn't see the channel alice <-> bob before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPointAlice) + err = net.Bob.WaitForNetworkChannelOpen(chanPointAlice) if err != nil { t.Fatalf("bob didn't see the channel alice <-> bob before "+ "timeout: %v", err) @@ -1299,20 +1290,17 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPointBob) + err = net.Bob.WaitForNetworkChannelOpen(chanPointBob) if err != nil { t.Fatalf("bob didn't see the channel bob <-> carol before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointBob) + err = carol.WaitForNetworkChannelOpen(chanPointBob) if err != nil { t.Fatalf("carol didn't see the channel bob <-> carol before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointBob) + err = net.Alice.WaitForNetworkChannelOpen(chanPointBob) if err != nil { t.Fatalf("alice didn't see the channel bob <-> carol before "+ "timeout: %v", err) @@ -1344,20 +1332,17 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) }, ) - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = carol.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("carol didn't see the channel carol <-> dave before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = dave.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("dave didn't see the channel carol <-> dave before "+ "timeout: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPointBob) + err = dave.WaitForNetworkChannelOpen(chanPointBob) if err != nil { t.Fatalf("dave didn't see the channel bob <-> carol before "+ "timeout: %v", err) @@ -1387,7 +1372,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) Private: true, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) resp, err := dave.AddInvoice(ctxt, invoice) if err != nil { t.Fatalf("unable to add invoice for dave: %v", err) @@ -1506,8 +1491,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -1802,8 +1786,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d) timed out waiting for "+ "channel(%s) open: %v", nodeNames[i], diff --git a/lntest/itest/lnd_single_hop_invoice_test.go b/lntest/itest/lnd_single_hop_invoice_test.go index b8a347d7c..2baf5c800 100644 --- a/lntest/itest/lnd_single_hop_invoice_test.go +++ b/lntest/itest/lnd_single_hop_invoice_test.go @@ -48,13 +48,12 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) { // Wait for Alice to recognize and advertise the new channel generated // above. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Alice.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("alice didn't advertise channel before "+ "timeout: %v", err) } - err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = net.Bob.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("bob didn't advertise channel before "+ "timeout: %v", err) @@ -78,7 +77,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) { payHash := &lnrpc.PaymentHash{ RHash: invoiceResp.RHash, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) dbInvoice, err := net.Bob.LookupInvoice(ctxt, payHash) if err != nil { t.Fatalf("unable to lookup invoice: %v", err) diff --git a/lntest/itest/lnd_switch_test.go b/lntest/itest/lnd_switch_test.go index e194101b4..4892ef543 100644 --- a/lntest/itest/lnd_switch_test.go +++ b/lntest/itest/lnd_switch_test.go @@ -118,8 +118,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -141,13 +140,11 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { // We'll wait for all parties to recognize the new channels within the // network. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) + err = dave.WaitForNetworkChannelOpen(chanPointDave) if err != nil { t.Fatalf("dave didn't advertise his channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = carol.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("carol didn't advertise her channel in time: %v", err) @@ -251,7 +248,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { Memo: "testing", Value: paymentAmt, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) resp, err := carol.AddInvoice(ctxt, finalInvoice) if err != nil { t.Fatalf("unable to add invoice: %v", err) @@ -396,8 +393,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -419,23 +415,19 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { // We'll wait for all parties to recognize the new channels within the // network. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) + err = dave.WaitForNetworkChannelOpen(chanPointDave) if err != nil { t.Fatalf("dave didn't advertise his channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = carol.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("carol didn't advertise her channel in time: %v", err) } // Make sure all nodes are fully synced before we continue. - ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) - defer cancel() for _, node := range nodes { - err := node.WaitForBlockchainSync(ctxt) + err := node.WaitForBlockchainSync() if err != nil { t.Fatalf("unable to wait for sync: %v", err) } @@ -503,10 +495,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { } // Make sure all nodes are fully synced again. - ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) - defer cancel() for _, node := range nodes { - err := node.WaitForBlockchainSync(ctxt) + err := node.WaitForBlockchainSync() if err != nil { t.Fatalf("unable to wait for sync: %v", err) } @@ -555,7 +545,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { Memo: "testing", Value: paymentAmt, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) resp, err := carol.AddInvoice(ctxt, finalInvoice) if err != nil { t.Fatalf("unable to add invoice: %v", err) @@ -702,8 +692,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -725,13 +714,11 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness // We'll wait for all parties to recognize the new channels within the // network. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) + err = dave.WaitForNetworkChannelOpen(chanPointDave) if err != nil { t.Fatalf("dave didn't advertise his channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = carol.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("carol didn't advertise her channel in time: %v", err) @@ -842,7 +829,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness Memo: "testing", Value: paymentAmt, } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) resp, err := carol.AddInvoice(ctxt, finalInvoice) if err != nil { t.Fatalf("unable to add invoice: %v", err) @@ -896,7 +883,6 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness // 5. Carol <-- Dave <-- Alice X expect settle to propagate func testSwitchOfflineDeliveryOutgoingOffline( net *lntest.NetworkHarness, t *harnessTest) { - ctxb := context.Background() const chanAmt = btcutil.Amount(1000000) const pushAmt = btcutil.Amount(900000) @@ -991,8 +977,7 @@ func testSwitchOfflineDeliveryOutgoingOffline( Index: chanPoint.OutputIndex, } - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = node.WaitForNetworkChannelOpen(chanPoint) if err != nil { t.Fatalf("%s(%d): timeout waiting for "+ "channel(%s) open: %v", nodeNames[i], @@ -1014,13 +999,11 @@ func testSwitchOfflineDeliveryOutgoingOffline( // We'll wait for all parties to recognize the new channels within the // network. - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) + err = dave.WaitForNetworkChannelOpen(chanPointDave) if err != nil { t.Fatalf("dave didn't advertise his channel: %v", err) } - ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) - err = carol.WaitForNetworkChannelOpen(ctxt, chanPointCarol) + err = carol.WaitForNetworkChannelOpen(chanPointCarol) if err != nil { t.Fatalf("carol didn't advertise her channel in time: %v", err) diff --git a/lntest/itest/lnd_wallet_import_test.go b/lntest/itest/lnd_wallet_import_test.go index db898282d..468dea8df 100644 --- a/lntest/itest/lnd_wallet_import_test.go +++ b/lntest/itest/lnd_wallet_import_test.go @@ -496,11 +496,9 @@ func fundChanAndCloseFromImportedAccount(t *harnessTest, srcNode, destNode, }, OutputIndex: upd.ChanPending.OutputIndex, } - ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) - defer cancel() - err = srcNode.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = srcNode.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) - err = destNode.WaitForNetworkChannelOpen(ctxt, chanPoint) + err = destNode.WaitForNetworkChannelOpen(chanPoint) require.NoError(t.t, err) // Send a test payment to ensure the channel is operating as normal. diff --git a/lntest/node.go b/lntest/node.go index c3e82748b..87095b971 100644 --- a/lntest/node.go +++ b/lntest/node.go @@ -924,13 +924,13 @@ func (hn *HarnessNode) initClientWhenReady(timeout time.Duration) error { // Init initializes a harness node by passing the init request via rpc. After // the request is submitted, this method will block until a -// macaroon-authenticated RPC connection can be established to the harness node. -// Once established, the new connection is used to initialize the +// macaroon-authenticated RPC connection can be established to the harness +// node. Once established, the new connection is used to initialize the // LightningClient and subscribes the HarnessNode to topology changes. -func (hn *HarnessNode) Init(ctx context.Context, +func (hn *HarnessNode) Init( initReq *lnrpc.InitWalletRequest) (*lnrpc.InitWalletResponse, error) { - ctxt, cancel := context.WithTimeout(ctx, DefaultTimeout) + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) defer cancel() response, err := hn.InitWallet(ctxt, initReq) if err != nil { @@ -969,11 +969,11 @@ func (hn *HarnessNode) Init(ctx context.Context, // a macaroon-authenticated RPC connection can be established to the harness // node. Once established, the new connection is used to initialize the // LightningClient and subscribes the HarnessNode to topology changes. -func (hn *HarnessNode) InitChangePassword(ctx context.Context, +func (hn *HarnessNode) InitChangePassword( chngPwReq *lnrpc.ChangePasswordRequest) (*lnrpc.ChangePasswordResponse, error) { - ctxt, cancel := context.WithTimeout(ctx, DefaultTimeout) + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) defer cancel() response, err := hn.ChangePassword(ctxt, chngPwReq) if err != nil { @@ -1011,10 +1011,9 @@ func (hn *HarnessNode) InitChangePassword(ctx context.Context, // should be called after the restart of a HarnessNode that was created with a // seed+password. Once this method returns, the HarnessNode will be ready to // accept normal gRPC requests and harness command. -func (hn *HarnessNode) Unlock(ctx context.Context, - unlockReq *lnrpc.UnlockWalletRequest) error { - - ctxt, _ := context.WithTimeout(ctx, DefaultTimeout) +func (hn *HarnessNode) Unlock(unlockReq *lnrpc.UnlockWalletRequest) error { + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) + defer cancel() // Otherwise, we'll need to unlock the node before it's able to start // up properly. @@ -1404,12 +1403,12 @@ func getChanPointFundingTxid(chanPoint *lnrpc.ChannelPoint) ([]byte, error) { return txid, nil } -func checkChanPointInGraph(ctx context.Context, - node *HarnessNode, chanPoint wire.OutPoint) bool { +func (hn *HarnessNode) checkChanPointInGraph(chanPoint wire.OutPoint) bool { - ctxt, cancel := context.WithTimeout(ctx, DefaultTimeout) + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) defer cancel() - chanGraph, err := node.DescribeGraph(ctxt, &lnrpc.ChannelGraphRequest{}) + + chanGraph, err := hn.DescribeGraph(ctxt, &lnrpc.ChannelGraphRequest{}) if err != nil { return false } @@ -1484,9 +1483,12 @@ func (hn *HarnessNode) lightningNetworkWatcher() { // outpoint is seen as being fully advertised within the network. A channel is // considered "fully advertised" once both of its directional edges has been // advertised within the test Lightning Network. -func (hn *HarnessNode) WaitForNetworkChannelOpen(ctx context.Context, +func (hn *HarnessNode) WaitForNetworkChannelOpen( chanPoint *lnrpc.ChannelPoint) error { + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) + defer cancel() + eventChan := make(chan struct{}) op, err := MakeOutpoint(chanPoint) @@ -1504,7 +1506,7 @@ func (hn *HarnessNode) WaitForNetworkChannelOpen(ctx context.Context, select { case <-eventChan: return nil - case <-ctx.Done(): + case <-ctxt.Done(): return fmt.Errorf("channel:%s not opened before timeout: %s", op, hn) } @@ -1514,9 +1516,12 @@ func (hn *HarnessNode) WaitForNetworkChannelOpen(ctx context.Context, // outpoint is seen as closed within the network. A channel is considered // closed once a transaction spending the funding outpoint is seen within a // confirmed block. -func (hn *HarnessNode) WaitForNetworkChannelClose(ctx context.Context, +func (hn *HarnessNode) WaitForNetworkChannelClose( chanPoint *lnrpc.ChannelPoint) error { + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) + defer cancel() + eventChan := make(chan struct{}) op, err := MakeOutpoint(chanPoint) @@ -1534,7 +1539,7 @@ func (hn *HarnessNode) WaitForNetworkChannelClose(ctx context.Context, select { case <-eventChan: return nil - case <-ctx.Done(): + case <-ctxt.Done(): return fmt.Errorf("channel:%s not closed before timeout: "+ "%s", op, hn) } @@ -1542,10 +1547,13 @@ func (hn *HarnessNode) WaitForNetworkChannelClose(ctx context.Context, // WaitForChannelPolicyUpdate will block until a channel policy with the target // outpoint and advertisingNode is seen within the network. -func (hn *HarnessNode) WaitForChannelPolicyUpdate(ctx context.Context, +func (hn *HarnessNode) WaitForChannelPolicyUpdate( advertisingNode string, policy *lnrpc.RoutingPolicy, chanPoint *lnrpc.ChannelPoint, includeUnannounced bool) error { + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) + defer cancel() + eventChan := make(chan struct{}) op, err := MakeOutpoint(chanPoint) @@ -1582,7 +1590,7 @@ func (hn *HarnessNode) WaitForChannelPolicyUpdate(ctx context.Context, case <-eventChan: return nil - case <-ctx.Done(): + case <-ctxt.Done(): return fmt.Errorf("channel:%s policy not updated "+ "before timeout: [%s:%v] %s", op, advertisingNode, policy, hn.String()) @@ -1594,12 +1602,15 @@ func (hn *HarnessNode) WaitForChannelPolicyUpdate(ctx context.Context, // the blockchain. If the passed context object has a set timeout, it will // continually poll until the timeout has elapsed. In the case that the chain // isn't synced before the timeout is up, this function will return an error. -func (hn *HarnessNode) WaitForBlockchainSync(ctx context.Context) error { +func (hn *HarnessNode) WaitForBlockchainSync() error { + ctxt, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) + defer cancel() + ticker := time.NewTicker(time.Millisecond * 100) defer ticker.Stop() for { - resp, err := hn.GetInfo(ctx, &lnrpc.GetInfoRequest{}) + resp, err := hn.GetInfo(ctxt, &lnrpc.GetInfoRequest{}) if err != nil { return err } @@ -1608,7 +1619,7 @@ func (hn *HarnessNode) WaitForBlockchainSync(ctx context.Context) error { } select { - case <-ctx.Done(): + case <-ctxt.Done(): return fmt.Errorf("timeout while waiting for " + "blockchain sync") case <-hn.runCtx.Done(): @@ -1740,7 +1751,7 @@ func (hn *HarnessNode) handleOpenChannelWatchRequest(req *chanWatchRequest) { // node. This lets us handle the case where a node has already seen a // channel before a notification has been requested, causing us to miss // it. - chanFound := checkChanPointInGraph(hn.runCtx, hn, targetChan) + chanFound := hn.checkChanPointInGraph(targetChan) if chanFound { close(req.eventChan) return