-
Notifications
You must be signed in to change notification settings - Fork 679
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
Add database analyze-contract-sizes #11249
Conversation
Add a command which looks at the current state and finds accounts with biggest contract sizes. Example usage: ``` $ ./neard database analyze-contract-sizes --topn 10 ... Analyzed 33165 accounts Accounts per shard: s0.v3: 6443 s1.v3: 1 s2.v3: 7916 s3.v3: 3643 s4.v3: 11208 s5.v3: 3954 Top 10 accounts by size: 3.9 MB: nearpay-portals.near 3.8 MB: moodev.near 2.8 MB: v2_1_0.perp.spin-fi.near 2.8 MB: v2_0_2.perp.spin-fi.near 2.8 MB: v2.perp.spin-fi.near 2.7 MB: switchboard-v2.near 2.6 MB: nft.contented.near 2.5 MB: spot.spin-fi.near 2.5 MB: nftstaking.jumpfinance.near 2.5 MB: exchange.slowisfast.near ```
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #11249 +/- ##
==========================================
+ Coverage 64.93% 71.12% +6.19%
==========================================
Files 771 785 +14
Lines 153218 155330 +2112
Branches 153218 155330 +2112
==========================================
+ Hits 99486 110485 +10999
+ Misses 49494 40098 -9396
- Partials 4238 4747 +509
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
if last_block.header().chunk_mask().contains(&false) { | ||
panic!("Last block doesn't have all chunks, please try again later!"); | ||
} |
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.
Hehe :) Consider taking ChunkExtra
s for last block - it will have all state roots. Alternatively we can iterate back in history to find block with all chunks, but we ever have 100 shards, that can become unstable.
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.
Oh and ChunkExtra
will exist even for missing chunks? That's nice, changed it to use ChunkExtra
then.
let trie = Trie::new(trie_storage, state_root, None); | ||
|
||
let mut iterator = trie.iter().unwrap(); | ||
iterator.seek_prefix(&[col::CONTRACT_CODE]).unwrap(); |
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.
Alternatively we can look at flat storage head and read all data from FlatState
. But if this is quick already / we already have all the results, proceed with Trie.
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.
It takes under 30s to analyze the current mainnet state on dev-release
, so I think it's fast enough.
Add a command which looks at the current state and finds accounts with the biggest contract sizes.
Example usage: