Skip to content

Commit

Permalink
Uses AccountHash in AppendVec (solana-labs#33764)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Oct 19, 2023
1 parent 383aef2 commit ce8ad77
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion accounts-db/src/account_storage/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
10 changes: 5 additions & 5 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use {
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
clock::Slot,
hash::Hash,
pubkey::Pubkey,
stake_history::Epoch,
},
Expand Down Expand Up @@ -115,15 +114,15 @@ 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> {
pub fn pubkey(&self) -> &'append_vec Pubkey {
&self.meta.pubkey
}

pub fn hash(&self) -> &'append_vec Hash {
pub fn hash(&self) -> &'append_vec AccountHash {
self.hash
}

Expand Down Expand Up @@ -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((
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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},
Expand Down
6 changes: 3 additions & 3 deletions accounts-db/src/storable_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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<_>>();
Expand Down

0 comments on commit ce8ad77

Please sign in to comment.