-
Notifications
You must be signed in to change notification settings - Fork 93
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
Track event indexing progress #3075
Conversation
Reminder: Please update the DB Readme. Caused by: |
database::last_processed_blocks::update( | ||
&mut ex, | ||
index_name, | ||
i64::try_from(last_block).context("new value of counter is not i64")?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to store in database u64
type for the last block instead of converting it to i64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately postgres doesn't support u64
natively. The alternative would be to use a bignumber type or sth like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing blocking.
Although, personally, I wouldn't introduce the function persist_last_processed_block
, but would rather adjust append_events
and replace_events
to save the last block atomically together with the events.
Mostly because of reorgs that could lower the block height and then autopilot restart could happen without updating the last_processed_blocks
.
So, bottom line, at the point in time when you store the new events (via append or replace) those functions have the responsibility to also update last_processed_blocks
to keep the db in consistent state and shouldn't move this responsibility to client.
crates/shared/src/event_handling.rs
Outdated
self.update_events_from_latest_blocks(&event_range.latest_blocks, event_range.is_reorg) | ||
.await?; | ||
self.store_mut() | ||
.persist_last_processed_block(last_block.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd move this call inside update_last_handled_blocks
as this function is where we update the local cache so aligning local cache and db makes sense.
Yeah, that is why I continued on that path rather than adjusting |
I double checked and it appears we after all have a list of checked blocks (not just blocks with events). https://github.com/cowprotocol/services/blob/main/crates/shared/src/event_handling.rs#L373-L377 Meaning, |
There is a code path here where we wouldn't know which "latest_block" to pass into Not sure if it's okay to make the Edit: nevermind we wouldn't be able to store the underlying event anyway if we don't know at which block it happened so it makes sense to err if Edit2: there seem to be quite a few places where |
Description
Our event indexing logic currently can't handle some cases well during restarts. Let's say a contract we index doesn't emit an event for 1 month our current logic would fetch the last indexed event from that contract and continue indexing from there. That means on restarts we might index ~1 month (theoretically unbounded) of blocks before we can start building new auctions (we recently started to require the indexing logic to have seen the tip of the chain before we can start building auctions).
Especially on fast chains like
arbitrum
this is a huge issue.Dusts off @squadgazzz's previous PR
Changes
last_processed_blocks
which associates a block number for an arbitrary stringsettlements
,ethflow_refunds
, andonchain_orders
How to test