pub struct StakeCache(/* private fields */);Expand description
A cache of stake and validator accounts.
This wraps StakeCacheData in Arc<RwLock<...>> to allow thread-safe shared
access during parallel transaction execution. The Arc allows the same data
to be shared between the Bank and StakesHandle, so mutations to pending
stake data by builtin programs are visible to the Bank.
Implementations§
Source§impl StakeCache
impl StakeCache
Sourcepub fn with_data(data: StakeCacheData) -> Self
pub fn with_data(data: StakeCacheData) -> Self
Create a stake cache with the given data.
Sourcepub fn from_arc(arc: Arc<RwLock<StakeCacheData>>) -> Self
pub fn from_arc(arc: Arc<RwLock<StakeCacheData>>) -> Self
Create a stake cache from an existing Arc (for sharing references).
Sourcepub fn arc_clone(&self) -> Arc<RwLock<StakeCacheData>>
pub fn arc_clone(&self) -> Arc<RwLock<StakeCacheData>>
Get a clone of the inner Arc for sharing.
Sourcepub fn read(&self) -> RwLockReadGuard<'_, StakeCacheData>
pub fn read(&self) -> RwLockReadGuard<'_, StakeCacheData>
Acquire a read lock on the inner data.
Sourcepub fn write(&self) -> RwLockWriteGuard<'_, StakeCacheData>
pub fn write(&self) -> RwLockWriteGuard<'_, StakeCacheData>
Acquire a write lock on the inner data.
Sourcepub fn get_stake_account(&self, pubkey: &Pubkey) -> Option<StakeAccount>
pub fn get_stake_account(&self, pubkey: &Pubkey) -> Option<StakeAccount>
Get a stake account by pubkey.
Note: This is a single-layer lookup on just this cache.
For layered lookup across baseline/frozen/pending, use StakesHandle::get_stake_account.
Sourcepub fn get_validator_account(&self, pubkey: &Pubkey) -> Option<ValidatorAccount>
pub fn get_validator_account(&self, pubkey: &Pubkey) -> Option<ValidatorAccount>
Get a validator account by pubkey.
Note: This is a single-layer lookup on just this cache.
For layered lookup across baseline/frozen/pending, use StakesHandle::get_validator_account.
Sourcepub fn get_all_validator_accounts(&self) -> Vec<(Pubkey, ValidatorAccount)>
pub fn get_all_validator_accounts(&self) -> Vec<(Pubkey, ValidatorAccount)>
Get all validator accounts from this cache (single layer).
Note: This is a single-layer lookup. For merged view across all layers,
use StakesHandle::get_all_validator_accounts.
Sourcepub fn contains_stake_account(&self, pubkey: &Pubkey) -> bool
pub fn contains_stake_account(&self, pubkey: &Pubkey) -> bool
Check if a stake account exists in this cache (single layer).
Sourcepub fn contains_validator_account(&self, pubkey: &Pubkey) -> bool
pub fn contains_validator_account(&self, pubkey: &Pubkey) -> bool
Check if a validator account exists in this cache (single layer).
Sourcepub fn insert_stake_account(&self, pubkey: Pubkey, account: StakeAccount)
pub fn insert_stake_account(&self, pubkey: Pubkey, account: StakeAccount)
Insert or update a stake account.
Also tracks the pubkey as modified for persistence.
Sourcepub fn insert_validator_account(
&self,
pubkey: Pubkey,
account: ValidatorAccount,
)
pub fn insert_validator_account( &self, pubkey: Pubkey, account: ValidatorAccount, )
Insert or update a validator account.
Also tracks the pubkey as modified for persistence.
Sourcepub fn tombstone_stake_account(&self, pubkey: Pubkey)
pub fn tombstone_stake_account(&self, pubkey: Pubkey)
Insert a tombstone for a stake account (marks as deleted).
Also tracks the pubkey as modified for persistence.
Sourcepub fn tombstone_validator_account(&self, pubkey: Pubkey)
pub fn tombstone_validator_account(&self, pubkey: Pubkey)
Insert a tombstone for a validator account (marks as deleted).
Also tracks the pubkey as modified for persistence.
Sourcepub fn set_timestamp(&self, timestamp: u64)
pub fn set_timestamp(&self, timestamp: u64)
Set the timestamp of this cache.
Sourcepub fn check_and_update(&self, pubkey: &Pubkey, account: &impl ReadableAccount)
pub fn check_and_update(&self, pubkey: &Pubkey, account: &impl ReadableAccount)
Check an account and store it in the appropriate cache if it belongs to StakeManager or ValidatorRegistry programs.
- If the account has zero kelvins, it is evicted from the cache (tombstoned)
- If the account is owned by StakeManager, it is stored in stake_accounts
- If the account is owned by ValidatorRegistry, it is stored in validator_accounts
Trait Implementations§
Source§impl Clone for StakeCache
impl Clone for StakeCache
Source§fn clone(&self) -> StakeCache
fn clone(&self) -> StakeCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StakeCache
impl Debug for StakeCache
Auto Trait Implementations§
impl Freeze for StakeCache
impl RefUnwindSafe for StakeCache
impl Send for StakeCache
impl Sync for StakeCache
impl Unpin for StakeCache
impl UnsafeUnpin for StakeCache
impl UnwindSafe for StakeCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more