multi: Add itest for funding timeout

This commit adds an integration test that
verifies the funding timeout behavior in the
funding manager, in dev/integration test.
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
This commit is contained in:
Nishant Bansal
2025-03-07 21:32:38 +05:30
parent a5f54d1d6b
commit 4569c07e08
9 changed files with 132 additions and 22 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest"
@@ -844,7 +845,7 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
// blocks and verify the value of FundingExpiryBlock at each step.
const numEmptyBlocks = 3
for i := int32(0); i < numEmptyBlocks; i++ {
expectedVal := funding.MaxWaitNumBlocksFundingConf - i
expectedVal := lncfg.DefaultMaxWaitNumBlocksFundingConf - i
pending := ht.AssertNumPendingOpenChannels(alice, 1)
require.Equal(ht, expectedVal, pending[0].FundingExpiryBlocks)
pending = ht.AssertNumPendingOpenChannels(bob, 1)
@@ -967,3 +968,55 @@ func testOpenChannelLockedBalance(ht *lntest.HarnessTest) {
// Finally, we check to make sure the balance is unlocked again.
ht.AssertWalletLockedBalance(alice, 0)
}
// testFundingManagerFundingTimeout tests that after an OpenChannel, and before
// the funding transaction is confirmed, if the node is not the channel
// initiator, the channel is forgotten after waitBlocksForFundingConf.
func testFundingManagerFundingTimeout(ht *lntest.HarnessTest) {
// Set the maximum wait blocks for funding confirmation.
waitBlocksForFundingConf := 10
// Create nodes for testing, ensuring Alice has sufficient initial
// funds.
alice := ht.NewNodeWithCoins("Alice", nil)
bob := ht.NewNode("Bob", nil)
// Restart Bob with the custom configuration for funding confirmation
// timeout.
ht.RestartNodeWithExtraArgs(bob, []string{
"--dev.maxwaitnumblocksfundingconf=10",
})
// Ensure Alice and Bob are connected.
ht.EnsureConnected(alice, bob)
// Open the channel between Alice and Bob. This runs through the process
// up until the funding transaction is broadcasted.
ht.OpenChannelAssertPending(alice, bob, lntest.OpenChannelParams{
Amt: 500000,
PushAmt: 0,
})
// At this point, both nodes have a pending channel waiting for the
// funding transaction to be confirmed.
ht.AssertNumPendingOpenChannels(alice, 1)
ht.AssertNumPendingOpenChannels(bob, 1)
// We expect Bob to forget the channel after waitBlocksForFundingConf
// blocks, so mine waitBlocksForFundingConf-1, and check that it is
// still pending.
ht.MineEmptyBlocks(waitBlocksForFundingConf - 1)
ht.AssertNumPendingOpenChannels(bob, 1)
// Now mine one additional block to reach waitBlocksForFundingConf.
ht.MineEmptyBlocks(1)
// Bob should now have forgotten the channel.
ht.AssertNumPendingOpenChannels(bob, 0)
// Since Alice was the initiator, her pending channel should remain.
ht.AssertNumPendingOpenChannels(alice, 1)
// Cleanup the mempool by mining blocks.
ht.MineBlocksAndAssertNumTxes(6, 1)
}