Skip to main content

ChainStateMachine

Struct ChainStateMachine 

Source
pub struct ChainStateMachine<S: ChainStore> { /* private fields */ }
Expand description

Pure state machine for chain connections — no networking, no async.

Processes JSON-RPC responses from smoldot (or smoldot-js on WASM), tracks chain status, and persists chain databases via a ChainStore.

Implementations§

Source§

impl<S: ChainStore> ChainStateMachine<S>

Source

pub fn new(store: S) -> Self

Source

pub fn register_chain(&mut self, chain: ChainId)

Register a chain for tracking. Initial state is Connecting.

Source

pub fn unregister_chain(&mut self, chain: ChainId)

Unregister a chain (sets state to Disconnected).

Source

pub fn set_state(&mut self, chain: ChainId, state: ChainState)

Set the chain state, preserving existing extra.

Source

pub fn set_state_with_extra( &mut self, chain: ChainId, state: ChainState, extra: ChainExtra, )

Set both state and extra data.

Source

pub fn store(&self) -> &S

Access the underlying store.

Source

pub fn process_response(&mut self, chain: ChainId, text: &str)

Process a JSON-RPC response from smoldot for a given chain.

Source

pub fn process_relay_response(&mut self, chain: ChainId, text: &str)

Process a JSON-RPC response for a relay chain DB save.

Source

pub fn set_error(&mut self, chain: ChainId, msg: String)

Set the chain state to Error.

Source

pub fn status(&self, chain: ChainId) -> ChainStatus

Source

pub fn all_statuses(&self) -> Vec<ChainStatus>

Source

pub fn subscribe_new_heads_request() -> String

Generate the chain_subscribeNewHeads JSON-RPC request.

Source

pub fn health_check_request(&mut self, chain: ChainId) -> Option<String>

Generate a system_health JSON-RPC request with an incrementing ID. Returns None if the chain is not registered.

Source

pub fn para_db_save_request() -> String

Generate a parachain DB save request.

Source

pub fn relay_db_save_request() -> String

Generate a relay chain DB save request.

Source

pub fn load_relay_db(&self, chain: ChainId) -> String

Load persisted relay chain DB.

Source

pub fn load_para_db(&self, chain: ChainId) -> String

Load persisted parachain DB.

Source

pub fn chain_specs(chain: ChainId) -> Option<(&'static str, &'static str)>

Get chain specs for a smoldot chain. Returns (relay_spec, para_spec).

Source

pub fn statement_submit_request(encoded_hex: &str, request_id: u64) -> String

Generate a statement_submit JSON-RPC request.

Source

pub fn statement_subscribe_request(request_id: u64) -> String

Generate a statement_subscribeStatement JSON-RPC request.

Source

pub fn statement_unsubscribe_request(sub_id: &str, request_id: u64) -> String

Generate a statement_unsubscribeStatement JSON-RPC request.

Source

pub fn statement_broadcasts_request( topic_hexes: &[String], request_id: u64, ) -> String

Generate a statement_broadcastsStatement JSON-RPC request.

Source

pub fn parse_statement_notification(text: &str) -> Vec<String>

Parse a statement_subscribeStatement notification. Returns hex-encoded statement strings found in the notification, or an empty vec if this is not a statement notification.

Auto Trait Implementations§

§

impl<S> Freeze for ChainStateMachine<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for ChainStateMachine<S>
where S: RefUnwindSafe,

§

impl<S> Send for ChainStateMachine<S>
where S: Send,

§

impl<S> Sync for ChainStateMachine<S>
where S: Sync,

§

impl<S> Unpin for ChainStateMachine<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for ChainStateMachine<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for ChainStateMachine<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more