pytest: make sure node order is stable before querying in test_gossmap_lost_node
What changed, and why it matters
This commit fixes a flaky test, not a security issue. The test compared lists of nodes in an order that could change depending on timing. The fix sorts the node lists before comparing them and adds a small synchronization step to ensure the test sees the latest block height. There is no vulnerability in the actual lightning node software.
No security action needed. This is a test reliability fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to tests/test_gossip.py in the test_gossmap_lost_node function. It replaces a wait_for() polling call with sync_blockheight() plus an explicit assertion, and sorts the ‘nodes’ arrays returned by listnodes() by nodeid before comparing pre-restart and post-restart state. The diff shows only test-ordering stabilization; no production code is modified.
Changed components
tests/test_gossip.pyInspect captured patch +6 / −3
diff --git a/tests/test_gossip.py b/tests/test_gossip.py
index df1717d7..45bbd177 100644
--- a/tests/test_gossip.py
+++ b/tests/test_gossip.py
@@ -2378,13 +2378,16 @@ def test_gossmap_lost_node(node_factory, bitcoind):
scid23 = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['short_channel_id']
l2.rpc.close(l3.info['id'])
bitcoind.generate_block(13, wait_for_mempool=1)
- wait_for(lambda: l1.rpc.listchannels(scid23) == {'channels': []})
+
+ # Order of nodes is not stable.
+ sync_blockheight(bitcoind, [l1])
+ assert l1.rpc.listchannels(scid23) == {'channels': []}
pre_channels = l1.rpc.listchannels()
- pre_nodes = l1.rpc.listnodes()
+ pre_nodes = sorted(l1.rpc.listnodes()['nodes'], key=lambda n: n['nodeid'])
l1.restart()
post_channels = l1.rpc.listchannels()
- post_nodes = l1.rpc.listnodes()
+ post_nodes = sorted(l1.rpc.listnodes()['nodes'], key=lambda n: n['nodeid'])
assert post_channels == pre_channels
assert post_nodes == pre_nodes
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.