pub struct ChainStateView<C>{Show 18 fields
pub execution_state: ExecutionStateView<C>,
pub execution_state_hash: RegisterView<C, Option<CryptoHash>>,
pub tip_state: RegisterView<C, ChainTipState>,
pub manager: ChainManager<C>,
pub pending_validated_blobs: PendingBlobsView<C>,
pub pending_proposed_blobs: ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>,
pub confirmed_log: LogView<C, CryptoHash>,
pub received_log: LogView<C, ChainAndHeight>,
pub received_certificate_trackers: RegisterView<C, HashMap<ValidatorPublicKey, u64>>,
pub inboxes: ReentrantCollectionView<C, ChainId, InboxStateView<C>>,
pub unskippable_bundles: BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>,
pub removed_unskippable_bundles: SetView<C, BundleInInbox>,
pub previous_message_blocks: MapView<C, ChainId, BlockHeight>,
pub previous_event_blocks: MapView<C, StreamId, BlockHeight>,
pub outboxes: ReentrantCollectionView<C, ChainId, OutboxStateView<C>>,
pub outbox_counters: RegisterView<C, BTreeMap<BlockHeight, u32>>,
pub nonempty_outboxes: RegisterView<C, BTreeSet<ChainId>>,
pub preprocessed_blocks: MapView<C, BlockHeight, CryptoHash>,
}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: ChainManager<C>Consensus state.
pending_validated_blobs: PendingBlobsView<C>Pending validated block that is still missing blobs. The incomplete set of blobs for the pending validated block.
pending_proposed_blobs: ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>The incomplete sets of blobs for upcoming proposals.
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).
received_certificate_trackers: RegisterView<C, HashMap<ValidatorPublicKey, u64>>The number of received_log entries we have synchronized, for each validator.
inboxes: ReentrantCollectionView<C, ChainId, InboxStateView<C>>Mailboxes used to receive messages indexed by their origin.
unskippable_bundles: BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>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.
previous_message_blocks: MapView<C, ChainId, BlockHeight>The heights of previous blocks that sent messages to the same recipients.
previous_event_blocks: MapView<C, StreamId, BlockHeight>The heights of previous blocks that published events to the same streams.
outboxes: ReentrantCollectionView<C, ChainId, 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.
nonempty_outboxes: RegisterView<C, BTreeSet<ChainId>>Outboxes with at least one pending message. This allows us to avoid loading all outboxes.
preprocessed_blocks: MapView<C, BlockHeight, CryptoHash>Blocks that have been verified but not executed yet, and that may not be contiguous.
Implementations§
Source§impl<C> ChainStateView<C>
impl<C> ChainStateView<C>
pub async fn execution_state( &self, ctx: &Context<'_>, ) -> Result<&ExecutionStateView<C>>
pub async fn execution_state_hash( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, Option<CryptoHash>>>
pub async fn tip_state( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, ChainTipState>>
pub async fn manager(&self, ctx: &Context<'_>) -> Result<&ChainManager<C>>
pub async fn pending_validated_blobs( &self, ctx: &Context<'_>, ) -> Result<&PendingBlobsView<C>>
pub async fn pending_proposed_blobs( &self, ctx: &Context<'_>, ) -> Result<&ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>>
pub async fn confirmed_log( &self, ctx: &Context<'_>, ) -> Result<&LogView<C, CryptoHash>>
pub async fn received_log( &self, ctx: &Context<'_>, ) -> Result<&LogView<C, ChainAndHeight>>
pub async fn received_certificate_trackers( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, HashMap<ValidatorPublicKey, u64>>>
pub async fn inboxes( &self, ctx: &Context<'_>, ) -> Result<&ReentrantCollectionView<C, ChainId, InboxStateView<C>>>
pub async fn unskippable_bundles( &self, ctx: &Context<'_>, ) -> Result<&BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>>
pub async fn removed_unskippable_bundles( &self, ctx: &Context<'_>, ) -> Result<&SetView<C, BundleInInbox>>
pub async fn previous_message_blocks( &self, ctx: &Context<'_>, ) -> Result<&MapView<C, ChainId, BlockHeight>>
pub async fn previous_event_blocks( &self, ctx: &Context<'_>, ) -> Result<&MapView<C, StreamId, BlockHeight>>
pub async fn outboxes( &self, ctx: &Context<'_>, ) -> Result<&ReentrantCollectionView<C, ChainId, OutboxStateView<C>>>
pub async fn outbox_counters( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, BTreeMap<BlockHeight, u32>>>
pub async fn nonempty_outboxes( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, BTreeSet<ChainId>>>
pub async fn preprocessed_blocks( &self, ctx: &Context<'_>, ) -> Result<&MapView<C, BlockHeight, CryptoHash>>
Source§impl<C> ChainStateView<C>
impl<C> ChainStateView<C>
Sourcepub fn chain_id(&self) -> ChainId
pub fn chain_id(&self) -> ChainId
Returns the ChainId of the chain this ChainStateView represents.
pub async fn query_application( &mut self, local_time: Timestamp, query: Query, service_runtime_endpoint: Option<&mut ServiceRuntimeEndpoint>, ) -> Result<QueryOutcome, ChainError>
pub async fn describe_application( &mut self, application_id: ApplicationId, ) -> Result<ApplicationDescription, ChainError>
pub async fn mark_messages_as_received( &mut self, target: &ChainId, height: BlockHeight, ) -> Result<bool, ChainError>
Sourcepub fn all_messages_delivered_up_to(&self, height: BlockHeight) -> bool
pub fn all_messages_delivered_up_to(&self, height: BlockHeight) -> bool
Returns true if there are no more outgoing messages in flight up to the given block height.
Sourcepub async fn initialize_if_needed(
&mut self,
local_time: Timestamp,
) -> Result<(), ChainError>
pub async fn initialize_if_needed( &mut self, local_time: Timestamp, ) -> Result<(), ChainError>
Initializes the chain if it is not active yet.
pub async fn next_block_height_to_receive( &self, origin: &ChainId, ) -> Result<BlockHeight, ChainError>
Sourcepub async fn next_height_to_preprocess(&self) -> Result<BlockHeight, ChainError>
pub async fn next_height_to_preprocess(&self) -> Result<BlockHeight, ChainError>
Returns the height of the highest block we have, plus one. Includes preprocessed blocks.
The “+ 1” is so that it can be used in the same places as next_block_height.
pub async fn last_anticipated_block_height( &self, origin: &ChainId, ) -> Result<Option<BlockHeight>, ChainError>
Sourcepub async fn receive_message_bundle(
&mut self,
origin: &ChainId,
bundle: MessageBundle,
local_time: Timestamp,
add_to_received_log: bool,
) -> Result<(), ChainError>
pub async fn receive_message_bundle( &mut self, origin: &ChainId, bundle: MessageBundle, local_time: Timestamp, add_to_received_log: bool, ) -> Result<(), 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.
Sourcepub fn update_received_certificate_trackers(
&mut self,
new_trackers: BTreeMap<ValidatorPublicKey, u64>,
)
pub fn update_received_certificate_trackers( &mut self, new_trackers: BTreeMap<ValidatorPublicKey, u64>, )
Updates the received_log trackers.
pub fn current_committee(&self) -> Result<(Epoch, &Committee), ChainError>
pub fn ownership(&self) -> &ChainOwnership
Sourcepub async fn remove_bundles_from_inboxes(
&mut self,
timestamp: Timestamp,
must_be_present: bool,
incoming_bundles: impl IntoIterator<Item = &IncomingBundle>,
) -> Result<(), ChainError>
pub async fn remove_bundles_from_inboxes( &mut self, timestamp: Timestamp, must_be_present: bool, incoming_bundles: impl IntoIterator<Item = &IncomingBundle>, ) -> Result<(), ChainError>
Removes the incoming message bundles in the block from the inboxes.
If must_be_present is true, an error is returned if any of the bundles have not been
added to the inbox yet. So this should be true if the bundles are in a block proposal,
and false if the block is already confirmed.
Sourcepub fn nonempty_outbox_chain_ids(&self) -> Vec<ChainId>
pub fn nonempty_outbox_chain_ids(&self) -> Vec<ChainId>
Returns the chain IDs of all recipients for which a message is waiting in the outbox.
Sourcepub async fn load_outboxes(
&self,
targets: &[ChainId],
) -> Result<Vec<ReadGuardedView<OutboxStateView<C>>>, ChainError>
pub async fn load_outboxes( &self, targets: &[ChainId], ) -> Result<Vec<ReadGuardedView<OutboxStateView<C>>>, ChainError>
Returns the outboxes for the given targets, or an error if any of them are missing.
Sourcepub async fn execute_block(
&mut self,
block: &ProposedBlock,
local_time: Timestamp,
round: Option<u32>,
published_blobs: &[Blob],
replaying_oracle_responses: Option<Vec<Vec<OracleResponse>>>,
) -> Result<BlockExecutionOutcome, ChainError>
pub async fn execute_block( &mut self, block: &ProposedBlock, local_time: Timestamp, round: Option<u32>, published_blobs: &[Blob], replaying_oracle_responses: Option<Vec<Vec<OracleResponse>>>, ) -> Result<BlockExecutionOutcome, ChainError>
Executes a block: first the incoming messages, then the main operation. Does not update chain state other than the execution state.
Sourcepub async fn apply_confirmed_block(
&mut self,
block: &ConfirmedBlock,
local_time: Timestamp,
) -> Result<(), ChainError>
pub async fn apply_confirmed_block( &mut self, block: &ConfirmedBlock, local_time: Timestamp, ) -> Result<(), ChainError>
Applies an execution outcome to the chain, updating the outboxes, state hash and chain manager. This does not touch the execution state itself, which must be updated separately. Returns the set of event streams that were updated as a result of applying the block.
Sourcepub async fn preprocess_block(
&mut self,
block: &ConfirmedBlock,
) -> Result<(), ChainError>
pub async fn preprocess_block( &mut self, block: &ConfirmedBlock, ) -> Result<(), ChainError>
Adds a block to preprocessed_blocks, and updates the outboxes where possible.
Sourcepub async fn block_hashes(
&self,
heights: impl IntoIterator<Item = BlockHeight>,
) -> Result<Vec<CryptoHash>, ChainError>
pub async fn block_hashes( &self, heights: impl IntoIterator<Item = BlockHeight>, ) -> Result<Vec<CryptoHash>, ChainError>
Returns the hashes of all blocks we have in the given range.
If the input heights are in ascending order, the hashes will be in the same order. Otherwise they may be unordered.
Trait Implementations§
Source§impl<C> Allocative for ChainStateView<C>
impl<C> Allocative for ChainStateView<C>
Source§impl<C> ClonableView for ChainStateView<C>where
C: Clone + Context + 'static,
ExecutionStateView<C>: ClonableView,
RegisterView<C, Option<CryptoHash>>: ClonableView,
RegisterView<C, ChainTipState>: ClonableView,
ChainManager<C>: ClonableView,
PendingBlobsView<C>: ClonableView,
ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>: ClonableView,
LogView<C, CryptoHash>: ClonableView,
LogView<C, ChainAndHeight>: ClonableView,
RegisterView<C, HashMap<ValidatorPublicKey, u64>>: ClonableView,
ReentrantCollectionView<C, ChainId, InboxStateView<C>>: ClonableView,
BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>: ClonableView,
SetView<C, BundleInInbox>: ClonableView,
MapView<C, ChainId, BlockHeight>: ClonableView,
MapView<C, StreamId, BlockHeight>: ClonableView,
ReentrantCollectionView<C, ChainId, OutboxStateView<C>>: ClonableView,
RegisterView<C, BTreeMap<BlockHeight, u32>>: ClonableView,
RegisterView<C, BTreeSet<ChainId>>: ClonableView,
MapView<C, BlockHeight, CryptoHash>: ClonableView,
Self: View,
impl<C> ClonableView for ChainStateView<C>where
C: Clone + Context + 'static,
ExecutionStateView<C>: ClonableView,
RegisterView<C, Option<CryptoHash>>: ClonableView,
RegisterView<C, ChainTipState>: ClonableView,
ChainManager<C>: ClonableView,
PendingBlobsView<C>: ClonableView,
ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>: ClonableView,
LogView<C, CryptoHash>: ClonableView,
LogView<C, ChainAndHeight>: ClonableView,
RegisterView<C, HashMap<ValidatorPublicKey, u64>>: ClonableView,
ReentrantCollectionView<C, ChainId, InboxStateView<C>>: ClonableView,
BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>: ClonableView,
SetView<C, BundleInInbox>: ClonableView,
MapView<C, ChainId, BlockHeight>: ClonableView,
MapView<C, StreamId, BlockHeight>: ClonableView,
ReentrantCollectionView<C, ChainId, OutboxStateView<C>>: ClonableView,
RegisterView<C, BTreeMap<BlockHeight, u32>>: ClonableView,
RegisterView<C, BTreeSet<ChainId>>: ClonableView,
MapView<C, BlockHeight, CryptoHash>: ClonableView,
Self: View,
Source§fn clone_unchecked(&mut self) -> Result<Self, ViewError>
fn clone_unchecked(&mut self) -> Result<Self, ViewError>
Source§impl<C> ContainerType for ChainStateView<C>
impl<C> ContainerType for ChainStateView<C>
Source§async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>>
async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>>
async_graphql::Value. Read moreSource§fn collect_all_fields<'a>(
&'a self,
ctx: &ContextBase<'a, &'a Positioned<SelectionSet>>,
fields: &mut Fields<'a>,
) -> Result<(), ServerError>
fn collect_all_fields<'a>( &'a self, ctx: &ContextBase<'a, &'a Positioned<SelectionSet>>, fields: &mut Fields<'a>, ) -> Result<(), ServerError>
Source§fn find_entity(
&self,
_: &ContextBase<'_, &Positioned<Field>>,
_params: &ConstValue,
) -> impl Future<Output = Result<Option<ConstValue>, ServerError>> + Send
fn find_entity( &self, _: &ContextBase<'_, &Positioned<Field>>, _params: &ConstValue, ) -> impl Future<Output = Result<Option<ConstValue>, ServerError>> + Send
Source§impl<C> Debug for ChainStateView<C>
impl<C> Debug for ChainStateView<C>
Source§impl<C> OutputType for ChainStateView<C>
impl<C> OutputType for ChainStateView<C>
Source§fn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
Source§async fn resolve(
&self,
ctx: &ContextSelectionSet<'_>,
_field: &Positioned<Field>,
) -> ServerResult<Value>
async fn resolve( &self, ctx: &ContextSelectionSet<'_>, _field: &Positioned<Field>, ) -> ServerResult<Value>
async_graphql::Value.Source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
Source§impl<C> RootView for ChainStateView<C>
impl<C> RootView for ChainStateView<C>
Source§impl<C> View for ChainStateView<C>where
C: Context + Clone + Context + 'static,
ExecutionStateView<C>: View<Context = C>,
RegisterView<C, Option<CryptoHash>>: View<Context = C>,
RegisterView<C, ChainTipState>: View<Context = C>,
ChainManager<C>: View<Context = C>,
PendingBlobsView<C>: View<Context = C>,
ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>: View<Context = C>,
LogView<C, CryptoHash>: View<Context = C>,
LogView<C, ChainAndHeight>: View<Context = C>,
RegisterView<C, HashMap<ValidatorPublicKey, u64>>: View<Context = C>,
ReentrantCollectionView<C, ChainId, InboxStateView<C>>: View<Context = C>,
BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>: View<Context = C>,
SetView<C, BundleInInbox>: View<Context = C>,
MapView<C, ChainId, BlockHeight>: View<Context = C>,
MapView<C, StreamId, BlockHeight>: View<Context = C>,
ReentrantCollectionView<C, ChainId, OutboxStateView<C>>: View<Context = C>,
RegisterView<C, BTreeMap<BlockHeight, u32>>: View<Context = C>,
RegisterView<C, BTreeSet<ChainId>>: View<Context = C>,
MapView<C, BlockHeight, CryptoHash>: View<Context = C>,
impl<C> View for ChainStateView<C>where
C: Context + Clone + Context + 'static,
ExecutionStateView<C>: View<Context = C>,
RegisterView<C, Option<CryptoHash>>: View<Context = C>,
RegisterView<C, ChainTipState>: View<Context = C>,
ChainManager<C>: View<Context = C>,
PendingBlobsView<C>: View<Context = C>,
ReentrantCollectionView<C, AccountOwner, PendingBlobsView<C>>: View<Context = C>,
LogView<C, CryptoHash>: View<Context = C>,
LogView<C, ChainAndHeight>: View<Context = C>,
RegisterView<C, HashMap<ValidatorPublicKey, u64>>: View<Context = C>,
ReentrantCollectionView<C, ChainId, InboxStateView<C>>: View<Context = C>,
BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>: View<Context = C>,
SetView<C, BundleInInbox>: View<Context = C>,
MapView<C, ChainId, BlockHeight>: View<Context = C>,
MapView<C, StreamId, BlockHeight>: View<Context = C>,
ReentrantCollectionView<C, ChainId, OutboxStateView<C>>: View<Context = C>,
RegisterView<C, BTreeMap<BlockHeight, u32>>: View<Context = C>,
RegisterView<C, BTreeSet<ChainId>>: View<Context = C>,
MapView<C, BlockHeight, CryptoHash>: View<Context = C>,
Source§const NUM_INIT_KEYS: usize
const NUM_INIT_KEYS: usize
Source§fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>
fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>
Source§fn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>
fn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>
Source§fn rollback(&mut self)
fn rollback(&mut self)
flush should have no effect to storage.Source§async fn has_pending_changes(&self) -> bool
async fn has_pending_changes(&self) -> bool
true if flushing this view would result in changes to the persistent storage.Source§fn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
fn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
batch variable.
The returned boolean indicates whether the operation removes the view or not.Source§fn post_save(&mut self)
fn post_save(&mut self)
pre_save and after the batch has been successfully written to storage.
This leaves the view in a clean state with no pending changes. Read moreimpl<C> ObjectType for ChainStateView<C>
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§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
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<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
Source§fn read<'instance>(
&self,
instance: &'instance &mut I,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
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>
fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the bytes to memory at the provided location.