pub struct SlotSequencer {
config: ExecutionConfig,
sequence: VecDeque<SlotInfo>,
latest_consensus_final_slots: Vec<Slot>,
latest_execution_final_slot: Slot,
latest_executed_final_slot: Slot,
latest_executed_candidate_slot: Slot,
}Expand description
Structure allowing execution slot sequence management.
The SlotSequencer::update method is called to notify the sequencer about blocks becoming CSS-final, about changes in the blockclique, or simply about slot ticks.
The sequencer then internally sequences the slots, and prepares a queue of slots that are ready to be executed by Execution.
SlotSequencer::is_task_available allows checking if a slot is ready to be executed.
SlotSequencer::run_task_with allows running the next slot in the queue, if any.
Note that SCE-final slots are executed in priority over candidate slots.
SlotSequencer::get_next_slot_deadline allows getting the time at which the next slot will happen (this is useful to sequence slots as they happen even if there is no block there).
Fields§
§config: ExecutionConfigConfig
sequence: VecDeque<SlotInfo>Continuous sequence of slots containing all the slots relevant for Execution and their current states (see SlotInfo). Oldest slot is at front.
latest_consensus_final_slots: Vec<Slot>latest CSS-final slots (one per thread)
latest_execution_final_slot: Slotlatest SCE-final slot
latest_executed_final_slot: Slotfinal slot execution cursor
latest_executed_candidate_slot: Slotcandidate slot execution cursor
Implementations§
source§impl SlotSequencer
impl SlotSequencer
sourcepub fn new(config: ExecutionConfig, final_cursor: Slot) -> Self
pub fn new(config: ExecutionConfig, final_cursor: Slot) -> Self
Create a new slot sequencer.
Note that this will create a SlotSequencer with an empty internal sequence
which makes it unusable until SlotSequencer::update is called a first time to feed the CSS-final blocks.
§Arguments
final_cursor: latest executed SCE-final slot. This is useful on bootstrap in particular in order to avoid re-executing previously executed slots.
sourcefn init(
&mut self,
initial_consensus_final_blocks: HashMap<Slot, BlockId>,
initial_blockclique: HashMap<Slot, BlockId>,
blocks_metadata: PreHashMap<BlockId, ExecutionBlockMetadata>,
)
fn init( &mut self, initial_consensus_final_blocks: HashMap<Slot, BlockId>, initial_blockclique: HashMap<Slot, BlockId>, blocks_metadata: PreHashMap<BlockId, ExecutionBlockMetadata>, )
Internal method that inits the sequencer.
This method is called on the first call to SlotSequencer::update.
It allows feeding the initial sequence of CSS-final blocks to the sequencer.
§Arguments
initial_consensus_final_blocks: the list of CSS-final blocks (must not be empty)
initial_blockclique: initial blockclique, usually empty except on major bootstrap latency
blocks_metadata: Metadata for all the blocks referenced in initial_consensus_final_blocks and initial_blockclique
sourcefn get_time_cursor(&self) -> Slot
fn get_time_cursor(&self) -> Slot
Internal function allowing to get the latest slot we should execute at the current time. This is useful to fill the sequencer with slots as they happen, even if there are no blocks there.
Note that this time cursor is shifted by self.config.cursor_delay
to avoid computing speculative slots that are too recent, and therefore subject to frequent re-writes.
sourcepub fn update(
&mut self,
new_consensus_final_blocks: HashMap<Slot, BlockId>,
new_blockclique: Option<HashMap<Slot, BlockId>>,
new_blocks_metadata: PreHashMap<BlockId, ExecutionBlockMetadata>,
)
pub fn update( &mut self, new_consensus_final_blocks: HashMap<Slot, BlockId>, new_blockclique: Option<HashMap<Slot, BlockId>>, new_blocks_metadata: PreHashMap<BlockId, ExecutionBlockMetadata>, )
Notify the sequencer of incoming changes: CSS-finalized blocks and changes in the blockclique. This function is also called on time slots to ensure new slots are taken into account even if they don’t contain a block.
§Arguments
new_consensus_final_blocks: new CSS-finalized blocksnew_blockclique: new blockclique (if changed since the last call to this method, otherwise None)new_blocks_metadata: metadata for blocks that have not been seen previously by the sequencer
sourcefn sequence_build_step(
slot: Slot,
prev_item: Option<SlotInfo>,
new_consensus_final: bool,
new_consensus_final_block: Option<BlockId>,
blockclique_updated: bool,
new_blockclique_block: Option<BlockId>,
new_blocks_metadata: &mut PreHashMap<BlockId, ExecutionBlockMetadata>,
in_execution_finality: bool,
) -> (SlotInfo, bool)
fn sequence_build_step( slot: Slot, prev_item: Option<SlotInfo>, new_consensus_final: bool, new_consensus_final_block: Option<BlockId>, blockclique_updated: bool, new_blockclique_block: Option<BlockId>, new_blocks_metadata: &mut PreHashMap<BlockId, ExecutionBlockMetadata>, in_execution_finality: bool, ) -> (SlotInfo, bool)
Internal method called by Self::update to construct one slot of the new slot sequence
by using info about newly CSS-finalized blocks, the new blockclique (if any) and the previous state of that slot.
§Arguments
slot: the slot being constructedprev_item: the corresponding slot status from the old sequence, if anynew_consensus_final: whether this slot was CSS-finalizednew_consensus_final_block: newly CSS-finalized block at that slot, if anyblockclique_updated: whether a new blockclique was provided whenSelf::updatewas callednew_blockclique_block: block at that slot within the new blockclique, if anynew_blocks_metadata: block metadata for executionin_execution_finality: whether the previous slot was SCE-final
§Returns
A pair (SlotInfo, truncate_history: bool) where truncate_history indicates that this slot changes the content of an existing candidate slot
sourcefn get_slot_index(&self, slot: &Slot) -> Option<usize>
fn get_slot_index(&self, slot: &Slot) -> Option<usize>
Get the index of a slot in the sequence, if present, otherwise None
sourcefn get_slot(&self, slot: &Slot) -> Option<&SlotInfo>
fn get_slot(&self, slot: &Slot) -> Option<&SlotInfo>
Gets an immutable reference to a SlotInfo, if any, otherwise None
sourcepub fn is_task_available(&self) -> bool
pub fn is_task_available(&self) -> bool
Returns true if there is a queued slot that needs to be executed now.
sourcefn cleanup_sequence(&mut self)
fn cleanup_sequence(&mut self)
Clean the slot sequence by removing slots that are not useful anymore.
The removed slots the ones that are strictly before the earliest executed CSS-final slot.
This function is called on Self::init to cleanup bootstrap artifacts,
and when a task is processed with Self::run_task_with.
sourcepub fn run_task_with<F, T>(&mut self, callback: F) -> Option<T>
pub fn run_task_with<F, T>(&mut self, callback: F) -> Option<T>
If a slot is ready for execution, this method will mark it as executed and call the provided callback function on it for execution. SCE-final slots are executed in priority over candidate slots.
§Arguments
callback: callback function that executes the slot- Callback arguments:
- a boolean indicating whether or not the slot is SCE-final
- a reference to the slot
- a reference to the block at that slot and its storage, if any (otherwise None)
- Callback return value: an arbitrary
T
- Callback arguments:
§Returns
An option that is None if there was no task to be executed,
or Some(T) where T is the value returned by the callback function otherwise.
sourcepub fn get_next_slot_deadline(&self) -> MassaTime
pub fn get_next_slot_deadline(&self) -> MassaTime
Gets the instant of the slot just after the latest slot in the sequence.
Note that config.cursor_delay is taken into account.
Auto Trait Implementations§
impl Freeze for SlotSequencer
impl !RefUnwindSafe for SlotSequencer
impl Send for SlotSequencer
impl Sync for SlotSequencer
impl Unpin for SlotSequencer
impl !UnwindSafe for SlotSequencer
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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<T> Conv for T
impl<T> Conv for T
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§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>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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 moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§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> 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.