pub struct EpochManager { /* private fields */ }Expand description
Primary state machine managing the current epoch’s lifecycle and archiving completed epochs.
Uses parking_lot::RwLock for interior mutability (start.md Hard
Requirement 12). Read operations allow concurrent access; write
operations block all other access.
Implementations§
Source§impl EpochManager
impl EpochManager
Sourcepub fn new(
network_id: Bytes32,
genesis_l1_height: u32,
initial_state_root: Bytes32,
) -> Self
pub fn new( network_id: Bytes32, genesis_l1_height: u32, initial_state_root: Bytes32, ) -> Self
Creates an EpochManager at epoch 0 with empty history and a
fresh Pending competition.
network_id and genesis_l1_height are immutable for the lifetime
of this manager. The initial EpochInfo starts at
GENESIS_HEIGHT in BlockProduction phase.
Sourcepub fn current_epoch(&self) -> u64
pub fn current_epoch(&self) -> u64
Returns the current epoch number.
Sourcepub fn current_epoch_info(&self) -> EpochInfo
pub fn current_epoch_info(&self) -> EpochInfo
Returns a clone of the current epoch’s full state.
Sourcepub fn current_phase(&self) -> EpochPhase
pub fn current_phase(&self) -> EpochPhase
Returns the current phase of the current epoch.
Sourcepub fn genesis_l1_height(&self) -> u32
pub fn genesis_l1_height(&self) -> u32
Returns the network’s genesis L1 height.
Sourcepub fn network_id(&self) -> Bytes32
pub fn network_id(&self) -> Bytes32
Returns the network ID.
Sourcepub fn epoch_for_l1_height(&self, l1_height: u32) -> u64
pub fn epoch_for_l1_height(&self, l1_height: u32) -> u64
Maps an L1 height to its epoch number using genesis_l1_height.
Heights before genesis map to epoch 0.
Sourcepub fn l1_range_for_epoch(&self, epoch: u64) -> (u32, u32)
pub fn l1_range_for_epoch(&self, epoch: u64) -> (u32, u32)
Returns (start_l1, end_l1) for the given epoch.
Sourcepub fn update_phase(&self, l1_height: u32) -> Option<PhaseTransition>
pub fn update_phase(&self, l1_height: u32) -> Option<PhaseTransition>
Recalculates the phase from l1_height. Returns Some(PhaseTransition)
if the phase changed, None if unchanged.
Sourcepub fn should_advance(&self, _l1_height: u32) -> bool
pub fn should_advance(&self, _l1_height: u32) -> bool
Returns true when the current phase is Complete.
Sourcepub fn record_block(&self, fees: u64, tx_count: u64) -> Result<(), EpochError>
pub fn record_block(&self, fees: u64, tx_count: u64) -> Result<(), EpochError>
Records a block in the current epoch.
Returns Err(PhaseMismatch) if not in BlockProduction.
Sourcepub fn set_current_epoch_chain_totals(&self, blocks: u32, fees: u64, txns: u64)
pub fn set_current_epoch_chain_totals(&self, blocks: u32, fees: u64, txns: u64)
Overwrites the current epoch’s block production statistics.
Used for resync / correction. No phase restriction; values are replaced, not incremented.
Sourcepub fn set_current_epoch_dfsp_close_snapshot(
&self,
snap: DfspCloseSnapshot,
) -> Result<(), EpochError>
pub fn set_current_epoch_dfsp_close_snapshot( &self, snap: DfspCloseSnapshot, ) -> Result<(), EpochError>
Applies DFSP close values to the current epoch before advance.
Returns Err(PhaseMismatch) if not in Finalization.
Sourcepub fn advance_epoch(
&self,
_l1_height: u32,
state_root: Bytes32,
) -> Result<u64, EpochError>
pub fn advance_epoch( &self, _l1_height: u32, state_root: Bytes32, ) -> Result<u64, EpochError>
Archives the current epoch and transitions to epoch + 1.
Preconditions:
- Current phase is
Complete. - Current competition is
Finalized.
Both preconditions are checked before any state mutation.
Sourcepub fn get_epoch_info(&self) -> EpochInfo
pub fn get_epoch_info(&self) -> EpochInfo
Returns a clone of the current EpochInfo.
Sourcepub fn get_epoch_summary(&self, epoch: u64) -> Option<EpochSummary>
pub fn get_epoch_summary(&self, epoch: u64) -> Option<EpochSummary>
Returns the EpochSummary for a specific completed epoch, or None.
Sourcepub fn recent_summaries(&self, n: usize) -> Vec<EpochSummary>
pub fn recent_summaries(&self, n: usize) -> Vec<EpochSummary>
Returns the last n summaries from the tail, preserving epoch order.
Sourcepub fn total_stats(&self) -> EpochStats
pub fn total_stats(&self) -> EpochStats
Aggregate statistics across all completed epochs plus the current one.
Sourcepub fn get_rewards(&self, epoch: u64) -> Option<RewardDistribution>
pub fn get_rewards(&self, epoch: u64) -> Option<RewardDistribution>
Returns the RewardDistribution for epoch, or None.
Sourcepub fn store_rewards(&self, distribution: RewardDistribution)
pub fn store_rewards(&self, distribution: RewardDistribution)
Archives a RewardDistribution keyed by its epoch field.
Sourcepub fn competition(&self) -> CheckpointCompetition
pub fn competition(&self) -> CheckpointCompetition
Returns a clone of the current competition. Read-only.
Sourcepub fn start_checkpoint_competition(&self) -> Result<(), EpochError>
pub fn start_checkpoint_competition(&self) -> Result<(), EpochError>
Transitions the current competition from Pending to Collecting.
Phase-gated to Checkpoint. Delegates to
CheckpointCompetition::start for the state transition.
Sourcepub fn submit_checkpoint(
&self,
submission: CheckpointSubmission,
) -> Result<bool, EpochError>
pub fn submit_checkpoint( &self, submission: CheckpointSubmission, ) -> Result<bool, EpochError>
Records a checkpoint submission against the current epoch’s competition.
Phase-gated to Checkpoint. Returns Ok(true) when the submission
becomes the new leader, Ok(false) is never returned (non-leading
submissions return Err(ScoreNotHigher)). Delegates scoring to
CheckpointCompetition::submit.
Sourcepub fn finalize_competition(
&self,
epoch: u64,
l1_height: u32,
) -> Result<Option<Checkpoint>, EpochError>
pub fn finalize_competition( &self, epoch: u64, l1_height: u32, ) -> Result<Option<Checkpoint>, EpochError>
Finalizes the competition for epoch at l1_height, transitioning
status to Finalized and setting the winning checkpoint on the
current EpochInfo.
Phase-gated to Finalization when epoch matches the current epoch.
Returns the winning checkpoint on success, or Ok(None) if no winner
was selected.
Sourcepub fn get_competition(&self, epoch: u64) -> Option<CheckpointCompetition>
pub fn get_competition(&self, epoch: u64) -> Option<CheckpointCompetition>
Returns a clone of the competition for epoch.
Only the current epoch’s competition is tracked; returns None for
past or future epochs.
Auto Trait Implementations§
impl !Freeze for EpochManager
impl !RefUnwindSafe for EpochManager
impl Send for EpochManager
impl Sync for EpochManager
impl Unpin for EpochManager
impl UnsafeUnpin for EpochManager
impl UnwindSafe for EpochManager
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> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§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
Source§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
Source§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.Source§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.Source§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.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.