pub struct ChainManager<C>{Show 17 fields
pub ownership: RegisterView<C, ChainOwnership>,
pub seed: RegisterView<C, u64>,
pub distribution: RegisterView<C, Option<WeightedAliasIndex<u64>>>,
pub fallback_distribution: RegisterView<C, Option<WeightedAliasIndex<u64>>>,
pub signed_proposal: RegisterView<C, Option<BlockProposal>>,
pub proposed: RegisterView<C, Option<BlockProposal>>,
pub proposed_blobs: MapView<C, BlobId, Blob>,
pub locking_block: RegisterView<C, Option<LockingBlock>>,
pub locking_blobs: MapView<C, BlobId, Blob>,
pub timeout: RegisterView<C, Option<TimeoutCertificate>>,
pub confirmed_vote: RegisterView<C, Option<Vote<ConfirmedBlock>>>,
pub validated_vote: RegisterView<C, Option<Vote<ValidatedBlock>>>,
pub timeout_vote: RegisterView<C, Option<Vote<Timeout>>>,
pub fallback_vote: RegisterView<C, Option<Vote<Timeout>>>,
pub round_timeout: RegisterView<C, Option<Timestamp>>,
pub current_round: RegisterView<C, Round>,
pub fallback_owners: RegisterView<C, BTreeMap<AccountOwner, u64>>,
}Expand description
The state of the certification process for a chain’s next block.
Fields§
§ownership: RegisterView<C, ChainOwnership>The public keys, weights and types of the chain’s owners.
seed: RegisterView<C, u64>The seed for the pseudo-random number generator that determines the round leaders.
distribution: RegisterView<C, Option<WeightedAliasIndex<u64>>>The probability distribution for choosing a round leader.
fallback_distribution: RegisterView<C, Option<WeightedAliasIndex<u64>>>The probability distribution for choosing a fallback round leader.
signed_proposal: RegisterView<C, Option<BlockProposal>>Highest-round authenticated block that we have received, but not necessarily checked yet. If there are multiple proposals in the same round, this contains only the first one. This can even contain proposals that did not execute successfully, to determine which round to propose in.
proposed: RegisterView<C, Option<BlockProposal>>Highest-round authenticated block that we have received and checked. If there are multiple proposals in the same round, this contains only the first one.
proposed_blobs: MapView<C, BlobId, Blob>These are blobs published or read by the proposed block.
locking_block: RegisterView<C, Option<LockingBlock>>Latest validated proposal that a validator may have voted to confirm. This is either the
latest ValidatedBlock we have seen, or the proposal from the Fast round.
locking_blobs: MapView<C, BlobId, Blob>These are blobs published or read by the locking block.
timeout: RegisterView<C, Option<TimeoutCertificate>>Latest leader timeout certificate we have received.
confirmed_vote: RegisterView<C, Option<Vote<ConfirmedBlock>>>Latest vote we cast to confirm a block.
validated_vote: RegisterView<C, Option<Vote<ValidatedBlock>>>Latest vote we cast to validate a block.
timeout_vote: RegisterView<C, Option<Vote<Timeout>>>Latest timeout vote we cast.
fallback_vote: RegisterView<C, Option<Vote<Timeout>>>Fallback vote we cast.
round_timeout: RegisterView<C, Option<Timestamp>>The time after which we are ready to sign a timeout certificate for the current round.
current_round: RegisterView<C, Round>The lowest round where we can still vote to validate or confirm a block. This is the round to which the timeout applies.
Having a leader timeout certificate in any given round causes the next one to become current. Seeing a validated block certificate or a valid proposal in any round causes that round to become current, unless a higher one already is.
fallback_owners: RegisterView<C, BTreeMap<AccountOwner, u64>>The owners that take over in fallback mode.
Implementations§
Source§impl<C> ChainManager<C>
impl<C> ChainManager<C>
pub async fn ownership( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, ChainOwnership>>
pub async fn seed(&self, ctx: &Context<'_>) -> Result<&RegisterView<C, u64>>
pub async fn proposed_blobs( &self, ctx: &Context<'_>, ) -> Result<&MapView<C, BlobId, Blob>>
pub async fn locking_blobs( &self, ctx: &Context<'_>, ) -> Result<&MapView<C, BlobId, Blob>>
pub async fn round_timeout( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, Option<Timestamp>>>
pub async fn fallback_owners( &self, ctx: &Context<'_>, ) -> Result<&RegisterView<C, BTreeMap<AccountOwner, u64>>>
Source§impl<C> ChainManager<C>
impl<C> ChainManager<C>
Sourcepub fn reset<'a>(
&mut self,
ownership: ChainOwnership,
height: BlockHeight,
local_time: Timestamp,
fallback_owners: impl Iterator<Item = (AccountPublicKey, u64)> + 'a,
) -> Result<(), ChainError>
pub fn reset<'a>( &mut self, ownership: ChainOwnership, height: BlockHeight, local_time: Timestamp, fallback_owners: impl Iterator<Item = (AccountPublicKey, u64)> + 'a, ) -> Result<(), ChainError>
Replaces self with a new chain manager.
Sourcepub fn confirmed_vote(&self) -> Option<&Vote<ConfirmedBlock>>
pub fn confirmed_vote(&self) -> Option<&Vote<ConfirmedBlock>>
Returns the most recent confirmed vote we cast.
Sourcepub fn validated_vote(&self) -> Option<&Vote<ValidatedBlock>>
pub fn validated_vote(&self) -> Option<&Vote<ValidatedBlock>>
Returns the most recent validated vote we cast.
Sourcepub fn timeout_vote(&self) -> Option<&Vote<Timeout>>
pub fn timeout_vote(&self) -> Option<&Vote<Timeout>>
Returns the most recent timeout vote we cast.
Sourcepub fn fallback_vote(&self) -> Option<&Vote<Timeout>>
pub fn fallback_vote(&self) -> Option<&Vote<Timeout>>
Returns the most recent fallback vote we cast.
Sourcepub fn current_round(&self) -> Round
pub fn current_round(&self) -> Round
Returns the lowest round where we can still vote to validate or confirm a block. This is the round to which the timeout applies.
Having a leader timeout certificate in any given round causes the next one to become current. Seeing a validated block certificate or a valid proposal in any round causes that round to become current, unless a higher one already is.
Sourcepub fn check_proposed_block(
&self,
proposal: &BlockProposal,
) -> Result<Outcome, ChainError>
pub fn check_proposed_block( &self, proposal: &BlockProposal, ) -> Result<Outcome, ChainError>
Verifies that a proposed block is relevant and should be handled.
Sourcepub fn create_timeout_vote(
&mut self,
chain_id: ChainId,
height: BlockHeight,
round: Round,
epoch: Epoch,
key_pair: Option<&ValidatorSecretKey>,
local_time: Timestamp,
) -> Result<bool, ChainError>
pub fn create_timeout_vote( &mut self, chain_id: ChainId, height: BlockHeight, round: Round, epoch: Epoch, key_pair: Option<&ValidatorSecretKey>, local_time: Timestamp, ) -> Result<bool, ChainError>
Checks if the current round has timed out, and signs a Timeout. Returns true if the
chain manager’s state has changed.
Sourcepub fn vote_fallback(
&mut self,
chain_id: ChainId,
height: BlockHeight,
epoch: Epoch,
key_pair: Option<&ValidatorSecretKey>,
) -> bool
pub fn vote_fallback( &mut self, chain_id: ChainId, height: BlockHeight, epoch: Epoch, key_pair: Option<&ValidatorSecretKey>, ) -> bool
Signs a Timeout certificate to switch to fallback mode.
This must only be called after verifying that the condition for fallback mode is satisfied locally.
Sourcepub fn check_validated_block(
&self,
certificate: &ValidatedBlockCertificate,
) -> Result<Outcome, ChainError>
pub fn check_validated_block( &self, certificate: &ValidatedBlockCertificate, ) -> Result<Outcome, ChainError>
Verifies that a validated block is still relevant and should be handled.
Sourcepub fn create_vote(
&mut self,
proposal: BlockProposal,
block: Block,
key_pair: Option<&ValidatorSecretKey>,
local_time: Timestamp,
blobs: BTreeMap<BlobId, Blob>,
) -> Result<Option<ValidatedOrConfirmedVote<'_>>, ChainError>
pub fn create_vote( &mut self, proposal: BlockProposal, block: Block, key_pair: Option<&ValidatorSecretKey>, local_time: Timestamp, blobs: BTreeMap<BlobId, Blob>, ) -> Result<Option<ValidatedOrConfirmedVote<'_>>, ChainError>
Signs a vote to validate the proposed block.
Sourcepub fn create_final_vote(
&mut self,
validated: ValidatedBlockCertificate,
key_pair: Option<&ValidatorSecretKey>,
local_time: Timestamp,
blobs: BTreeMap<BlobId, Blob>,
) -> Result<(), ViewError>
pub fn create_final_vote( &mut self, validated: ValidatedBlockCertificate, key_pair: Option<&ValidatorSecretKey>, local_time: Timestamp, blobs: BTreeMap<BlobId, Blob>, ) -> Result<(), ViewError>
Signs a vote to confirm the validated block.
Sourcepub async fn pending_blob(
&self,
blob_id: &BlobId,
) -> Result<Option<Blob>, ViewError>
pub async fn pending_blob( &self, blob_id: &BlobId, ) -> Result<Option<Blob>, ViewError>
Returns the requested blob if it belongs to the proposal or the locking block.
Sourcepub fn handle_timeout_certificate(
&mut self,
certificate: TimeoutCertificate,
local_time: Timestamp,
)
pub fn handle_timeout_certificate( &mut self, certificate: TimeoutCertificate, local_time: Timestamp, )
Updates the round number and timer if the timeout certificate is from a higher round than any known certificate.
Sourcepub fn verify_owner(
&self,
proposal_owner: &AccountOwner,
proposal_round: Round,
) -> Result<bool, CryptoError>
pub fn verify_owner( &self, proposal_owner: &AccountOwner, proposal_round: Round, ) -> Result<bool, CryptoError>
Returns whether the signer is a valid owner and allowed to propose a block in the proposal’s round.
Sourcepub fn update_signed_proposal(
&mut self,
proposal: &BlockProposal,
local_time: Timestamp,
) -> bool
pub fn update_signed_proposal( &mut self, proposal: &BlockProposal, local_time: Timestamp, ) -> bool
Sets the signed proposal, if it is newer than the known one, at most from the first single-leader round. Returns whether it was updated.
We don’t update the signed proposal for any rounds later than SingleLeader(0),
because single-leader rounds cannot be skipped without a timeout certificate.
Trait Implementations§
Source§impl<C> Allocative for ChainManager<C>
impl<C> Allocative for ChainManager<C>
Source§impl<C> ClonableView for ChainManager<C>where
C: Clone + Context + 'static,
RegisterView<C, ChainOwnership>: ClonableView,
RegisterView<C, u64>: ClonableView,
RegisterView<C, Option<WeightedAliasIndex<u64>>>: ClonableView,
RegisterView<C, Option<BlockProposal>>: ClonableView,
MapView<C, BlobId, Blob>: ClonableView,
RegisterView<C, Option<LockingBlock>>: ClonableView,
RegisterView<C, Option<TimeoutCertificate>>: ClonableView,
RegisterView<C, Option<Vote<ConfirmedBlock>>>: ClonableView,
RegisterView<C, Option<Vote<ValidatedBlock>>>: ClonableView,
RegisterView<C, Option<Vote<Timeout>>>: ClonableView,
RegisterView<C, Option<Timestamp>>: ClonableView,
RegisterView<C, Round>: ClonableView,
RegisterView<C, BTreeMap<AccountOwner, u64>>: ClonableView,
Self: View,
impl<C> ClonableView for ChainManager<C>where
C: Clone + Context + 'static,
RegisterView<C, ChainOwnership>: ClonableView,
RegisterView<C, u64>: ClonableView,
RegisterView<C, Option<WeightedAliasIndex<u64>>>: ClonableView,
RegisterView<C, Option<BlockProposal>>: ClonableView,
MapView<C, BlobId, Blob>: ClonableView,
RegisterView<C, Option<LockingBlock>>: ClonableView,
RegisterView<C, Option<TimeoutCertificate>>: ClonableView,
RegisterView<C, Option<Vote<ConfirmedBlock>>>: ClonableView,
RegisterView<C, Option<Vote<ValidatedBlock>>>: ClonableView,
RegisterView<C, Option<Vote<Timeout>>>: ClonableView,
RegisterView<C, Option<Timestamp>>: ClonableView,
RegisterView<C, Round>: ClonableView,
RegisterView<C, BTreeMap<AccountOwner, u64>>: 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 ChainManager<C>
impl<C> ContainerType for ChainManager<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 ChainManager<C>where
C: Clone + Context + 'static,
RegisterView<C, ChainOwnership>: Debug,
RegisterView<C, u64>: Debug,
RegisterView<C, Option<WeightedAliasIndex<u64>>>: Debug,
RegisterView<C, Option<BlockProposal>>: Debug,
MapView<C, BlobId, Blob>: Debug,
RegisterView<C, Option<LockingBlock>>: Debug,
RegisterView<C, Option<TimeoutCertificate>>: Debug,
RegisterView<C, Option<Vote<ConfirmedBlock>>>: Debug,
RegisterView<C, Option<Vote<ValidatedBlock>>>: Debug,
RegisterView<C, Option<Vote<Timeout>>>: Debug,
RegisterView<C, Option<Timestamp>>: Debug,
RegisterView<C, Round>: Debug,
RegisterView<C, BTreeMap<AccountOwner, u64>>: Debug,
impl<C> Debug for ChainManager<C>where
C: Clone + Context + 'static,
RegisterView<C, ChainOwnership>: Debug,
RegisterView<C, u64>: Debug,
RegisterView<C, Option<WeightedAliasIndex<u64>>>: Debug,
RegisterView<C, Option<BlockProposal>>: Debug,
MapView<C, BlobId, Blob>: Debug,
RegisterView<C, Option<LockingBlock>>: Debug,
RegisterView<C, Option<TimeoutCertificate>>: Debug,
RegisterView<C, Option<Vote<ConfirmedBlock>>>: Debug,
RegisterView<C, Option<Vote<ValidatedBlock>>>: Debug,
RegisterView<C, Option<Vote<Timeout>>>: Debug,
RegisterView<C, Option<Timestamp>>: Debug,
RegisterView<C, Round>: Debug,
RegisterView<C, BTreeMap<AccountOwner, u64>>: Debug,
Source§impl<C> From<&ChainManager<C>> for ChainManagerInfo
impl<C> From<&ChainManager<C>> for ChainManagerInfo
Source§fn from(manager: &ChainManager<C>) -> Self
fn from(manager: &ChainManager<C>) -> Self
Source§impl<C> OutputType for ChainManager<C>
impl<C> OutputType for ChainManager<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> View for ChainManager<C>where
C: Context + Clone + Context + 'static,
RegisterView<C, ChainOwnership>: View<Context = C>,
RegisterView<C, u64>: View<Context = C>,
RegisterView<C, Option<WeightedAliasIndex<u64>>>: View<Context = C>,
RegisterView<C, Option<BlockProposal>>: View<Context = C>,
MapView<C, BlobId, Blob>: View<Context = C>,
RegisterView<C, Option<LockingBlock>>: View<Context = C>,
RegisterView<C, Option<TimeoutCertificate>>: View<Context = C>,
RegisterView<C, Option<Vote<ConfirmedBlock>>>: View<Context = C>,
RegisterView<C, Option<Vote<ValidatedBlock>>>: View<Context = C>,
RegisterView<C, Option<Vote<Timeout>>>: View<Context = C>,
RegisterView<C, Option<Timestamp>>: View<Context = C>,
RegisterView<C, Round>: View<Context = C>,
RegisterView<C, BTreeMap<AccountOwner, u64>>: View<Context = C>,
impl<C> View for ChainManager<C>where
C: Context + Clone + Context + 'static,
RegisterView<C, ChainOwnership>: View<Context = C>,
RegisterView<C, u64>: View<Context = C>,
RegisterView<C, Option<WeightedAliasIndex<u64>>>: View<Context = C>,
RegisterView<C, Option<BlockProposal>>: View<Context = C>,
MapView<C, BlobId, Blob>: View<Context = C>,
RegisterView<C, Option<LockingBlock>>: View<Context = C>,
RegisterView<C, Option<TimeoutCertificate>>: View<Context = C>,
RegisterView<C, Option<Vote<ConfirmedBlock>>>: View<Context = C>,
RegisterView<C, Option<Vote<ValidatedBlock>>>: View<Context = C>,
RegisterView<C, Option<Vote<Timeout>>>: View<Context = C>,
RegisterView<C, Option<Timestamp>>: View<Context = C>,
RegisterView<C, Round>: View<Context = C>,
RegisterView<C, BTreeMap<AccountOwner, u64>>: 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 ChainManager<C>
Auto Trait Implementations§
impl<C> Freeze for ChainManager<C>where
C: Freeze,
impl<C> RefUnwindSafe for ChainManager<C>where
C: RefUnwindSafe,
impl<C> Send for ChainManager<C>
impl<C> Sync for ChainManager<C>
impl<C> Unpin for ChainManager<C>where
C: Unpin,
impl<C> UnwindSafe for ChainManager<C>where
C: UnwindSafe,
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.