runner obeys config.backfill

This commit is contained in:
tim
2024-10-22 03:55:57 -04:00
parent 5efc1fa82e
commit 05c1a121f6
4 changed files with 28 additions and 3 deletions

View File

@@ -15,5 +15,6 @@ async-lru
eth-bloom
python-dateutil
eth_abi
eth_utils
pdpyras # pagerduty
numpy

View File

@@ -149,7 +149,10 @@ def promotion_height(chain: Blockchain=None, latest_height: int=None):
if chain is None:
chain = current_chain.get()
if latest_height is None:
latest_height = latest_block.get(chain.id).height
block = latest_block.get(chain.id)
if block is None:
return 0
latest_height = block.height
if latest_height is None:
return 0
confirm_offset = config.confirms if config.confirms is not None else chain.confirms

View File

@@ -26,7 +26,7 @@ class Config:
concurrent_rpc_connections: int = 4
parallel_logevent_queries: bool = True
polling: float = 0 # seconds between queries for a new block. 0 disables polling and uses a websocket subscription on ws_url instead
backfill: int = 0 # if not 0, then runner will initialize an empty database by backfilling from the given block height
backfill: int = 0 # if not 0, then runner will initialize an empty database by backfilling from the given block height. Use negative numbers to indicate a number of blocks before the present.
account: Optional[str] = None # may be a private key or an account alias
accounts: Optional[dict[str,str]] = field(default_factory=dict) # account aliases

View File

@@ -17,6 +17,7 @@ from dexorder.blockstate import BlockState, current_blockstate
from dexorder.blockstate.branch import Branch
from dexorder.blockstate.diff import DiffEntryItem
from dexorder.blockstate.fork import current_fork, Fork
from dexorder.contract.dexorder import get_dexorder_contract, get_factory_contract, get_vault_init_code_hash
from dexorder.progressor import BlockProgressor
from dexorder.transactions import create_and_send_transactions
from dexorder.util import hexstr, hexbytes
@@ -217,9 +218,29 @@ class BlockStateRunner(BlockProgressor):
w3 = current_w3.get()
chain = current_chain.get()
assert chain.id == await w3.eth.chain_id
log.info(f'''
Chain {chain}
Factory {get_factory_contract().address}
Dexorder {get_dexorder_contract().address}
VICH {hexstr(get_vault_init_code_hash())}''')
# backfill
if self.state is None and config.backfill != 0:
if config.backfill > 0:
height = config.backfill
else:
cur = await w3.eth.get_block_number()
height = cur + config.backfill if config.backfill < 0 else cur
block = await get_block(height)
self.set_latest_block(block)
self.new_head_event.set()
log.info(f'Backfilling from block {block}')
# main run loop
while self.running:
try:
await asyncio.wait_for(self.new_head_event.wait(), timeout=1) # todo configure
await asyncio.wait_for(self.new_head_event.wait(), timeout=1)
except TimeoutError:
# DISABLED. See note on handle_time_tick()
# if fork is not None: