Skip to content

Commit

Permalink
Move async_handle_initial_iteration outside main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lesigh-3100 committed Apr 30, 2024
1 parent 7dfcf7d commit 5be7953
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
3 changes: 1 addition & 2 deletions fastlane_bot/events/async_backdate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def async_handle_initial_iteration(
last_block: int,
mgr: Any,
start_block: int,
current_block: int,
):
if last_block == 0:
non_multicall_rows_to_update = mgr.get_rows_to_update(start_block)
Expand All @@ -105,7 +104,7 @@ def async_handle_initial_iteration(
)

mgr.cfg.logger.info(
f"Backdating {len(other_pool_rows)} pools from {start_block} to {current_block}"
f"Backdating {len(other_pool_rows)} pools from {start_block}"
)
start_time = time.time()
async_backdate_from_contracts(
Expand Down
42 changes: 21 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ def run(mgr, args, tenderly_uri=None) -> None:
mainnet_uri = mgr.cfg.w3.provider.endpoint_uri
handle_static_pools_update(mgr)

# Handle the initial iteration (backdate pools, update pools from contracts, etc.)
async_handle_initial_iteration(
backdate_pools=args.backdate_pools,
last_block=last_block,
mgr=mgr,
start_block=args.replay_from_block,
)

while True:
try:
# Save initial state of pool data to assert whether it has changed
Expand Down Expand Up @@ -355,22 +363,22 @@ def run(mgr, args, tenderly_uri=None) -> None:
args.use_cached_events,
)

latest_events = (
get_cached_events(mgr, args.logging_path)
if args.use_cached_events
else get_latest_events(
current_block,
mgr,
args.n_jobs,
start_block,
args.cache_latest_only,
args.logging_path,
)
)
# latest_events = (
# get_cached_events(mgr, args.logging_path)
# if args.use_cached_events
# else get_latest_events(
# current_block,
# mgr,
# args.n_jobs,
# start_block,
# args.cache_latest_only,
# args.logging_path,
# )
# )
iteration_start_time = time.time()

# Update the pools from the latest events
update_pools_from_events(args.n_jobs, mgr, latest_events)
#update_pools_from_events(args.n_jobs, mgr, latest_events)

# Update new pool events from contracts
if len(mgr.pools_to_add_from_contracts) > 0:
Expand All @@ -395,14 +403,6 @@ def run(mgr, args, tenderly_uri=None) -> None:
tenderly_fork_id=args.tenderly_fork_id,
)

# Handle the initial iteration (backdate pools, update pools from contracts, etc.)
async_handle_initial_iteration(
backdate_pools=args.backdate_pools,
current_block=current_block,
last_block=last_block,
mgr=mgr,
start_block=start_block,
)

# Run multicall every iteration
multicall_every_iteration(current_block=current_block, mgr=mgr)
Expand Down

0 comments on commit 5be7953

Please sign in to comment.