forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 1k
Gets snapshot storages before calling verify_accounts_hash() #1202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brooksprumo
merged 1 commit into
anza-xyz:master
from
brooksprumo:verify-accounts-hash/get-storages
May 7, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7488,6 +7488,7 @@ impl AccountsDb { | |
| /// and then calculate the incremental accounts hash for `(base slot, slot]`. | ||
| pub fn verify_accounts_hash_and_lamports( | ||
| &self, | ||
| snapshot_storages_and_slots: (&[Arc<AccountStorageEntry>], &[Slot]), | ||
| slot: Slot, | ||
| total_lamports: u64, | ||
| base: Option<(Slot, /*capitalization*/ u64)>, | ||
|
|
@@ -7503,11 +7504,21 @@ impl AccountsDb { | |
| let hash_mismatch_is_error = !config.ignore_mismatch; | ||
|
|
||
| if let Some((base_slot, base_capitalization)) = base { | ||
| self.verify_accounts_hash_and_lamports(base_slot, base_capitalization, None, config)?; | ||
| let (storages, slots) = | ||
| self.get_snapshot_storages(base_slot.checked_add(1).unwrap()..=slot); | ||
| let sorted_storages = | ||
| SortedStorages::new_with_slots(storages.iter().zip(slots), None, None); | ||
| self.verify_accounts_hash_and_lamports( | ||
| snapshot_storages_and_slots, | ||
| base_slot, | ||
| base_capitalization, | ||
| None, | ||
| config, | ||
| )?; | ||
|
|
||
| let storages_and_slots = snapshot_storages_and_slots | ||
| .0 | ||
| .iter() | ||
| .zip(snapshot_storages_and_slots.1.iter()) | ||
| .filter(|storage_and_slot| *storage_and_slot.1 > base_slot) | ||
| .map(|(storage, slot)| (storage, *slot)); | ||
| let sorted_storages = SortedStorages::new_with_slots(storages_and_slots, None, None); | ||
| let calculated_incremental_accounts_hash = self.calculate_incremental_accounts_hash( | ||
| &calc_config, | ||
| &sorted_storages, | ||
|
|
@@ -7526,9 +7537,13 @@ impl AccountsDb { | |
| } | ||
| } | ||
| } else { | ||
| let (storages, slots) = self.get_snapshot_storages(..=slot); | ||
| let sorted_storages = | ||
| SortedStorages::new_with_slots(storages.iter().zip(slots), None, None); | ||
| let storages_and_slots = snapshot_storages_and_slots | ||
| .0 | ||
| .iter() | ||
| .zip(snapshot_storages_and_slots.1.iter()) | ||
| .filter(|storage_and_slot| *storage_and_slot.1 <= slot) | ||
| .map(|(storage, slot)| (storage, *slot)); | ||
| let sorted_storages = SortedStorages::new_with_slots(storages_and_slots, None, None); | ||
| let (calculated_accounts_hash, calculated_lamports) = | ||
| self.calculate_accounts_hash(&calc_config, &sorted_storages, HashStats::default()); | ||
| if calculated_lamports != total_lamports { | ||
|
|
@@ -9448,7 +9463,18 @@ impl AccountsDb { | |
| total_lamports: u64, | ||
| config: VerifyAccountsHashAndLamportsConfig, | ||
| ) -> Result<(), AccountsHashVerificationError> { | ||
| self.verify_accounts_hash_and_lamports(slot, total_lamports, None, config) | ||
| let snapshot_storages = self.get_snapshot_storages(..); | ||
| let snapshot_storages_and_slots = ( | ||
| snapshot_storages.0.as_slice(), | ||
| snapshot_storages.1.as_slice(), | ||
| ); | ||
| self.verify_accounts_hash_and_lamports( | ||
| snapshot_storages_and_slots, | ||
| slot, | ||
| total_lamports, | ||
| None, | ||
| config, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -12400,7 +12426,7 @@ pub mod tests { | |
| db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true); | ||
|
|
||
| assert_matches!( | ||
| db.verify_accounts_hash_and_lamports(some_slot, 1, None, config.clone()), | ||
| db.verify_accounts_hash_and_lamports_for_tests(some_slot, 1, config.clone()), | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed this one in the previous PR. |
||
| Ok(_) | ||
| ); | ||
| continue; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,7 +185,7 @@ use { | |
| collections::{HashMap, HashSet}, | ||
| convert::TryFrom, | ||
| fmt, mem, | ||
| ops::{AddAssign, RangeInclusive}, | ||
| ops::{AddAssign, RangeFull, RangeInclusive}, | ||
| path::PathBuf, | ||
| slice, | ||
| sync::{ | ||
|
|
@@ -5620,7 +5620,15 @@ impl Bank { | |
| panic!("cannot verify accounts hash because slot {slot} is not a root"); | ||
| } | ||
| } | ||
| let cap = self.capitalization(); | ||
| // The snapshot storages must be captured *before* starting the background verification. | ||
| // Otherwise, it is possible that a delayed call to `get_snapshot_storages()` will *not* | ||
| // get the correct storages required to calculate and verify the accounts hashes. | ||
| let snapshot_storages = self | ||
| .rc | ||
| .accounts | ||
| .accounts_db | ||
| .get_snapshot_storages(RangeFull); | ||
|
Comment on lines
+5623
to
+5630
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get the snapshot storages here, before starting the background thread to verify the account hashes. |
||
| let capitalization = self.capitalization(); | ||
| let verify_config = VerifyAccountsHashAndLamportsConfig { | ||
| ancestors: &self.ancestors, | ||
| epoch_schedule: self.epoch_schedule(), | ||
|
|
@@ -5641,9 +5649,14 @@ impl Bank { | |
| .name("solBgHashVerify".into()) | ||
| .spawn(move || { | ||
| info!("Initial background accounts hash verification has started"); | ||
| let snapshot_storages_and_slots = ( | ||
| snapshot_storages.0.as_slice(), | ||
| snapshot_storages.1.as_slice(), | ||
| ); | ||
| let result = accounts_.verify_accounts_hash_and_lamports( | ||
| snapshot_storages_and_slots, | ||
| slot, | ||
| cap, | ||
| capitalization, | ||
| base, | ||
| VerifyAccountsHashAndLamportsConfig { | ||
| ancestors: &ancestors, | ||
|
|
@@ -5663,7 +5676,17 @@ impl Bank { | |
| }); | ||
| true // initial result is true. We haven't failed yet. If verification fails, we'll panic from bg thread. | ||
| } else { | ||
| let result = accounts.verify_accounts_hash_and_lamports(slot, cap, base, verify_config); | ||
| let snapshot_storages_and_slots = ( | ||
| snapshot_storages.0.as_slice(), | ||
| snapshot_storages.1.as_slice(), | ||
| ); | ||
| let result = accounts.verify_accounts_hash_and_lamports( | ||
| snapshot_storages_and_slots, | ||
| slot, | ||
| capitalization, | ||
| base, | ||
| verify_config, | ||
| ); | ||
| self.set_initial_accounts_hash_verification_completed(); | ||
| result | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benchmark needed to be updated too.