From ce8ad77373bca151b85c007e53fac4e42a028834 Mon Sep 17 00:00:00 2001 From: Brooks Date: Thu, 19 Oct 2023 17:38:09 -0400 Subject: [PATCH] Uses AccountHash in AppendVec (#33764) --- accounts-db/src/account_storage/meta.rs | 2 +- accounts-db/src/accounts_db.rs | 10 +++++----- accounts-db/src/ancient_append_vecs.rs | 6 +++--- accounts-db/src/append_vec.rs | 12 ++++++------ accounts-db/src/storable_accounts.rs | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/accounts-db/src/account_storage/meta.rs b/accounts-db/src/account_storage/meta.rs index 0cdf200f70..1442b4845b 100644 --- a/accounts-db/src/account_storage/meta.rs +++ b/accounts-db/src/account_storage/meta.rs @@ -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), } } diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index fc4fe5d58e..604fed349c 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -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, diff --git a/accounts-db/src/ancient_append_vecs.rs b/accounts-db/src/ancient_append_vecs.rs index eabc7ef064..685b6962b9 100644 --- a/accounts-db/src/ancient_append_vecs.rs +++ b/accounts-db/src/ancient_append_vecs.rs @@ -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, diff --git a/accounts-db/src/append_vec.rs b/accounts-db/src/append_vec.rs index 2cd8612828..8cc2a6f5b3 100644 --- a/accounts-db/src/append_vec.rs +++ b/accounts-db/src/append_vec.rs @@ -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::()), (account_meta_ptr as *const u8, mem::size_of::()), - (hash_ptr, mem::size_of::()), + (hash_ptr, mem::size_of::()), (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}, diff --git a/accounts-db/src/storable_accounts.rs b/accounts-db/src/storable_accounts.rs index 900b4b5ba2..7e12063a05 100644 --- a/accounts-db/src/storable_accounts.rs +++ b/accounts-db/src/storable_accounts.rs @@ -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::>();