Skip to content

Commit

Permalink
Update genesis processing to have a fallback collector id for tests (s…
Browse files Browse the repository at this point in the history
…olana-labs#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 <[email protected]>
  • Loading branch information
jstarry and brooksprumo authored Jan 10, 2024
1 parent 4839115 commit 5f74fc4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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 @@ -834,6 +834,7 @@ impl ProgramTest {
false,
None,
None,
None,
Arc::default(),
);

Expand Down
30 changes: 21 additions & 9 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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();

Expand All @@ -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(),
Expand Down Expand Up @@ -8184,6 +8194,7 @@ impl Bank {
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Some(Pubkey::new_unique()),
Arc::default(),
)
}
Expand All @@ -8206,6 +8217,7 @@ impl Bank {
false,
Some(ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS),
None,
Some(Pubkey::new_unique()),
Arc::default(),
)
}
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 @@ -9035,6 +9035,7 @@ where
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
None,
Arc::default(),
));
let vote_and_stake_accounts =
Expand Down Expand Up @@ -12664,6 +12665,7 @@ fn test_rewards_computation_and_partitioned_distribution_two_blocks() {
false,
Some(accounts_db_config),
None,
None,
Arc::default(),
);

Expand Down Expand Up @@ -13383,6 +13385,7 @@ fn test_get_reward_distribution_num_blocks_cap() {
false,
Some(accounts_db_config),
None,
Some(Pubkey::new_unique()),
Arc::default(),
);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5f74fc4

Please sign in to comment.