Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix function async_update_pools_from_contracts #616

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions fastlane_bot/events/async_event_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ def _get_new_pool_data(
all_keys = set()
for pool in mgr.pool_data:
all_keys.update(pool.keys())
if "last_updated_block" not in all_keys:
all_keys.update(["last_updated_block"])
pool_data_keys: frozenset = frozenset(all_keys)
new_pool_data: List[Dict] = []
for idx, pool in tokens_and_fee_df.iterrows():
Expand Down Expand Up @@ -394,6 +392,10 @@ def async_update_pools_from_contracts(mgr: Any, current_block: int):
mgr, current_block, tokens_and_fee_df, tokens_df
)

if len(new_pool_data) == 0:
mgr.cfg.logger.info("No pools found in contracts")
return

new_pool_data_df = pd.DataFrame(new_pool_data).sort_values(
"last_updated_block", ascending=False
)
Expand All @@ -410,6 +412,10 @@ def async_update_pools_from_contracts(mgr: Any, current_block: int):
]
)

if new_pool_data_df.empty:
mgr.cfg.logger.info("No valid pools found in contracts")
return

new_pool_data_df["descr"] = (
new_pool_data_df["exchange_name"]
+ " "
Expand Down
20 changes: 0 additions & 20 deletions fastlane_bot/events/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,3 @@ def handle_trading_fee_updated(self):
pool["fee_float"] = pool["fee"] / 1e6
pool["descr"] = self.pool_descr_from_info(pool)
self.pool_data[idx] = pool


def update_remaining_pools(self):
remaining_pools = []
all_events = [pool[2] for pool in self.pools_to_add_from_contracts]
for event in all_events:
addr = self.web3.to_checksum_address(event["address"])
ex_name = self.exchange_name_from_event(event)
if not ex_name:
self.cfg.logger.warning("[update_remaining_pools] ex_name not found from event")
continue

key, key_value = self.get_key_and_value(event, addr, ex_name)
pool_info = self.get_pool_info(key, key_value, ex_name)

if not pool_info:
remaining_pools.append((addr, ex_name, event, key, key_value))

random.shuffle(remaining_pools)
self.pools_to_add_from_contracts = remaining_pools
7 changes: 0 additions & 7 deletions fastlane_bot/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ def __str__(self):
f"create this file.")


class AsyncUpdateRetryException(Exception):
"""
Exception raised when async_update_pools_from_contracts fails and needs to be retried.
"""
pass


class FlashloanUnavailableException(Exception):
"""
Exception raised when not configured to use self_fund on a blockchain that does not support Flashloans.
Expand Down
54 changes: 0 additions & 54 deletions fastlane_bot/tests/test_068_exceptions.py

This file was deleted.

25 changes: 2 additions & 23 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Licensed under MIT
"""

from fastlane_bot.exceptions import AsyncUpdateRetryException, ReadOnlyException, FlashloanUnavailableException
from fastlane_bot.exceptions import ReadOnlyException, FlashloanUnavailableException
from fastlane_bot.events.version_utils import check_version_requirements
from fastlane_bot.tools.cpc import T

Expand Down Expand Up @@ -370,7 +370,7 @@ def run(mgr, args, tenderly_uri=None) -> None:
f"Adding {len(mgr.pools_to_add_from_contracts)} new pools from contracts, "
f"{len(mgr.pool_data)} total pools currently exist. Current block: {current_block}."
)
_run_async_update_with_retries(mgr, current_block=current_block)
async_update_pools_from_contracts(mgr, current_block=current_block)
mgr.pools_to_add_from_contracts = []

# Increment the loop index
Expand Down Expand Up @@ -538,27 +538,6 @@ def run(mgr, args, tenderly_uri=None) -> None:
break


def _run_async_update_with_retries(mgr, current_block, max_retries=5):
failed_async_calls = 0

while failed_async_calls < max_retries:
try:
async_update_pools_from_contracts(mgr, current_block)
return # Successful execution
except AsyncUpdateRetryException as e:
failed_async_calls += 1
mgr.cfg.logger.error(f"Attempt {failed_async_calls} failed: {e}")
mgr.update_remaining_pools()

# Handling failure after retries
mgr.cfg.logger.error(
f"[main run.py] async_update_pools_from_contracts failed after "
f"{len(mgr.pools_to_add_from_contracts)} attempts. List of failed pools: {mgr.pools_to_add_from_contracts}"
)

raise AsyncUpdateRetryException("[main.py] async_update_pools_from_contracts failed after maximum retries.")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down
Loading