Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit adc4e63

Browse files
accounts hash calc refactoring (#28164)
1 parent 7fd8540 commit adc4e63

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

runtime/src/accounts_db.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6950,8 +6950,7 @@ impl AccountsDb {
69506950
.end
69516951
.saturating_sub(slots_per_epoch);
69526952

6953-
let mut file_name = String::default();
6954-
if (should_cache_hash_data && eligible_for_caching)
6953+
let file_name = if (should_cache_hash_data && eligible_for_caching)
69556954
|| config.store_detailed_debug_info_on_failure
69566955
{
69576956
let mut load_from_cache = true;
@@ -6972,10 +6971,12 @@ impl AccountsDb {
69726971
load_from_cache = false;
69736972
break;
69746973
}
6975-
let storage_file = sub_storages.first().unwrap().accounts.get_path();
6974+
let append_vec = sub_storages.first().unwrap();
6975+
// check written_bytes here. This is necessary for tests and removes a potential for false positives.
6976+
append_vec.written_bytes().hash(&mut hasher);
6977+
let storage_file = append_vec.accounts.get_path();
69766978
slot.hash(&mut hasher);
69776979
storage_file.hash(&mut hasher);
6978-
// check alive_bytes, etc. here?
69796980
let amod = std::fs::metadata(storage_file);
69806981
if amod.is_err() {
69816982
load_from_cache = false;
@@ -6998,7 +6999,7 @@ impl AccountsDb {
69986999
// we have a hash value for all the storages in this slot
69997000
// so, build a file name:
70007001
let hash = hasher.finish();
7001-
file_name = format!(
7002+
let file_name = format!(
70027003
"{}.{}.{}.{}.{}",
70037004
start, end_exclusive, bin_range.start, bin_range.end, hash
70047005
);
@@ -7018,14 +7019,18 @@ impl AccountsDb {
70187019
scanner.set_accum(retval);
70197020

70207021
// fall through and load normally - we failed to load
7022+
file_name
7023+
} else {
7024+
String::default()
70217025
}
70227026
} else {
70237027
for (slot, sub_storages) in snapshot_storages.iter_range(start..end_exclusive) {
70247028
if bin_range.start == 0 && slot < one_epoch_old {
70257029
self.update_old_slot_stats(stats, sub_storages);
70267030
}
70277031
}
7028-
}
7032+
String::default()
7033+
};
70297034

70307035
for (slot, sub_storages) in snapshot_storages.iter_range(start..end_exclusive) {
70317036
scanner.set_slot(slot);
@@ -7188,6 +7193,7 @@ impl AccountsDb {
71887193
bank_hash_info.snapshot_hash = hash;
71897194
}
71907195

7196+
/// scan 'storage', return a vec of 'CacheHashDataFile', one per pass
71917197
fn scan_snapshot_stores_with_cache(
71927198
&self,
71937199
cache_hash_data: &CacheHashData,
@@ -7340,6 +7346,7 @@ impl AccountsDb {
73407346
},
73417347
};
73427348

7349+
// get raw data by scanning
73437350
let result = self.scan_snapshot_stores_with_cache(
73447351
&cache_hash_data,
73457352
storages,
@@ -7350,6 +7357,7 @@ impl AccountsDb {
73507357
hash.filler_account_suffix.as_ref(),
73517358
)?;
73527359

7360+
// turn raw data into merkel tree hashes and sum of lamports
73537361
let (hash, lamports, for_next_pass) = hash.rest_of_hash_calculation(
73547362
result,
73557363
&mut stats,

0 commit comments

Comments
 (0)