Update genesis processing to have a fallback collector id for tests (#34135)

* Update genesis processing to have a fallback collector id for tests

* DCOU-ify the collector id for tests parameter (#1902)

* wrap test_collector_id in DCOU

* rename param to collector_id_for_tests

* fix program test

* fix dcou

---------

Co-authored-by: Brooks <brooks@prumo.org>
This commit is contained in:
Justin Starry 2024-01-10 08:34:41 +08:00 committed by GitHub
parent 48391152ae
commit 5f74fc4f16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 9 deletions

View File

@ -794,6 +794,7 @@ pub(crate) fn process_blockstore_for_bank_0(
false,
opts.accounts_db_config.clone(),
accounts_update_notifier,
None,
exit,
);
let bank0_slot = bank0.slot();

View File

@ -834,6 +834,7 @@ impl ProgramTest {
false,
None,
None,
None,
Arc::default(),
);

View File

@ -1040,6 +1040,7 @@ impl Bank {
debug_do_not_add_builtins: bool,
accounts_db_config: Option<AccountsDbConfig>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
#[allow(unused)] collector_id_for_tests: Option<Pubkey>,
exit: Arc<AtomicBool>,
) -> Self {
let accounts_db = AccountsDb::new_with_config(
@ -1058,7 +1059,11 @@ impl Bank {
bank.runtime_config = runtime_config;
bank.cluster_type = Some(genesis_config.cluster_type);
#[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.finish_init(
genesis_config,
additional_builtins,
@ -3736,7 +3741,11 @@ impl Bank {
self.parent_hash
}
fn process_genesis_config(&mut self, genesis_config: &GenesisConfig) {
fn process_genesis_config(
&mut self,
genesis_config: &GenesisConfig,
#[cfg(feature = "dev-context-only-utils")] collector_id_for_tests: Option<Pubkey>,
) {
// Bootstrap validator collects fees until `new_from_parent` is called.
self.fee_rate_governor = genesis_config.fee_rate_governor.clone();
@ -3762,14 +3771,15 @@ impl Bank {
self.accounts_data_size_initial += account.data().len() as u64;
}
// Highest staked node is the first collector but if a genesis config
// doesn't define any staked nodes, we assume this genesis config is for
// testing and set the collector id to a unique pubkey.
self.collector_id = self
.stakes_cache
.stakes()
.highest_staked_node()
.unwrap_or_else(Pubkey::new_unique);
// After storing genesis accounts, the bank stakes cache will be warmed
// up and can be used to set the collector id to the highest staked
// node. If no staked nodes exist, allow fallback to an unstaked test
// collector id during tests.
let collector_id = self.stakes_cache.stakes().highest_staked_node();
#[cfg(feature = "dev-context-only-utils")]
let collector_id = collector_id.or(collector_id_for_tests);
self.collector_id =
collector_id.expect("genesis processing failed because no staked nodes exist");
self.blockhash_queue.write().unwrap().genesis_hash(
&genesis_config.hash(),
@ -8184,6 +8194,7 @@ impl Bank {
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Some(Pubkey::new_unique()),
Arc::default(),
)
}
@ -8206,6 +8217,7 @@ impl Bank {
false,
Some(ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS),
None,
Some(Pubkey::new_unique()),
Arc::default(),
)
}

View File

@ -9035,6 +9035,7 @@ where
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
None,
Arc::default(),
));
let vote_and_stake_accounts =
@ -12664,6 +12665,7 @@ fn test_rewards_computation_and_partitioned_distribution_two_blocks() {
false,
Some(accounts_db_config),
None,
None,
Arc::default(),
);
@ -13383,6 +13385,7 @@ fn test_get_reward_distribution_num_blocks_cap() {
false,
Some(accounts_db_config),
None,
Some(Pubkey::new_unique()),
Arc::default(),
);
@ -13850,6 +13853,7 @@ fn test_rehash_with_skipped_rewrites() {
false,
Some(accounts_db_config),
None,
Some(Pubkey::new_unique()),
Arc::new(AtomicBool::new(false)),
));
// This test is only meaningful while the bank hash contains rewrites.
@ -13910,6 +13914,7 @@ fn test_rebuild_skipped_rewrites() {
false,
Some(accounts_db_config.clone()),
None,
Some(Pubkey::new_unique()),
Arc::new(AtomicBool::new(false)),
));
// This test is only meaningful while the bank hash contains rewrites.