feature flag cleanup: fix_recent_blockhashes (#32443)
* feature flag cleanup: fix_recent_blockhashes * flip test logic
This commit is contained in:
parent
cec6b861cf
commit
d344ae5297
|
@ -4250,92 +4250,6 @@ pub mod tests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_confirm_slot_entries_without_fix() {
|
|
||||||
const HASHES_PER_TICK: u64 = 10;
|
|
||||||
const TICKS_PER_SLOT: u64 = 2;
|
|
||||||
|
|
||||||
let collector_id = Pubkey::new_unique();
|
|
||||||
|
|
||||||
let GenesisConfigInfo {
|
|
||||||
mut genesis_config,
|
|
||||||
mint_keypair,
|
|
||||||
..
|
|
||||||
} = create_genesis_config(10_000);
|
|
||||||
genesis_config.poh_config.hashes_per_tick = Some(HASHES_PER_TICK);
|
|
||||||
genesis_config.ticks_per_slot = TICKS_PER_SLOT;
|
|
||||||
let genesis_hash = genesis_config.hash();
|
|
||||||
|
|
||||||
let mut slot_0_bank = Bank::new_for_tests(&genesis_config);
|
|
||||||
slot_0_bank.deactivate_feature(&feature_set::fix_recent_blockhashes::id());
|
|
||||||
let slot_0_bank = Arc::new(slot_0_bank);
|
|
||||||
assert_eq!(slot_0_bank.slot(), 0);
|
|
||||||
assert_eq!(slot_0_bank.tick_height(), 0);
|
|
||||||
assert_eq!(slot_0_bank.max_tick_height(), 2);
|
|
||||||
assert_eq!(slot_0_bank.last_blockhash(), genesis_hash);
|
|
||||||
assert_eq!(slot_0_bank.get_hash_age(&genesis_hash), Some(0));
|
|
||||||
|
|
||||||
let slot_0_entries = entry::create_ticks(TICKS_PER_SLOT, HASHES_PER_TICK, genesis_hash);
|
|
||||||
let slot_0_hash = slot_0_entries.last().unwrap().hash;
|
|
||||||
confirm_slot_entries_for_tests(&slot_0_bank, slot_0_entries, true, genesis_hash).unwrap();
|
|
||||||
assert_eq!(slot_0_bank.tick_height(), slot_0_bank.max_tick_height());
|
|
||||||
assert_eq!(slot_0_bank.last_blockhash(), slot_0_hash);
|
|
||||||
assert_eq!(slot_0_bank.get_hash_age(&genesis_hash), Some(1));
|
|
||||||
assert_eq!(slot_0_bank.get_hash_age(&slot_0_hash), Some(0));
|
|
||||||
|
|
||||||
let slot_2_bank = Arc::new(Bank::new_from_parent(&slot_0_bank, &collector_id, 2));
|
|
||||||
assert_eq!(slot_2_bank.slot(), 2);
|
|
||||||
assert_eq!(slot_2_bank.tick_height(), 2);
|
|
||||||
assert_eq!(slot_2_bank.max_tick_height(), 6);
|
|
||||||
assert_eq!(slot_2_bank.last_blockhash(), slot_0_hash);
|
|
||||||
|
|
||||||
let slot_1_entries = entry::create_ticks(TICKS_PER_SLOT, HASHES_PER_TICK, slot_0_hash);
|
|
||||||
let slot_1_hash = slot_1_entries.last().unwrap().hash;
|
|
||||||
confirm_slot_entries_for_tests(&slot_2_bank, slot_1_entries, false, slot_0_hash).unwrap();
|
|
||||||
assert_eq!(slot_2_bank.tick_height(), 4);
|
|
||||||
assert_eq!(slot_2_bank.last_blockhash(), slot_1_hash);
|
|
||||||
assert_eq!(slot_2_bank.get_hash_age(&genesis_hash), Some(2));
|
|
||||||
assert_eq!(slot_2_bank.get_hash_age(&slot_0_hash), Some(1));
|
|
||||||
assert_eq!(slot_2_bank.get_hash_age(&slot_1_hash), Some(0));
|
|
||||||
|
|
||||||
// Check that slot 2 transactions can use any previous slot hash, including the
|
|
||||||
// hash for slot 1 which is just ticks.
|
|
||||||
let slot_2_entries = {
|
|
||||||
let to_pubkey = Pubkey::new_unique();
|
|
||||||
let mut prev_entry_hash = slot_1_hash;
|
|
||||||
let mut remaining_entry_hashes = HASHES_PER_TICK;
|
|
||||||
let mut entries: Vec<Entry> = [genesis_hash, slot_0_hash, slot_1_hash]
|
|
||||||
.into_iter()
|
|
||||||
.map(|recent_hash| {
|
|
||||||
let tx =
|
|
||||||
system_transaction::transfer(&mint_keypair, &to_pubkey, 1, recent_hash);
|
|
||||||
remaining_entry_hashes = remaining_entry_hashes.checked_sub(1).unwrap();
|
|
||||||
next_entry_mut(&mut prev_entry_hash, 1, vec![tx])
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
entries.push(next_entry_mut(
|
|
||||||
&mut prev_entry_hash,
|
|
||||||
remaining_entry_hashes,
|
|
||||||
vec![],
|
|
||||||
));
|
|
||||||
entries.push(next_entry_mut(
|
|
||||||
&mut prev_entry_hash,
|
|
||||||
HASHES_PER_TICK,
|
|
||||||
vec![],
|
|
||||||
));
|
|
||||||
entries
|
|
||||||
};
|
|
||||||
let slot_2_hash = slot_2_entries.last().unwrap().hash;
|
|
||||||
confirm_slot_entries_for_tests(&slot_2_bank, slot_2_entries, true, slot_1_hash).unwrap();
|
|
||||||
assert_eq!(slot_2_bank.tick_height(), slot_2_bank.max_tick_height());
|
|
||||||
assert_eq!(slot_2_bank.last_blockhash(), slot_2_hash);
|
|
||||||
assert_eq!(slot_2_bank.get_hash_age(&genesis_hash), Some(3));
|
|
||||||
assert_eq!(slot_2_bank.get_hash_age(&slot_0_hash), Some(2));
|
|
||||||
assert_eq!(slot_2_bank.get_hash_age(&slot_1_hash), Some(1));
|
|
||||||
assert_eq!(slot_2_bank.get_hash_age(&slot_2_hash), Some(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_confirm_slot_entries_progress_num_txs_indexes() {
|
fn test_confirm_slot_entries_progress_num_txs_indexes() {
|
||||||
let GenesisConfigInfo {
|
let GenesisConfigInfo {
|
||||||
|
|
|
@ -4448,14 +4448,7 @@ impl Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_block_boundary(&self, tick_height: u64) -> bool {
|
pub fn is_block_boundary(&self, tick_height: u64) -> bool {
|
||||||
if self
|
tick_height == self.max_tick_height
|
||||||
.feature_set
|
|
||||||
.is_active(&feature_set::fix_recent_blockhashes::id())
|
|
||||||
{
|
|
||||||
tick_height == self.max_tick_height
|
|
||||||
} else {
|
|
||||||
tick_height % self.ticks_per_slot == 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the max number of accounts that a transaction may lock in this block
|
/// Get the max number of accounts that a transaction may lock in this block
|
||||||
|
|
|
@ -4979,17 +4979,18 @@ fn test_hash_internal_state_unchanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ticks_change_state() {
|
fn test_hash_internal_state_unchanged_with_ticks() {
|
||||||
let (genesis_config, _) = create_genesis_config(500);
|
let (genesis_config, _) = create_genesis_config(500);
|
||||||
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
|
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
|
||||||
let bank1 = new_from_parent(&bank);
|
let bank1 = new_from_parent(&bank);
|
||||||
let hash1 = bank1.hash_internal_state();
|
let hash1 = bank1.hash_internal_state();
|
||||||
// ticks don't change its state unless a block boundary is crossed
|
// ticks don't change its state even if a slot boundary is crossed
|
||||||
|
// because blockhashes are only recorded at block boundaries
|
||||||
for _ in 0..genesis_config.ticks_per_slot {
|
for _ in 0..genesis_config.ticks_per_slot {
|
||||||
assert_eq!(bank1.hash_internal_state(), hash1);
|
assert_eq!(bank1.hash_internal_state(), hash1);
|
||||||
bank1.register_tick(&Hash::default());
|
bank1.register_tick(&Hash::default());
|
||||||
}
|
}
|
||||||
assert_ne!(bank1.hash_internal_state(), hash1);
|
assert_eq!(bank1.hash_internal_state(), hash1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ignore]
|
#[ignore]
|
||||||
|
|
Loading…
Reference in New Issue