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 <brooks@prumo.org>

Co-authored-by: Brooks Prumo <brooks@prumo.org>
This commit is contained in:
Jeff Washington (jwash) 2022-03-23 11:57:32 -05:00 committed by GitHub
parent 7b89222fde
commit b1280b670a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 35 deletions

View File

@ -10,7 +10,7 @@ use {
solana_gossip::cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES}, solana_gossip::cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES},
solana_measure::measure::Measure, solana_measure::measure::Measure,
solana_runtime::{ solana_runtime::{
accounts_db::{self, AccountsDb}, accounts_db::{self},
accounts_hash::HashStats, accounts_hash::HashStats,
snapshot_config::SnapshotConfig, snapshot_config::SnapshotConfig,
snapshot_package::{ snapshot_package::{
@ -129,17 +129,20 @@ impl AccountsHashVerifier {
let mut measure_hash = Measure::start("hash"); let mut measure_hash = Measure::start("hash");
if let Some(expected_hash) = accounts_package.hash_for_testing { if let Some(expected_hash) = accounts_package.hash_for_testing {
let sorted_storages = SortedStorages::new(&accounts_package.snapshot_storages); let sorted_storages = SortedStorages::new(&accounts_package.snapshot_storages);
let (hash, lamports) = AccountsDb::calculate_accounts_hash_without_index( let (hash, lamports) = accounts_package
ledger_path, .accounts
&sorted_storages, .accounts_db
thread_pool, .calculate_accounts_hash_without_index(
HashStats::default(), ledger_path,
false, &sorted_storages,
None, thread_pool,
None, // this will fail with filler accounts HashStats::default(),
None, // this code path is only for testing, so use default # passes here false,
) None,
.unwrap(); 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!(accounts_package.expected_capitalization, lamports);
assert_eq!(expected_hash, hash); assert_eq!(expected_hash, hash);
@ -353,6 +356,7 @@ mod tests {
incremental_snapshot_archive_interval_slots: Slot::MAX, incremental_snapshot_archive_interval_slots: Slot::MAX,
..SnapshotConfig::default() ..SnapshotConfig::default()
}; };
let accounts = Arc::new(solana_runtime::accounts::Accounts::default_for_tests());
for i in 0..MAX_SNAPSHOT_HASHES + 1 { for i in 0..MAX_SNAPSHOT_HASHES + 1 {
let accounts_package = AccountsPackage { let accounts_package = AccountsPackage {
slot: full_snapshot_archive_interval_slots + i as u64, slot: full_snapshot_archive_interval_slots + i as u64,
@ -368,6 +372,7 @@ mod tests {
hash_for_testing: None, hash_for_testing: None,
cluster_type: ClusterType::MainnetBeta, cluster_type: ClusterType::MainnetBeta,
snapshot_type: None, snapshot_type: None,
accounts: Arc::clone(&accounts),
}; };
let ledger_path = TempDir::new().unwrap(); let ledger_path = TempDir::new().unwrap();

View File

@ -5524,7 +5524,7 @@ impl AccountsDb {
} else { } else {
Some(&self.thread_pool_clean) Some(&self.thread_pool_clean)
}; };
Self::calculate_accounts_hash_without_index( self.calculate_accounts_hash_without_index(
&self.accounts_hash_cache_path, &self.accounts_hash_cache_path,
&storages, &storages,
thread_pool, thread_pool,
@ -5728,6 +5728,7 @@ impl AccountsDb {
// modeled after get_accounts_delta_hash // modeled after get_accounts_delta_hash
// intended to be faster than calculate_accounts_hash // intended to be faster than calculate_accounts_hash
pub fn calculate_accounts_hash_without_index( pub fn calculate_accounts_hash_without_index(
&self,
accounts_hash_cache_path: &Path, accounts_hash_cache_path: &Path,
storages: &SortedStorages, storages: &SortedStorages,
thread_pool: Option<&ThreadPool>, thread_pool: Option<&ThreadPool>,
@ -7911,17 +7912,19 @@ pub mod tests {
solana_logger::setup(); solana_logger::setup();
let (storages, _size, _slot_expected) = sample_storage(); let (storages, _size, _slot_expected) = sample_storage();
let result = AccountsDb::calculate_accounts_hash_without_index( let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
TempDir::new().unwrap().path(), let result = db
&get_storage_refs(&storages), .calculate_accounts_hash_without_index(
None, TempDir::new().unwrap().path(),
HashStats::default(), &get_storage_refs(&storages),
false, None,
None, HashStats::default(),
None, false,
None, None,
) None,
.unwrap(); None,
)
.unwrap();
let expected_hash = Hash::from_str("GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn").unwrap(); let expected_hash = Hash::from_str("GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn").unwrap();
assert_eq!(result, (expected_hash, 0)); assert_eq!(result, (expected_hash, 0));
} }
@ -7936,17 +7939,19 @@ pub mod tests {
item.hash item.hash
}); });
let sum = raw_expected.iter().map(|item| item.lamports).sum(); let sum = raw_expected.iter().map(|item| item.lamports).sum();
let result = AccountsDb::calculate_accounts_hash_without_index( let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
TempDir::new().unwrap().path(), let result = db
&get_storage_refs(&storages), .calculate_accounts_hash_without_index(
None, TempDir::new().unwrap().path(),
HashStats::default(), &get_storage_refs(&storages),
false, None,
None, HashStats::default(),
None, false,
None, None,
) None,
.unwrap(); None,
)
.unwrap();
assert_eq!(result, (expected_hash, sum)); assert_eq!(result, (expected_hash, sum));
} }

View File

@ -1,5 +1,6 @@
use { use {
crate::{ crate::{
accounts::Accounts,
accounts_db::SnapshotStorages, accounts_db::SnapshotStorages,
bank::{Bank, BankSlotDelta}, bank::{Bank, BankSlotDelta},
snapshot_archive_info::{SnapshotArchiveInfo, SnapshotArchiveInfoGetter}, snapshot_archive_info::{SnapshotArchiveInfo, SnapshotArchiveInfoGetter},
@ -47,6 +48,7 @@ pub struct AccountsPackage {
pub hash_for_testing: Option<Hash>, pub hash_for_testing: Option<Hash>,
pub cluster_type: ClusterType, pub cluster_type: ClusterType,
pub snapshot_type: Option<SnapshotType>, pub snapshot_type: Option<SnapshotType>,
pub accounts: Arc<Accounts>,
} }
impl AccountsPackage { impl AccountsPackage {
@ -109,6 +111,7 @@ impl AccountsPackage {
hash_for_testing, hash_for_testing,
cluster_type: bank.cluster_type(), cluster_type: bank.cluster_type(),
snapshot_type, snapshot_type,
accounts: bank.accounts(),
}) })
} }
} }