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

Remove conservative deletes on restarts #63

Merged
merged 3 commits into from
Oct 4, 2024
Merged
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
22 changes: 12 additions & 10 deletions src/transaction_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def __init__(

def get_start_block(self) -> int:
"""
Retrieve the most recent block already present in raw_token_imbalances table,
delete entries for that block, and return this block number as start_block.
Retrieve the most recent block X already present in raw_token_imbalances table,
and return block X+1 as start_block.
If block X is from more than 1 day ago, a recent finalized block is returned.
TODO: Remove that rule before moving to production.

If no entries are present, fallback to get_finalized_block_number().
"""
try:
Expand All @@ -47,19 +50,18 @@ def get_start_block(self) -> int:
)
row = result.fetchone()
max_block = row[0] if row is not None else None
blockchain_latest_block = self.blockchain_data.get_latest_block()

# If no entries present, fallback to get_latest_block()
if max_block is None:
return self.blockchain_data.get_latest_block()
return blockchain_latest_block

logger.info("Fetched max block number from database: %d", max_block)

# Delete entries for the max block from the table
delete_sql = read_sql_file("src/sql/delete_entries_max_block.sql")
self.db.execute_and_commit(
delete_sql, {"chain_name": self.chain_name, "block_number": max_block}
)
return max_block
if max_block > blockchain_latest_block - 7200:
return max_block + 1
else:
# TODO: Remove this rule before moving to production.
return blockchain_latest_block
except Exception as e:
logger.error("Error fetching start block from database: %s", e)
raise
Expand Down
Loading