Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Update genesis processing to have a fallback collector id for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Dec 21, 2023
1 parent 1db76cf commit 7388d39
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 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
21 changes: 15 additions & 6 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ impl Bank {
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Some(Pubkey::new_unique()),
Arc::default(),
)
}
Expand All @@ -1077,6 +1078,7 @@ impl Bank {
debug_do_not_add_builtins: bool,
accounts_db_config: Option<AccountsDbConfig>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
test_collector_id: Option<Pubkey>,
exit: Arc<AtomicBool>,
) -> Self {
let accounts_db = AccountsDb::new_with_config(
Expand All @@ -1095,7 +1097,7 @@ impl Bank {
bank.runtime_config = runtime_config;
bank.cluster_type = Some(genesis_config.cluster_type);

bank.process_genesis_config(genesis_config);
bank.process_genesis_config(genesis_config, test_collector_id);
bank.finish_init(
genesis_config,
additional_builtins,
Expand Down Expand Up @@ -3785,7 +3787,11 @@ impl Bank {
self.parent_hash
}

fn process_genesis_config(&mut self, genesis_config: &GenesisConfig) {
fn process_genesis_config(
&mut self,
genesis_config: &GenesisConfig,
test_collector_id: Option<Pubkey>,
) {
// Bootstrap validator collects fees until `new_from_parent` is called.
self.fee_rate_governor = genesis_config.fee_rate_governor.clone();

Expand All @@ -3811,14 +3817,16 @@ 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.
// 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.
self.collector_id = self
.stakes_cache
.stakes()
.highest_staked_node()
.unwrap_or_else(Pubkey::new_unique);
.or(test_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 @@ -8250,6 +8258,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 @@ -9040,6 +9040,7 @@ where
false,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
None,
Arc::default(),
));
let vote_and_stake_accounts =
Expand Down Expand Up @@ -12671,6 +12672,7 @@ fn test_rewards_computation_and_partitioned_distribution_two_blocks() {
false,
Some(accounts_db_config),
None,
None,
Arc::default(),
);

Expand Down Expand Up @@ -13390,6 +13392,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 @@ -13857,6 +13860,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 @@ -13917,6 +13921,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 7388d39

Please sign in to comment.