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:
parent
7b89222fde
commit
b1280b670a
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<Hash>,
|
||||
pub cluster_type: ClusterType,
|
||||
pub snapshot_type: Option<SnapshotType>,
|
||||
pub accounts: Arc<Accounts>,
|
||||
}
|
||||
|
||||
impl AccountsPackage {
|
||||
|
@ -109,6 +111,7 @@ impl AccountsPackage {
|
|||
hash_for_testing,
|
||||
cluster_type: bank.cluster_type(),
|
||||
snapshot_type,
|
||||
accounts: bank.accounts(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue