pytest: fix flake in test_coinmoves_unilateral_htlc_timeout
What changed, and why it matters
This commit fixes a flaky automated test in Core Lightning. The test sometimes failed because it told Bitcoin to mine a block before waiting for an extra 'anchor' transaction to arrive in the memory pool. The fix simply tells the test to wait for two mempool transactions instead of one. It does not change any production code or fix a security bug in the software itself.
No security action required. Treat as a normal test reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to tests/test_coinmoves.py. In two test functions (test_coinmoves_unilateral_htlc_timeout and test_coinmoves_unilateral_htlc_fulfill), bitcoind.generate_block(1, wait_for_mempool=1) is changed to wait_for_mempool=2, and comments are added noting ‘Close, and anchor.’ Two other tests receive comments ‘Close, no anchor.’ The failure diff shows the test expected wallet withdrawal/deposit coin moves that only occur when the anchor spend is included in the same block as the commitment close; when the anchor was not yet in the mempool, the block was mined without it, producing a different coin-move sequence. This is purely a test synchronization fix.
Changed components
tests/test_coinmoves.pyInspect captured patch +6 / −2
diff --git a/tests/test_coinmoves.py b/tests/test_coinmoves.py
index 291f857b..927347d0 100644
--- a/tests/test_coinmoves.py
+++ b/tests/test_coinmoves.py
@@ -521,6 +521,7 @@ def test_coinmoves_unilateral_htlc_before_included(node_factory, bitcoind):
check_chain_moves(l2, expected_chain2)
close_info = l1.rpc.close(l2.info['id'], unilateraltimeout=1)
+ # Close, no anchor.
bitcoind.generate_block(1, wait_for_mempool=1)
# Make sure onchaind has digested it.
@@ -714,7 +715,8 @@ def test_coinmoves_unilateral_htlc_timeout(node_factory, bitcoind):
line = l1.daemon.wait_for_log("Creating anchor spend for local commit tx ")
anchor_spend_txid = re.search(r'Creating anchor spend for local commit tx ([0-9a-f]{64})', line).group(1)
- bitcoind.generate_block(1, wait_for_mempool=1)
+ # Close, and anchor.
+ bitcoind.generate_block(1, wait_for_mempool=2)
sync_blockheight(bitcoind, [l1, l2])
# Make sure onchaind has digested it.
@@ -1024,6 +1026,7 @@ def test_coinmoves_unilateral_htlc_dust(node_factory, bitcoind):
check_chain_moves(l2, expected_chain2)
close_info = l1.rpc.close(l2.info['id'], unilateraltimeout=1)
+ # Close, no anchor.
bitcoind.generate_block(1, wait_for_mempool=1)
sync_blockheight(bitcoind, [l1, l2])
@@ -1217,7 +1220,8 @@ def test_coinmoves_unilateral_htlc_fulfill(node_factory, bitcoind):
line = l1.daemon.wait_for_log("Creating anchor spend for local commit tx ")
anchor_spend_txid = re.search(r'Creating anchor spend for local commit tx ([0-9a-f]{64})', line).group(1)
- bitcoind.generate_block(1, wait_for_mempool=1)
+ # Close, and anchor.
+ bitcoind.generate_block(1, wait_for_mempool=2)
sync_blockheight(bitcoind, [l1, l2])
# Make sure onchaind has digested it.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.