From ef8d3206d79f228dee650274a96533d232520542 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 25 Jul 2023 14:12:20 -0700 Subject: [PATCH] Move bank specific code out of epoch_accounts_hash/utils.rs (#32623) * Move bank specific code out of epoch_accounts_hash/utils.rs * cleanup --- core/tests/epoch_accounts_hash.rs | 18 +++++++++--------- runtime/src/accounts_background_service.rs | 4 ++-- runtime/src/bank.rs | 11 ++++++----- .../epoch_accounts_hash_utils.rs} | 0 runtime/src/bank/serde_snapshot.rs | 9 ++++++--- runtime/src/bank_forks.rs | 7 +++---- runtime/src/epoch_accounts_hash.rs | 3 --- 7 files changed, 26 insertions(+), 26 deletions(-) rename runtime/src/{epoch_accounts_hash/utils.rs => bank/epoch_accounts_hash_utils.rs} (100%) diff --git a/core/tests/epoch_accounts_hash.rs b/core/tests/epoch_accounts_hash.rs index 8f89bd9f39..21922113b4 100755 --- a/core/tests/epoch_accounts_hash.rs +++ b/core/tests/epoch_accounts_hash.rs @@ -16,9 +16,9 @@ use { }, accounts_hash::CalcAccountsHashConfig, accounts_index::AccountSecondaryIndexes, - bank::{Bank, BankTestConfig}, + bank::{epoch_accounts_hash_utils, Bank, BankTestConfig}, bank_forks::BankForks, - epoch_accounts_hash::{self, EpochAccountsHash}, + epoch_accounts_hash::EpochAccountsHash, genesis_utils::{self, GenesisConfigInfo}, runtime_config::RuntimeConfig, snapshot_archive_info::SnapshotArchiveInfoGetter, @@ -140,7 +140,7 @@ impl TestEnvironment { assert!(bank .feature_set .is_active(&feature_set::epoch_accounts_hash::id())); - assert!(epoch_accounts_hash::is_enabled_this_epoch(&bank)); + assert!(epoch_accounts_hash_utils::is_enabled_this_epoch(&bank)); bank.set_startup_verification_complete(); @@ -304,7 +304,7 @@ fn test_epoch_accounts_hash_basic(test_environment: TestEnvironment) { // To ensure EAH calculations are correct, calculate the accounts hash here, in-band. // This will be the expected EAH that gets saved into the "stop" bank. - if bank.slot() == epoch_accounts_hash::calculation_start(&bank) { + if bank.slot() == epoch_accounts_hash_utils::calculation_start(&bank) { bank.freeze(); let (accounts_hash, _) = bank .rc @@ -332,7 +332,7 @@ fn test_epoch_accounts_hash_basic(test_environment: TestEnvironment) { } // Test: Ensure that the "stop" bank has the correct EAH - if bank.slot() == epoch_accounts_hash::calculation_stop(&bank) { + if bank.slot() == epoch_accounts_hash_utils::calculation_stop(&bank) { // Sometimes AHV does not get scheduled to run, which causes the test to fail // spuriously. Sleep a bit here to ensure AHV gets a chance to run. std::thread::sleep(Duration::from_secs(1)); @@ -414,7 +414,7 @@ fn test_snapshots_have_expected_epoch_accounts_hash() { // After submitting an EAH calculation request, wait until it gets handled by ABS so that // subsequent snapshot requests are not swallowed. - if bank.slot() == epoch_accounts_hash::calculation_start(&bank) { + if bank.slot() == epoch_accounts_hash_utils::calculation_start(&bank) { while bank.epoch_accounts_hash().is_none() { std::thread::sleep(Duration::from_secs(1)); } @@ -520,7 +520,7 @@ fn test_background_services_request_handling_for_epoch_accounts_hash() { // Based on the EAH start and snapshot interval, pick a slot to mass-root all the banks in // this range such that an EAH request will be sent and also a snapshot request. - let eah_start_slot = epoch_accounts_hash::calculation_start(&bank); + let eah_start_slot = epoch_accounts_hash_utils::calculation_start(&bank); let set_root_slot = next_multiple_of(eah_start_slot, FULL_SNAPSHOT_INTERVAL); if bank.block_height() == set_root_slot { @@ -577,7 +577,7 @@ fn test_epoch_accounts_hash_and_warping() { // Ensure warping past the EAH stop slot is OK info!("Warping past EAH stop slot..."); - let eah_stop_offset = epoch_accounts_hash::calculation_offset_stop(&bank); + let eah_stop_offset = epoch_accounts_hash_utils::calculation_offset_stop(&bank); let eah_stop_slot_in_next_epoch = epoch_schedule.get_first_slot_in_epoch(bank.epoch() + 1) + eah_stop_offset; // have to set root here so that we can flush the write cache @@ -619,7 +619,7 @@ fn test_epoch_accounts_hash_and_warping() { // Ensure warping past the EAH start slot is OK info!("Warping past EAH start slot..."); - let eah_start_offset = epoch_accounts_hash::calculation_offset_start(&bank); + let eah_start_offset = epoch_accounts_hash_utils::calculation_offset_start(&bank); let eah_start_slot_in_next_epoch = epoch_schedule.get_first_slot_in_epoch(bank.epoch() + 1) + eah_start_offset; // flush the write cache so warping can calculate the accounts hash from storages diff --git a/runtime/src/accounts_background_service.rs b/runtime/src/accounts_background_service.rs index 6c642f1a2a..d2f9fe8603 100644 --- a/runtime/src/accounts_background_service.rs +++ b/runtime/src/accounts_background_service.rs @@ -774,7 +774,7 @@ mod test { use { super::*, crate::{ - epoch_accounts_hash::{self, EpochAccountsHash}, + bank::epoch_accounts_hash_utils, epoch_accounts_hash::EpochAccountsHash, genesis_utils::create_genesis_config, }, crossbeam_channel::unbounded, @@ -896,7 +896,7 @@ mod test { // Since we're not using `BankForks::set_root()`, we have to handle sending the // correct snapshot requests ourself. - if bank.slot() == epoch_accounts_hash::calculation_start(&bank) { + if bank.slot() == epoch_accounts_hash_utils::calculation_start(&bank) { send_snapshot_request( Arc::clone(&bank), SnapshotRequestType::EpochAccountsHash, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 8309c51a53..85ab249085 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -57,7 +57,7 @@ use { bank::metrics::*, blockhash_queue::BlockhashQueue, builtins::{BuiltinPrototype, BUILTINS}, - epoch_accounts_hash::{self, EpochAccountsHash}, + epoch_accounts_hash::EpochAccountsHash, epoch_rewards_hasher::hash_rewards_into_partitions, epoch_stakes::{EpochStakes, NodeVoteAccounts}, nonce_info::{NonceInfo, NoncePartial}, @@ -209,6 +209,7 @@ struct VerifyAccountsHashConfig { mod address_lookup_table; mod builtin_programs; +pub mod epoch_accounts_hash_utils; mod metrics; mod serde_snapshot; mod sysvar_cache; @@ -7030,11 +7031,11 @@ impl Bank { return false; } - if !epoch_accounts_hash::is_enabled_this_epoch(self) { + if !epoch_accounts_hash_utils::is_enabled_this_epoch(self) { return false; } - let stop_slot = epoch_accounts_hash::calculation_stop(self); + let stop_slot = epoch_accounts_hash_utils::calculation_stop(self); self.parent_slot() < stop_slot && self.slot() >= stop_slot } @@ -8086,8 +8087,8 @@ impl Bank { let should_get_epoch_accounts_hash = self .feature_set .is_active(&feature_set::epoch_accounts_hash::id()) - && epoch_accounts_hash::is_enabled_this_epoch(self) - && epoch_accounts_hash::is_in_calculation_window(self); + && epoch_accounts_hash_utils::is_enabled_this_epoch(self) + && epoch_accounts_hash_utils::is_in_calculation_window(self); if !should_get_epoch_accounts_hash { return None; } diff --git a/runtime/src/epoch_accounts_hash/utils.rs b/runtime/src/bank/epoch_accounts_hash_utils.rs similarity index 100% rename from runtime/src/epoch_accounts_hash/utils.rs rename to runtime/src/bank/epoch_accounts_hash_utils.rs diff --git a/runtime/src/bank/serde_snapshot.rs b/runtime/src/bank/serde_snapshot.rs index 5cd8373d35..ecec8e4aba 100644 --- a/runtime/src/bank/serde_snapshot.rs +++ b/runtime/src/bank/serde_snapshot.rs @@ -10,8 +10,11 @@ mod tests { accounts_file::{AccountsFile, AccountsFileError}, accounts_hash::{AccountsDeltaHash, AccountsHash}, accounts_index::AccountSecondaryIndexes, - bank::{Bank, BankTestConfig, EpochRewardStatus, StartBlockHeightAndRewards}, - epoch_accounts_hash::{self, EpochAccountsHash}, + bank::{ + epoch_accounts_hash_utils, Bank, BankTestConfig, EpochRewardStatus, + StartBlockHeightAndRewards, + }, + epoch_accounts_hash::EpochAccountsHash, genesis_utils::{activate_all_features, activate_feature}, runtime_config::RuntimeConfig, serde_snapshot::{ @@ -97,7 +100,7 @@ mod tests { activate_feature(&mut genesis_config, feature_set::epoch_accounts_hash::id()); genesis_config.epoch_schedule = EpochSchedule::custom(400, 400, false); let bank0 = Arc::new(Bank::new_for_tests(&genesis_config)); - let eah_start_slot = epoch_accounts_hash::calculation_start(&bank0); + let eah_start_slot = epoch_accounts_hash_utils::calculation_start(&bank0); let bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1); bank0.squash(); diff --git a/runtime/src/bank_forks.rs b/runtime/src/bank_forks.rs index 91f2304fd2..93307df2f4 100644 --- a/runtime/src/bank_forks.rs +++ b/runtime/src/bank_forks.rs @@ -3,8 +3,7 @@ use { crate::{ accounts_background_service::{AbsRequestSender, SnapshotRequest, SnapshotRequestType}, - bank::{Bank, SquashTiming}, - epoch_accounts_hash, + bank::{epoch_accounts_hash_utils, Bank, SquashTiming}, snapshot_config::SnapshotConfig, }, log::*, @@ -636,11 +635,11 @@ impl BankForks { return false; } - if !epoch_accounts_hash::is_enabled_this_epoch(bank) { + if !epoch_accounts_hash_utils::is_enabled_this_epoch(bank) { return false; } - let start_slot = epoch_accounts_hash::calculation_start(bank); + let start_slot = epoch_accounts_hash_utils::calculation_start(bank); bank.slot() > self.last_accounts_hash_slot && bank.parent_slot() < start_slot && bank.slot() >= start_slot diff --git a/runtime/src/epoch_accounts_hash.rs b/runtime/src/epoch_accounts_hash.rs index c6d1b820c2..8457f639e1 100644 --- a/runtime/src/epoch_accounts_hash.rs +++ b/runtime/src/epoch_accounts_hash.rs @@ -9,9 +9,6 @@ use {crate::accounts_hash::AccountsHash, solana_sdk::hash::Hash}; -mod utils; -pub use utils::*; - mod manager; pub use manager::Manager as EpochAccountsHashManager;