Browse Source

Slightly cleaner semaphore fix

master
Neil Booth 8 years ago
parent
commit
67908b3541
  1. 11
      server/block_processor.py

11
server/block_processor.py

@ -1,4 +1,4 @@
# Copyright (c) 2016, Neil Booth
# Copyright (c) 2016-2017, Neil Booth
#
# All rights reserved.
#
@ -88,9 +88,8 @@ class Prefetcher(LoggedClass):
while True:
try:
with await self.semaphore:
fetched = await self._prefetch_blocks(caught_up_event.is_set())
if not fetched:
# Sleep a while if there is nothing to prefetch
if not await self._prefetch_blocks(caught_up_event.is_set()):
await asyncio.sleep(5)
await self.refill_event.wait()
except DaemonError as e:
@ -106,6 +105,7 @@ class Prefetcher(LoggedClass):
sleep for a period of time before returning.
'''
daemon_height = await self.daemon.height(mempool)
with await self.semaphore:
while self.cache_size < self.min_cache_size:
# Try and catch up all blocks but limit to room in cache.
# Constrain fetch count to between 0 and 2500 regardless.
@ -121,8 +121,9 @@ class Prefetcher(LoggedClass):
hex_hashes = await self.daemon.block_hex_hashes(first, count)
if self.caught_up:
self.logger.info('new block height {:,d} hash {}'
.format(first + count - 1, hex_hashes[-1]))
.format(first + count-1, hex_hashes[-1]))
blocks = await self.daemon.raw_blocks(hex_hashes)
assert count == len(blocks)
# Strip the unspendable genesis coinbase

Loading…
Cancel
Save