-
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
Handle accounts data size changes due to rent-collected accounts #22412
Handle accounts data size changes due to rent-collected accounts #22412
Conversation
Codecov Report
@@ Coverage Diff @@
## master #22412 +/- ##
=========================================
- Coverage 81.1% 81.0% -0.1%
=========================================
Files 553 551 -2
Lines 150439 150249 -190
=========================================
- Hits 122075 121848 -227
- Misses 28364 28401 +37 |
runtime/src/bank.rs
Outdated
self.rewards | ||
.write() | ||
.unwrap() | ||
.extend(rent_debits.into_unordered_rewards_iter()); | ||
if total_collected.account_data_len > 0 { | ||
self.update_accounts_data_len(-(total_collected.account_data_len as i64)); |
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.
Originally I wanted to use atomic fetch_sub()
here, but that doesn't have a 'saturating' version (more details below). I need the update_accounts_data_len()
version for a future PR to handle where the accounts data len can either shrink or grow, so pulled that in to use here.
So fetch_sub()
should work in all real/production cases†, but causes quite a few tests to fail. This is because the Bank that's created for tests has an accounts_data_len
of 0. The test adds accounts, but not in a way that updates accounts data len. Thus, the tests that check for rent cleaning up accounts cause the accounts_data_len
to wrap back to a very large positive number.
† The bank's accounts_data_len is not 100% the true size, and I'm not sure it will be. So I'm also concerned of a production scenario that causes the wrap around to happen and takes down the cluster.
To solve, I could've:
- Update all the test by manually setting a non zero
accounts_data_len
- Have a test and not-test (
#[cfg(test)]
and#[cfg(not(test))]
block right here at this line - My current impl
I went with (3) because (1) seems fragile, and (2) seems a bit dangerous to not have the same logic for tests and not tests on such a core component.
Let me know if you'd like a different solution!
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
Pull request has been modified.
6395e4d
to
94b11b7
Compare
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 good, thanks for adding the tests!
) (cherry picked from commit c45dde6) # Conflicts: # runtime/src/bank.rs # runtime/src/rent_collector.rs
) (#22919) Co-authored-by: Brooks Prumo <[email protected]>
Problem
Accounts that are reclaimed during rent collection (i.e. lamports go to zero) are not factored into the Bank's
accounts_data_len
.Summary of Changes
Track reclaimed accounts data len during rent collection, then return that information to the bank so it can update its accounts data len.
CollectedInfo
fromcollect_from_existing_account()
to track both the rent amount and account data lencollect_rent_in_partition()
, sum all the collected-infos then use that final value to update the bank's accounts data len