-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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 more accounts data size changes #26467
Track more accounts data size changes #26467
Conversation
93ca829
to
d2d3293
Compare
runtime/src/bank.rs
Outdated
self.capitalization | ||
.fetch_add(native_mint_account.lamports(), Relaxed); | ||
true | ||
}; | ||
|
||
if store { | ||
self.store_account(&inline_spl_token::native_mint::id(), &native_mint_account); | ||
let data_size_delta = (native_mint_account.data().len() as i64) | ||
.saturating_sub(old_account_data_size as i64); | ||
self.update_accounts_data_size_delta_off_chain(data_size_delta); |
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.
seems useful to have an update function that takes (new_lamports, prev_lamports) and does the casts, saturating subs, delta update, etc.
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.
Done!
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.
I think I was thinking combine both of these:
let data_size_delta =
compute_data_size_delta(old_account.data().len(), new_account.data().len());
self.update_accounts_data_size_delta_off_chain(data_size_delta);
```
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.
self.update_accounts_data_size_difference_off_chain(old, new);
?
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.
name is bad. just the idea.
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.
Got it. Done! (I chose calculate_and_update_accounts_data_size_delta_off_chain()
🙃)
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, I am so much happy
&solana_sdk::pubkey::new_rand(), | ||
); | ||
let mut account = | ||
AccountSharedData::new(account_balance, 0, &solana_sdk::pubkey::new_rand()); |
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.
is this still rent exempt? Not sure how test is relying on that, but test name implies 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.
I didn't add this test originally, but did later modify it to include a non-zero data size. Since then, I have added more tests for the accounts data size and it's no longer required here, so I wanted to return this test back to its original behavior. Since store_account()
is called, I wanted to remove as much special-case code around it as possible. Let me know if you'd like me to change something in here.
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.
that's fine. just a little confusing and making sure we understand.
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.
lgtm
Problem
Not all of the off-chain changes to accounts data size are tracked. In addition, calling
Bank::get_total_accounts_stats()
used to always be greater thanBank::load_accounts_data_size()
by a constant amount—no more!As I investigate why the accounts data size is different when starting from a snapshot vs replay, I found some accounts data size changes that weren't tracked. This PR doesn't fully solve that issue, but that's the context behind this PR.
Summary of Changes
Track 'em! (Also add some tests.)
Mostly audited all calls to
store_account()
andstore_accounts()
to see if the account may've changed size.