diff --git a/Cargo.lock b/Cargo.lock index c9995e72c..00f0bd016 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4745,6 +4745,15 @@ dependencies = [ "pest", ] +[[package]] +name = "seqlock" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c67b6f14ecc5b86c66fa63d76b5092352678545a8a3cdae80aef5128371910" +dependencies = [ + "parking_lot 0.12.1", +] + [[package]] name = "serde" version = "1.0.189" @@ -5210,6 +5219,7 @@ dependencies = [ "rayon", "regex", "rustc_version 0.4.0", + "seqlock", "serde", "serde_derive", "solana-accounts-db", diff --git a/Cargo.toml b/Cargo.toml index ceb0e67c1..9d09f953f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index 36ddf7d0e..0cafcfe3e 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -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 } diff --git a/accounts-db/src/accounts_cache.rs b/accounts-db/src/accounts_cache.rs index 04d1ef9d7..cb38243fd 100644 --- a/accounts-db/src/accounts_cache.rs +++ b/accounts-db/src/accounts_cache.rs @@ -4,6 +4,7 @@ use { accounts_hash::AccountHash, }, dashmap::DashMap, + seqlock::SeqLock, solana_sdk::{ account::{AccountSharedData, ReadableAccount}, clock::Slot, @@ -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, @@ -143,7 +144,7 @@ pub type CachedAccount = Arc; #[derive(Debug)] pub struct CachedAccountInner { pub account: AccountSharedData, - hash: RwLock>, + hash: SeqLock>, slot: Slot, pubkey: Pubkey, /// temporarily here during feature activation @@ -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 } } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index e1a4c686e..915b4fe0f 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4133,6 +4133,15 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +[[package]] +name = "seqlock" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c67b6f14ecc5b86c66fa63d76b5092352678545a8a3cdae80aef5128371910" +dependencies = [ + "parking_lot 0.12.1", +] + [[package]] name = "serde" version = "1.0.189" @@ -4501,6 +4510,7 @@ dependencies = [ "rayon", "regex", "rustc_version", + "seqlock", "serde", "serde_derive", "solana-bucket-map",