From e018c02d40a5952aa0ebab84ceaad02ee19c7423 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 20 Apr 2023 06:08:15 +0800 Subject: [PATCH 1/5] itest: refactor `createThreeHopNetwork` to open channels async This will save us 6 blocks each time we call this function. --- itest/lnd_multi-hop_test.go | 60 ++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/itest/lnd_multi-hop_test.go b/itest/lnd_multi-hop_test.go index 61b5cf9fa..d45a272be 100644 --- a/itest/lnd_multi-hop_test.go +++ b/itest/lnd_multi-hop_test.go @@ -1779,31 +1779,15 @@ func createThreeHopNetwork(ht *lntest.HarnessTest, ) } - var ( - cancel context.CancelFunc - acceptStream rpc.AcceptorClient - ) - // If a zero-conf channel is being opened, the nodes are signalling the - // zero-conf feature bit. Setup a ChannelAcceptor for the fundee. - if zeroConf { - acceptStream, cancel = bob.RPC.ChannelAcceptor() - go acceptChannel(ht.T, true, acceptStream) - } - + // Prepare params for Alice. aliceParams := lntest.OpenChannelParams{ Amt: chanAmt, CommitmentType: c, FundingShim: aliceFundingShim, ZeroConf: zeroConf, } - aliceChanPoint := ht.OpenChannel(alice, bob, aliceParams) - // Remove the ChannelAcceptor for Bob. - if zeroConf { - cancel() - } - - // We'll then create a channel from Bob to Carol. After this channel is + // We'll create a channel from Bob to Carol. After this channel is // open, our topology looks like: A -> B -> C. var bobFundingShim *lnrpc.FundingShim if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE { @@ -1812,24 +1796,44 @@ func createThreeHopNetwork(ht *lntest.HarnessTest, ) } - // Setup a ChannelAcceptor for Carol if a zero-conf channel open is - // being attempted. - if zeroConf { - acceptStream, cancel = carol.RPC.ChannelAcceptor() - go acceptChannel(ht.T, true, acceptStream) - } - + // Prepare params for Bob. bobParams := lntest.OpenChannelParams{ Amt: chanAmt, CommitmentType: c, FundingShim: bobFundingShim, ZeroConf: zeroConf, } - bobChanPoint := ht.OpenChannel(bob, carol, bobParams) - // Remove the ChannelAcceptor for Carol. + var ( + acceptStreamBob rpc.AcceptorClient + acceptStreamCarol rpc.AcceptorClient + cancelBob context.CancelFunc + cancelCarol context.CancelFunc + ) + + // If a zero-conf channel is being opened, the nodes are signalling the + // zero-conf feature bit. Setup a ChannelAcceptor for the fundee. if zeroConf { - cancel() + acceptStreamBob, cancelBob = bob.RPC.ChannelAcceptor() + go acceptChannel(ht.T, true, acceptStreamBob) + + acceptStreamCarol, cancelCarol = carol.RPC.ChannelAcceptor() + go acceptChannel(ht.T, true, acceptStreamCarol) + } + + // Open channels in batch to save blocks mined. + reqs := []*lntest.OpenChannelRequest{ + {Local: alice, Remote: bob, Param: aliceParams}, + {Local: bob, Remote: carol, Param: bobParams}, + } + resp := ht.OpenMultiChannelsAsync(reqs) + aliceChanPoint := resp[0] + bobChanPoint := resp[1] + + // Remove the ChannelAcceptor for Bob and Carol. + if zeroConf { + cancelBob() + cancelCarol() } // Make sure alice and carol know each other's channels. From cdc6f63f17713688c89fe21e67ca06475e1b6f16 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 28 Apr 2023 23:36:22 +0800 Subject: [PATCH 2/5] itest: reorder test cases to even out blocks per tranche --- itest/list_on_test.go | 64 +++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/itest/list_on_test.go b/itest/list_on_test.go index cc735afad..0de448027 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -13,34 +13,10 @@ var allTestCases = []*lntest.TestCase{ Name: "basic funding flow", TestFunc: testBasicChannelFunding, }, - { - Name: "multi hop htlc local timeout", - TestFunc: testMultiHopHtlcLocalTimeout, - }, { Name: "multi hop receiver chain claim", TestFunc: testMultiHopReceiverChainClaim, }, - { - Name: "multi hop local force close on-chain htlc timeout", - TestFunc: testMultiHopLocalForceCloseOnChainHtlcTimeout, - }, - { - Name: "multi hop remote force close on-chain htlc timeout", - TestFunc: testMultiHopRemoteForceCloseOnChainHtlcTimeout, - }, - { - Name: "multi hop htlc local chain claim", - TestFunc: testMultiHopHtlcLocalChainClaim, - }, - { - Name: "multi hop htlc remote chain claim", - TestFunc: testMultiHopHtlcRemoteChainClaim, - }, - { - Name: "multi hop htlc aggregation", - TestFunc: testMultiHopHtlcAggregation, - }, { Name: "external channel funding", TestFunc: testExternalFundingChanPoint, @@ -145,14 +121,6 @@ var allTestCases = []*lntest.TestCase{ Name: "send update disable channel", TestFunc: testSendUpdateDisableChannel, }, - { - Name: "private channel update policy", - TestFunc: testUpdateChannelPolicyForPrivateChannel, - }, - { - Name: "update channel policy fee rate accuracy", - TestFunc: testUpdateChannelPolicyFeeRateAccuracy, - }, { Name: "connection timeout", TestFunc: testNetworkConnectionTimeout, @@ -165,6 +133,26 @@ var allTestCases = []*lntest.TestCase{ Name: "addpeer config", TestFunc: testAddPeerConfig, }, + { + Name: "multi hop htlc local timeout", + TestFunc: testMultiHopHtlcLocalTimeout, + }, + { + Name: "multi hop local force close on-chain htlc timeout", + TestFunc: testMultiHopLocalForceCloseOnChainHtlcTimeout, + }, + { + Name: "multi hop remote force close on-chain htlc timeout", + TestFunc: testMultiHopRemoteForceCloseOnChainHtlcTimeout, + }, + { + Name: "private channel update policy", + TestFunc: testUpdateChannelPolicyForPrivateChannel, + }, + { + Name: "update channel policy fee rate accuracy", + TestFunc: testUpdateChannelPolicyFeeRateAccuracy, + }, { Name: "unannounced channels", TestFunc: testUnannouncedChannels, @@ -297,6 +285,18 @@ var allTestCases = []*lntest.TestCase{ Name: "REST API", TestFunc: testRestAPI, }, + { + Name: "multi hop htlc local chain claim", + TestFunc: testMultiHopHtlcLocalChainClaim, + }, + { + Name: "multi hop htlc remote chain claim", + TestFunc: testMultiHopHtlcRemoteChainClaim, + }, + { + Name: "multi hop htlc aggregation", + TestFunc: testMultiHopHtlcAggregation, + }, { Name: "revoked uncooperative close retribution", TestFunc: testRevokedCloseRetribution, From 4bbb4ed978294262b5020783dbbbc52cab1f5c8a Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 4 May 2023 11:58:07 +0800 Subject: [PATCH 3/5] lntest: skip killing dead process --- lntest/node/harness_node.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lntest/node/harness_node.go b/lntest/node/harness_node.go index ed4f324ae..d337f906f 100644 --- a/lntest/node/harness_node.go +++ b/lntest/node/harness_node.go @@ -732,7 +732,14 @@ func (hn *HarnessNode) Stop() error { // manually. hn.printErrf("found nil RPC clients") if err := hn.Kill(); err != nil { - return fmt.Errorf("killing process got: %v", err) + // Skip the error if the process is already dead. + if !strings.Contains( + err.Error(), "process already finished", + ) { + + return fmt.Errorf("killing process got: %w", + err) + } } } From 3f2675f10d25433833788baef6e42601960c6b5f Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 4 May 2023 19:11:03 +0800 Subject: [PATCH 4/5] itest: remove potential parallel usage of the watchtower default port --- itest/list_on_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/itest/list_on_test.go b/itest/list_on_test.go index 0de448027..04eebd383 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -310,11 +310,6 @@ var allTestCases = []*lntest.TestCase{ Name: "revoked uncooperative close retribution remote hodl", TestFunc: testRevokedCloseRetributionRemoteHodl, }, - { - Name: "revoked uncooperative close retribution altruist " + - "watchtower", - TestFunc: testRevokedCloseRetributionAltruistWatchtower, - }, { Name: "single-hop send to route", TestFunc: testSingleHopSendToRoute, @@ -519,6 +514,14 @@ var allTestCases = []*lntest.TestCase{ Name: "watchtower session management", TestFunc: testWatchtowerSessionManagement, }, + { + // NOTE: this test must be put in the same tranche as + // `testWatchtowerSessionManagement` to avoid parallel use of + // the default watchtower port. + Name: "revoked uncooperative close retribution altruist " + + "watchtower", + TestFunc: testRevokedCloseRetributionAltruistWatchtower, + }, { Name: "channel fundmax", TestFunc: testChannelFundMax, From 1dc66302cd64925bf8bcae1a890c4fc1531e06eb Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 10 May 2023 02:01:54 +0800 Subject: [PATCH 5/5] itest: fix test flake in testHtlcTimeoutResolverExtractPreimageRemote --- itest/lnd_multi-hop_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/itest/lnd_multi-hop_test.go b/itest/lnd_multi-hop_test.go index d45a272be..69807fcf3 100644 --- a/itest/lnd_multi-hop_test.go +++ b/itest/lnd_multi-hop_test.go @@ -1936,6 +1936,11 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest, // notice the force close from Carol. require.NoError(ht, restartBob()) + // For anchor channels, Bob should sweep his anchor output. + if lntest.CommitTypeHasAnchors(c) { + ht.Miner.AssertNumTxsInMempool(1) + } + // Get the current height to compute number of blocks to mine to // trigger the htlc timeout resolver from Bob. _, height := ht.Miner.GetBestBlock()