Struct ChainStateView

Source
pub struct ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static,
{ pub execution_state: ExecutionStateView<C>, pub execution_state_hash: RegisterView<C, Option<CryptoHash>>, pub tip_state: RegisterView<C, ChainTipState>, pub manager: RegisterView<C, ChainManager>, pub confirmed_log: LogView<C, CryptoHash>, pub received_log: LogView<C, ChainAndHeight>, pub inboxes: ReentrantCollectionView<C, Origin, InboxStateView<C>>, pub unskippable_bundles: QueueView<C, TimestampedBundleInInbox>, pub removed_unskippable_bundles: SetView<C, BundleInInbox>, pub outboxes: ReentrantCollectionView<C, Target, OutboxStateView<C>>, pub outbox_counters: RegisterView<C, BTreeMap<BlockHeight, u32>>, pub channels: ReentrantCollectionView<C, ChannelFullName, ChannelStateView<C>>, }
Expand description

A view accessing the state of a chain.

Fields§

§execution_state: ExecutionStateView<C>

Execution state, including system and user applications.

§execution_state_hash: RegisterView<C, Option<CryptoHash>>

Hash of the execution state.

§tip_state: RegisterView<C, ChainTipState>

Block-chaining state.

§manager: RegisterView<C, ChainManager>

Consensus state.

§confirmed_log: LogView<C, CryptoHash>

Hashes of all certified blocks for this sender. This ends with block_hash and has length usize::from(next_block_height).

§received_log: LogView<C, ChainAndHeight>

Sender chain and height of all certified blocks known as a receiver (local ordering).

§inboxes: ReentrantCollectionView<C, Origin, InboxStateView<C>>

Mailboxes used to receive messages indexed by their origin.

§unskippable_bundles: QueueView<C, TimestampedBundleInInbox>

A queue of unskippable bundles, with the timestamp when we added them to the inbox.

§removed_unskippable_bundles: SetView<C, BundleInInbox>

Unskippable bundles that have been removed but are still in the queue.

§outboxes: ReentrantCollectionView<C, Target, OutboxStateView<C>>

Mailboxes used to send messages, indexed by their target.

§outbox_counters: RegisterView<C, BTreeMap<BlockHeight, u32>>

Number of outgoing messages in flight for each block height. We use a RegisterView to prioritize speed for small maps.

§channels: ReentrantCollectionView<C, ChannelFullName, ChannelStateView<C>>

Channels able to multicast messages to subscribers.

Implementations§

Source§

impl<C> ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static,

Source

pub async fn execution_state( &self, ctx: &Context<'_>, ) -> Result<&ExecutionStateView<C>>

Source

pub async fn execution_state_hash( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, Option<CryptoHash>>>

Source

pub async fn tip_state( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, ChainTipState>>

Source

pub async fn manager( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, ChainManager>>

Source

pub async fn confirmed_log( &self, ctx: &Context<'_>, ) -> Result<&LogView<C, CryptoHash>>

Source

pub async fn received_log( &self, ctx: &Context<'_>, ) -> Result<&LogView<C, ChainAndHeight>>

Source

pub async fn inboxes( &self, ctx: &Context<'_>, ) -> Result<&ReentrantCollectionView<C, Origin, InboxStateView<C>>>

Source

pub async fn unskippable_bundles( &self, ctx: &Context<'_>, ) -> Result<&QueueView<C, TimestampedBundleInInbox>>

Source

pub async fn removed_unskippable_bundles( &self, ctx: &Context<'_>, ) -> Result<&SetView<C, BundleInInbox>>

Source

pub async fn outboxes( &self, ctx: &Context<'_>, ) -> Result<&ReentrantCollectionView<C, Target, OutboxStateView<C>>>

Source

pub async fn outbox_counters( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, BTreeMap<BlockHeight, u32>>>

Source

pub async fn channels( &self, ctx: &Context<'_>, ) -> Result<&ReentrantCollectionView<C, ChannelFullName, ChannelStateView<C>>>

Source§

impl<C> ChainStateView<C>
where C: Context + Clone + Send + Sync + 'static, C::Extra: ExecutionRuntimeContext,

Source

pub fn chain_id(&self) -> ChainId

Returns the ChainId of the chain this ChainStateView represents.

Source

pub async fn query_application( &mut self, local_time: Timestamp, query: Query, service_runtime_endpoint: Option<&mut ServiceRuntimeEndpoint>, ) -> Result<Response, ChainError>

Source

pub async fn describe_application( &mut self, application_id: UserApplicationId, ) -> Result<UserApplicationDescription, ChainError>

Source

pub async fn mark_messages_as_received( &mut self, target: &Target, height: BlockHeight, ) -> Result<bool, ChainError>

Source

pub fn all_messages_delivered_up_to(&mut self, height: BlockHeight) -> bool

Returns true if there are no more outgoing messages in flight up to the given block height.

Source

pub fn is_active(&self) -> bool

Invariant for the states of active chains.

Source

pub fn is_closed(&self) -> bool

Returns whether this chain has been closed.

Source

pub fn ensure_is_active(&self) -> Result<(), ChainError>

Invariant for the states of active chains.

Source

pub async fn validate_incoming_bundles(&self) -> Result<(), ChainError>

Verifies that this chain is up-to-date and all the messages executed ahead of time have been properly received by now.

Source

pub async fn next_block_height_to_receive( &self, origin: &Origin, ) -> Result<BlockHeight, ChainError>

Source

pub async fn last_anticipated_block_height( &self, origin: &Origin, ) -> Result<Option<BlockHeight>, ChainError>

Source

pub async fn receive_message_bundle( &mut self, origin: &Origin, bundle: MessageBundle, local_time: Timestamp, add_to_received_log: bool, ) -> Result<bool, ChainError>

Attempts to process a new bundle of messages from the given origin. Returns an internal error if the bundle doesn’t appear to be new, based on the sender’s height. The value local_time is specific to each validator and only used for round timeouts.

Returns true if incoming Subscribe messages created new outbox entries.

Source

pub async fn execute_init_message( &mut self, message_id: MessageId, config: &OpenChainConfig, timestamp: Timestamp, local_time: Timestamp, ) -> Result<bool, ChainError>

Source

pub async fn remove_bundles_from_inboxes( &mut self, block: &Block, ) -> Result<(), ChainError>

Removes the incoming message bundles in the block from the inboxes.

Source

pub async fn execute_block( &mut self, block: &Block, local_time: Timestamp, replaying_oracle_responses: Option<Vec<Vec<OracleResponse>>>, ) -> Result<BlockExecutionOutcome, ChainError>

Executes a block: first the incoming messages, then the main operation.

  • Modifies the state of outboxes and channels, if needed.
  • As usual, in case of errors, self may not be consistent any more and should be thrown away.
  • Returns the outcome of the execution.

Trait Implementations§

Source§

impl<C> ClonableView<C> for ChainStateView<C>
where C: Context + Send + Sync + Clone + 'static,

Source§

fn clone_unchecked(&mut self) -> Result<Self, ViewError>

Creates a clone of this view, sharing the underlying storage context but prone to data races which can corrupt the view state.
Source§

impl<C> ContainerType for ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static,

Source§

async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>>

Resolves a field value and outputs it as a json value async_graphql::Value. Read more
Source§

fn collect_all_fields<'a>( &'a self, ctx: &ContextBase<'a, &'a Positioned<SelectionSet>>, fields: &mut Fields<'a>, ) -> Result<(), ServerError>
where Self: Send + Sync,

Collect all the fields of the container that are queried in the selection set. Read more
Source§

fn find_entity( &self, _: &ContextBase<'_, &Positioned<Field>>, _params: &ConstValue, ) -> impl Future<Output = Result<Option<ConstValue>, ServerError>> + Send

Find the GraphQL entity with the given name from the parameter. Read more
Source§

impl<C> Debug for ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C> OutputType for ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static,

Source§

fn type_name() -> Cow<'static, str>

Type the name.
Source§

fn create_type_info(registry: &mut Registry) -> String

Create type information in the registry and return qualified typename.
Source§

async fn resolve( &self, ctx: &ContextSelectionSet<'_>, _field: &Positioned<Field>, ) -> ServerResult<Value>

Resolve an output value to async_graphql::Value.
Source§

fn qualified_type_name() -> String

Qualified typename.
Source§

fn introspection_type_name(&self) -> Cow<'static, str>

Introspection type name Read more
Source§

impl<C> RootView<C> for ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static + Context,

Source§

fn save<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), ViewError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Saves the root view to the database context
Source§

impl<C> View<C> for ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static + Context,

Source§

const NUM_INIT_KEYS: usize = 29usize

The number of keys used for the initialization
Source§

fn context(&self) -> &C

Obtains a mutable reference to the internal context.
Source§

fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>

Creates the keys needed for loading the view
Source§

fn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>

Loads a view from the values
Source§

fn load<'async_trait>( context: C, ) -> Pin<Box<dyn Future<Output = Result<Self, ViewError>> + Send + 'async_trait>>
where Self: 'async_trait,

Loads a view
Source§

fn rollback(&mut self)

Discards all pending changes. After that flush should have no effect to storage.
Source§

fn has_pending_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns true if flushing this view would result in changes to the persistent storage.
Source§

fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>

Persists changes to storage. This leaves the view still usable and is essentially neutral to the program running. Crash-resistant storage implementations are expected to accumulate the desired changes in the batch variable first. If the view is dropped without calling flush, staged changes are simply lost. The returned boolean indicates whether the operation removes the view or not.
Source§

fn clear(&mut self)

Clears the view. That can be seen as resetting to default. If the clear is followed by a flush then all the relevant data is removed on the storage.
Source§

fn new(context: C) -> Result<Self, ViewError>

Builds a trivial view that is already deleted
Source§

impl<C> ObjectType for ChainStateView<C>
where C: Clone + Context + Send + Sync + 'static,

Auto Trait Implementations§

§

impl<C> !Freeze for ChainStateView<C>

§

impl<C> !RefUnwindSafe for ChainStateView<C>

§

impl<C> Send for ChainStateView<C>

§

impl<C> Sync for ChainStateView<C>

§

impl<C> Unpin for ChainStateView<C>
where C: Unpin,

§

impl<C> !UnwindSafe for ChainStateView<C>

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<Choices> CoproductSubsetter<CNil, HNil> for Choices

Source§

type Remainder = Choices

Source§

fn subset( self, ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

Source§

fn lift_into(self) -> U

Performs the indexed conversion.
Source§

impl<M, I> RuntimeMemory<&mut I> for M
where M: RuntimeMemory<I>,

Source§

fn read<'instance>( &self, instance: &'instance &mut I, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>

Reads length bytes from memory from the provided location.

Source§

fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>

Writes the bytes to memory at the provided location.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Source> Sculptor<HNil, HNil> for Source

Source§

type Remainder = Source

Source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
Source§

impl<AnyTail> Split<HNil> for AnyTail

Source§

type Remainder = AnyTail

The tail of remaining elements after splitting up the list.
Source§

fn split(self) -> (HNil, <AnyTail as Split<HNil>>::Remainder)

Splits the current heterogeneous list in two.
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T