From b1280b670af8749bb3ac9694f9695589ea4c0621 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Wed, 23 Mar 2022 11:57:32 -0500 Subject: [PATCH] calculate_accounts_hash_without_index takes &self (#23846) * calculate_accounts_hash_without_index takes &self * Update runtime/src/snapshot_package.rs Co-authored-by: Brooks Prumo Co-authored-by: Brooks Prumo --- core/src/accounts_hash_verifier.rs | 29 ++++++++++------- runtime/src/accounts_db.rs | 51 ++++++++++++++++-------------- runtime/src/snapshot_package.rs | 3 ++ 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index 59761633d8..a18d4df36e 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -10,7 +10,7 @@ use { solana_gossip::cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES}, solana_measure::measure::Measure, solana_runtime::{ - accounts_db::{self, AccountsDb}, + accounts_db::{self}, accounts_hash::HashStats, snapshot_config::SnapshotConfig, snapshot_package::{ @@ -129,17 +129,20 @@ impl AccountsHashVerifier { let mut measure_hash = Measure::start("hash"); if let Some(expected_hash) = accounts_package.hash_for_testing { let sorted_storages = SortedStorages::new(&accounts_package.snapshot_storages); - let (hash, lamports) = AccountsDb::calculate_accounts_hash_without_index( - ledger_path, - &sorted_storages, - thread_pool, - HashStats::default(), - false, - None, - None, // this will fail with filler accounts - None, // this code path is only for testing, so use default # passes here - ) - .unwrap(); + let (hash, lamports) = accounts_package + .accounts + .accounts_db + .calculate_accounts_hash_without_index( + ledger_path, + &sorted_storages, + thread_pool, + HashStats::default(), + false, + None, + None, // this will fail with filler accounts + None, // this code path is only for testing, so use default # passes here + ) + .unwrap(); assert_eq!(accounts_package.expected_capitalization, lamports); assert_eq!(expected_hash, hash); @@ -353,6 +356,7 @@ mod tests { incremental_snapshot_archive_interval_slots: Slot::MAX, ..SnapshotConfig::default() }; + let accounts = Arc::new(solana_runtime::accounts::Accounts::default_for_tests()); for i in 0..MAX_SNAPSHOT_HASHES + 1 { let accounts_package = AccountsPackage { slot: full_snapshot_archive_interval_slots + i as u64, @@ -368,6 +372,7 @@ mod tests { hash_for_testing: None, cluster_type: ClusterType::MainnetBeta, snapshot_type: None, + accounts: Arc::clone(&accounts), }; let ledger_path = TempDir::new().unwrap(); diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 25e64efb3f..7daa62676f 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5524,7 +5524,7 @@ impl AccountsDb { } else { Some(&self.thread_pool_clean) }; - Self::calculate_accounts_hash_without_index( + self.calculate_accounts_hash_without_index( &self.accounts_hash_cache_path, &storages, thread_pool, @@ -5728,6 +5728,7 @@ impl AccountsDb { // modeled after get_accounts_delta_hash // intended to be faster than calculate_accounts_hash pub fn calculate_accounts_hash_without_index( + &self, accounts_hash_cache_path: &Path, storages: &SortedStorages, thread_pool: Option<&ThreadPool>, @@ -7911,17 +7912,19 @@ pub mod tests { solana_logger::setup(); let (storages, _size, _slot_expected) = sample_storage(); - let result = AccountsDb::calculate_accounts_hash_without_index( - TempDir::new().unwrap().path(), - &get_storage_refs(&storages), - None, - HashStats::default(), - false, - None, - None, - None, - ) - .unwrap(); + let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + let result = db + .calculate_accounts_hash_without_index( + TempDir::new().unwrap().path(), + &get_storage_refs(&storages), + None, + HashStats::default(), + false, + None, + None, + None, + ) + .unwrap(); let expected_hash = Hash::from_str("GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn").unwrap(); assert_eq!(result, (expected_hash, 0)); } @@ -7936,17 +7939,19 @@ pub mod tests { item.hash }); let sum = raw_expected.iter().map(|item| item.lamports).sum(); - let result = AccountsDb::calculate_accounts_hash_without_index( - TempDir::new().unwrap().path(), - &get_storage_refs(&storages), - None, - HashStats::default(), - false, - None, - None, - None, - ) - .unwrap(); + let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + let result = db + .calculate_accounts_hash_without_index( + TempDir::new().unwrap().path(), + &get_storage_refs(&storages), + None, + HashStats::default(), + false, + None, + None, + None, + ) + .unwrap(); assert_eq!(result, (expected_hash, sum)); } diff --git a/runtime/src/snapshot_package.rs b/runtime/src/snapshot_package.rs index 6f2bd321c2..670dcfbbbe 100644 --- a/runtime/src/snapshot_package.rs +++ b/runtime/src/snapshot_package.rs @@ -1,5 +1,6 @@ use { crate::{ + accounts::Accounts, accounts_db::SnapshotStorages, bank::{Bank, BankSlotDelta}, snapshot_archive_info::{SnapshotArchiveInfo, SnapshotArchiveInfoGetter}, @@ -47,6 +48,7 @@ pub struct AccountsPackage { pub hash_for_testing: Option, pub cluster_type: ClusterType, pub snapshot_type: Option, + pub accounts: Arc, } impl AccountsPackage { @@ -109,6 +111,7 @@ impl AccountsPackage { hash_for_testing, cluster_type: bank.cluster_type(), snapshot_type, + accounts: bank.accounts(), }) } }