pub struct State { /* private fields */ }Expand description
The rollup state, read-only.
Mutations go through the BlockWriter and ProofWriter capabilities returned by
LoadedState::start; every holder of this type can only query and subscribe.
All tree and database reads go through a request-scoped StateView obtained from
State::view; this type itself only exposes chain-tip queries, subscriptions, and
block-store access.
Implementations§
Source§impl State
impl State
Sourcepub fn spawn_disk_monitor(&self, shutdown: CancellationToken) -> JoinHandle<()> ⓘ
pub fn spawn_disk_monitor(&self, shutdown: CancellationToken) -> JoinHandle<()> ⓘ
Spawns a background task that periodically records the on-disk size of every store data path
as OTel span attributes.
Source§impl State
impl State
Sourcepub async fn load(
data_path: &Path,
storage_options: StorageOptions,
) -> Result<LoadedState, StateInitializationError>
pub async fn load( data_path: &Path, storage_options: StorageOptions, ) -> Result<LoadedState, StateInitializationError>
Loads the state from the data directory.
The loaded state owns all store data structures and exposes subscription methods for
sequencer and replica tasks. Call LoadedState::start on the result to spawn the block
writer and obtain the usable State.
Sourcepub async fn load_with_database_options(
data_path: &Path,
storage_options: StorageOptions,
database_options: DatabaseOptions,
) -> Result<LoadedState, StateInitializationError>
pub async fn load_with_database_options( data_path: &Path, storage_options: StorageOptions, database_options: DatabaseOptions, ) -> Result<LoadedState, StateInitializationError>
Loads the state from the data directory using explicit database options.
The loaded state owns all store data structures and exposes subscription methods for
sequencer and replica tasks. Call LoadedState::start on the result to spawn the block
writer and obtain the usable State.
Source§impl State
impl State
Sourcepub async fn load_block(
&self,
block_num: BlockNumber,
) -> Result<Option<Vec<u8>>, DatabaseError>
pub async fn load_block( &self, block_num: BlockNumber, ) -> Result<Option<Vec<u8>>, DatabaseError>
Loads a block from the in-memory replica cache or block store. Return Ok(None) if the
block is not found.
Sourcepub async fn load_proof(
&self,
block_num: BlockNumber,
) -> Result<Option<Vec<u8>>, DatabaseError>
pub async fn load_proof( &self, block_num: BlockNumber, ) -> Result<Option<Vec<u8>>, DatabaseError>
Loads a block proof from the in-memory replica cache or block store. Returns Ok(None) if
the proof is not found.
Sourcepub async fn load_proving_inputs(
&self,
block_num: BlockNumber,
) -> Result<Option<Vec<u8>>>
pub async fn load_proving_inputs( &self, block_num: BlockNumber, ) -> Result<Option<Vec<u8>>>
Loads serialized block proving inputs from the block store.
Source§impl State
impl State
Sourcepub fn committed_tip(&self) -> BlockNumber
pub fn committed_tip(&self) -> BlockNumber
Returns the latest committed (but not necessarily proven) block number.
This is a live value: it advances independently of any StateView.
Reads that must be consistent with data must use a view’s tip instead.
Ordering matters when combining this with a view: read the tip before creating the view. Tips are monotonic and the committed tip is published after its snapshot, so a view created afterwards can always serve a tip read earlier. Reading a live tip after creating a view is racy — the tip may have advanced past the view’s pinned snapshot.
Sourcepub fn proven_tip(&self) -> BlockNumber
pub fn proven_tip(&self) -> BlockNumber
Returns the latest block number proven in an unbroken sequence from genesis.
This is a live value published by the proof scheduler (sequencer mode) or the proof sync loop (full-node mode); it is always at or behind the committed tip.
Ordering matters when combining this with a view: read the tip before creating the view. Proofs are only applied to committed blocks and each committed tip is published after its snapshot, so a view created afterwards can always serve a proven tip read earlier. Reading it after creating a view is racy — a block may commit and prove concurrently, putting the proven tip past the view’s pinned snapshot.
Sourcepub fn subscribe_committed_tip(&self) -> Receiver<BlockNumber>
pub fn subscribe_committed_tip(&self) -> Receiver<BlockNumber>
Returns a watch receiver that wakes every time a new block is committed.
Sourcepub fn subscribe_proven_tip(&self) -> Receiver<BlockNumber>
pub fn subscribe_proven_tip(&self) -> Receiver<BlockNumber>
Returns a watch receiver that wakes every time the proven-in-sequence tip advances.
Source§impl State
impl State
Sourcepub fn view(&self) -> StateView
pub fn view(&self) -> StateView
Returns a read view pinned at the current chain tip (wait-free, no lock required).
The view is frozen: it is unaffected if the writer publishes a new snapshot while it is held.
Use this only for one single-expression read (state.view().get_account(..)),
where the temporary view drops at the end of the statement. Two view() calls observe
potentially different snapshots — a block can commit between them — so reads that must
be mutually consistent (e.g. a query and the tip it was served at) must share one view via
Self::with_view. Binding a view to a variable is also discouraged: it keeps the
snapshot generation pinned until the end of the scope.
Sourcepub async fn with_view<R>(&self, f: impl AsyncFnOnce(&StateView) -> R) -> R
pub async fn with_view<R>(&self, f: impl AsyncFnOnce(&StateView) -> R) -> R
Runs a read operation over a view pinned at the current chain tip, dropping the view — and releasing its snapshot generation — as soon as the operation completes.
This is the required form whenever multiple reads must observe the same snapshot: the
closure’s view is one consistent generation, whereas consecutive Self::view calls may
straddle a commit. The typical case is pairing a query with StateView::tip so a
response reports exactly the height it was served at.
The closure receives a shared reference, so the view cannot escape the call, and the
snapshot is not pinned through unrelated work that follows (e.g. response encoding). A
single read doesn’t need it — state.view().get_account(..) drops its temporary view at
the end of the statement.
Work in the closure should be kept to low-complexity compute over the view, ideally with no
I/O and no other .await points. Anything slower holds the pinned snapshot, and therefore
its underlying RocksDB snapshot, for as long as it runs. The snapshot’s lifetime is logged
as a warning if held too long, but that is a backstop, not a substitute for keeping closures
short.
Auto Trait Implementations§
impl !RefUnwindSafe for State
impl !UnwindSafe for State
impl Freeze for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§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>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§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.Source§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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> 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::RequestSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more