From 94f45b2b822b0956fbc385fee9438b6862ec1e7b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 18 Aug 2023 17:08:49 -0700 Subject: [PATCH] itest: use explicit chan type negotiation for taproot chan cases The prior commit removed implicit negotiation, so we'll need to make sure to use the explicit chan type feature vector when we go to negotiate. --- itest/lnd_channel_force_close_test.go | 7 ++-- itest/lnd_funding_test.go | 52 +++++++++++++++++++++------ itest/lnd_multi-hop_test.go | 12 +++++++ itest/lnd_revocation_test.go | 12 ++++--- 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/itest/lnd_channel_force_close_test.go b/itest/lnd_channel_force_close_test.go index fa0c93022..1bb2ff080 100644 --- a/itest/lnd_channel_force_close_test.go +++ b/itest/lnd_channel_force_close_test.go @@ -279,9 +279,10 @@ func channelForceClosureTest(ht *lntest.HarnessTest, chanPoint := ht.OpenChannel( alice, carol, lntest.OpenChannelParams{ - Private: privateChan, - Amt: chanAmt, - PushAmt: pushAmt, + Private: privateChan, + Amt: chanAmt, + PushAmt: pushAmt, + CommitmentType: channelType, }, ) diff --git a/itest/lnd_funding_test.go b/itest/lnd_funding_test.go index 909f20a58..68bcbc100 100644 --- a/itest/lnd_funding_test.go +++ b/itest/lnd_funding_test.go @@ -37,8 +37,6 @@ func testBasicChannelFunding(ht *lntest.HarnessTest) { lnrpc.CommitmentType_SIMPLE_TAPROOT, } - // TODO(roasbeef): only testing implicit negotiation not also explicit? - // testFunding is a function closure that takes Carol and Dave's // commitment types and test the funding flow. testFunding := func(ht *lntest.HarnessTest, carolCommitType, @@ -71,8 +69,28 @@ func testBasicChannelFunding(ht *lntest.HarnessTest) { privateChan = true } + // If carol wants taproot, but dave wants something + // else, then we'll assert that the channel negotiation + // attempt fails. + if carolCommitType == lnrpc.CommitmentType_SIMPLE_TAPROOT && + daveCommitType != lnrpc.CommitmentType_SIMPLE_TAPROOT { + + expectedErr := fmt.Errorf("requested channel type " + + "not supported") + amt := funding.MaxBtcFundingAmount + ht.OpenChannelAssertErr( + carol, dave, lntest.OpenChannelParams{ + Private: privateChan, + Amt: amt, + CommitmentType: carolCommitType, + }, expectedErr, + ) + + return + } + carolChan, daveChan, closeChan := basicChannelFundingTest( - ht, carol, dave, nil, privateChan, + ht, carol, dave, nil, privateChan, &carolCommitType, ) // Both nodes should report the same commitment @@ -155,6 +173,7 @@ test: testName := fmt.Sprintf( "carol_commit=%v,dave_commit=%v", cc, dc, ) + success := ht.Run(testName, func(t *testing.T) { st := ht.Subtest(t) testFunding(st, cc, dc) @@ -172,8 +191,8 @@ test: // then return a function closure that should be called to assert proper // channel closure. func basicChannelFundingTest(ht *lntest.HarnessTest, - alice, bob *node.HarnessNode, - fundingShim *lnrpc.FundingShim, privateChan bool) (*lnrpc.Channel, + alice, bob *node.HarnessNode, fundingShim *lnrpc.FundingShim, + privateChan bool, commitType *lnrpc.CommitmentType) (*lnrpc.Channel, *lnrpc.Channel, func()) { chanAmt := funding.MaxBtcFundingAmount @@ -206,6 +225,16 @@ func basicChannelFundingTest(ht *lntest.HarnessTest, ht.AssertChannelBalanceResp(node, newResp) } + // For taproot channels, the only way we can negotiate is using the + // explicit commitment type. This allows us to continue supporting the + // existing min version comparison for implicit negotiation. + var commitTypeParam lnrpc.CommitmentType + if commitType != nil && + *commitType == lnrpc.CommitmentType_SIMPLE_TAPROOT { + + commitTypeParam = *commitType + } + // First establish a channel with a capacity of 0.5 BTC between Alice // and Bob with Alice pushing 100k satoshis to Bob's side during // funding. This function will block until the channel itself is fully @@ -214,11 +243,12 @@ func basicChannelFundingTest(ht *lntest.HarnessTest, // successfully. chanPoint := ht.OpenChannel( alice, bob, lntest.OpenChannelParams{ - Private: privateChan, - Amt: chanAmt, - PushAmt: pushAmt, - FundingShim: fundingShim, - SatPerVByte: satPerVbyte, + Private: privateChan, + Amt: chanAmt, + PushAmt: pushAmt, + FundingShim: fundingShim, + SatPerVByte: satPerVbyte, + CommitmentType: commitTypeParam, }, ) @@ -558,7 +588,7 @@ func testExternalFundingChanPoint(ht *lntest.HarnessTest) { // test as everything should now proceed as normal (a regular channel // funding flow). carolChan, daveChan, _ := basicChannelFundingTest( - ht, carol, dave, fundingShim2, false, + ht, carol, dave, fundingShim2, false, nil, ) // Both channels should be marked as frozen with the proper thaw diff --git a/itest/lnd_multi-hop_test.go b/itest/lnd_multi-hop_test.go index 846e45958..24b47dec1 100644 --- a/itest/lnd_multi-hop_test.go +++ b/itest/lnd_multi-hop_test.go @@ -2023,6 +2023,12 @@ func createThreeHopNetwork(ht *lntest.HarnessTest, ZeroConf: zeroConf, } + // If the channel type is taproot, then use an explicit channel type to + // open it. + if c == lnrpc.CommitmentType_SIMPLE_TAPROOT { + aliceParams.CommitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT + } + // 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 @@ -2041,6 +2047,12 @@ func createThreeHopNetwork(ht *lntest.HarnessTest, ZeroConf: zeroConf, } + // If the channel type is taproot, then use an explicit channel type to + // open it. + if c == lnrpc.CommitmentType_SIMPLE_TAPROOT { + bobParams.CommitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT + } + var ( acceptStreamBob rpc.AcceptorClient acceptStreamCarol rpc.AcceptorClient diff --git a/itest/lnd_revocation_test.go b/itest/lnd_revocation_test.go index 671f07348..4350c92a2 100644 --- a/itest/lnd_revocation_test.go +++ b/itest/lnd_revocation_test.go @@ -250,8 +250,9 @@ func revokedCloseRetributionZeroValueRemoteOutputCase(ht *lntest.HarnessTest, privateChan := commitType == lnrpc.CommitmentType_SIMPLE_TAPROOT chanPoint := ht.OpenChannel( dave, carol, lntest.OpenChannelParams{ - Amt: chanAmt, - Private: privateChan, + CommitmentType: commitType, + Amt: chanAmt, + Private: privateChan, }, ) @@ -436,9 +437,10 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest, privateChan := commitType == lnrpc.CommitmentType_SIMPLE_TAPROOT chanPoint := ht.OpenChannel( dave, carol, lntest.OpenChannelParams{ - Amt: chanAmt, - PushAmt: pushAmt, - Private: privateChan, + Amt: chanAmt, + PushAmt: pushAmt, + Private: privateChan, + CommitmentType: commitType, }, )