Helper functions for getting rent partitions between slots (#25669)

This commit is contained in:
apfitzge 2022-06-01 20:20:44 -05:00 committed by GitHub
parent 934da5ef99
commit 369ff0858d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 17 deletions

View File

@ -5541,9 +5541,17 @@ impl Bank {
partitions
}
fn fixed_cycle_partitions(&self) -> Vec<Partition> {
fn fixed_cycle_partitions_between_slots(
&self,
starting_slot: Slot,
ending_slot: Slot,
) -> Vec<Partition> {
let slot_count_in_two_day = self.slot_count_in_two_day();
Self::get_partitions(self.slot(), self.parent_slot(), slot_count_in_two_day)
Self::get_partitions(ending_slot, starting_slot, slot_count_in_two_day)
}
fn fixed_cycle_partitions(&self) -> Vec<Partition> {
self.fixed_cycle_partitions_between_slots(self.parent_slot(), self.slot())
}
/// used only by filler accounts in debug path
@ -5574,48 +5582,56 @@ impl Bank {
)
}
fn variable_cycle_partitions(&self) -> Vec<Partition> {
let (current_epoch, current_slot_index) = self.get_epoch_and_slot_index(self.slot());
let (parent_epoch, mut parent_slot_index) =
self.get_epoch_and_slot_index(self.parent_slot());
fn variable_cycle_partitions_between_slots(
&self,
starting_slot: Slot,
ending_slot: Slot,
) -> Vec<Partition> {
let (starting_epoch, mut starting_slot_index) =
self.get_epoch_and_slot_index(starting_slot);
let (ending_epoch, ending_slot_index) = self.get_epoch_and_slot_index(ending_slot);
let mut partitions = vec![];
if parent_epoch < current_epoch {
let slot_skipped = (self.slot() - self.parent_slot()) > 1;
if starting_epoch < ending_epoch {
let slot_skipped = (ending_slot - starting_slot) > 1;
if slot_skipped {
// Generate special partitions because there are skipped slots
// exactly at the epoch transition.
let parent_last_slot_index = self.get_slots_in_epoch(parent_epoch) - 1;
let parent_last_slot_index = self.get_slots_in_epoch(starting_epoch) - 1;
// ... for parent epoch
partitions.push(self.partition_from_slot_indexes_with_gapped_epochs(
parent_slot_index,
starting_slot_index,
parent_last_slot_index,
parent_epoch,
starting_epoch,
));
if current_slot_index > 0 {
if ending_slot_index > 0 {
// ... for current epoch
partitions.push(self.partition_from_slot_indexes_with_gapped_epochs(
0,
0,
current_epoch,
ending_epoch,
));
}
}
parent_slot_index = 0;
starting_slot_index = 0;
}
partitions.push(self.partition_from_normal_slot_indexes(
parent_slot_index,
current_slot_index,
current_epoch,
starting_slot_index,
ending_slot_index,
ending_epoch,
));
partitions
}
fn variable_cycle_partitions(&self) -> Vec<Partition> {
self.variable_cycle_partitions_between_slots(self.parent_slot(), self.slot())
}
fn do_partition_from_slot_indexes(
&self,
start_slot_index: SlotIndex,