(cherry picked from commit f1c1152948
)
Co-authored-by: Ryo Onodera <ryoqun@gmail.com>
This commit is contained in:
@ -1845,9 +1845,32 @@ impl Bank {
|
|||||||
let (parent_epoch, mut parent_slot_index) =
|
let (parent_epoch, mut parent_slot_index) =
|
||||||
self.get_epoch_and_slot_index(self.parent_slot());
|
self.get_epoch_and_slot_index(self.parent_slot());
|
||||||
|
|
||||||
|
let should_enable = match self.operating_mode() {
|
||||||
|
OperatingMode::Development => true,
|
||||||
|
OperatingMode::Preview => current_epoch >= Epoch::max_value(),
|
||||||
|
OperatingMode::Stable => {
|
||||||
|
#[cfg(not(test))]
|
||||||
|
let should_enable = current_epoch >= Epoch::max_value();
|
||||||
|
|
||||||
|
// needed for test_rent_eager_across_epoch_with_gap_under_multi_epoch_cycle,
|
||||||
|
// which depends on OperatingMode::Stable
|
||||||
|
#[cfg(test)]
|
||||||
|
let should_enable = true;
|
||||||
|
|
||||||
|
should_enable
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut partitions = vec![];
|
let mut partitions = vec![];
|
||||||
if parent_epoch < current_epoch {
|
if parent_epoch < current_epoch {
|
||||||
if current_slot_index > 0 {
|
// this needs to be gated because this potentially can change the behavior
|
||||||
|
// (= bank hash) at each start of epochs
|
||||||
|
let slot_skipped = if should_enable {
|
||||||
|
(self.slot() - self.parent_slot()) > 1
|
||||||
|
} else {
|
||||||
|
current_slot_index > 0
|
||||||
|
};
|
||||||
|
if slot_skipped {
|
||||||
// Generate special partitions because there are skipped slots
|
// Generate special partitions because there are skipped slots
|
||||||
// exactly at the epoch transition.
|
// exactly at the epoch transition.
|
||||||
|
|
||||||
@ -1860,24 +1883,9 @@ impl Bank {
|
|||||||
parent_epoch,
|
parent_epoch,
|
||||||
));
|
));
|
||||||
|
|
||||||
let should_enable = match self.operating_mode() {
|
|
||||||
OperatingMode::Development => true,
|
|
||||||
OperatingMode::Preview => current_epoch >= Epoch::max_value(),
|
|
||||||
OperatingMode::Stable => {
|
|
||||||
#[cfg(not(test))]
|
|
||||||
let should_enable = current_epoch >= Epoch::max_value();
|
|
||||||
|
|
||||||
// needed for test_rent_eager_across_epoch_with_gap_under_multi_epoch_cycle,
|
|
||||||
// which depends on OperatingMode::Stable
|
|
||||||
#[cfg(test)]
|
|
||||||
let should_enable = true;
|
|
||||||
|
|
||||||
should_enable
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// this needs to be gated because this potentially can change the behavior
|
// this needs to be gated because this potentially can change the behavior
|
||||||
// (= bank hash) at each start of epochs
|
// (= bank hash) at each start of epochs
|
||||||
if should_enable {
|
if should_enable && current_slot_index > 0 {
|
||||||
// ... for current epoch
|
// ... for current epoch
|
||||||
partitions.push(self.partition_from_slot_indexes_with_gapped_epochs(
|
partitions.push(self.partition_from_slot_indexes_with_gapped_epochs(
|
||||||
0,
|
0,
|
||||||
@ -3597,7 +3605,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rent_eager_across_epoch_with_gap() {
|
fn test_rent_eager_across_epoch_with_full_gap() {
|
||||||
let (genesis_config, _mint_keypair) = create_genesis_config(1);
|
let (genesis_config, _mint_keypair) = create_genesis_config(1);
|
||||||
|
|
||||||
let mut bank = Arc::new(Bank::new(&genesis_config));
|
let mut bank = Arc::new(Bank::new(&genesis_config));
|
||||||
@ -3614,6 +3622,30 @@ mod tests {
|
|||||||
bank.rent_collection_partitions(),
|
bank.rent_collection_partitions(),
|
||||||
vec![(14, 31, 32), (0, 0, 64), (0, 17, 64)]
|
vec![(14, 31, 32), (0, 0, 64), (0, 17, 64)]
|
||||||
);
|
);
|
||||||
|
bank = Arc::new(new_from_parent(&bank));
|
||||||
|
assert_eq!(bank.rent_collection_partitions(), vec![(17, 18, 64)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rent_eager_across_epoch_with_half_gap() {
|
||||||
|
let (genesis_config, _mint_keypair) = create_genesis_config(1);
|
||||||
|
|
||||||
|
let mut bank = Arc::new(Bank::new(&genesis_config));
|
||||||
|
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 32)]);
|
||||||
|
|
||||||
|
bank = Arc::new(new_from_parent(&bank));
|
||||||
|
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 32)]);
|
||||||
|
for _ in 2..15 {
|
||||||
|
bank = Arc::new(new_from_parent(&bank));
|
||||||
|
}
|
||||||
|
assert_eq!(bank.rent_collection_partitions(), vec![(13, 14, 32)]);
|
||||||
|
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 32));
|
||||||
|
assert_eq!(
|
||||||
|
bank.rent_collection_partitions(),
|
||||||
|
vec![(14, 31, 32), (0, 0, 64)]
|
||||||
|
);
|
||||||
|
bank = Arc::new(new_from_parent(&bank));
|
||||||
|
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 64)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Reference in New Issue
Block a user