Skip to content
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

Renames fn to AccountsDb::get_storages() #3873

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ impl AccountsDb {
let acceptable_straggler_slot_count = 100;
let old_slot_cutoff =
slot_one_epoch_old.saturating_sub(acceptable_straggler_slot_count);
let (old_storages, old_slots) = self.get_snapshot_storages(..old_slot_cutoff);
let (old_storages, old_slots) = self.get_storages(..old_slot_cutoff);
let num_old_storages = old_storages.len();
self.accounts_index
.add_uncleaned_roots(old_slots.iter().copied());
Expand Down Expand Up @@ -6936,7 +6936,7 @@ impl AccountsDb {
}

let mut collect_time = Measure::start("collect");
let (combined_maps, slots) = self.get_snapshot_storages(..=slot);
let (combined_maps, slots) = self.get_storages(..=slot);
collect_time.stop();

let mut sort_time = Measure::start("sort_storages");
Expand Down Expand Up @@ -8469,8 +8469,8 @@ impl AccountsDb {
}
}

/// Get storages to use for snapshots, for the requested slots
pub fn get_snapshot_storages(
/// Returns storages for `requested_slots`
pub fn get_storages(
&self,
requested_slots: impl RangeBounds<Slot> + Sync,
) -> (Vec<Arc<AccountStorageEntry>>, Vec<Slot>) {
Expand Down Expand Up @@ -9532,7 +9532,7 @@ impl AccountsDb {
total_lamports: u64,
config: VerifyAccountsHashAndLamportsConfig,
) -> Result<(), AccountsHashVerificationError> {
let snapshot_storages = self.get_snapshot_storages(..);
let snapshot_storages = self.get_storages(..);
let snapshot_storages_and_slots = (
snapshot_storages.0.as_slice(),
snapshot_storages.1.as_slice(),
Expand Down
32 changes: 16 additions & 16 deletions accounts-db/src/accounts_db/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ pub(crate) fn sample_storages_and_account_in_slot(
accounts.store_for_tests(slot, &to_store[..]);
accounts.add_root_and_flush_write_cache(slot);

let (storages, slots) = accounts.get_snapshot_storages(..=slot);
let (storages, slots) = accounts.get_storages(..=slot);
assert_eq!(storages.len(), slots.len());
storages
.iter()
Expand Down Expand Up @@ -2623,7 +2623,7 @@ fn test_storage_finder() {
#[test]
fn test_get_snapshot_storages_empty() {
let db = AccountsDb::new_single_for_tests();
assert!(db.get_snapshot_storages(..=0).0.is_empty());
assert!(db.get_storages(..=0).0.is_empty());
}

#[test]
Expand All @@ -2638,10 +2638,10 @@ fn test_get_snapshot_storages_only_older_than_or_equal_to_snapshot_slot() {

db.store_for_tests(base_slot, &[(&key, &account)]);
db.add_root_and_flush_write_cache(base_slot);
assert!(db.get_snapshot_storages(..=before_slot).0.is_empty());
assert!(db.get_storages(..=before_slot).0.is_empty());

assert_eq!(1, db.get_snapshot_storages(..=base_slot).0.len());
assert_eq!(1, db.get_snapshot_storages(..=after_slot).0.len());
assert_eq!(1, db.get_storages(..=base_slot).0.len());
assert_eq!(1, db.get_storages(..=after_slot).0.len());
}

#[test]
Expand All @@ -2658,13 +2658,13 @@ fn test_get_snapshot_storages_only_non_empty() {
if pass == 0 {
db.add_root_and_flush_write_cache(base_slot);
db.storage.remove(&base_slot, false);
assert!(db.get_snapshot_storages(..=after_slot).0.is_empty());
assert!(db.get_storages(..=after_slot).0.is_empty());
continue;
}

db.store_for_tests(base_slot, &[(&key, &account)]);
db.add_root_and_flush_write_cache(base_slot);
assert_eq!(1, db.get_snapshot_storages(..=after_slot).0.len());
assert_eq!(1, db.get_storages(..=after_slot).0.len());
}
}

Expand All @@ -2678,10 +2678,10 @@ fn test_get_snapshot_storages_only_roots() {
let after_slot = base_slot + 1;

db.store_for_tests(base_slot, &[(&key, &account)]);
assert!(db.get_snapshot_storages(..=after_slot).0.is_empty());
assert!(db.get_storages(..=after_slot).0.is_empty());

db.add_root_and_flush_write_cache(base_slot);
assert_eq!(1, db.get_snapshot_storages(..=after_slot).0.len());
assert_eq!(1, db.get_storages(..=after_slot).0.len());
}

#[test]
Expand All @@ -2695,13 +2695,13 @@ fn test_get_snapshot_storages_exclude_empty() {

db.store_for_tests(base_slot, &[(&key, &account)]);
db.add_root_and_flush_write_cache(base_slot);
assert_eq!(1, db.get_snapshot_storages(..=after_slot).0.len());
assert_eq!(1, db.get_storages(..=after_slot).0.len());

db.storage
.get_slot_storage_entry(0)
.unwrap()
.remove_accounts(0, true, 1);
assert!(db.get_snapshot_storages(..=after_slot).0.is_empty());
assert!(db.get_storages(..=after_slot).0.is_empty());
}

#[test]
Expand All @@ -2714,8 +2714,8 @@ fn test_get_snapshot_storages_with_base_slot() {
let slot = 10;
db.store_for_tests(slot, &[(&key, &account)]);
db.add_root_and_flush_write_cache(slot);
assert_eq!(0, db.get_snapshot_storages(slot + 1..=slot + 1).0.len());
assert_eq!(1, db.get_snapshot_storages(slot..=slot + 1).0.len());
assert_eq!(0, db.get_storages(slot + 1..=slot + 1).0.len());
assert_eq!(1, db.get_storages(slot..=slot + 1).0.len());
}

define_accounts_db_test!(
Expand Down Expand Up @@ -2812,7 +2812,7 @@ fn do_full_clean_refcount(mut accounts: AccountsDb, store1_first: bool, store_si
accounts.store_for_tests(current_slot, &[(&pubkey2, &zero_lamport_account)]);
accounts.store_for_tests(current_slot, &[(&pubkey3, &zero_lamport_account)]);

let snapshot_stores = accounts.get_snapshot_storages(..=current_slot).0;
let snapshot_stores = accounts.get_storages(..=current_slot).0;
let total_accounts: usize = snapshot_stores.iter().map(|s| s.accounts_count()).sum();
assert!(!snapshot_stores.is_empty());
assert!(total_accounts > 0);
Expand Down Expand Up @@ -8068,7 +8068,7 @@ define_accounts_db_test!(test_calculate_incremental_accounts_hash, |accounts_db|
&EpochSchedule::default(),
OldStoragesPolicy::Leave,
);
let (storages, _) = accounts_db.get_snapshot_storages(..=slot);
let (storages, _) = accounts_db.get_storages(..=slot);
let storages = SortedStorages::new(&storages);
accounts_db.calculate_accounts_hash(
&CalcAccountsHashConfig::default(),
Expand Down Expand Up @@ -8139,7 +8139,7 @@ define_accounts_db_test!(test_calculate_incremental_accounts_hash, |accounts_db|
&EpochSchedule::default(),
OldStoragesPolicy::Leave,
);
let (storages, _) = accounts_db.get_snapshot_storages(full_accounts_hash_slot + 1..=slot);
let (storages, _) = accounts_db.get_storages(full_accounts_hash_slot + 1..=slot);
let storages = SortedStorages::new(&storages);
accounts_db.calculate_incremental_accounts_hash(
&CalcAccountsHashConfig::default(),
Expand Down
12 changes: 2 additions & 10 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5769,11 +5769,7 @@ impl Bank {
// 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);
let snapshot_storages = self.rc.accounts.accounts_db.get_storages(RangeFull);
let capitalization = self.capitalization();
let verify_config = VerifyAccountsHashAndLamportsConfig {
ancestors: &self.ancestors,
Expand Down Expand Up @@ -5955,11 +5951,7 @@ impl Bank {
// we want to *include* the storage at our slot
let requested_slots = start_slot..=self.slot();

self.rc
.accounts
.accounts_db
.get_snapshot_storages(requested_slots)
.0
self.rc.accounts.accounts_db.get_storages(requested_slots).0
}

#[must_use]
Expand Down
6 changes: 1 addition & 5 deletions runtime/src/bank/accounts_lt_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,11 +875,7 @@ mod tests {
let expected_accounts_lt_hash = bank.accounts_lt_hash.lock().unwrap().clone();

// go through the storages to find the duplicates
let (mut storages, _slots) = bank
.rc
.accounts
.accounts_db
.get_snapshot_storages(RangeFull);
let (mut storages, _slots) = bank.rc.accounts.accounts_db.get_storages(RangeFull);
// sort the storages in slot-descending order
// this makes skipping the latest easier
storages.sort_unstable_by_key(|storage| cmp::Reverse(storage.slot()));
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod tests {
output_dir: P,
storage_access: StorageAccess,
) -> Result<StorageAndNextAccountsFileId, AccountsFileError> {
let storage_entries = accounts_db.get_snapshot_storages(RangeFull).0;
let storage_entries = accounts_db.get_storages(RangeFull).0;
let storage: AccountStorageMap = AccountStorageMap::with_capacity(storage_entries.len());
let mut next_append_vec_id = 0;
for storage_entry in storage_entries.into_iter() {
Expand Down Expand Up @@ -583,7 +583,7 @@ mod tests {
S: serde::Serializer,
{
let bank = Bank::default_for_tests();
let snapshot_storages = AccountsDb::example().get_snapshot_storages(0..1).0;
let snapshot_storages = AccountsDb::example().get_storages(0..1).0;
// ensure there is at least one snapshot storage example for ABI digesting
assert!(!snapshot_storages.is_empty());

Expand Down
6 changes: 3 additions & 3 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod serde_snapshot_tests {
output_dir: impl AsRef<Path>,
storage_access: StorageAccess,
) -> Result<StorageAndNextAccountsFileId, AccountsFileError> {
let storage_entries = accounts_db.get_snapshot_storages(RangeFull).0;
let storage_entries = accounts_db.get_storages(RangeFull).0;
let storage: AccountStorageMap = AccountStorageMap::with_capacity(storage_entries.len());
let mut next_append_vec_id = 0;
for storage_entry in storage_entries.into_iter() {
Expand Down Expand Up @@ -175,7 +175,7 @@ mod serde_snapshot_tests {
storage_access: StorageAccess,
) -> AccountsDb {
let mut writer = Cursor::new(vec![]);
let snapshot_storages = accounts.get_snapshot_storages(..=slot).0;
let snapshot_storages = accounts.get_storages(..=slot).0;
accountsdb_to_stream(
&mut writer,
accounts,
Expand Down Expand Up @@ -241,7 +241,7 @@ mod serde_snapshot_tests {
&mut writer,
&accounts.accounts_db,
slot,
&get_storages_to_serialize(&accounts.accounts_db.get_snapshot_storages(..=slot).0),
&get_storages_to_serialize(&accounts.accounts_db.get_storages(..=slot).0),
)
.unwrap();

Expand Down
7 changes: 2 additions & 5 deletions runtime/src/snapshot_minimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ impl<'a> SnapshotMinimizer<'a> {
&self,
minimized_slot_set: DashSet<Slot>,
) -> (Vec<Slot>, Vec<Arc<AccountStorageEntry>>) {
let snapshot_storages = self
.accounts_db()
.get_snapshot_storages(..=self.starting_slot)
.0;
let snapshot_storages = self.accounts_db().get_storages(..=self.starting_slot).0;

let dead_slots = Mutex::new(Vec::new());
let dead_storages = Mutex::new(Vec::new());
Expand Down Expand Up @@ -656,7 +653,7 @@ mod tests {
};
minimizer.minimize_accounts_db();

let snapshot_storages = accounts.get_snapshot_storages(..=current_slot).0;
let snapshot_storages = accounts.get_storages(..=current_slot).0;
assert_eq!(snapshot_storages.len(), 3);

let mut account_count = 0;
Expand Down
Loading