mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 06:04:21 +01:00
watcher - Fixes cache setup for regtest
Cache setup in regtest was raising some warnings due to the blocks not being found
This commit is contained in:
@@ -61,14 +61,19 @@ class LocatorCache:
|
|||||||
# Not doing so implies store temporary variables in the Watcher and initialising the cache as None.
|
# Not doing so implies store temporary variables in the Watcher and initialising the cache as None.
|
||||||
target_block_hash = last_known_block
|
target_block_hash = last_known_block
|
||||||
for _ in range(self.cache_size):
|
for _ in range(self.cache_size):
|
||||||
target_block = block_processor.get_block(target_block_hash)
|
|
||||||
|
|
||||||
# In some setups, like regtest, it could be the case that there are no enough previous blocks.
|
# In some setups, like regtest, it could be the case that there are no enough previous blocks.
|
||||||
if target_block:
|
# In those cases we pull as many as we can.
|
||||||
locators = {compute_locator(txid): txid for txid in target_block.get("tx")}
|
if target_block_hash:
|
||||||
self.cache.update(locators)
|
target_block = block_processor.get_block(target_block_hash)
|
||||||
self.blocks[target_block_hash] = locators
|
if not target_block:
|
||||||
target_block_hash = target_block.get("previousblockhash")
|
break
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
locators = {compute_locator(txid): txid for txid in target_block.get("tx")}
|
||||||
|
self.cache.update(locators)
|
||||||
|
self.blocks[target_block_hash] = locators
|
||||||
|
target_block_hash = target_block.get("previousblockhash")
|
||||||
|
|
||||||
self.blocks = OrderedDict(reversed((list(self.blocks.items()))))
|
self.blocks = OrderedDict(reversed((list(self.blocks.items()))))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user