Skip to content

Commit 1ce7559

Browse files
yyforyongyuRoasbeef
authored andcommitted
lntest+itest: clean mempool in testHtlcTimeoutResolverExtractPreimageRemote
1 parent 5e1664d commit 1ce7559

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

itest/lnd_multi-hop_test.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,23 +1940,52 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
19401940
numBlocks = htlc.ExpirationHeight - uint32(height) -
19411941
lncfg.DefaultOutgoingBroadcastDelta
19421942

1943-
// Mine empty blocks so Carol's htlc success tx stays in mempool. Once
1944-
// the height is reached, Bob's timeout resolver will resolve the htlc
1945-
// by extracing the preimage from the mempool.
1946-
ht.MineEmptyBlocks(int(numBlocks))
1943+
// We should now have Carol's htlc suucess tx in the mempool.
1944+
numTxesMempool := 1
19471945

19481946
// For neutrino backend, the timeout resolver needs to extract the
19491947
// preimage from the blocks.
19501948
if ht.IsNeutrinoBackend() {
19511949
// Mine a block to confirm Carol's 2nd level success tx.
19521950
ht.MineBlocksAndAssertNumTxes(1, 1)
1951+
numTxesMempool--
19531952
}
1953+
// Mine empty blocks so Carol's htlc success tx stays in mempool. Once
1954+
// the height is reached, Bob's timeout resolver will resolve the htlc
1955+
// by extracing the preimage from the mempool.
1956+
ht.MineEmptyBlocks(int(numBlocks))
19541957

19551958
// Finally, check that the Alice's payment is marked as succeeded as
19561959
// Bob has settled the htlc using the preimage extracted from Carol's
19571960
// 2nd level success tx.
19581961
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
19591962

1963+
switch c {
1964+
// For non-anchor channel type, we should expect to see Bob's commit
1965+
// sweep in the mempool.
1966+
case lnrpc.CommitmentType_LEGACY:
1967+
numTxesMempool++
1968+
1969+
// For non-anchor channel type, we should expect to see Bob's commit
1970+
// sweep and his anchor sweep tx in the mempool.
1971+
case lnrpc.CommitmentType_ANCHORS:
1972+
numTxesMempool += 2
1973+
1974+
// For script-enforced leased channel, we should expect to see Bob's
1975+
// anchor sweep tx in the mempool.
1976+
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
1977+
numTxesMempool++
1978+
1979+
// For neutrino backend, because of the additional block mined,
1980+
// Bob's output is now mature.
1981+
if ht.IsNeutrinoBackend() {
1982+
numTxesMempool++
1983+
}
1984+
}
1985+
1986+
// Mine a block to clean the mempool.
1987+
ht.MineBlocksAndAssertNumTxes(1, numTxesMempool)
1988+
19601989
// NOTE: for non-standby nodes there's no need to clean up the force
19611990
// close as long as the mempool is cleaned.
19621991
ht.CleanShutDown()

lntest/harness.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,18 +1632,12 @@ func (h *HarnessTest) cleanMempool() {
16321632
blocks := h.Miner.MineBlocksSlow(1)
16331633
bestBlock = blocks[len(blocks)-1]
16341634

1635+
// Make sure all the active nodes are synced.
1636+
h.AssertActiveNodesSyncedTo(bestBlock)
1637+
16351638
return fmt.Errorf("still have %d txes in mempool", len(mem))
16361639
}, wait.MinerMempoolTimeout)
16371640
require.NoError(h, err, "timeout cleaning up mempool")
1638-
1639-
// Exit early if the best block is nil, which means we haven't mined
1640-
// any blocks during the cleanup.
1641-
if bestBlock == nil {
1642-
return
1643-
}
1644-
1645-
// Make sure all the active nodes are synced.
1646-
h.AssertActiveNodesSyncedTo(bestBlock)
16471641
}
16481642

16491643
// CleanShutDown is used to quickly end a test by shutting down all non-standby

0 commit comments

Comments
 (0)