AccountsHashVerifier remembers last full snapshot info (#30582)
AHV remembers last full snapshot info
This commit is contained in:
parent
38e74325e3
commit
120b0c92d1
|
@ -9,10 +9,11 @@ use {
|
||||||
solana_gossip::cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES},
|
solana_gossip::cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES},
|
||||||
solana_measure::{measure::Measure, measure_us},
|
solana_measure::{measure::Measure, measure_us},
|
||||||
solana_runtime::{
|
solana_runtime::{
|
||||||
accounts_hash::{AccountsHashEnum, CalcAccountsHashConfig, HashStats},
|
accounts_hash::{AccountsHash, AccountsHashEnum, CalcAccountsHashConfig, HashStats},
|
||||||
snapshot_config::SnapshotConfig,
|
snapshot_config::SnapshotConfig,
|
||||||
snapshot_package::{
|
snapshot_package::{
|
||||||
self, retain_max_n_elements, AccountsPackage, AccountsPackageType, SnapshotPackage,
|
self, retain_max_n_elements, AccountsPackage, AccountsPackageType, SnapshotPackage,
|
||||||
|
SnapshotType,
|
||||||
},
|
},
|
||||||
sorted_storages::SortedStorages,
|
sorted_storages::SortedStorages,
|
||||||
},
|
},
|
||||||
|
@ -55,6 +56,7 @@ impl AccountsHashVerifier {
|
||||||
let t_accounts_hash_verifier = Builder::new()
|
let t_accounts_hash_verifier = Builder::new()
|
||||||
.name("solAcctHashVer".to_string())
|
.name("solAcctHashVer".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
|
let mut last_full_snapshot = None;
|
||||||
let mut hashes = vec![];
|
let mut hashes = vec![];
|
||||||
loop {
|
loop {
|
||||||
if exit.load(Ordering::Relaxed) {
|
if exit.load(Ordering::Relaxed) {
|
||||||
|
@ -85,6 +87,7 @@ impl AccountsHashVerifier {
|
||||||
&exit,
|
&exit,
|
||||||
fault_injection_rate_slots,
|
fault_injection_rate_slots,
|
||||||
&snapshot_config,
|
&snapshot_config,
|
||||||
|
&mut last_full_snapshot,
|
||||||
));
|
));
|
||||||
|
|
||||||
datapoint_info!(
|
datapoint_info!(
|
||||||
|
@ -184,8 +187,10 @@ impl AccountsHashVerifier {
|
||||||
exit: &Arc<AtomicBool>,
|
exit: &Arc<AtomicBool>,
|
||||||
fault_injection_rate_slots: u64,
|
fault_injection_rate_slots: u64,
|
||||||
snapshot_config: &SnapshotConfig,
|
snapshot_config: &SnapshotConfig,
|
||||||
|
last_full_snapshot: &mut Option<FullSnapshotAccountsHashInfo>,
|
||||||
) {
|
) {
|
||||||
let accounts_hash = Self::calculate_and_verify_accounts_hash(&accounts_package);
|
let accounts_hash =
|
||||||
|
Self::calculate_and_verify_accounts_hash(&accounts_package, last_full_snapshot);
|
||||||
|
|
||||||
Self::save_epoch_accounts_hash(&accounts_package, accounts_hash);
|
Self::save_epoch_accounts_hash(&accounts_package, accounts_hash);
|
||||||
|
|
||||||
|
@ -209,7 +214,10 @@ impl AccountsHashVerifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns calculated accounts hash
|
/// returns calculated accounts hash
|
||||||
fn calculate_and_verify_accounts_hash(accounts_package: &AccountsPackage) -> AccountsHashEnum {
|
fn calculate_and_verify_accounts_hash(
|
||||||
|
accounts_package: &AccountsPackage,
|
||||||
|
last_full_snapshot: &mut Option<FullSnapshotAccountsHashInfo>,
|
||||||
|
) -> AccountsHashEnum {
|
||||||
let mut measure_hash = Measure::start("hash");
|
let mut measure_hash = Measure::start("hash");
|
||||||
let mut sort_time = Measure::start("sort_storages");
|
let mut sort_time = Measure::start("sort_storages");
|
||||||
let sorted_storages = SortedStorages::new(&accounts_package.snapshot_storages);
|
let sorted_storages = SortedStorages::new(&accounts_package.snapshot_storages);
|
||||||
|
@ -302,6 +310,17 @@ impl AccountsHashVerifier {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if accounts_package.package_type
|
||||||
|
== AccountsPackageType::Snapshot(SnapshotType::FullSnapshot)
|
||||||
|
{
|
||||||
|
*last_full_snapshot = Some(FullSnapshotAccountsHashInfo {
|
||||||
|
slot: accounts_package.slot,
|
||||||
|
accounts_hash,
|
||||||
|
capitalization: lamports,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
datapoint_info!(
|
datapoint_info!(
|
||||||
"accounts_hash_verifier",
|
"accounts_hash_verifier",
|
||||||
("calculate_hash", measure_hash.as_us(), i64),
|
("calculate_hash", measure_hash.as_us(), i64),
|
||||||
|
@ -450,6 +469,16 @@ impl AccountsHashVerifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Soon incremental snapshots will no longer calculate a *full* accounts hash. To support correct
|
||||||
|
/// snapshot verification at load time, the incremental snapshot will need to include *this*
|
||||||
|
/// information about the full snapshot it was based on.
|
||||||
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
|
struct FullSnapshotAccountsHashInfo {
|
||||||
|
slot: Slot,
|
||||||
|
accounts_hash: AccountsHash,
|
||||||
|
capitalization: u64,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {
|
use {
|
||||||
|
@ -536,6 +565,7 @@ mod tests {
|
||||||
&exit,
|
&exit,
|
||||||
0,
|
0,
|
||||||
&snapshot_config,
|
&snapshot_config,
|
||||||
|
&mut None,
|
||||||
);
|
);
|
||||||
|
|
||||||
// sleep for 1ms to create a newer timestamp for gossip entry
|
// sleep for 1ms to create a newer timestamp for gossip entry
|
||||||
|
|
Loading…
Reference in New Issue