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

Precompute runtime account stats (total_sent, total_received) #618

Merged
merged 2 commits into from
Feb 13, 2024

Conversation

Andrew7234
Copy link
Collaborator

@lukaw3d noticed that a query to the runtime accounts endpoint for the fee accumulator address (https://nexus.oasis.io/v1/sapphire/accounts/oasis1qp3r8hgsnphajmfzfuaa8fhjag7e0yt35cjxq0u4) was timing out. Further investigation showed that the db operation to calculate the account statistics for total_sent and total_received were timing out because they were calculated on the fly and the fee accumulator account was involved in ~30% of all transfers. The query optimizer was therefore doing a full table scan on chain.runtime_transfers instead of using the existing (flawed) index.

This PR includes changes to dead-reckon the total_sent and total_received amounts in the chain.runtime_accounts table. It also fixes the existing indexes on the chain.runtime_transfers table.

Copy link
Member

@ptrus ptrus left a comment

Choose a reason for hiding this comment

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

Looks good to me, couple of minor questions

storage/migrations/07_runtime_accounts_stats.up.sql Outdated Show resolved Hide resolved
analyzer/runtime/runtime.go Show resolved Hide resolved
@Andrew7234 Andrew7234 force-pushed the andrew7234/account-stats branch from a8e3448 to 385c196 Compare January 29, 2024 19:12
@Andrew7234 Andrew7234 requested a review from ptrus January 31, 2024 02:27
Copy link
Contributor

@mitjat mitjat left a comment

Choose a reason for hiding this comment

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

Nice, thank you! Nits only from my side.

storage/client/client.go Outdated Show resolved Hide resolved
storage/client/client.go Show resolved Hide resolved
@Andrew7234 Andrew7234 force-pushed the andrew7234/account-stats branch from b8167a1 to 932be12 Compare February 13, 2024 03:16
track total sent/received for runtime_accounts

recreate index in migration

nit

nit

query nits

fix default account stats

address comment
@Andrew7234 Andrew7234 force-pushed the andrew7234/account-stats branch from 932be12 to 544c041 Compare February 13, 2024 03:21
@Andrew7234 Andrew7234 enabled auto-merge February 13, 2024 03:41
@Andrew7234 Andrew7234 merged commit c8dd4a0 into main Feb 13, 2024
9 checks passed
@Andrew7234 Andrew7234 deleted the andrew7234/account-stats branch February 13, 2024 03:44
@mitjat mitjat changed the title Andrew7234/account stats Precompute runtime account stats (total_sent, total_received) Feb 15, 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.

3 participants