diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index d4655f31b3..cedcdb0e9a 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -48,7 +48,9 @@ pub type AccountMap = InMemAccountsIndex; pub(crate) type AccountMapEntry = Arc>; -pub trait IsCached: 'static + Clone + Debug + PartialEq + ZeroLamport + Copy + Default { +pub trait IsCached: + 'static + Clone + Debug + PartialEq + ZeroLamport + Copy + Default + Sync + Send +{ fn is_cached(&self) -> bool; } @@ -694,7 +696,7 @@ pub struct AccountsIndex { // scanning the fork with that Bank at the tip is no longer possible. pub removed_bank_ids: Mutex>, - storage: AccountsIndexStorage, + storage: AccountsIndexStorage, } impl AccountsIndex { @@ -725,7 +727,11 @@ impl AccountsIndex { fn allocate_accounts_index( config: Option, - ) -> (LockMapType, PubkeyBinCalculator16, AccountsIndexStorage) { + ) -> ( + LockMapType, + PubkeyBinCalculator16, + AccountsIndexStorage, + ) { let bins = config .and_then(|config| config.bins) .unwrap_or(BINS_DEFAULT); diff --git a/runtime/src/accounts_index_storage.rs b/runtime/src/accounts_index_storage.rs index d2fda9b24e..e1567ed4e0 100644 --- a/runtime/src/accounts_index_storage.rs +++ b/runtime/src/accounts_index_storage.rs @@ -1,3 +1,4 @@ +use crate::accounts_index::IsCached; use crate::bucket_map_holder::BucketMapHolder; use crate::waitable_condvar::WaitableCondvar; use std::{ @@ -14,17 +15,17 @@ use std::{ // and it will stop all the background threads and join them. #[derive(Debug, Default)] -pub struct AccountsIndexStorage { +pub struct AccountsIndexStorage { // for managing the bg threads exit: Arc, wait: Arc, handle: Option>, // eventually the backing storage - storage: Arc, + storage: Arc>, } -impl Drop for AccountsIndexStorage { +impl Drop for AccountsIndexStorage { fn drop(&mut self) { self.exit.store(true, Ordering::Relaxed); self.wait.notify_all(); @@ -34,8 +35,8 @@ impl Drop for AccountsIndexStorage { } } -impl AccountsIndexStorage { - pub fn new() -> AccountsIndexStorage { +impl AccountsIndexStorage { + pub fn new() -> AccountsIndexStorage { let storage = Arc::new(BucketMapHolder::new()); let storage_ = storage.clone(); let exit = Arc::new(AtomicBool::default()); @@ -59,7 +60,7 @@ impl AccountsIndexStorage { } } - pub fn storage(&self) -> &Arc { + pub fn storage(&self) -> &Arc> { &self.storage } } diff --git a/runtime/src/bucket_map_holder.rs b/runtime/src/bucket_map_holder.rs index 29de87ea29..2709eed1e4 100644 --- a/runtime/src/bucket_map_holder.rs +++ b/runtime/src/bucket_map_holder.rs @@ -1,3 +1,4 @@ +use crate::accounts_index::IsCached; use crate::bucket_map_holder_stats::BucketMapHolderStats; use crate::waitable_condvar::WaitableCondvar; use std::fmt::Debug; @@ -7,15 +8,14 @@ use std::time::Duration; // will eventually hold the bucket map #[derive(Debug, Default)] -pub struct BucketMapHolder { +pub struct BucketMapHolder { pub stats: BucketMapHolderStats, + _phantom: std::marker::PhantomData, } -impl BucketMapHolder { +impl BucketMapHolder { pub fn new() -> Self { - Self { - stats: BucketMapHolderStats::default(), - } + Self::default() } // intended to execute in a bg thread diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 06dfdf7767..4f19acc7e1 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -22,12 +22,12 @@ type K = Pubkey; pub struct InMemAccountsIndex { // backing store map: HashMap>, - storage: Arc, + storage: Arc>, bin: usize, } impl InMemAccountsIndex { - pub fn new(storage: &AccountsIndexStorage, bin: usize) -> Self { + pub fn new(storage: &AccountsIndexStorage, bin: usize) -> Self { Self { map: HashMap::new(), storage: storage.storage().clone(), @@ -35,7 +35,7 @@ impl InMemAccountsIndex { } } - pub fn new_bucket_map_holder() -> Arc { + pub fn new_bucket_map_holder() -> Arc> { Arc::new(BucketMapHolder::new()) }