Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Uses SeqLock for CachedAccountInner::hash
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Oct 13, 2023
1 parent 64b0044 commit 73427be
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions accounts-db/src/accounts_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
accounts_hash::AccountHash,
},
dashmap::DashMap,
seqlock::SeqLock,
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
clock::Slot,
Expand Down Expand Up @@ -77,7 +78,7 @@ impl SlotCacheInner {
let data_len = account.data().len() as u64;
let item = Arc::new(CachedAccountInner {
account,
hash: RwLock::new(None),
hash: SeqLock::new(None),
slot,
pubkey: *pubkey,
include_slot_in_hash,
Expand Down Expand Up @@ -143,7 +144,7 @@ pub type CachedAccount = Arc<CachedAccountInner>;
#[derive(Debug)]
pub struct CachedAccountInner {
pub account: AccountSharedData,
hash: RwLock<Option<AccountHash>>,
hash: SeqLock<Option<AccountHash>>,
slot: Slot,
pubkey: Pubkey,
/// temporarily here during feature activation
Expand All @@ -153,18 +154,17 @@ pub struct CachedAccountInner {

impl CachedAccountInner {
pub fn hash(&self) -> AccountHash {
let hash = self.hash.read().unwrap();
match *hash {
let hash = self.hash.read();
match hash {
Some(hash) => hash,
None => {
drop(hash);
let hash = AccountsDb::hash_account(
self.slot,
&self.account,
&self.pubkey,
self.include_slot_in_hash,
);
*self.hash.write().unwrap() = Some(hash);
*self.hash.lock_write() = Some(hash);
hash
}
}
Expand Down

0 comments on commit 73427be

Please sign in to comment.