Skip to main content

StakesHandle

Struct StakesHandle 

Source
pub struct StakesHandle {
    pub pending: StakeCache,
    pub history: StakeHistory,
    pub needs_refresh: Arc<AtomicBool>,
}
Expand description

Handle for builtin programs to access stake cache data and freeze stakes.

This handle provides:

  • Read/write access to the pending (next epoch) stake cache data
  • The ability to freeze the pending stakes into history via freeze_and_get_validator_stakes()

§Epoch Semantics

Important: The pending field contains data for the NEXT epoch (i.e., changes being accumulated that will take effect after FreezeStakes). To get the CURRENT epoch’s frozen data for lookups, use history.back() instead.

The handle is cached at block level for performance. When freeze_and_get_validator_stakes() is called, it sets needs_refresh to signal that subsequent transactions should recreate the handle to see the updated epoch.

§Thread Safety

Both StakeCache and StakeHistory wrap their data in Arc<RwLock<...>> internally, allowing safe concurrent access from builtin programs during transaction execution. Mutations to pending are immediately visible to the owning Bank since they share the same Arc.

Fields§

§pending: StakeCache

Stake cache data for the NEXT epoch (pending/accumulating changes).

This is a mutable working copy that accumulates stake and validator account modifications throughout the epoch. These changes will become effective after the next FreezeStakes call. For current epoch lookups (the frozen effective state), use history.back() instead.

The StakeCache wrapper contains Arc<RwLock<...>> internally, allowing builtin programs to mutate the pending stake data during transaction execution, with changes visible to the Bank.

§history: StakeHistory

Target history to push frozen snapshots to.

The StakeHistory wrapper contains Arc<RwLock<...>> internally.

§needs_refresh: Arc<AtomicBool>

Flag to signal that the cache needs to be refreshed after FreezeStakes. Set to true by freeze_and_get_validator_stakes().

Implementations§

Source§

impl StakesHandle

Source

pub fn new(pending: StakeCacheData, history: StakeHistory) -> Self

Create a new stakes handle with fresh data.

This creates new Arc<RwLock<...>> wrappers for the provided data. Note: This creates NEW Arcs, so changes won’t be visible to the original data. Use new_shared instead when you want to share Arcs with the Bank.

Source

pub fn new_shared(pending: StakeCache, history: StakeHistory) -> Self

Create a new stakes handle with shared references.

This shares the same Arc<RwLock<...>> with the Bank, so mutations to pending by builtin programs are immediately visible to the Bank.

Source

pub fn needs_refresh(&self) -> bool

Check if this handle needs to be refreshed (was invalidated by FreezeStakes).

Source

pub fn freeze_and_get_validator_stakes(&self) -> Vec<(Pubkey, u64)>

Freeze the pending stake cache data and return validator stakes.

This performs an O(1) clone of the pending stake cache data (via ImHashMap structural sharing) and pushes it to the back of the stake history queue. This is typically called by the ValidatorRegistry program’s FreezeStakes instruction to capture the validator set at a specific point. It then extracts and returns a vector of (Pubkey, stake) pairs for all validators in the frozen snapshot.

Important: This sets needs_refresh to true, signaling that subsequent transactions should recreate their StakesHandle to see the updated epoch.

Returns the validator stakes list, sorted by pubkey for determinism.

Trait Implementations§

Source§

impl Clone for StakesHandle

Source§

fn clone(&self) -> StakesHandle

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 StakesHandle

Source§

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

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

impl Default for StakesHandle

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> 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