tests: fix flaky bwatch 1-block reorg test
What changed, and why it matters
This commit fixes a flaky automated test for a Core Lightning plugin called bwatch. The test was sometimes failing because it reorged a block before the plugin had actually recorded it, so the plugin saw the replacement as a normal new block instead of a reorg. The fix simply makes the test wait until the plugin has stored the block before triggering the reorg. There is no change to production code and no security issue.
No security action needed; this is a test-only reliability fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to tests/test_plugin.py in test_bwatch_reorg_1_block. It replaces a wait for the log line ‘No block change’ with a wait for the log line ‘Added block {expected_height} to history’ and an explicit datastore check that listdatastore([‘bwatch’, ‘block_history’]) contains an entry whose key ends with the zero-padded expected block height. This ensures bwatch has persisted the to-be-reorged block before the test invalidates it, eliminating a race condition that caused intermittent test timeouts waiting for ‘Reorg detected’.
Changed components
tests/test_plugin.py::test_bwatch_reorg_1_blockInspect captured patch +5 / −1
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 2aa2922f..f0dc56c4 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -5463,9 +5463,13 @@ def test_bwatch_reorg_1_block(node_factory, bitcoind):
# Mine a few blocks to establish history
bitcoind.generate_block(5)
+ expected_height = bitcoind.rpc.getblockcount()
# Wait for bwatch to fully catch up (important: bwatch must have the block
# that will be reorged, otherwise it can't detect the reorg)
- l1.daemon.wait_for_log(r'No block change')
+ l1.daemon.wait_for_log(rf'Added block {expected_height} to history', timeout=60)
+ wait_for(lambda: any(e['key'][-1] == f"{expected_height:010d}"
+ for e in l1.rpc.listdatastore(['bwatch', 'block_history'])['datastore']),
+ timeout=60)
# Get the actual number of blocks bwatch has stored before reorg
ds_before = l1.rpc.listdatastore(['bwatch', 'block_history'])
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.