Skip to content

Commit

Permalink
cache account hash info (#19426)
Browse files Browse the repository at this point in the history
* cache account hash info

* ledger_path -> accounts_hash_cache_path
  • Loading branch information
jeffwashington committed Sep 14, 2021
1 parent dca49a6 commit b57e86a
Show file tree
Hide file tree
Showing 9 changed files with 737 additions and 48 deletions.
11 changes: 10 additions & 1 deletion core/src/accounts_hash_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use solana_runtime::{
use solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey};
use std::collections::{HashMap, HashSet};
use std::{
path::{Path, PathBuf},
sync::{
atomic::{AtomicBool, Ordering},
mpsc::RecvTimeoutError,
Expand All @@ -43,6 +44,7 @@ impl AccountsHashVerifier {
halt_on_trusted_validators_accounts_hash_mismatch: bool,
fault_injection_rate_slots: u64,
snapshot_config: Option<SnapshotConfig>,
ledger_path: PathBuf,
) -> Self {
let exit = exit.clone();
let cluster_info = cluster_info.clone();
Expand Down Expand Up @@ -74,6 +76,7 @@ impl AccountsHashVerifier {
fault_injection_rate_slots,
snapshot_config.as_ref(),
thread_pool.as_ref(),
&ledger_path,
);
}
Err(RecvTimeoutError::Disconnected) => break,
Expand All @@ -99,8 +102,9 @@ impl AccountsHashVerifier {
fault_injection_rate_slots: u64,
snapshot_config: Option<&SnapshotConfig>,
thread_pool: Option<&ThreadPool>,
ledger_path: &Path,
) {
Self::verify_accounts_package_hash(&accounts_package, thread_pool);
Self::verify_accounts_package_hash(&accounts_package, thread_pool, ledger_path);

Self::push_accounts_hashes_to_cluster(
&accounts_package,
Expand All @@ -118,11 +122,13 @@ impl AccountsHashVerifier {
fn verify_accounts_package_hash(
accounts_package: &AccountsPackage,
thread_pool: Option<&ThreadPool>,
ledger_path: &Path,
) {
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(),
Expand Down Expand Up @@ -357,6 +363,8 @@ mod tests {
snapshot_type: None,
};

let ledger_path = TempDir::new().unwrap();

AccountsHashVerifier::process_accounts_package(
accounts_package,
&cluster_info,
Expand All @@ -368,6 +376,7 @@ mod tests {
0,
Some(&snapshot_config),
None,
ledger_path.path(),
);

// sleep for 1ms to create a newer timestmap for gossip entry
Expand Down
1 change: 1 addition & 0 deletions core/src/tvu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ impl Tvu {
tvu_config.halt_on_trusted_validators_accounts_hash_mismatch,
tvu_config.accounts_hash_fault_injection_slots,
snapshot_config.clone(),
blockstore.ledger_path().to_path_buf(),
);

let (snapshot_request_sender, snapshot_request_handler) = match snapshot_config {
Expand Down
2 changes: 2 additions & 0 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ mod tests {
snapshot_test_config.snapshot_config.clone(),
);

let tmpdir = TempDir::new().unwrap();
let accounts_hash_verifier = AccountsHashVerifier::new(
accounts_package_receiver,
Some(pending_snapshot_package),
Expand All @@ -937,6 +938,7 @@ mod tests {
false,
0,
Some(snapshot_test_config.snapshot_config.clone()),
tmpdir.path().to_path_buf(),
);

let accounts_background_service = AccountsBackgroundService::new(
Expand Down
6 changes: 4 additions & 2 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1893,8 +1893,10 @@ fn main() {
.ok()
.map(|bins| AccountsIndexConfig { bins: Some(bins) });

let accounts_db_config =
accounts_index_config.map(|x| AccountsDbConfig { index: Some(x) });
let accounts_db_config = Some(AccountsDbConfig {
index: accounts_index_config,
accounts_hash_cache_path: Some(ledger_path.clone()),
});

let process_options = ProcessOptions {
dev_halt_at_slot: value_t!(arg_matches, "halt_at_slot", Slot).ok(),
Expand Down
Loading

0 comments on commit b57e86a

Please sign in to comment.