diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 761f88be6607e2..f01bf15fa934fb 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -59,7 +59,7 @@ use { solana_rpc_client_api::response::SlotUpdate, solana_runtime::{ accounts_background_service::AbsRequestSender, - bank::{Bank, NewBankOptions}, + bank::{bank_hash_details, Bank, NewBankOptions}, bank_forks::{BankForks, MAX_ROOT_DISTANCE_FOR_VOTE_ONLY}, commitment::BlockCommitmentCache, prioritization_fee_cache::PrioritizationFeeCache, @@ -1500,7 +1500,7 @@ impl ReplayStage { let bank = w_bank_forks .remove(*slot) .expect("BankForks should not have been purged yet"); - let _ = bank.write_hash_details_file(); + let _ = bank_hash_details::write_bank_hash_details_file(&bank); ((*slot, bank.bank_id()), bank) }) .unzip() diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 25ddcc2811d280..f27a49707becc7 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -49,7 +49,7 @@ use { accounts::Accounts, accounts_db::CalcAccountsHashDataSource, accounts_index::ScanConfig, - bank::{Bank, RewardCalculationEvent, TotalAccountsStats}, + bank::{bank_hash_details, Bank, RewardCalculationEvent, TotalAccountsStats}, bank_forks::BankForks, hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE, runtime_config::RuntimeConfig, @@ -2679,7 +2679,7 @@ fn main() { } if write_bank_file { let working_bank = bank_forks.read().unwrap().working_bank(); - let _ = working_bank.write_hash_details_file(); + let _ = bank_hash_details::write_bank_hash_details_file(&working_bank); } exit_signal.store(true, Ordering::Relaxed); system_monitor_service.join().unwrap(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 9870c931b9be45..ddb3be2b2d15ed 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -210,8 +210,7 @@ struct VerifyAccountsHashConfig { } mod address_lookup_table; -mod bank_hash_details; -use bank_hash_details::BankHashDetails; +pub mod bank_hash_details; mod builtin_programs; pub mod epoch_accounts_hash_utils; mod metrics; @@ -8223,41 +8222,6 @@ impl Bank { } false } - - /// Output the components that comprise bank hash - pub fn write_hash_details_file(&self) -> std::result::Result<(), String> { - let details = BankHashDetails::try_from(self)?; - - let slot = details.slot; - let hash = &details.bank_hash; - let file_name = format!("{slot}-{hash}.json"); - let parent_dir = self - .rc - .accounts - .accounts_db - .get_base_working_path() - .join("bank_hash_details"); - let path = parent_dir.join(file_name); - // A file with the same name implies the same hash for this slot. Skip - // rewriting a duplicate file in this scenario - if !path.exists() { - info!("writing details of bank {} to {}", slot, path.display()); - - // std::fs::write may fail (depending on platform) if the full directory - // path does not exist. So, call std::fs_create_dir_all first. - // https://doc.rust-lang.org/std/fs/fn.write.html - _ = std::fs::create_dir_all(parent_dir); - let file = std::fs::File::create(&path).map_err(|err| { - format!( - "Unable to create bank hash file at {}: {err}", - path.display() - ) - })?; - serde_json::to_writer_pretty(file, &details) - .map_err(|err| format!("Unable to write bank hash file contents: {err}"))?; - } - Ok(()) - } } /// Compute how much an account has changed size. This function is useful when the data size delta diff --git a/runtime/src/bank/bank_hash_details.rs b/runtime/src/bank/bank_hash_details.rs index 090093a060fa8a..36b83e48d9a89e 100644 --- a/runtime/src/bank/bank_hash_details.rs +++ b/runtime/src/bank/bank_hash_details.rs @@ -3,6 +3,7 @@ use { super::Bank, base64::{prelude::BASE64_STANDARD, Engine}, + log::*, serde::{ de::{self, Deserialize, Deserializer}, ser::{Serialize, SerializeSeq, Serializer}, @@ -162,6 +163,41 @@ impl<'de> Deserialize<'de> for BankHashAccounts { } } +/// Output the components that comprise bank hash +pub fn write_bank_hash_details_file(bank: &Bank) -> std::result::Result<(), String> { + let details = BankHashDetails::try_from(bank)?; + + let slot = details.slot; + let hash = &details.bank_hash; + let file_name = format!("{slot}-{hash}.json"); + let parent_dir = bank + .rc + .accounts + .accounts_db + .get_base_working_path() + .join("bank_hash_details"); + let path = parent_dir.join(file_name); + // A file with the same name implies the same hash for this slot. Skip + // rewriting a duplicate file in this scenario + if !path.exists() { + info!("writing details of bank {} to {}", slot, path.display()); + + // std::fs::write may fail (depending on platform) if the full directory + // path does not exist. So, call std::fs_create_dir_all first. + // https://doc.rust-lang.org/std/fs/fn.write.html + _ = std::fs::create_dir_all(parent_dir); + let file = std::fs::File::create(&path).map_err(|err| { + format!( + "Unable to create bank hash file at {}: {err}", + path.display() + ) + })?; + serde_json::to_writer_pretty(file, &details) + .map_err(|err| format!("Unable to write bank hash file contents: {err}"))?; + } + Ok(()) +} + #[cfg(test)] pub mod tests { use super::*;