diff --git a/lntest/harness.go b/lntest/harness.go index 3e7ae3fae..e8996e9a6 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -1626,31 +1626,14 @@ func (h *HarnessTest) OpenChannelPsbt(srcNode, destNode *node.HarnessNode, return respStream, upd.PsbtFund.Psbt } -// CleanupForceClose mines a force close commitment found in the mempool and -// the following sweep transaction from the force closing node. +// CleanupForceClose mines blocks to clean up the force close process. This is +// used for tests that are not asserting the expected behavior is found during +// the force close process, e.g., num of sweeps, etc. Instead, it provides a +// shortcut to move the test forward with a clean mempool. func (h *HarnessTest) CleanupForceClose(hn *node.HarnessNode) { // Wait for the channel to be marked pending force close. h.AssertNumPendingForceClose(hn, 1) - // Mine enough blocks for the node to sweep its funds from the force - // closed channel. The commit sweep resolver is able to offer the input - // to the sweeper at defaulCSV-1, and broadcast the sweep tx once one - // more block is mined. - // - // NOTE: we might empty blocks here as we don't know the exact number - // of blocks to mine. This may end up mining more blocks than needed. - h.MineEmptyBlocks(node.DefaultCSV - 1) - - // Assert there is one pending sweep. - h.AssertNumPendingSweeps(hn, 1) - - // Mine a block to trigger the sweep. - h.MineEmptyBlocks(1) - - // The node should now sweep the funds, clean up by mining the sweeping - // tx. - h.MineBlocksAndAssertNumTxes(1, 1) - // Mine blocks to get any second level HTLC resolved. If there are no // HTLCs, this will behave like h.AssertNumPendingCloseChannels. h.mineTillForceCloseResolved(hn) diff --git a/lntest/harness_miner.go b/lntest/harness_miner.go index 65994d254..bc9aef180 100644 --- a/lntest/harness_miner.go +++ b/lntest/harness_miner.go @@ -167,16 +167,9 @@ func (h *HarnessTest) cleanMempool() { } // mineTillForceCloseResolved asserts that the number of pending close channels -// are zero. Each time it checks, a new block is mined using MineBlocksSlow to -// give the node some time to catch up the chain. -// -// NOTE: this method is a workaround to make sure we have a clean mempool at -// the end of a channel force closure. We cannot directly mine blocks and -// assert channels being fully closed because the subsystems in lnd don't share -// the same block height. This is especially the case when blocks are produced -// too fast. -// TODO(yy): remove this workaround when syncing blocks are unified in all the -// subsystems. +// are zero. Each time it checks, an empty block is mined, followed by a +// mempool check to see if there are any sweeping txns. If found, these txns +// are then mined to clean up the mempool. func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) { _, startHeight := h.GetBestBlock() @@ -184,7 +177,15 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) { resp := hn.RPC.PendingChannels() total := len(resp.PendingForceClosingChannels) if total != 0 { - h.MineBlocks(1) + // Mine an empty block first. + h.MineEmptyBlocks(1) + + // If there are new sweeping txns, mine a block to + // confirm it. + mem := h.GetRawMempool() + if len(mem) != 0 { + h.MineBlocksAndAssertNumTxes(1, len(mem)) + } return fmt.Errorf("expected num of pending force " + "close channel to be zero")