pub struct EpochCommittees {
inner: Arc<RwLock<Inner>>,
fetcher: Arc<Fetcher>,
update_fixed_block_reward_lock: Arc<Mutex<()>>,
load_from_storage_lock: Arc<Mutex<()>>,
storage_read_timeout: Duration,
epoch_height: BlockNumber,
}Expand description
Type to describe DA and Stake memberships.
Fields§
§inner: Arc<RwLock<Inner>>§fetcher: Arc<Fetcher>§update_fixed_block_reward_lock: Arc<Mutex<()>>§load_from_storage_lock: Arc<Mutex<()>>§storage_read_timeout: Duration§epoch_height: BlockNumberImplementations§
Source§impl EpochCommittees
impl EpochCommittees
pub fn epoch_height(&self) -> BlockNumber
pub fn first_epoch(&self) -> EpochNumber
pub fn fetcher(&self) -> &Fetcher
pub fn fixed_block_reward(&self) -> Option<RewardAmount>
Sourcepub fn latest_peer_config(&self, key: &PubKey) -> Option<PeerConfig<SeqTypes>>
pub fn latest_peer_config(&self, key: &PubKey) -> Option<PeerConfig<SeqTypes>>
Find the most recent stake-table entry for key.
Scanns loaded epochs from highest to lowest and falling back to the genesis bootstrap committee.
pub fn latest_account(&self, key: &PubKey) -> Option<Address>
Sourceasync fn fetch_and_update_fixed_block_reward(
&self,
epoch: EpochNumber,
) -> Result<RewardAmount>
async fn fetch_and_update_fixed_block_reward( &self, epoch: EpochNumber, ) -> Result<RewardAmount>
Fetch the fixed block reward and update it if its None. We used a fixed block reward for version v3 Version v4 uses the dynamic block reward Assumes the stake table contract proxy address does not change
Sourceasync fn calculate_dynamic_block_reward(
&self,
epoch: EpochNumber,
header: &Header,
validators: &AuthenticatedValidatorMap,
coordinator: &EpochMembershipCoordinator<SeqTypes>,
) -> Result<Option<RewardAmount>>
async fn calculate_dynamic_block_reward( &self, epoch: EpochNumber, header: &Header, validators: &AuthenticatedValidatorMap, coordinator: &EpochMembershipCoordinator<SeqTypes>, ) -> Result<Option<RewardAmount>>
Calculates the dynamic block reward for a given block header within an epoch.
The reward is based on a dynamic inflation rate computed from the current stake ratio (p),
where p = total_stake / total_supply. The inflation function R(p) is defined piecewise:
- If
p <= 0.01: R(p) = 0.03 / sqrt(2 * 0.01) - Else: R(p) = 0.03 / sqrt(2 * p)
Sourcepub fn epoch_block_reward(&self, epoch: EpochNumber) -> Option<RewardAmount>
pub fn epoch_block_reward(&self, epoch: EpochNumber) -> Option<RewardAmount>
This function just returns the stored block reward in epoch committee
Sourcepub fn get_validator_index(
&self,
epoch: EpochNumber,
bls_key: &PubKey,
) -> Option<usize>
pub fn get_validator_index( &self, epoch: EpochNumber, bls_key: &PubKey, ) -> Option<usize>
Get the index of a validator’s BLS key in the epoch’s stake table. Returns None if the validator is not in the stake table for this epoch.
The index corresponds to the position in the leader_counts array in V6 headers.
pub fn active_validators( &self, e: EpochNumber, ) -> Result<AuthenticatedValidatorMap>
pub fn address(&self, e: EpochNumber, key: &BLSPubKey) -> Result<Address>
pub fn get_validator_config( &self, epoch: EpochNumber, key: &BLSPubKey, ) -> Result<AuthenticatedValidator<BLSPubKey>>
Sourcepub fn new<B: Into<BlockNumber>>(
committee_members: Vec<PeerConfig<SeqTypes>>,
da_members: Vec<PeerConfig<SeqTypes>>,
fixed_block_reward: Option<RewardAmount>,
fetcher: Fetcher,
epoch_height: B,
first_epoch: EpochNumber,
) -> Self
pub fn new<B: Into<BlockNumber>>( committee_members: Vec<PeerConfig<SeqTypes>>, da_members: Vec<PeerConfig<SeqTypes>>, fixed_block_reward: Option<RewardAmount>, fetcher: Fetcher, epoch_height: B, first_epoch: EpochNumber, ) -> Self
The membership of a chain whose epochs start at first_epoch.
first_epoch and first_epoch + 1 run on the genesis stake table,
committee_members, with the initial DRB result.
Sourcepub fn with_storage_read_timeout(self, timeout: Duration) -> Self
pub fn with_storage_read_timeout(self, timeout: Duration) -> Self
Override how long load_stake_table may spend on each of its two
phases. Mostly for tests.
pub async fn reload_stake(&mut self, limit: u64)
Sourcefn map_header<E, F, R>(&self, epoch: E, f: F) -> Option<R>
fn map_header<E, F, R>(&self, epoch: E, f: F) -> Option<R>
Get root leaf header for a given epoch
Sourcefn seed_first_epoch(&self, epoch: EpochNumber)
fn seed_first_epoch(&self, epoch: EpochNumber)
Run epoch and epoch + 1 on the genesis stake table with the initial DRB result.
fn randomized_committee( &self, epoch: EpochNumber, drb: DrbResult, ) -> Option<RandomizedCommittee<StakeTableEntry<PubKey>>>
Trait Implementations§
Source§impl Clone for EpochCommittees
impl Clone for EpochCommittees
Source§fn clone(&self) -> EpochCommittees
fn clone(&self) -> EpochCommittees
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EpochCommittees
impl Debug for EpochCommittees
Source§impl Membership<SeqTypes> for EpochCommittees
impl Membership<SeqTypes> for EpochCommittees
Source§async fn load_stake_table(&self, epoch: EpochNumber) -> bool
async fn load_stake_table(&self, epoch: EpochNumber) -> bool
Load the committee for epoch from storage.
Everything persisted for the epoch is restored: the stake table, the epoch root header, and the randomized committee (rebuilt from the DRB result).
Source§async fn add_epoch_root(
&self,
block_header: Header,
coordinator: &EpochMembershipCoordinator<SeqTypes>,
) -> Result<(), Self::Error>
async fn add_epoch_root( &self, block_header: Header, coordinator: &EpochMembershipCoordinator<SeqTypes>, ) -> Result<(), Self::Error>
Adds the epoch committee and block reward for a given epoch, either by fetching from L1 or using local state if available. It also calculates and stores the block reward based on header version.
type Error = EpochCommitteesError
Source§type Snapshot = EpochSnapshot
type Snapshot = EpochSnapshot
Self::snapshot.Source§fn snapshot(&self, epoch: EpochNumber) -> Option<Self::Snapshot>
fn snapshot(&self, epoch: EpochNumber) -> Option<Self::Snapshot>
Source§fn genesis_stake_tables(&self) -> Arc<GenesisStakeTables<SeqTypes>> ⓘ
fn genesis_stake_tables(&self) -> Arc<GenesisStakeTables<SeqTypes>> ⓘ
Source§async fn get_epoch_root(
&self,
epoch: EpochNumber,
coordinator: &EpochMembershipCoordinator<SeqTypes>,
) -> Result<Leaf2, Self::Error>
async fn get_epoch_root( &self, epoch: EpochNumber, coordinator: &EpochMembershipCoordinator<SeqTypes>, ) -> Result<Leaf2, Self::Error>
Source§async fn get_epoch_drb(
&self,
epoch: EpochNumber,
coordinator: &EpochMembershipCoordinator<SeqTypes>,
) -> Result<DrbResult, Self::Error>
async fn get_epoch_drb( &self, epoch: EpochNumber, coordinator: &EpochMembershipCoordinator<SeqTypes>, ) -> Result<DrbResult, Self::Error>
Source§fn add_drb_result(&self, epoch: EpochNumber, drb: DrbResult)
fn add_drb_result(&self, epoch: EpochNumber, drb: DrbResult)
Source§fn first_epoch(&self) -> EpochNumber
fn first_epoch(&self) -> EpochNumber
Source§fn highest_known_epoch(&self) -> Option<EpochNumber>
fn highest_known_epoch(&self) -> Option<EpochNumber>
None if no stake tables are loaded. It is where catchup resumes
from, so an implementation that leaves it at None makes catchup
rediscover that point one epoch at a time.Source§fn add_da_committee(
&self,
first_epoch: EpochNumber,
committee: Vec<PeerConfig<SeqTypes>>,
)
fn add_da_committee( &self, first_epoch: EpochNumber, committee: Vec<PeerConfig<SeqTypes>>, )
first_epoch.Auto Trait Implementations§
impl !RefUnwindSafe for EpochCommittees
impl !UnwindSafe for EpochCommittees
impl Freeze for EpochCommittees
impl Send for EpochCommittees
impl Sync for EpochCommittees
impl Unpin for EpochCommittees
impl UnsafeUnpin for EpochCommittees
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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 moreimpl<T> JsonSchemaMaybe for T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.