Skip to main content

StakeCache

Struct StakeCache 

Source
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

Source

pub fn new() -> Self

Create a new empty stake cache.

Source

pub fn with_data(data: StakeCacheData) -> Self

Create a stake cache with the given data.

Source

pub fn from_arc(arc: Arc<RwLock<StakeCacheData>>) -> Self

Create a stake cache from an existing Arc (for sharing references).

Source

pub fn arc_clone(&self) -> Arc<RwLock<StakeCacheData>>

Get a clone of the inner Arc for sharing.

Source

pub fn read(&self) -> RwLockReadGuard<'_, StakeCacheData>

Acquire a read lock on the inner data.

Source

pub fn write(&self) -> RwLockWriteGuard<'_, StakeCacheData>

Acquire a write lock on the inner data.

Source

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.

Source

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.

Source

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.

Source

pub fn contains_stake_account(&self, pubkey: &Pubkey) -> bool

Check if a stake account exists in this cache (single layer).

Source

pub fn contains_validator_account(&self, pubkey: &Pubkey) -> bool

Check if a validator account exists in this cache (single layer).

Source

pub fn insert_stake_account(&self, pubkey: Pubkey, account: StakeAccount)

Insert or update a stake account.

Also tracks the pubkey as modified for persistence.

Source

pub fn insert_validator_account( &self, pubkey: Pubkey, account: ValidatorAccount, )

Insert or update a validator account.

Also tracks the pubkey as modified for persistence.

Source

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.

Source

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.

Source

pub fn epoch(&self) -> Epoch

Get the epoch of this cache.

Source

pub fn timestamp(&self) -> u64

Get the timestamp of this cache.

Source

pub fn set_epoch(&self, epoch: Epoch)

Set the epoch of this cache.

Source

pub fn set_timestamp(&self, timestamp: u64)

Set the timestamp of this cache.

Source

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

Source§

fn clone(&self) -> StakeCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StakeCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StakeCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V