From 30c2b9f2df187d0efd7c59b281fb1ac80effdece Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sun, 7 Apr 2024 16:02:07 +0800 Subject: [PATCH] itest: fix channel backup tests --- contractcourt/htlc_timeout_resolver.go | 3 +- itest/lnd_channel_backup_test.go | 76 ++++++++++++++------------ 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/contractcourt/htlc_timeout_resolver.go b/contractcourt/htlc_timeout_resolver.go index 8d3f7504d..e8f846cd9 100644 --- a/contractcourt/htlc_timeout_resolver.go +++ b/contractcourt/htlc_timeout_resolver.go @@ -442,7 +442,8 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) { log.Infof("%T(%v): HTLC has been swept with pre-image by "+ "remote party during timeout flow! Adding pre-image to "+ - "witness cache", h.htlcResolution.ClaimOutpoint) + "witness cache", h, h.htlc.RHash[:], + h.htlcResolution.ClaimOutpoint) return h.claimCleanUp(commitSpend) } diff --git a/itest/lnd_channel_backup_test.go b/itest/lnd_channel_backup_test.go index 8d0c00712..c29859e32 100644 --- a/itest/lnd_channel_backup_test.go +++ b/itest/lnd_channel_backup_test.go @@ -1417,15 +1417,16 @@ func chanRestoreViaRPC(ht *lntest.HarnessTest, password []byte, func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode, carolStartingBalance, daveStartingBalance int64) { - // We expect Carol to sweep her funds and also the anchor tx. In - // addition, Dave will also sweep his anchor output. - expectedTxes := 3 - // Carol should sweep her funds immediately, as they are not // timelocked. ht.AssertNumPendingSweeps(carol, 2) ht.AssertNumPendingSweeps(dave, 1) + // We expect Carol to sweep her funds and her anchor in a single sweep + // tx. In addition, Dave will attempt to sweep his anchor output but + // fail due to the sweeping tx being uneconomical. + expectedTxes := 1 + // Mine a block to trigger the sweeps. ht.MineBlocks(1) ht.Miner.AssertNumTxsInMempool(expectedTxes) @@ -1457,11 +1458,11 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode, // The commit sweep resolver publishes the sweep tx at defaultCSV-1 and // we already mined one block after the commitment was published, and // one block to trigger Carol's sweeps, so take that into account. - ht.MineBlocks(1) - ht.AssertNumPendingSweeps(dave, 1) + ht.MineEmptyBlocks(1) + ht.AssertNumPendingSweeps(dave, 2) // Mine a block to trigger the sweeps. - ht.MineBlocks(1) + ht.MineEmptyBlocks(1) daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0] block := ht.MineBlocksAndAssertNumTxes(1, 1)[0] ht.Miner.AssertTxInBlock(block, daveSweep) @@ -1541,29 +1542,27 @@ func assertDLPExecuted(ht *lntest.HarnessTest, // Dave should sweep his anchor only, since he still has the // lease CLTV constraint on his commitment output. We'd also // see Carol's anchor sweep here. + + // Both Dave and Carol should have an anchor sweep request. + // Note that they cannot sweep them as these anchor sweepings + // are uneconomical. ht.AssertNumPendingSweeps(dave, 1) ht.AssertNumPendingSweeps(carol, 1) - // Mine a block to trigger the sweeps. - ht.MineBlocks(1) - blocksMined++ - ht.Miner.AssertNumTxsInMempool(2) - - // Mine anchor sweep txes for Carol and Dave. - ht.MineBlocksAndAssertNumTxes(1, 2) - blocksMined++ - // After Carol's output matures, she should also reclaim her // funds. // // The commit sweep resolver publishes the sweep tx at // defaultCSV-1 and we already mined one block after the // commitmment was published, so take that into account. - ht.MineBlocks(defaultCSV - blocksMined) - ht.AssertNumPendingSweeps(carol, 1) + ht.MineEmptyBlocks(int(defaultCSV - blocksMined)) + + // Carol should have two sweep requests - one for her commit + // output and the other for her anchor. + ht.AssertNumPendingSweeps(carol, 2) // Mine a block to trigger the sweep. - ht.MineBlocks(1) + ht.MineEmptyBlocks(1) ht.MineBlocksAndAssertNumTxes(1, 1) // Now the channel should be fully closed also from Carol's POV. @@ -1576,11 +1575,14 @@ func assertDLPExecuted(ht *lntest.HarnessTest, resp.PendingForceClosingChannels[0].BlocksTilMaturity require.Positive(ht, blocksTilMaturity) - ht.MineBlocks(uint32(blocksTilMaturity)) - ht.AssertNumPendingSweeps(dave, 1) + ht.MineEmptyBlocks(int(blocksTilMaturity)) + + // Dave should have two sweep requests - one for his commit + // output and the other for his anchor. + ht.AssertNumPendingSweeps(dave, 2) // Mine a block to trigger the sweep. - ht.MineBlocks(1) + ht.MineEmptyBlocks(1) ht.MineBlocksAndAssertNumTxes(1, 1) // Now Dave should consider the channel fully closed. @@ -1597,19 +1599,13 @@ func assertDLPExecuted(ht *lntest.HarnessTest, } // Mine one block to trigger the sweeper to sweep. - ht.MineBlocks(1) + ht.MineEmptyBlocks(1) blocksMined++ - // For anchor channels, we expect three txns, - // 1. the anchor sweeping tx from Dave. - // 2. the anchor sweeping tx from Carol. - // 3. the commitment sweep from Dave. - if lntest.CommitTypeHasAnchors(commitType) { - ht.MineBlocksAndAssertNumTxes(1, 3) - } else { - ht.MineBlocksAndAssertNumTxes(1, 1) - } - + // Expect one tx - the commitment sweep from Dave. For anchor + // channels, we expect the two anchor sweeping txns to be + // failed due they are uneconomical. + ht.MineBlocksAndAssertNumTxes(1, 1) blocksMined++ // Now Dave should consider the channel fully closed. @@ -1621,11 +1617,19 @@ func assertDLPExecuted(ht *lntest.HarnessTest, // The commit sweep resolver publishes the sweep tx at // defaultCSV-1 and we already have blocks mined after the // commitmment was published, so take that into account. - ht.MineBlocks(defaultCSV - blocksMined) + ht.MineEmptyBlocks(int(defaultCSV - blocksMined)) // Mine one block to trigger the sweeper to sweep. - ht.MineBlocks(1) - ht.AssertNumPendingSweeps(carol, 1) + ht.MineEmptyBlocks(1) + + // Carol should have two pending sweeps: + // 1. her commit output. + // 2. her anchor output, if this is anchor channel. + if lntest.CommitTypeHasAnchors(commitType) { + ht.AssertNumPendingSweeps(carol, 2) + } else { + ht.AssertNumPendingSweeps(carol, 1) + } // Assert the sweeping tx is mined. ht.MineBlocksAndAssertNumTxes(1, 1)