From cb4c3668c77fced388bb8da0be77ad76994e1b15 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Mon, 31 Oct 2022 13:58:42 -0700 Subject: [PATCH] .pubkey() instead of meta.pubkey for stored account (#28682) --- .../src/accounts_update_notifier.rs | 2 +- runtime/src/accounts_db.rs | 38 +++++++++---------- runtime/src/append_vec.rs | 8 ++-- runtime/store-tool/src/main.rs | 4 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/geyser-plugin-manager/src/accounts_update_notifier.rs b/geyser-plugin-manager/src/accounts_update_notifier.rs index b774966d7f..8c39e921d0 100644 --- a/geyser-plugin-manager/src/accounts_update_notifier.rs +++ b/geyser-plugin-manager/src/accounts_update_notifier.rs @@ -125,7 +125,7 @@ impl AccountsUpdateNotifierImpl { stored_account_meta: &'a StoredAccountMeta, ) -> Option> { Some(ReplicaAccountInfoV2 { - pubkey: stored_account_meta.meta.pubkey.as_ref(), + pubkey: stored_account_meta.pubkey().as_ref(), lamports: stored_account_meta.account_meta.lamports, owner: stored_account_meta.account_meta.owner.as_ref(), executable: stored_account_meta.account_meta.executable, diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 2c6ba4b10c..b24f88484b 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -299,7 +299,7 @@ impl AncientSlotPubkeys { .append_vec() .accounts .account_iter() - .map(|account| account.meta.pubkey) + .map(|account| *account.pubkey()) .collect::>(); self.inner = Some(AncientSlotPubkeysInner { pubkeys, @@ -733,7 +733,7 @@ impl<'a> LoadedAccount<'a> { pub fn pubkey(&self) -> &Pubkey { match self { - LoadedAccount::Stored(stored_account_meta) => &stored_account_meta.meta.pubkey, + LoadedAccount::Stored(stored_account_meta) => stored_account_meta.pubkey(), LoadedAccount::Cached(cached_account) => cached_account.pubkey(), } } @@ -755,7 +755,7 @@ impl<'a> LoadedAccount<'a> { LoadedAccount::Stored(stored_account_meta) => AccountsDb::hash_account( slot, stored_account_meta, - &stored_account_meta.meta.pubkey, + stored_account_meta.pubkey(), include_slot, ), LoadedAccount::Cached(cached_account) => { @@ -2911,7 +2911,7 @@ impl AccountsDb { } oldest_dirty_slot = oldest_dirty_slot.min(*slot); store.accounts.account_iter().for_each(|account| { - pubkeys.insert(account.meta.pubkey); + pubkeys.insert(*account.pubkey()); }); }); oldest_dirty_slot @@ -3010,8 +3010,8 @@ impl AccountsDb { .unwrap_or_default() { storage.all_accounts().iter().for_each(|account| { - let pk = account.meta.pubkey; - match pubkey_refcount.entry(pk) { + let pk = account.pubkey(); + match pubkey_refcount.entry(*pk) { dashmap::mapref::entry::Entry::Occupied(mut occupied_entry) => { if !occupied_entry.get().iter().any(|s| s == &slot) { occupied_entry.get_mut().push(slot); @@ -3749,7 +3749,7 @@ impl AccountsDb { let store_id = store.append_vec_id(); store.accounts.account_iter().for_each(|account| { let new_entry = FoundStoredAccount { account, store_id }; - match stored_accounts.entry(new_entry.account.meta.pubkey) { + match stored_accounts.entry(*new_entry.account.pubkey()) { Entry::Occupied(mut occupied_entry) => { if new_entry.account.meta.write_version > occupied_entry.get().account.meta.write_version @@ -4312,7 +4312,7 @@ impl AccountsDb { /// returns the pubkeys that are in 'accounts' that are already in 'existing_ancient_pubkeys' /// Also updated 'existing_ancient_pubkeys' to include all pubkeys in 'accounts' since they will soon be written into the ancient slot. fn get_keys_to_unref_ancient<'a>( - accounts: &'a [(&StoredAccountMeta<'_>, u64)], + accounts: &'a [(&StoredAccountMeta<'_>, Slot)], existing_ancient_pubkeys: &mut HashSet, ) -> HashSet<&'a Pubkey> { let mut unref = HashSet::<&Pubkey>::default(); @@ -4334,7 +4334,7 @@ impl AccountsDb { /// As a side effect, on exit, 'existing_ancient_pubkeys' will now contain all pubkeys in 'accounts'. fn unref_accounts_already_in_storage( &self, - accounts: &[(&StoredAccountMeta<'_>, u64)], + accounts: &[(&StoredAccountMeta<'_>, Slot)], existing_ancient_pubkeys: &mut HashSet, ) { let unref = Self::get_keys_to_unref_ancient(accounts, existing_ancient_pubkeys); @@ -6993,7 +6993,7 @@ impl AccountsDb { if len == 1 { // only 1 storage, so no need to interleave between multiple storages based on write_version storages[0].accounts.account_iter().for_each(|account| { - if scanner.filter(&account.meta.pubkey) { + if scanner.filter(account.pubkey()) { scanner.found_account(&LoadedAccount::Stored(account)) } }); @@ -7023,10 +7023,10 @@ impl AccountsDb { } let found_account = &mut current[min_index]; if scanner.filter( - &found_account + found_account .1 .as_ref() - .map(|stored_account| stored_account.meta.pubkey) + .map(|stored_account| stored_account.pubkey()) .unwrap(), // will always be 'Some' ) { let account = std::mem::take(found_account); @@ -8199,7 +8199,7 @@ impl AccountsDb { store .accounts .account_iter() - .map(|account| (slot, account.meta.pubkey)) + .map(|account| (slot, *account.pubkey())) .collect::>() }) .flatten() @@ -8686,9 +8686,9 @@ impl AccountsDb { storage_maps.iter().for_each(|storage| { storage.accounts.account_iter().for_each(|stored_account| { let this_version = stored_account.meta.write_version; - let pubkey = stored_account.meta.pubkey; - assert!(!self.is_filler_account(&pubkey)); - match accounts_map.entry(pubkey) { + let pubkey = stored_account.pubkey(); + assert!(!self.is_filler_account(pubkey)); + match accounts_map.entry(*pubkey) { Entry::Vacant(entry) => { entry.insert(IndexAccountMapEntry { write_version: this_version, @@ -12581,7 +12581,7 @@ pub mod tests { AccountsDb::hash_account( slot, &stored_account, - &stored_account.meta.pubkey, + stored_account.pubkey(), INCLUDE_SLOT_IN_HASH_TESTS ), expected_account_hash, @@ -12591,7 +12591,7 @@ pub mod tests { AccountsDb::hash_account( slot, &account, - &stored_account.meta.pubkey, + stored_account.pubkey(), INCLUDE_SLOT_IN_HASH_TESTS ), expected_account_hash, @@ -14857,7 +14857,7 @@ pub mod tests { let before_size = storage0.alive_bytes.load(Ordering::Acquire); let account_info = accounts_db .accounts_index - .get_account_read_entry(&account.meta.pubkey) + .get_account_read_entry(account.pubkey()) .map(|locked_entry| { // Should only be one entry per key, since every key was only stored to slot 0 locked_entry.slot_list()[0] diff --git a/runtime/src/append_vec.rs b/runtime/src/append_vec.rs index c979d7231a..f22f755e1c 100644 --- a/runtime/src/append_vec.rs +++ b/runtime/src/append_vec.rs @@ -114,6 +114,10 @@ impl<'a> StoredAccountMeta<'a> { }) } + pub fn pubkey(&self) -> &Pubkey { + &self.meta.pubkey + } + fn sanitize(&self) -> bool { self.sanitize_executable() && self.sanitize_lamports() } @@ -136,10 +140,6 @@ impl<'a> StoredAccountMeta<'a> { let executable_byte: &u8 = unsafe { &*(executable_bool as *const bool as *const u8) }; executable_byte } - - pub fn pubkey(&self) -> &Pubkey { - &self.meta.pubkey - } } pub struct AppendVecAccountsIter<'a> { diff --git a/runtime/store-tool/src/main.rs b/runtime/store-tool/src/main.rs index 8f7d2f2a40..642b81b68b 100644 --- a/runtime/store-tool/src/main.rs +++ b/runtime/store-tool/src/main.rs @@ -41,7 +41,7 @@ fn main() { } info!( " account: {:?} version: {} lamports: {} data: {} hash: {:?}", - account.meta.pubkey, + account.pubkey(), account.meta.write_version, account.account_meta.lamports, account.meta.data_len, @@ -60,7 +60,7 @@ fn is_account_zeroed(account: &StoredAccountMeta) -> bool { account.hash == &Hash::default() && account.meta.data_len == 0 && account.meta.write_version == 0 - && account.meta.pubkey == Pubkey::default() + && account.pubkey() == &Pubkey::default() && account.clone_account() == AccountSharedData::default() }