interface: skip stale header notifications in run_fetch_blocks
What changed, and why it matters
This commit is a performance optimization, not a security fix. It changes how Electrum handles notifications about new Bitcoin blocks so that if several notifications pile up, only the newest one is processed. This avoids wasting time re-checking older blocks and prevents test timeouts on slow systems. There is no indication it fixes a vulnerability or protects against an attack.
No security action required. Treat as a normal performance/test-reliability improvement. Reviewers may still want to confirm that skipping stale notifications never drops a reorganization notification, but the commit message and diff do not suggest this is a security concern.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In electrum/interface.py, run_fetch_blocks() now checks whether the header_queue still has items after reading one and skips the current item if newer notifications are waiting. Because _process_header_at_tip already fetches all missing headers up to the latest tip, processing every queued notification caused redundant backward searches and catch-up requests. The change reduces redundant work and resolves a timeout in regtest scenarios with slow block production and buffered network responses.
Changed components
electrum/interface.pyrun_fetch_blocksblockchain.headers.subscribe notification handlingInspect captured patch +2 / −0
### electrum/interface.py
@@ -1143,6 +1143,8 @@ async def run_fetch_blocks(self):
await self.session.subscribe('blockchain.headers.subscribe', [], header_queue)
while True:
item = await header_queue.get()
+ if not header_queue.empty():
+ continue # skip stale notifications
# parse response
assert len(item) == 1
resp_header = item[0]Why this scored 18/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.