daemon: getting height optionally gets mempool
Improve daemon startup log message
This commit is contained in:
parent
5fe49bb261
commit
ac48695db8
@ -67,8 +67,13 @@ class Prefetcher(LoggedClass):
|
|||||||
|
|
||||||
async def main_loop(self):
|
async def main_loop(self):
|
||||||
'''Loop forever polling for more blocks.'''
|
'''Loop forever polling for more blocks.'''
|
||||||
self.logger.info('catching up to daemon height {:,d}...'
|
daemon_height = await self.daemon.height()
|
||||||
.format(await self.daemon.height()))
|
if daemon_height > height:
|
||||||
|
log_msg = 'catching up to daemon height {:,d}...'
|
||||||
|
else:
|
||||||
|
log_msg = 'caught up to daemon height {:,d}'
|
||||||
|
self.logger.info(log_msg.format(daemon_height))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
secs = 0
|
secs = 0
|
||||||
@ -87,10 +92,7 @@ class Prefetcher(LoggedClass):
|
|||||||
'''Prefetch blocks unless the prefetch queue is full.'''
|
'''Prefetch blocks unless the prefetch queue is full.'''
|
||||||
# Refresh the mempool after updating the daemon height, if and
|
# Refresh the mempool after updating the daemon height, if and
|
||||||
# only if we've caught up
|
# only if we've caught up
|
||||||
daemon_height = await self.daemon.height()
|
daemon_height = await self.daemon.height(mempool=self.caught_up)
|
||||||
if self.caught_up:
|
|
||||||
await self.daemon.refresh_mempool_hashes()
|
|
||||||
|
|
||||||
cache_room = self.target_cache_size // self.ave_size
|
cache_room = self.target_cache_size // self.ave_size
|
||||||
with await self.semaphore:
|
with await self.semaphore:
|
||||||
# Try and catch up all blocks but limit to room in cache.
|
# Try and catch up all blocks but limit to room in cache.
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class Daemon(util.LoggedClass):
|
|||||||
self.urls = urls
|
self.urls = urls
|
||||||
self.url_index = 0
|
self.url_index = 0
|
||||||
self._height = None
|
self._height = None
|
||||||
self.mempool_hashes = set()
|
self._mempool_hashes = set()
|
||||||
self.mempool_refresh_event = asyncio.Event()
|
self.mempool_refresh_event = asyncio.Event()
|
||||||
# Limit concurrent RPC calls to this number.
|
# Limit concurrent RPC calls to this number.
|
||||||
# See DEFAULT_HTTP_WORKQUEUE in bitcoind, which is typically 16
|
# See DEFAULT_HTTP_WORKQUEUE in bitcoind, which is typically 16
|
||||||
@ -150,10 +150,9 @@ class Daemon(util.LoggedClass):
|
|||||||
# Convert hex string to bytes
|
# Convert hex string to bytes
|
||||||
return [bytes.fromhex(block) for block in blocks]
|
return [bytes.fromhex(block) for block in blocks]
|
||||||
|
|
||||||
async def refresh_mempool_hashes(self):
|
async def mempool_hashes(self):
|
||||||
'''Update our record of the daemon's mempool hashes.'''
|
'''Update our record of the daemon's mempool hashes.'''
|
||||||
self.mempool_hashes = set(await self._send_single('getrawmempool'))
|
return await self._send_single('getrawmempool')
|
||||||
self.mempool_refresh_event.set()
|
|
||||||
|
|
||||||
async def estimatefee(self, params):
|
async def estimatefee(self, params):
|
||||||
'''Return the fee estimate for the given parameters.'''
|
'''Return the fee estimate for the given parameters.'''
|
||||||
@ -187,11 +186,18 @@ class Daemon(util.LoggedClass):
|
|||||||
'''Broadcast a transaction to the network.'''
|
'''Broadcast a transaction to the network.'''
|
||||||
return await self._send_single('sendrawtransaction', params)
|
return await self._send_single('sendrawtransaction', params)
|
||||||
|
|
||||||
async def height(self):
|
async def height(self, mempool=False):
|
||||||
'''Query the daemon for its current height.'''
|
'''Query the daemon for its current height.'''
|
||||||
self._height = await self._send_single('getblockcount')
|
self._height = await self._send_single('getblockcount')
|
||||||
|
if mempool:
|
||||||
|
self._mempool_hashes = set(await self.mempool_hashes())
|
||||||
|
self.mempool_refresh_event.set()
|
||||||
return self._height
|
return self._height
|
||||||
|
|
||||||
|
def cached_mempool_hashes(self):
|
||||||
|
'''Return the cached mempool hashes.'''
|
||||||
|
return self._mempool_hashes
|
||||||
|
|
||||||
def cached_height(self):
|
def cached_height(self):
|
||||||
'''Return the cached daemon height.
|
'''Return the cached daemon height.
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,7 @@ class MemPool(util.LoggedClass):
|
|||||||
hash168s = self.hash168s
|
hash168s = self.hash168s
|
||||||
touched = self.touched
|
touched = self.touched
|
||||||
|
|
||||||
hashes = self.daemon.mempool_hashes
|
hashes = self.daemon.cached_mempool_hashes()
|
||||||
gone = set(txs).difference(hashes)
|
gone = set(txs).difference(hashes)
|
||||||
for hex_hash in gone:
|
for hex_hash in gone:
|
||||||
unfetched.discard(hex_hash)
|
unfetched.discard(hex_hash)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user