Rework bank to allow RentCollectionCycleParams private (#31361)

This commit is contained in:
Brennan 2023-04-26 14:48:51 -07:00 committed by GitHub
parent 6b1980285b
commit 685ebcb3b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 27 deletions

View File

@ -17,7 +17,7 @@ use {
pub(crate) type PartitionIndex = u64;
type PartitionsPerCycle = u64;
pub(crate) type Partition = (PartitionIndex, PartitionIndex, PartitionsPerCycle);
pub(crate) type RentCollectionCycleParams = (
type RentCollectionCycleParams = (
Epoch,
SlotCount,
bool,
@ -163,6 +163,23 @@ pub(crate) fn rent_single_epoch_collection_cycle_params(
)
}
pub(crate) fn rent_multi_epoch_collection_cycle_params(
epoch: Epoch,
slot_count_per_epoch: SlotCount,
first_normal_epoch: Epoch,
epoch_count_in_cycle: Epoch,
) -> RentCollectionCycleParams {
let partition_count = slot_count_per_epoch * epoch_count_in_cycle;
(
epoch,
slot_count_per_epoch,
true,
first_normal_epoch,
epoch_count_in_cycle,
partition_count,
)
}
pub(crate) fn get_partitions(
slot: Slot,
parent_slot: Slot,

View File

@ -51,7 +51,7 @@ use {
},
accounts_hash::{AccountsHash, CalcAccountsHashConfig, HashStats, IncrementalAccountsHash},
accounts_index::{AccountSecondaryIndexes, IndexKey, ScanConfig, ScanResult, ZeroLamport},
accounts_partition::{self, Partition, PartitionIndex, RentCollectionCycleParams},
accounts_partition::{self, Partition, PartitionIndex},
accounts_update_notifier_interface::AccountsUpdateNotifier,
ancestors::{Ancestors, AncestorsForSerialization},
bank::metrics::*,
@ -5794,7 +5794,22 @@ impl Bank {
epoch: Epoch,
generated_for_gapped_epochs: bool,
) -> Partition {
let cycle_params = self.determine_collection_cycle_params(epoch);
let slot_count_per_epoch = self.get_slots_in_epoch(epoch);
let cycle_params = if !self.use_multi_epoch_collection_cycle(epoch) {
// mnb should always go through this code path
accounts_partition::rent_single_epoch_collection_cycle_params(
epoch,
slot_count_per_epoch,
)
} else {
accounts_partition::rent_multi_epoch_collection_cycle_params(
epoch,
slot_count_per_epoch,
self.first_normal_epoch(),
self.slot_count_in_two_day() / slot_count_per_epoch,
)
};
accounts_partition::get_partition_from_slot_indexes(
cycle_params,
start_slot_index,
@ -5821,30 +5836,6 @@ impl Bank {
self.do_partition_from_slot_indexes(start_slot_index, end_slot_index, epoch, true)
}
fn determine_collection_cycle_params(&self, epoch: Epoch) -> RentCollectionCycleParams {
let slot_count_per_epoch = self.get_slots_in_epoch(epoch);
if !self.use_multi_epoch_collection_cycle(epoch) {
// mnb should always go through this code path
accounts_partition::rent_single_epoch_collection_cycle_params(
epoch,
slot_count_per_epoch,
)
} else {
let epoch_count_in_cycle = self.slot_count_in_two_day() / slot_count_per_epoch;
let partition_count = slot_count_per_epoch * epoch_count_in_cycle;
(
epoch,
slot_count_per_epoch,
true,
self.first_normal_epoch(),
epoch_count_in_cycle,
partition_count,
)
}
}
// Given short epochs, it's too costly to collect rent eagerly
// within an epoch, so lower the frequency of it.
// These logic isn't strictly eager anymore and should only be used