Browse Source

interface: subscribe to headers in run_fetch_blocks

so that 'monitor_connection' is already running while waiting for first header
3.3.3.1
SomberNight 6 years ago
parent
commit
825d7c2cbd
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 8
      electrum/interface.py

8
electrum/interface.py

@ -340,7 +340,6 @@ class Interface(PrintError):
return conn, res['count']
async def open_session(self, sslc, exit_early):
header_queue = asyncio.Queue()
self.session = NotificationSession(self.host, self.port, ssl=sslc, proxy=self.proxy)
async with self.session as session:
try:
@ -350,11 +349,10 @@ class Interface(PrintError):
if exit_early:
return
self.print_error("connection established. version: {}".format(ver))
await session.subscribe('blockchain.headers.subscribe', [], header_queue)
async with self.group as group:
await group.spawn(self.ping())
await group.spawn(self.run_fetch_blocks(header_queue))
await group.spawn(self.run_fetch_blocks())
await group.spawn(self.monitor_connection())
# NOTE: group.__aexit__ will be called here; this is needed to notice exceptions in the group!
@ -373,7 +371,9 @@ class Interface(PrintError):
self.fut.cancel()
asyncio.get_event_loop().create_task(self.group.cancel_remaining())
async def run_fetch_blocks(self, header_queue):
async def run_fetch_blocks(self):
header_queue = asyncio.Queue()
await self.session.subscribe('blockchain.headers.subscribe', [], header_queue)
while True:
self.network.notify('updated')
item = await header_queue.get()

Loading…
Cancel
Save