Uses AccountHash in AppendVec (#33764)
This commit is contained in:
parent
383aef218d
commit
ce8ad77373
|
@ -127,7 +127,7 @@ impl<'storage> StoredAccountMeta<'storage> {
|
|||
|
||||
pub fn hash(&self) -> &'storage AccountHash {
|
||||
match self {
|
||||
Self::AppendVec(av) => bytemuck::cast_ref(av.hash()),
|
||||
Self::AppendVec(av) => av.hash(),
|
||||
Self::Hot(hot) => hot.hash().unwrap_or(&DEFAULT_ACCOUNT_HASH),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10186,7 +10186,7 @@ pub mod tests {
|
|||
rent_epoch: 0,
|
||||
};
|
||||
let offset = 3;
|
||||
let hash = Hash::new(&[2; 32]);
|
||||
let hash = AccountHash(Hash::new(&[2; 32]));
|
||||
let stored_meta = StoredMeta {
|
||||
// global write version
|
||||
write_version_obsolete: 0,
|
||||
|
@ -10289,7 +10289,7 @@ pub mod tests {
|
|||
};
|
||||
let offset = 99;
|
||||
let stored_size = 101;
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let stored_account = StoredAccountMeta::AppendVec(AppendVecStoredAccountMeta {
|
||||
meta: &meta,
|
||||
account_meta: &account_meta,
|
||||
|
@ -12649,7 +12649,7 @@ pub mod tests {
|
|||
};
|
||||
let offset = 99;
|
||||
let stored_size = 101;
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let stored_account = StoredAccountMeta::AppendVec(AppendVecStoredAccountMeta {
|
||||
meta: &meta,
|
||||
account_meta: &account_meta,
|
||||
|
@ -12691,11 +12691,11 @@ pub mod tests {
|
|||
const ACCOUNT_DATA_LEN: usize = 3;
|
||||
let data: [u8; ACCOUNT_DATA_LEN] = [0x69, 0x6a, 0x6b];
|
||||
let offset: usize = 0x6c_6d_6e_6f_70_71_72_73;
|
||||
let hash = Hash::from([
|
||||
let hash = AccountHash(Hash::from([
|
||||
0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
|
||||
0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93,
|
||||
]);
|
||||
]));
|
||||
|
||||
let stored_account = StoredAccountMeta::AppendVec(AppendVecStoredAccountMeta {
|
||||
meta: &meta,
|
||||
|
|
|
@ -2026,7 +2026,7 @@ pub mod tests {
|
|||
rent_epoch: 0,
|
||||
};
|
||||
let offset = 3;
|
||||
let hash = Hash::new(&[2; 32]);
|
||||
let hash = AccountHash(Hash::new(&[2; 32]));
|
||||
let stored_meta = StoredMeta {
|
||||
// global write version
|
||||
write_version_obsolete: 0,
|
||||
|
@ -3009,7 +3009,7 @@ pub mod tests {
|
|||
};
|
||||
let offset = 99;
|
||||
let stored_size = 101;
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let stored_account = StoredAccountMeta::AppendVec(AppendVecStoredAccountMeta {
|
||||
meta: &meta,
|
||||
account_meta: &account_meta,
|
||||
|
@ -3091,7 +3091,7 @@ pub mod tests {
|
|||
};
|
||||
let offset = 99;
|
||||
let stored_size = 1; // size is 1 byte for each entry to test `bytes` later
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let stored_account = StoredAccountMeta::AppendVec(AppendVecStoredAccountMeta {
|
||||
meta: &meta,
|
||||
account_meta: &account_meta,
|
||||
|
|
|
@ -20,7 +20,6 @@ use {
|
|||
solana_sdk::{
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::Slot,
|
||||
hash::Hash,
|
||||
pubkey::Pubkey,
|
||||
stake_history::Epoch,
|
||||
},
|
||||
|
@ -115,7 +114,7 @@ pub struct AppendVecStoredAccountMeta<'append_vec> {
|
|||
pub(crate) data: &'append_vec [u8],
|
||||
pub(crate) offset: usize,
|
||||
pub(crate) stored_size: usize,
|
||||
pub(crate) hash: &'append_vec Hash,
|
||||
pub(crate) hash: &'append_vec AccountHash,
|
||||
}
|
||||
|
||||
impl<'append_vec> AppendVecStoredAccountMeta<'append_vec> {
|
||||
|
@ -123,7 +122,7 @@ impl<'append_vec> AppendVecStoredAccountMeta<'append_vec> {
|
|||
&self.meta.pubkey
|
||||
}
|
||||
|
||||
pub fn hash(&self) -> &'append_vec Hash {
|
||||
pub fn hash(&self) -> &'append_vec AccountHash {
|
||||
self.hash
|
||||
}
|
||||
|
||||
|
@ -488,7 +487,7 @@ impl AppendVec {
|
|||
pub fn get_account(&self, offset: usize) -> Option<(StoredAccountMeta, usize)> {
|
||||
let (meta, next): (&StoredMeta, _) = self.get_type(offset)?;
|
||||
let (account_meta, next): (&AccountMeta, _) = self.get_type(next)?;
|
||||
let (hash, next): (&Hash, _) = self.get_type(next)?;
|
||||
let (hash, next): (&AccountHash, _) = self.get_type(next)?;
|
||||
let (data, next) = self.get_slice(next, meta.data_len as usize)?;
|
||||
let stored_size = next - offset;
|
||||
Some((
|
||||
|
@ -612,11 +611,11 @@ impl AppendVec {
|
|||
.map(|account| account.data())
|
||||
.unwrap_or_default()
|
||||
.as_ptr();
|
||||
let hash_ptr = hash.0.as_ref().as_ptr();
|
||||
let hash_ptr = bytemuck::bytes_of(hash).as_ptr();
|
||||
let ptrs = [
|
||||
(meta_ptr as *const u8, mem::size_of::<StoredMeta>()),
|
||||
(account_meta_ptr as *const u8, mem::size_of::<AccountMeta>()),
|
||||
(hash_ptr, mem::size_of::<Hash>()),
|
||||
(hash_ptr, mem::size_of::<AccountHash>()),
|
||||
(data_ptr, data_len),
|
||||
];
|
||||
if let Some(res) = self.append_ptrs_locked(&mut offset, &ptrs) {
|
||||
|
@ -655,6 +654,7 @@ pub mod tests {
|
|||
rand::{thread_rng, Rng},
|
||||
solana_sdk::{
|
||||
account::{accounts_equal, Account, AccountSharedData, WritableAccount},
|
||||
hash::Hash,
|
||||
timing::duration_as_ms,
|
||||
},
|
||||
std::{mem::ManuallyDrop, time::Instant},
|
||||
|
|
|
@ -384,7 +384,7 @@ pub mod tests {
|
|||
let data = Vec::default();
|
||||
let offset = 99;
|
||||
let stored_size = 101;
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let stored_account = StoredAccountMeta::AppendVec(AppendVecStoredAccountMeta {
|
||||
meta: &meta,
|
||||
account_meta: &account_meta,
|
||||
|
@ -410,7 +410,7 @@ pub mod tests {
|
|||
for entries in 0..2 {
|
||||
for starting_slot in 0..max_slots {
|
||||
let data = Vec::default();
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let mut raw = Vec::new();
|
||||
let mut raw2 = Vec::new();
|
||||
let mut raw4 = Vec::new();
|
||||
|
@ -564,7 +564,7 @@ pub mod tests {
|
|||
data: &data,
|
||||
offset,
|
||||
stored_size,
|
||||
hash: &hashes[entry as usize].0,
|
||||
hash: &hashes[entry as usize],
|
||||
}));
|
||||
}
|
||||
let raw2_refs = raw2.iter().collect::<Vec<_>>();
|
||||
|
|
Loading…
Reference in New Issue