Skip to content

Commit

Permalink
Allow the registration of genesis hash and recent block hash for fuzz…
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte authored Jun 25, 2024
1 parent 0cc9fe3 commit 9ad1712
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ pub(crate) fn process_blockstore_for_bank_0(
accounts_update_notifier,
None,
exit,
None,
);
let bank0_slot = bank0.slot();
let bank_forks = BankForks::new_rw_arc(bank0);
Expand Down
1 change: 1 addition & 0 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ impl ProgramTest {
None,
None,
Arc::default(),
None,
);

// Add commonly-used SPL programs as a convenience to the user
Expand Down
24 changes: 19 additions & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ impl Bank {
accounts_update_notifier: Option<AccountsUpdateNotifier>,
#[allow(unused)] collector_id_for_tests: Option<Pubkey>,
exit: Arc<AtomicBool>,
#[allow(unused)] genesis_hash: Option<Hash>,
) -> Self {
let accounts_db = AccountsDb::new_with_config(
paths,
Expand All @@ -1050,7 +1051,7 @@ impl Bank {
#[cfg(not(feature = "dev-context-only-utils"))]
bank.process_genesis_config(genesis_config);
#[cfg(feature = "dev-context-only-utils")]
bank.process_genesis_config(genesis_config, collector_id_for_tests);
bank.process_genesis_config(genesis_config, collector_id_for_tests, genesis_hash);

bank.finish_init(
genesis_config,
Expand Down Expand Up @@ -2921,6 +2922,7 @@ impl Bank {
&mut self,
genesis_config: &GenesisConfig,
#[cfg(feature = "dev-context-only-utils")] collector_id_for_tests: Option<Pubkey>,
#[cfg(feature = "dev-context-only-utils")] genesis_hash: Option<Hash>,
) {
// Bootstrap validator collects fees until `new_from_parent` is called.
self.fee_rate_governor = genesis_config.fee_rate_governor.clone();
Expand Down Expand Up @@ -2957,10 +2959,15 @@ impl Bank {
self.collector_id =
collector_id.expect("genesis processing failed because no staked nodes exist");

self.blockhash_queue.write().unwrap().genesis_hash(
&genesis_config.hash(),
self.fee_rate_governor.lamports_per_signature,
);
#[cfg(not(feature = "dev-context-only-utils"))]
let genesis_hash = genesis_config.hash();
#[cfg(feature = "dev-context-only-utils")]
let genesis_hash = genesis_hash.unwrap_or(genesis_config.hash());

self.blockhash_queue
.write()
.unwrap()
.genesis_hash(&genesis_hash, self.fee_rate_governor.lamports_per_signature);

self.hashes_per_tick = genesis_config.hashes_per_tick();
self.ticks_per_slot = genesis_config.ticks_per_slot();
Expand Down Expand Up @@ -3228,6 +3235,11 @@ impl Bank {
)
}

#[cfg(feature = "dev-context-only-utils")]
pub fn register_recent_blockhash_for_test(&self, hash: &Hash) {
self.register_recent_blockhash(hash, &BankWithScheduler::no_scheduler_available());
}

/// Tell the bank which Entry IDs exist on the ledger. This function assumes subsequent calls
/// correspond to later entries, and will boot the oldest ones once its internal cache is full.
/// Once boot, the bank will reject transactions using that `hash`.
Expand Down Expand Up @@ -6897,6 +6909,7 @@ impl Bank {
None,
Some(Pubkey::new_unique()),
Arc::default(),
None,
)
}

Expand All @@ -6920,6 +6933,7 @@ impl Bank {
None,
Some(Pubkey::new_unique()),
Arc::default(),
None,
)
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/src/bank/partitioned_epoch_rewards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ mod tests {
None,
Some(Pubkey::new_unique()),
Arc::default(),
None,
);

// Fill bank_forks with banks with votes landing in the next slot
Expand Down Expand Up @@ -486,6 +487,7 @@ mod tests {
None,
Some(Pubkey::new_unique()),
Arc::default(),
None,
);

let stake_account_stores_per_block =
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9072,6 +9072,7 @@ fn test_epoch_schedule_from_genesis_config() {
None,
None,
Arc::default(),
None,
));

assert_eq!(bank.epoch_schedule(), &genesis_config.epoch_schedule);
Expand Down Expand Up @@ -9102,6 +9103,7 @@ where
None,
None,
Arc::default(),
None,
));
let vote_and_stake_accounts =
load_vote_and_stake_accounts(&bank).vote_with_stake_delegations_map;
Expand Down Expand Up @@ -12645,6 +12647,7 @@ fn test_rehash_with_skipped_rewrites() {
None,
Some(Pubkey::new_unique()),
Arc::new(AtomicBool::new(false)),
None,
));
// This test is only meaningful while the bank hash contains rewrites.
// Once this feature is enabled, it may be possible to remove this test entirely.
Expand Down Expand Up @@ -12706,6 +12709,7 @@ fn test_rebuild_skipped_rewrites() {
None,
Some(Pubkey::new_unique()),
Arc::new(AtomicBool::new(false)),
None,
));
// This test is only meaningful while the bank hash contains rewrites.
// Once this feature is enabled, it may be possible to remove this test entirely.
Expand Down Expand Up @@ -12816,6 +12820,7 @@ fn test_get_accounts_for_bank_hash_details(skip_rewrites: bool) {
None,
Some(Pubkey::new_unique()),
Arc::new(AtomicBool::new(false)),
None,
));
// This test is only meaningful while the bank hash contains rewrites.
// Once this feature is enabled, it may be possible to remove this test entirely.
Expand Down

0 comments on commit 9ad1712

Please sign in to comment.