Removes hash() and has_hash() from StorableAccounts (#867)

This commit is contained in:
Brooks 2024-04-17 16:41:41 -04:00 committed by GitHub
parent ee2c29ca2f
commit da0d78c504
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 38 deletions

View File

@ -1,9 +1,6 @@
//! trait for abstracting underlying storage of pubkey and account pairs to be written
use {
crate::{
account_storage::meta::StoredAccountMeta, accounts_hash::AccountHash,
accounts_index::ZeroLamport,
},
crate::{account_storage::meta::StoredAccountMeta, accounts_index::ZeroLamport},
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
clock::{Epoch, Slot},
@ -135,19 +132,6 @@ pub trait StorableAccounts<'a>: Sync {
fn contains_multiple_slots(&self) -> bool {
false
}
/// true iff the impl can provide hash
/// Otherwise, hash has to be provided separately to store functions.
fn has_hash(&self) -> bool {
false
}
/// return hash for account at 'index'
/// Should only be called if 'has_hash' = true
fn hash(&self, _index: usize) -> &AccountHash {
// this should never be called if has_hash returns false
unimplemented!();
}
}
/// accounts that are moving from 'old_slot' to 'target_slot'
@ -249,12 +233,6 @@ impl<'a> StorableAccounts<'a> for (Slot, &'a [&'a StoredAccountMeta<'a>]) {
fn len(&self) -> usize {
self.1.len()
}
fn has_hash(&self) -> bool {
true
}
fn hash(&self, index: usize) -> &AccountHash {
self.1[index].hash()
}
}
/// holds slices of accounts being moved FROM a common source slot to 'target_slot'
@ -342,13 +320,6 @@ impl<'a> StorableAccounts<'a> for StorableAccountsBySlot<'a> {
fn contains_multiple_slots(&self) -> bool {
self.contains_multiple_slots
}
fn has_hash(&self) -> bool {
true
}
fn hash(&self, index: usize) -> &AccountHash {
let indexes = self.find_internal_index(index);
self.slots_and_accounts[indexes.0].1[indexes.1].hash()
}
}
/// this tuple contains a single different source slot that applies to all accounts
@ -371,12 +342,6 @@ impl<'a> StorableAccounts<'a> for (Slot, &'a [&'a StoredAccountMeta<'a>], Slot)
fn len(&self) -> usize {
self.1.len()
}
fn has_hash(&self) -> bool {
true
}
fn hash(&self, index: usize) -> &AccountHash {
self.1[index].hash()
}
}
#[cfg(test)]
@ -385,6 +350,7 @@ pub mod tests {
super::*,
crate::{
account_storage::meta::{AccountMeta, StoredAccountMeta, StoredMeta},
accounts_hash::AccountHash,
append_vec::AppendVecStoredAccountMeta,
},
solana_sdk::{
@ -623,7 +589,6 @@ pub mod tests {
})
.collect::<Vec<_>>();
let storable = StorableAccountsBySlot::new(99, &slots_and_accounts[..]);
assert!(storable.has_hash());
assert_eq!(99, storable.target_slot());
assert_eq!(entries0 != entries, storable.contains_multiple_slots());
(0..entries).for_each(|index| {
@ -632,7 +597,6 @@ pub mod tests {
assert!(accounts_equal(&account, &raw2[index]));
assert_eq!(account.pubkey(), raw2[index].pubkey());
});
assert_eq!(storable.hash(index), raw2[index].hash());
assert_eq!(storable.slot(index), expected_slots[index]);
})
}