From a5120d772cf59f1fbdc0bf6993d4cc720d0abf6d Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Sat, 2 Apr 2022 11:44:55 -0400 Subject: [PATCH] try making sending header notifications faster --- scribe/hub/mempool.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scribe/hub/mempool.py b/scribe/hub/mempool.py index fa64ed7..d556eea 100644 --- a/scribe/hub/mempool.py +++ b/scribe/hub/mempool.py @@ -221,13 +221,18 @@ class MemPool: return if height_changed: - header_tasks = [ - session.send_notification('blockchain.headers.subscribe', (self.session_manager.hsub_results[session.subscribe_headers_raw], )) - for session in self.session_manager.sessions.values() if session.subscribe_headers - ] - if header_tasks: - self.logger.info(f'notify {len(header_tasks)} sessions of new header') - asyncio.create_task(asyncio.wait(header_tasks)) + notified = 0 + for session in self.session_manager.sessions.values(): + if session.subscribe_headers: + notified += 1 + asyncio.create_task( + session.send_notification('blockchain.headers.subscribe', + (self.session_manager.hsub_results[session.subscribe_headers_raw], )) + ) + if notified % 10 == 0: + await asyncio.sleep(0) # break up the loop somewhat, there can be many headers notifications + if notified: + self.logger.info(f'queued notify {notified} sessions of new header') for hashX in touched.intersection(self.session_manager.mempool_statuses.keys()): self.session_manager.mempool_statuses.pop(hashX, None) # self.bp._chain_executor