remove StorableAccounts.pubkey() (#829)
remove `StorableAccounts`.`pubkey()`
This commit is contained in:
parent
f0375596dd
commit
877591ea7d
|
@ -64,9 +64,8 @@ impl<'a: 'b, 'b, U: StorableAccounts<'a>, V: Borrow<AccountHash>>
|
|||
pub fn get<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
mut callback: impl FnMut((AccountForStorage, &Pubkey, &AccountHash)) -> Ret,
|
||||
mut callback: impl FnMut(AccountForStorage, &AccountHash) -> Ret,
|
||||
) -> Ret {
|
||||
let pubkey = self.accounts.pubkey(index);
|
||||
let hash = if self.accounts.has_hash() {
|
||||
self.accounts.hash(index)
|
||||
} else {
|
||||
|
@ -74,7 +73,7 @@ impl<'a: 'b, 'b, U: StorableAccounts<'a>, V: Borrow<AccountHash>>
|
|||
item[index].borrow()
|
||||
};
|
||||
self.accounts
|
||||
.account_default_if_zero_lamport(index, |account| callback((account, pubkey, hash)))
|
||||
.account_default_if_zero_lamport(index, |account| callback(account, hash))
|
||||
}
|
||||
|
||||
/// None if account at index has lamports == 0
|
||||
|
|
|
@ -6393,19 +6393,20 @@ impl AccountsDb {
|
|||
.map(|(i, txn)| {
|
||||
let mut account_info = AccountInfo::default();
|
||||
accounts_and_meta_to_store.account_default_if_zero_lamport(i, |account| {
|
||||
let account = account.to_account_shared_data();
|
||||
let pubkey = accounts_and_meta_to_store.pubkey(i);
|
||||
let account_shared_data = account.to_account_shared_data();
|
||||
let pubkey = account.pubkey();
|
||||
account_info = AccountInfo::new(StorageLocation::Cached, account.lamports());
|
||||
|
||||
self.notify_account_at_accounts_update(
|
||||
slot,
|
||||
&account,
|
||||
&account_shared_data,
|
||||
txn,
|
||||
pubkey,
|
||||
&mut write_version_producer,
|
||||
);
|
||||
|
||||
let cached_account = self.accounts_cache.store(slot, pubkey, account);
|
||||
let cached_account =
|
||||
self.accounts_cache.store(slot, pubkey, account_shared_data);
|
||||
// hash this account in the bg
|
||||
match &self.sender_bg_hasher {
|
||||
Some(ref sender) => {
|
||||
|
@ -6433,11 +6434,12 @@ impl AccountsDb {
|
|||
.can_slot_be_in_cache(accounts.target_slot())
|
||||
{
|
||||
(0..accounts.len()).for_each(|index| {
|
||||
let pubkey = accounts.pubkey(index);
|
||||
// based on the patterns of how a validator writes accounts, it is almost always the case that there is no read only cache entry
|
||||
// for this pubkey and slot. So, we can give that hint to the `remove` for performance.
|
||||
self.read_only_accounts_cache
|
||||
.remove_assume_not_present(*pubkey);
|
||||
accounts.account(index, |account| {
|
||||
// based on the patterns of how a validator writes accounts, it is almost always the case that there is no read only cache entry
|
||||
// for this pubkey and slot. So, we can give that hint to the `remove` for performance.
|
||||
self.read_only_accounts_cache
|
||||
.remove_assume_not_present(*account.pubkey());
|
||||
})
|
||||
});
|
||||
}
|
||||
calc_stored_meta_time.stop();
|
||||
|
@ -6478,9 +6480,8 @@ impl AccountsDb {
|
|||
let len = accounts.len();
|
||||
let mut hashes = Vec::with_capacity(len);
|
||||
for index in 0..accounts.len() {
|
||||
let pubkey = accounts.pubkey(index);
|
||||
accounts.account(index, |account| {
|
||||
let hash = Self::hash_account(&account, pubkey);
|
||||
let hash = Self::hash_account(&account, account.pubkey());
|
||||
hashes.push(hash);
|
||||
});
|
||||
}
|
||||
|
@ -7780,13 +7781,12 @@ impl AccountsDb {
|
|||
|
||||
(start..end).for_each(|i| {
|
||||
let info = infos[i];
|
||||
let pubkey = accounts.pubkey(i);
|
||||
accounts.account(i, |account| {
|
||||
let old_slot = accounts.slot(i);
|
||||
self.accounts_index.upsert(
|
||||
target_slot,
|
||||
old_slot,
|
||||
pubkey,
|
||||
account.pubkey(),
|
||||
&account,
|
||||
&self.account_indexes,
|
||||
info,
|
||||
|
@ -9631,9 +9631,6 @@ pub mod tests {
|
|||
where
|
||||
AccountForStorage<'a>: From<&'a T>,
|
||||
{
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
self.1[index].0
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
|
|
@ -754,7 +754,7 @@ impl AppendVec {
|
|||
if stop {
|
||||
break;
|
||||
}
|
||||
accounts.get(i, |(account, pubkey, hash)| {
|
||||
accounts.get(i, |account, hash| {
|
||||
let account_meta = AccountMeta {
|
||||
lamports: account.lamports(),
|
||||
owner: *account.owner(),
|
||||
|
@ -763,7 +763,7 @@ impl AppendVec {
|
|||
};
|
||||
|
||||
let stored_meta = StoredMeta {
|
||||
pubkey: *pubkey,
|
||||
pubkey: *account.pubkey(),
|
||||
data_len: account.data().len() as u64,
|
||||
write_version_obsolete: 0,
|
||||
};
|
||||
|
@ -954,9 +954,9 @@ pub mod tests {
|
|||
assert_eq!(storable.len(), pubkeys.len());
|
||||
assert!(!storable.is_empty());
|
||||
(0..2).for_each(|i| {
|
||||
storable.get(i, |(_, pubkey, hash)| {
|
||||
storable.get(i, |account, hash| {
|
||||
assert_eq!(hash, &hashes[i]);
|
||||
assert_eq!(pubkey, &pubkeys[i]);
|
||||
assert_eq!(account.pubkey(), &pubkeys[i]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,9 +22,6 @@ impl StakeReward {
|
|||
|
||||
/// allow [StakeReward] to be passed to `StoreAccounts` directly without copies or vec construction
|
||||
impl<'a> StorableAccounts<'a> for (Slot, &'a [StakeReward]) {
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
&self.1[index].stake_pubkey
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
|
|
@ -37,7 +37,7 @@ impl<'a> ZeroLamport for AccountForStorage<'a> {
|
|||
}
|
||||
|
||||
impl<'a> AccountForStorage<'a> {
|
||||
pub(crate) fn pubkey(&self) -> &'a Pubkey {
|
||||
pub fn pubkey(&self) -> &'a Pubkey {
|
||||
match self {
|
||||
AccountForStorage::AddressAndAccount((pubkey, _account)) => pubkey,
|
||||
AccountForStorage::StoredAccountMeta(account) => account.pubkey(),
|
||||
|
@ -96,8 +96,6 @@ lazy_static! {
|
|||
/// This trait avoids having to allocate redundant data when there is a duplicated slot parameter.
|
||||
/// All legacy callers do not have a unique slot per account to store.
|
||||
pub trait StorableAccounts<'a>: Sync {
|
||||
/// pubkey at 'index'
|
||||
fn pubkey(&self, index: usize) -> &Pubkey;
|
||||
/// account at 'index'
|
||||
fn account<Ret>(&self, index: usize, callback: impl FnMut(AccountForStorage<'a>) -> Ret)
|
||||
-> Ret;
|
||||
|
@ -165,9 +163,6 @@ impl<'a, T: ReadableAccount + Sync> StorableAccounts<'a> for StorableAccountsMov
|
|||
where
|
||||
AccountForStorage<'a>: From<(&'a Pubkey, &'a T)>,
|
||||
{
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
self.accounts[index].0
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
@ -192,9 +187,6 @@ impl<'a: 'b, 'b, T: ReadableAccount + Sync + 'a> StorableAccounts<'a>
|
|||
where
|
||||
AccountForStorage<'a>: From<(&'a Pubkey, &'a T)>,
|
||||
{
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
self.1[index].0
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
@ -217,9 +209,6 @@ impl<'a, T: ReadableAccount + Sync> StorableAccounts<'a> for (Slot, &'a [&'a (Pu
|
|||
where
|
||||
AccountForStorage<'a>: From<(&'a Pubkey, &'a T)>,
|
||||
{
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
&self.1[index].0
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
@ -240,9 +229,6 @@ where
|
|||
}
|
||||
|
||||
impl<'a> StorableAccounts<'a> for (Slot, &'a [&'a StoredAccountMeta<'a>]) {
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
self.1[index].pubkey()
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
@ -332,10 +318,6 @@ impl<'a> StorableAccountsBySlot<'a> {
|
|||
}
|
||||
|
||||
impl<'a> StorableAccounts<'a> for StorableAccountsBySlot<'a> {
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
let indexes = self.find_internal_index(index);
|
||||
self.slots_and_accounts[indexes.0].1[indexes.1].pubkey()
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
@ -369,9 +351,6 @@ impl<'a> StorableAccounts<'a> for StorableAccountsBySlot<'a> {
|
|||
/// this tuple contains a single different source slot that applies to all accounts
|
||||
/// accounts are StoredAccountMeta
|
||||
impl<'a> StorableAccounts<'a> for (Slot, &'a [&'a StoredAccountMeta<'a>], Slot) {
|
||||
fn pubkey(&self, index: usize) -> &Pubkey {
|
||||
self.1[index].pubkey()
|
||||
}
|
||||
fn account<Ret>(
|
||||
&self,
|
||||
index: usize,
|
||||
|
@ -416,9 +395,9 @@ pub mod tests {
|
|||
assert_eq!(a.len(), b.len());
|
||||
assert_eq!(a.is_empty(), b.is_empty());
|
||||
(0..a.len()).for_each(|i| {
|
||||
assert_eq!(a.pubkey(i), b.pubkey(i));
|
||||
b.account(i, |account| {
|
||||
a.account(i, |account_a| {
|
||||
assert_eq!(account_a.pubkey(), account.pubkey());
|
||||
assert!(accounts_equal(&account_a, &account));
|
||||
});
|
||||
});
|
||||
|
@ -542,8 +521,8 @@ pub mod tests {
|
|||
compare(&test2, &test_moving_slots);
|
||||
compare(&test2, &test_moving_slots2);
|
||||
for (i, raw) in raw.iter().enumerate() {
|
||||
assert_eq!(raw.0, *test3.pubkey(i));
|
||||
test3.account(i, |account| {
|
||||
assert_eq!(raw.0, *account.pubkey());
|
||||
assert!(accounts_equal(&raw.1, &account));
|
||||
});
|
||||
assert_eq!(raw.2, test3.slot(i));
|
||||
|
@ -648,8 +627,8 @@ pub mod tests {
|
|||
let index = index as usize;
|
||||
storable.account(index, |account| {
|
||||
assert!(accounts_equal(&account, &raw2[index]));
|
||||
assert_eq!(account.pubkey(), raw2[index].pubkey());
|
||||
});
|
||||
assert_eq!(storable.pubkey(index), raw2[index].pubkey());
|
||||
assert_eq!(storable.hash(index), raw2[index].hash());
|
||||
assert_eq!(storable.slot(index), expected_slots[index]);
|
||||
})
|
||||
|
|
|
@ -355,8 +355,8 @@ mod tests {
|
|||
|
||||
let mut expected_accounts_map = HashMap::new();
|
||||
for i in 0..num_accounts {
|
||||
storable_accounts.get(i, |(account, address, _account_hash)| {
|
||||
expected_accounts_map.insert(*address, account.to_account_shared_data());
|
||||
storable_accounts.get(i, |account, _account_hash| {
|
||||
expected_accounts_map.insert(*account.pubkey(), account.to_account_shared_data());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -747,12 +747,12 @@ impl HotStorageWriter {
|
|||
let total_input_accounts = len - skip;
|
||||
let mut stored_infos = Vec::with_capacity(total_input_accounts);
|
||||
for i in skip..len {
|
||||
accounts.get::<TieredStorageResult<()>>(i, |(account, address, _account_hash)| {
|
||||
accounts.get::<TieredStorageResult<()>>(i, |account, _account_hash| {
|
||||
let index_entry = AccountIndexWriterEntry {
|
||||
address: *address,
|
||||
address: *account.pubkey(),
|
||||
offset: HotAccountOffset::new(cursor)?,
|
||||
};
|
||||
address_range.update(address);
|
||||
address_range.update(account.pubkey());
|
||||
|
||||
// Obtain necessary fields from the account, or default fields
|
||||
// for a zero-lamport account in the None case.
|
||||
|
@ -1559,11 +1559,11 @@ mod tests {
|
|||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
storable_accounts.get(i, |(account, address, _account_hash)| {
|
||||
storable_accounts.get(i, |account, _account_hash| {
|
||||
verify_test_account(
|
||||
&stored_account_meta,
|
||||
&account.to_account_shared_data(),
|
||||
address,
|
||||
account.pubkey(),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -1582,11 +1582,11 @@ mod tests {
|
|||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
storable_accounts.get(stored_info.offset, |(account, address, _account_hash)| {
|
||||
storable_accounts.get(stored_info.offset, |account, _account_hash| {
|
||||
verify_test_account(
|
||||
&stored_account_meta,
|
||||
&account.to_account_shared_data(),
|
||||
address,
|
||||
account.pubkey(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -1596,8 +1596,12 @@ mod tests {
|
|||
|
||||
// first, we verify everything
|
||||
for (i, stored_meta) in accounts.iter().enumerate() {
|
||||
storable_accounts.get(i, |(account, address, _account_hash)| {
|
||||
verify_test_account(stored_meta, &account.to_account_shared_data(), address);
|
||||
storable_accounts.get(i, |account, _account_hash| {
|
||||
verify_test_account(
|
||||
stored_meta,
|
||||
&account.to_account_shared_data(),
|
||||
account.pubkey(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -5064,7 +5064,7 @@ impl Bank {
|
|||
(0..accounts.len()).for_each(|i| {
|
||||
accounts.account(i, |account| {
|
||||
self.stakes_cache.check_and_store(
|
||||
accounts.pubkey(i),
|
||||
account.pubkey(),
|
||||
&account,
|
||||
new_warmup_cooldown_rate_epoch,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue