pub struct StakeHistory(pub Arc<RwLock<VecDeque<StakeCacheData>>>);Expand description
A history of frozen stake cache snapshots across epochs.
This wraps VecDeque<StakeCacheData> in Arc<RwLock<...>> to allow thread-safe
shared access. The Arc allows the same history to be shared between the Bank
and StakesHandle.
This maintains a queue of stake snapshots, with the oldest at the front and the most recent at the back. The ValidatorRegistry builtin pushes new snapshots, and the Bank pops completed epochs after reward distribution.
Tuple Fields§
§0: Arc<RwLock<VecDeque<StakeCacheData>>>Implementations§
Source§impl StakeHistory
impl StakeHistory
Sourcepub fn with_entry(data: StakeCacheData) -> Self
pub fn with_entry(data: StakeCacheData) -> Self
Create a stake history with an initial entry.
Sourcepub fn from_arc(arc: Arc<RwLock<VecDeque<StakeCacheData>>>) -> Self
pub fn from_arc(arc: Arc<RwLock<VecDeque<StakeCacheData>>>) -> Self
Create a stake history from an existing Arc (for sharing references).
Sourcepub fn arc_clone(&self) -> Arc<RwLock<VecDeque<StakeCacheData>>>
pub fn arc_clone(&self) -> Arc<RwLock<VecDeque<StakeCacheData>>>
Get a clone of the inner Arc for sharing.
Sourcepub fn push_back(&self, data: StakeCacheData)
pub fn push_back(&self, data: StakeCacheData)
Push a new snapshot to the back of the history.
Sourcepub fn pop_front(&self) -> Option<StakeCacheData>
pub fn pop_front(&self) -> Option<StakeCacheData>
Pop the oldest snapshot from the front of the history.
Sourcepub fn front(&self) -> Option<StakeCacheData>
pub fn front(&self) -> Option<StakeCacheData>
Get a clone of the oldest snapshot (front).
Sourcepub fn back(&self) -> Option<StakeCacheData>
pub fn back(&self) -> Option<StakeCacheData>
Get a clone of the newest snapshot (back).
This returns the CURRENT epoch’s frozen stake data. In normal operation,
this is never None because Bank initialization guarantees at least one
entry exists after genesis/register_validators.
Use this for lookups that need the current epoch’s effective stake state
(as opposed to StakesHandle::pending which is the next epoch being accumulated).
Sourcepub fn iter_cloned(&self) -> Vec<StakeCacheData>
pub fn iter_cloned(&self) -> Vec<StakeCacheData>
Iterate over all snapshots from oldest to newest, returning cloned data.
Note: This clones all entries. For large histories, consider accessing
specific entries via front() or back() instead.
Trait Implementations§
Source§impl Clone for StakeHistory
impl Clone for StakeHistory
Source§fn clone(&self) -> StakeHistory
fn clone(&self) -> StakeHistory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StakeHistory
impl Debug for StakeHistory
Auto Trait Implementations§
impl Freeze for StakeHistory
impl RefUnwindSafe for StakeHistory
impl Send for StakeHistory
impl Sync for StakeHistory
impl Unpin for StakeHistory
impl UnsafeUnpin for StakeHistory
impl UnwindSafe for StakeHistory
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