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

storage: add index for efficient fetching of events emitted by a specific contract #808

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

ptrus
Copy link
Member

@ptrus ptrus commented Nov 29, 2024

Part of: #804

This will enable efficient querying of all transfers of a specific ERC20 token. This is needed for the Transfer tab in the tokens details page (https://explorer.oasis.io/mainnet/sapphire/token/0x6665a6Cae3F52959f0f653E3D04270D54e6f13d8). See issue description for some more details.

Creating the index on the live instance might take some time, so ideally, the index is created CONCURENTLY sometime before deployment to prevent the migration from blocking the deployment.

Note: This doesn't resolve the inefficient accounts-related query, which is also mentioned in the issue. That one will require a separate (likely more significant) change.

TODO:

@ptrus ptrus force-pushed the ptrus/feature/events-contract-index branch 2 times, most recently from 6ac3950 to e57a8dc Compare December 1, 2024 19:06
Copy link
Collaborator

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index looks ok, so I'll just approve it. but this won't be the last we hear from this category of problems.

for #804, I think the original intention of the db design was to get a good-enough scan of the events_related_accounts index and then filter specifically token transfers emitted by the contract. but from what I'm hearing, the events_related_accounts index is not viable, I'm guessing due to it not being sorted by round. we need to do something about that, which can be separate from this PR, but still ugh

@ptrus
Copy link
Member Author

ptrus commented Dec 3, 2024

events_related_accounts index is not viable, I'm guessing due to it not being sorted by round

Yeah exactly. It works ok for contracts/accounts that don't have a lot of transactions. Probably when it cannot do the sort in-memory anymore. I started tackling that one in #809 but it's still in progress.

However, this PR solves a slightly orthogonal problem since the related_accounts query was actually the wrong query for this specific case.

@ptrus ptrus merged commit 1505498 into main Dec 3, 2024
16 checks passed
@ptrus ptrus deleted the ptrus/feature/events-contract-index branch December 3, 2024 07:21
@ptrus ptrus self-assigned this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants