From f7bdbb9e730e94b1aa3ab904e5aa60dd989be222 Mon Sep 17 00:00:00 2001 From: Maxwell Sayles Date: Tue, 7 Mar 2023 14:37:13 -0800 Subject: [PATCH] funding: integration test to verify the value of FundingExpiryBlock on pending channels that are waiting for funding confirmation. --- itest/list_on_test.go | 4 ++++ itest/lnd_open_channel_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/itest/list_on_test.go b/itest/list_on_test.go index 04eebd383..183ef7f5e 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -57,6 +57,10 @@ var allTestCases = []*lntest.TestCase{ Name: "sphinx replay persistence", TestFunc: testSphinxReplayPersistence, }, + { + Name: "funding expiry blocks on pending", + TestFunc: testFundingExpiryBlocksOnPending, + }, { Name: "list channels", TestFunc: testListChannels, diff --git a/itest/lnd_open_channel_test.go b/itest/lnd_open_channel_test.go index 0b26b2171..29946e4cc 100644 --- a/itest/lnd_open_channel_test.go +++ b/itest/lnd_open_channel_test.go @@ -621,3 +621,34 @@ func verifyCloseUpdate(chanUpdate *lnrpc.ChannelEventUpdate, return nil } + +// testFundingExpiryBlocksOnPending checks that after an OpenChannel, and +// before the funding transaction is confirmed, that the FundingExpiryBlocks +// field of a PendingChannels decreases. +func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) { + alice, bob := ht.Alice, ht.Bob + param := lntest.OpenChannelParams{Amt: 100000} + update := ht.OpenChannelAssertPending(alice, bob, param) + + // At this point, the channel's funding transaction will have been + // broadcast, but not confirmed. Alice and Bob's nodes should reflect + // this when queried via RPC. FundingExpiryBlock should decrease + // as blocks are mined, until the channel is confirmed. Empty blocks + // won't confirm the funding transaction, so let's mine a few empty + // blocks and verify the value of FundingExpiryBlock at each step. + const numEmptyBlocks = 3 + for i := int32(0); i < numEmptyBlocks; i++ { + expectedVal := funding.MaxWaitNumBlocksFundingConf - i + pending := ht.AssertNumPendingOpenChannels(alice, 1) + require.Equal(ht, expectedVal, pending[0].FundingExpiryBlocks) + pending = ht.AssertNumPendingOpenChannels(bob, 1) + require.Equal(ht, expectedVal, pending[0].FundingExpiryBlocks) + ht.MineEmptyBlocks(1) + } + + // Mine 1 block to confirm the funding transaction, and then close the + // channel. + ht.MineBlocksAndAssertNumTxes(1, 1) + chanPoint := lntest.ChanPointFromPendingUpdate(update) + ht.CloseChannel(alice, chanPoint) +}