Skip to content

Commit

Permalink
Uses SeqLock for CachedAccountInner::hash (solana-labs#33696)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Oct 18, 2023
1 parent c699bc9 commit e96678b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ rustls = { version = "0.21.7", default-features = false, features = ["quic"] }
rustversion = "1.0.14"
scopeguard = "1.2.0"
semver = "1.0.20"
seqlock = "0.2.0"
serde = "1.0.189"
serde_bytes = "0.11.12"
serde_derive = "1.0.103"
Expand Down
1 change: 1 addition & 0 deletions accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ qualifier_attr = { workspace = true }
rand = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
seqlock = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true }
solana-bucket-map = { workspace = true }
Expand Down
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
10 changes: 10 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e96678b

Please sign in to comment.