diff --git a/itest/list_on_test.go b/itest/list_on_test.go index c04fb3d070..66a371ba53 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -3,8 +3,6 @@ package itest import ( - "math/rand" - "github.com/lightningnetwork/lnd/lntest" ) @@ -636,12 +634,12 @@ var allTestCases = []*lntest.TestCase{ }, } -func init() { - // Shuffle the test cases so they are executed in a random order. This - // is done to even out the blocks mined in each test tranche so they - // can run faster. - rand.Shuffle(len(allTestCases), func(i, j int) { - allTestCases[i], allTestCases[j] = - allTestCases[j], allTestCases[i] - }) -} +// func init() { +// // Shuffle the test cases so they are executed in a random order. This +// // is done to even out the blocks mined in each test tranche so they +// // can run faster. +// rand.Shuffle(len(allTestCases), func(i, j int) { +// allTestCases[i], allTestCases[j] = +// allTestCases[j], allTestCases[i] +// }) +// } diff --git a/itest/lnd_multi-hop_test.go b/itest/lnd_multi-hop_test.go index 863bae8ad6..e50354d748 100644 --- a/itest/lnd_multi-hop_test.go +++ b/itest/lnd_multi-hop_test.go @@ -244,17 +244,15 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest, ) ht.MineBlocks(int(numBlocks)) - // Bob's force close transaction should now be found in the mempool. - ht.AssertNumTxsInMempool(1) + // Bob's force close transaction should now be found in the mempool, + // along with his anchor sweeping tx. + ht.AssertNumTxsInMempool(2) op := ht.OutPointFromChannelPoint(bobChanPoint) closeTx := ht.AssertOutpointInMempool(op) - // Bob's anchor output should be offered to his sweep since Bob has - // time-sensitive HTLCs - we expect both anchors are offered. - ht.AssertNumPendingSweeps(bob, 2) - - // Mine a block to confirm the closing transaction. - ht.MineBlocksAndAssertNumTxes(1, 1) + // Mine a block to confirm the closing transaction and the anchor + // sweeping tx. + ht.MineBlocksAndAssertNumTxes(1, 2) // At this point, Bob should have canceled backwards the dust HTLC // that we sent earlier. This means Alice should now only have a single @@ -263,32 +261,22 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest, // With the closing transaction confirmed, we should expect Bob's HTLC // timeout transaction to be offered to the sweeper due to the expiry - // being reached. we also expect Bon and Carol's anchor sweeps. - ht.AssertNumPendingSweeps(bob, 2) + // being reached. we also expect Carol's anchor sweeps. + ht.AssertNumPendingSweeps(bob, 1) ht.AssertNumPendingSweeps(carol, 1) - // Mine a block to trigger Bob's sweeper to sweep. - ht.MineEmptyBlocks(1) - // The above mined block would trigger Bob and Carol's sweepers to take - // action. We now expect two txns: - // 1. Bob's sweeping tx anchor sweep should now be found in the mempool. - // 2. Bob's HTLC timeout tx sweep should now be found in the mempool. + // action. We now expect one tx: + // 1. Bob's HTLC timeout tx sweep should now be found in the mempool. // Carol's anchor sweep should be failed due to output being dust. - ht.AssertNumTxsInMempool(2) + ht.AssertNumTxsInMempool(1) htlcOutpoint := wire.OutPoint{Hash: closeTx.TxHash(), Index: 2} commitOutpoint := wire.OutPoint{Hash: closeTx.TxHash(), Index: 3} - htlcTimeoutTxid := ht.AssertOutpointInMempool( - htlcOutpoint, - ).TxHash() - - // Mine a block to confirm the above two sweeping txns. - ht.MineBlocksAndAssertNumTxes(1, 2) + htlcTimeoutTxid := ht.AssertOutpointInMempool(htlcOutpoint).TxHash() - // With Bob's HTLC timeout transaction confirmed, there should be no - // active HTLC's on the commitment transaction from Alice -> Bob. - ht.AssertNumActiveHtlcs(alice, 0) + // Mine a block to confirm Bob's HTLC timeout sweeping txns. + ht.MineBlocksAndAssertNumTxes(1, 1) // At this point, Bob should show that the pending HTLC has advanced to // the second stage and is ready to be swept once the timelock is up. @@ -314,39 +302,25 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest, // We now mine enough blocks to trigger the sweep of the HTLC // timeout tx. - ht.MineEmptyBlocks(blocksTilMaturity - 1) - - // Check that Bob has one pending sweeping tx - the HTLC - // timeout tx. - ht.AssertNumPendingSweeps(bob, 1) - - // Mine one more blocks, then his commit output will mature. - // This will also trigger the sweeper to sweep his HTLC timeout - // tx. - ht.MineEmptyBlocks(1) + ht.MineEmptyBlocks(blocksTilMaturity) - // Check that Bob has two pending sweeping txns. + // Check that Bob has two pending sweeping requests - the HTLC + // timeout tx and his to_local output. ht.AssertNumPendingSweeps(bob, 2) // Assert that the HTLC timeout tx is now in the mempool. ht.AssertOutpointInMempool(htlcTimeoutOutpoint) - // Mine a block to trigger the sweep of his commit output and - // confirm his HTLC timeout sweep. + // Assert the to_local output is also in the mempool. + ht.AssertOutpointInMempool(commitOutpoint) + + // Mine a block to confirm the sweeping tx. ht.MineBlocksAndAssertNumTxes(1, 1) - // For leased channels, we need to mine one more block to - // confirm Bob's commit output sweep. - // - // NOTE: we mine this block conditionally, as the commit output - // may have already been swept one block earlier due to the - // race in block consumption among subsystems. - pendingChanResp := bob.RPC.PendingChannels() - if len(pendingChanResp.PendingForceClosingChannels) != 0 { - // Check that the sweep spends the expected inputs. - ht.AssertOutpointInMempool(commitOutpoint) - ht.MineBlocksAndAssertNumTxes(1, 1) - } + // With Bob's HTLC timeout transaction confirmed, there should + // be no active HTLC's on the commitment transaction from Alice + // -> Bob. + ht.AssertNumActiveHtlcs(alice, 0) } else { // Since Bob force closed the channel between him and Carol, he // will incur the usual CSV delay on any outputs that he can @@ -364,16 +338,19 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest, // Check that the sweep spends from the mined commitment. ht.AssertOutpointInMempool(commitOutpoint) - // Mine one more block to trigger the timeout path. - ht.MineBlocksAndAssertNumTxes(1, 1) - // Bob's sweeper should now broadcast his second layer sweep - // due to the CSV on the HTLC timeout output. - ht.AssertOutpointInMempool(htlcTimeoutOutpoint) + // due to the CSV on the HTLC timeout output, along with his + // to_local output sweep. + ht.MineBlocksAndAssertNumTxes(1, 2) // Next, we'll mine a final block that should confirm the // sweeping transactions left. - ht.MineBlocksAndAssertNumTxes(1, 1) + // ht.MineBlocksAndAssertNumTxes(1, 2) + + // With Bob's HTLC timeout transaction confirmed, there should + // be no active HTLC's on the commitment transaction from Alice + // -> Bob. + ht.AssertNumActiveHtlcs(alice, 0) } // Once this transaction has been confirmed, Bob should detect that he @@ -481,38 +458,22 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest, ht.MineEmptyBlocks(int(numBlocks)) // At this point, Carol should broadcast her active commitment - // transaction in order to go to the chain and sweep her HTLC. - ht.AssertNumTxsInMempool(1) + // transaction in order to go to the chain and sweep her HTLC, along + // with her anchor sweeping tx. + ht.AssertNumTxsInMempool(2) closingTx := ht.AssertOutpointInMempool( ht.OutPointFromChannelPoint(bobChanPoint), ) closingTxid := closingTx.TxHash() - // Carol's anchor should have been offered to her sweeper as she has - // time-sensitive HTLCs. Assert that we have two anchors - one for the - // anchor on the local commitment and the other for the anchor on the - // remote commitment (invalid). - ht.AssertNumPendingSweeps(carol, 2) - // Confirm the commitment. - ht.MineBlocksAndAssertNumTxes(1, 1) - - // The above mined block will trigger Carol's sweeper to publish the - // anchor sweeping tx. - // - // TODO(yy): should instead cancel the broadcast of the anchor sweeping - // tx to save fees since we know the force close tx has been confirmed? - // This is very difficult as it introduces more complicated RBF - // scenarios, as we are using a wallet utxo, which means any txns using - // that wallet utxo must pay more fees. On the other hand, there's no - // way to remove that anchor-CPFP tx from the mempool. - ht.AssertNumTxsInMempool(1) + ht.MineBlocksAndAssertNumTxes(1, 2) // After the force close transaction is mined, Carol should offer her - // second level HTLC tx to the sweeper, which means we should see two - // pending inputs now - the anchor and the htlc. - ht.AssertNumPendingSweeps(carol, 2) + // second level HTLC tx to the sweeper, which means we should see one + // pending input now - the htlc. + ht.AssertNumPendingSweeps(carol, 1) // Restart bob again. require.NoError(ht, restartBob()) @@ -524,25 +485,23 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest, // second level transaction in the mempool, he will extract the // preimage and settle the HTLC back off-chain. switch c { - // We expect to see three txns in the mempool: + // We expect to see two txns in the mempool: // 1. Carol should broadcast her second level HTLC tx. - // 2. Carol should broadcast her anchor sweeping tx. - // 3. Bob should broadcast a sweep tx to sweep his output in the + // 2. Bob should broadcast a sweep tx to sweep his output in the // channel with Carol, and in the same sweep tx to sweep his anchor // output. case lnrpc.CommitmentType_ANCHORS, lnrpc.CommitmentType_SIMPLE_TAPROOT: - expectedTxes = 3 + expectedTxes = 2 ht.AssertNumPendingSweeps(bob, 2) - // We expect to see two txns in the mempool: + // We expect to see one tx in the mempool: // 1. Carol should broadcast her second level HTLC tx. - // 2. Carol should broadcast her anchor sweeping tx. // Bob would offer his anchor output to his sweeper, but it cannot be // swept due to it being uneconomical. Bob's commit output can't be // swept yet as he's incurring an additional CLTV from being the // channel initiator of a script-enforced leased channel. case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE: - expectedTxes = 2 + expectedTxes = 1 ht.AssertNumPendingSweeps(bob, 1) default: @@ -578,7 +537,7 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest, ht.AssertNumPendingSweeps(carol, 1) // Mine one block to trigger the sweeper to sweep. - ht.MineEmptyBlocks(1) + // ht.MineEmptyBlocks(1) // We should have a new transaction in the mempool. ht.AssertNumTxsInMempool(1) @@ -650,6 +609,8 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest) { func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest, alice, bob *node.HarnessNode, c lnrpc.CommitmentType, zeroConf bool) { + ht.SetMinRelayFeerate(10000) + // First, we'll create a three hop network: Alice -> Bob -> Carol, with // Carol refusing to actually settle or directly cancel any HTLC's // self. @@ -951,10 +912,6 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest, ht.Fatalf("unhandled commitment type %v", c) } - // Mine one block to trigger the sweeps. - ht.MineEmptyBlocks(1) - blocksMined++ - // We now mine a block to clear up the mempool. ht.MineBlocksAndAssertNumTxes(1, expectedTxes) blocksMined++ @@ -971,16 +928,14 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest, // initial first stage since this is a direct HTLC. ht.AssertNumHTLCsAndStage(bob, bobChanPoint, 1, 2) - // We need to generate an additional block to expire the CSV 1. - ht.MineEmptyBlocks(1) - // For script-enforced leased channels, Bob has failed to sweep his // anchor output before, so it's still pending. if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE { ht.AssertNumPendingSweeps(bob, 2) } else { - // Bob should have a pending sweep request. - ht.AssertNumPendingSweeps(bob, 1) + // Bob should have two pending sweep requests - the anchor + // output and the outgoing HTLC. + ht.AssertNumPendingSweeps(bob, 2) } // Mine a block to trigger the sweeper to sweep it. diff --git a/lntest/node/config.go b/lntest/node/config.go index de1ea92ec0..74fd472fba 100644 --- a/lntest/node/config.go +++ b/lntest/node/config.go @@ -199,7 +199,7 @@ func (cfg *BaseNodeConfig) GenArgs() []string { nodeArgs := []string{ "--nobootstrap", - "--debuglevel=debug", + "--debuglevel=debug,CHIO=trace", "--bitcoin.defaultchanconfs=1", "--accept-keysend", "--keep-failed-payment-attempts", diff --git a/lntest/wait/timeouts_darwin.go b/lntest/wait/timeouts_darwin.go index f992d06b22..e7e506cb89 100644 --- a/lntest/wait/timeouts_darwin.go +++ b/lntest/wait/timeouts_darwin.go @@ -8,7 +8,7 @@ import "time" const ( // MinerMempoolTimeout is the max time we will wait for a transaction // to propagate to the mining node's mempool. - MinerMempoolTimeout = time.Minute + MinerMempoolTimeout = time.Second * 5 // ChannelOpenTimeout is the max time we will wait before a channel to // be considered opened. @@ -20,7 +20,7 @@ const ( // DefaultTimeout is a timeout that will be used for various wait // scenarios where no custom timeout value is defined. - DefaultTimeout = time.Second * 30 + DefaultTimeout = time.Second * 3 // AsyncBenchmarkTimeout is the timeout used when running the async // payments benchmark. This timeout takes considerably longer on darwin