collect_rent_eagerly can just do rewrites (#24438)

This commit is contained in:
Jeff Washington (jwash) 2022-04-18 22:44:19 -05:00 committed by GitHub
parent bf1e0c89e8
commit 94d3ec37d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -3035,7 +3035,7 @@ impl Bank {
let mut hash = self.hash.write().unwrap();
if *hash == Hash::default() {
// finish up any deferred changes to account state
self.collect_rent_eagerly();
self.collect_rent_eagerly(false);
self.collect_fees();
self.distribute_rent();
self.update_slot_history();
@ -4741,7 +4741,12 @@ impl Bank {
}
}
fn collect_rent_eagerly(&self) {
/// after deserialize, populate rewrites with accounts that would normally have had their data rewritten in this slot due to rent collection (but didn't)
pub fn prepare_rewrites_for_hash(&self) {
self.collect_rent_eagerly(true);
}
fn collect_rent_eagerly(&self, just_rewrites: bool) {
if self.lazy_rent_collection.load(Relaxed) {
return;
}
@ -4751,7 +4756,7 @@ impl Bank {
let count = partitions.len();
let account_count: usize = partitions
.into_iter()
.map(|partition| self.collect_rent_in_partition(partition))
.map(|partition| self.collect_rent_in_partition(partition, just_rewrites))
.sum();
measure.stop();
datapoint_info!(
@ -4787,7 +4792,17 @@ impl Bank {
}
}
fn collect_rent_in_partition(&self, partition: Partition) -> usize {
/// load accounts with pubkeys in 'partition'
/// collect rent
/// store accounts, whether rent was collected or not
/// update bank's rewrites set for all rewrites that were skipped
/// if 'just_rewrites', function will only update bank's rewrites set and not actually store any accounts
/// return # accounts loaded
fn collect_rent_in_partition(&self, partition: Partition, just_rewrites: bool) -> usize {
if just_rewrites {
// this is not implemented yet. In the meantime, this call can have no side effects.
return 0;
}
let subrange = Self::pubkey_range_from_partition(partition);
let thread_pool = &self.rc.accounts.accounts_db.thread_pool;
@ -8781,7 +8796,7 @@ pub(crate) mod tests {
vec![genesis_slot]
);
bank.collect_rent_in_partition((0, 0, 1)); // all range
bank.collect_rent_in_partition((0, 0, 1), false); // all range
assert_eq!(bank.collected_rent.load(Relaxed), rent_collected);
assert_eq!(
@ -8864,8 +8879,8 @@ pub(crate) mod tests {
assert_eq!(hash1_with_zero, hash1_without_zero);
assert_ne!(hash1_with_zero, Hash::default());
bank2_with_zero.collect_rent_in_partition((0, 0, 1)); // all
bank2_without_zero.collect_rent_in_partition((0, 0, 1)); // all
bank2_with_zero.collect_rent_in_partition((0, 0, 1), false); // all
bank2_without_zero.collect_rent_in_partition((0, 0, 1), false); // all
bank2_with_zero.freeze();
let hash2_with_zero = bank2_with_zero.hash();

View File

@ -1632,6 +1632,8 @@ fn rebuild_bank_from_snapshots(
bank.src.append(&slot_deltas);
bank.prepare_rewrites_for_hash();
info!("Loaded bank for slot: {}", bank.slot());
Ok(bank)
}