calculate hash from store instead of index (#15034)

* calculate hash from store instead of index

* restore update hash in abs
This commit is contained in:
Jeff Washington (jwash)
2021-02-04 09:00:33 -06:00
committed by GitHub
parent d0118a5c42
commit 600ff0d915
15 changed files with 701 additions and 61 deletions

View File

@ -8,7 +8,9 @@ use crate::{
cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES},
snapshot_packager_service::PendingSnapshotPackage,
};
use solana_runtime::snapshot_package::{AccountsPackage, AccountsPackageReceiver};
use solana_runtime::snapshot_package::{
AccountsPackage, AccountsPackagePre, AccountsPackageReceiver,
};
use solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey};
use std::collections::{HashMap, HashSet};
use std::{
@ -49,7 +51,7 @@ impl AccountsHashVerifier {
match accounts_package_receiver.recv_timeout(Duration::from_secs(1)) {
Ok(accounts_package) => {
Self::process_accounts_package(
Self::process_accounts_package_pre(
accounts_package,
&cluster_info,
&trusted_validators,
@ -72,6 +74,32 @@ impl AccountsHashVerifier {
}
}
fn process_accounts_package_pre(
accounts_package: AccountsPackagePre,
cluster_info: &ClusterInfo,
trusted_validators: &Option<HashSet<Pubkey>>,
halt_on_trusted_validator_accounts_hash_mismatch: bool,
pending_snapshot_package: &Option<PendingSnapshotPackage>,
hashes: &mut Vec<(Slot, Hash)>,
exit: &Arc<AtomicBool>,
fault_injection_rate_slots: u64,
snapshot_interval_slots: u64,
) {
let accounts_package =
solana_runtime::snapshot_utils::process_accounts_package_pre(accounts_package);
Self::process_accounts_package(
accounts_package,
cluster_info,
trusted_validators,
halt_on_trusted_validator_accounts_hash_mismatch,
pending_snapshot_package,
hashes,
exit,
fault_injection_rate_slots,
snapshot_interval_slots,
);
}
fn process_accounts_package(
accounts_package: AccountsPackage,
cluster_info: &ClusterInfo,
@ -83,6 +111,7 @@ impl AccountsHashVerifier {
fault_injection_rate_slots: u64,
snapshot_interval_slots: u64,
) {
let hash = accounts_package.hash;
if fault_injection_rate_slots != 0
&& accounts_package.slot % fault_injection_rate_slots == 0
{
@ -91,10 +120,10 @@ impl AccountsHashVerifier {
use solana_sdk::hash::extend_and_hash;
warn!("inserting fault at slot: {}", accounts_package.slot);
let rand = thread_rng().gen_range(0, 10);
let hash = extend_and_hash(&accounts_package.hash, &[rand]);
let hash = extend_and_hash(&hash, &[rand]);
hashes.push((accounts_package.slot, hash));
} else {
hashes.push((accounts_package.slot, accounts_package.hash));
hashes.push((accounts_package.slot, hash));
}
while hashes.len() > MAX_SNAPSHOT_HASHES {

View File

@ -156,7 +156,7 @@ mod tests {
// Create a packageable snapshot
let output_tar_path = snapshot_utils::get_snapshot_archive_path(
&snapshot_package_output_path,
snapshot_package_output_path,
&(42, Hash::default()),
ArchiveFormat::TarBzip2,
);

View File

@ -79,6 +79,7 @@ pub struct TvuConfig {
pub repair_validators: Option<HashSet<Pubkey>>,
pub accounts_hash_fault_injection_slots: u64,
pub accounts_db_caching_enabled: bool,
pub test_hash_calculation: bool,
}
impl Tvu {
@ -274,6 +275,7 @@ impl Tvu {
&exit,
accounts_background_request_handler,
tvu_config.accounts_db_caching_enabled,
tvu_config.test_hash_calculation,
);
Tvu {

View File

@ -121,6 +121,7 @@ pub struct ValidatorConfig {
pub account_indexes: HashSet<AccountIndex>,
pub accounts_db_caching_enabled: bool,
pub warp_slot: Option<Slot>,
pub accounts_db_test_hash_calculation: bool,
}
impl Default for ValidatorConfig {
@ -168,6 +169,7 @@ impl Default for ValidatorConfig {
account_indexes: HashSet::new(),
accounts_db_caching_enabled: false,
warp_slot: None,
accounts_db_test_hash_calculation: false,
}
}
}
@ -641,6 +643,7 @@ impl Validator {
repair_validators: config.repair_validators.clone(),
accounts_hash_fault_injection_slots: config.accounts_hash_fault_injection_slots,
accounts_db_caching_enabled: config.accounts_db_caching_enabled,
test_hash_calculation: config.accounts_db_test_hash_calculation,
},
);