-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Check bank capitalization #11927
Check bank capitalization #11927
Conversation
btw, because the testnet ledger was restarted, it's now safe to start to enforce this everytime validator starts. (thanks @mvines). |
@@ -2843,22 +2845,7 @@ impl Bank { | |||
} | |||
|
|||
pub fn calculate_capitalization(&self) -> u64 { | |||
self.get_program_accounts(None) |
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.
This has been solely used for the ledger-tool capitalization
subcommand.
Move to AccountsDB::
and use this from ledger-tool
and snapshot
codepaths
Codecov Report
@@ Coverage Diff @@
## master #11927 +/- ##
========================================
Coverage 82.0% 82.0%
========================================
Files 337 337
Lines 79220 79369 +149
========================================
+ Hits 65015 65160 +145
- Misses 14205 14209 +4 |
@ryoqun Let's say we had an inflation bug, like an overflow in the contract, would this catch it? I want to make sure that we can compute the max possible supply in the snapshot and fail if it exceeds it. |
@aeyakovenko Yeah, I've tested this locally. These catches them as the last protection mechanism. For both inflation and overflow in contracts, these will be protected by their specific protections, btw. So, I've manually disabled them while testing locally. I've added some sanity assertion: Lines 932 to 940 in 11ac4eb
solana/runtime/src/message_processor.rs Lines 559 to 578 in 11ac4eb
|
@sakridge Could you review this? I have still something to do (add test for overflow; benchmark checked u64 vs u128 for summing) but mostly this should be done. What I have added to your original pr:
|
0a64fb0
to
d4d1831
Compare
All of these are now done. For benchmarking, I saw no noticeable difference and doing the cap calculation should be no harm because it's so small compared to hashing: slower:
faster:
For completeness and pure curiosity, I've went into details and found that https://docs.google.com/spreadsheets/d/1nsnNwkaTQ4pjpQKPwEhYcxhuhU0YCnvYm81Nmvf9zjA/edit#gid=0 |
f9b58ac
to
4ba5a8c
Compare
@sakridge Thanks for reviewing. I think I've addressed all your review comments. |
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.
looks really good, thanks!
* Check bank capitalization * Simplify and unify capitalization calculation * Improve and add tests * Avoid overflow and inhibit automatic restart * Fix test * Tweak checked sum for cap. and add tests * Fix broken build after merge conflicts.. * Rename to ClusterType * Rename confusing method * Clarify comment * Verify cap. in rent and inflation tests Co-authored-by: Stephen Akridge <sakridge@gmail.com> (cherry picked from commit de4a613) # Conflicts: # Cargo.lock # accounts-bench/Cargo.toml
* Check bank capitalization (#11927) * Check bank capitalization * Simplify and unify capitalization calculation * Improve and add tests * Avoid overflow and inhibit automatic restart * Fix test * Tweak checked sum for cap. and add tests * Fix broken build after merge conflicts.. * Rename to ClusterType * Rename confusing method * Clarify comment * Verify cap. in rent and inflation tests Co-authored-by: Stephen Akridge <sakridge@gmail.com> (cherry picked from commit de4a613) # Conflicts: # Cargo.lock # accounts-bench/Cargo.toml * Fix conflict 1/2 * Fix conflict 2/2 Co-authored-by: Ryo Onodera <ryoqun@gmail.com>
Problem
No check for bank capitalization.
Also, the current offline bank capitalization check doesn't catch overflows.
Summary of Changes
On accounts hashing, load the total accounts capitalization and compare with bank.capitalization.
Fixes #
context
reboot of #10937