pub struct ChainManager {Show 14 fields
pub ownership: ChainOwnership,
pub seed: u64,
pub distribution: Option<WeightedAliasIndex<u64>>,
pub fallback_distribution: Option<WeightedAliasIndex<u64>>,
pub proposed: Option<BlockProposal>,
pub locked: Option<Certificate>,
pub timeout: Option<Certificate>,
pub pending: Option<Vote>,
pub timeout_vote: Option<Vote>,
pub fallback_vote: Option<Vote>,
pub round_timeout: Option<Timestamp>,
pub current_round: Round,
pub fallback_owners: BTreeMap<Owner, (PublicKey, u64)>,
pub pending_blobs: BTreeMap<BlobId, Blob>,
}
Expand description
The state of the certification process for a chain’s next block.
Fields§
§ownership: ChainOwnership
The public keys, weights and types of the chain’s owners.
seed: u64
The seed for the pseudo-random number generator that determines the round leaders.
distribution: Option<WeightedAliasIndex<u64>>
The probability distribution for choosing a round leader.
fallback_distribution: Option<WeightedAliasIndex<u64>>
The probability distribution for choosing a fallback round leader.
proposed: 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.
locked: Option<Certificate>
Latest validated proposal that we have voted to confirm (or would have, if we are not a validator).
timeout: Option<Certificate>
Latest leader timeout certificate we have received.
pending: Option<Vote>
Latest vote we have cast, to validate or confirm.
timeout_vote: Option<Vote>
Latest timeout vote we cast.
fallback_vote: Option<Vote>
Fallback vote we cast.
round_timeout: Option<Timestamp>
The time after which we are ready to sign a timeout certificate for the current round.
current_round: 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: BTreeMap<Owner, (PublicKey, u64)>
The owners that take over in fallback mode.
pending_blobs: BTreeMap<BlobId, Blob>
These are blobs belonging to proposed or validated blocks that have not been confirmed yet.
Implementations§
Source§impl ChainManager
impl ChainManager
Sourcepub fn reset<'a>(
&mut self,
ownership: &ChainOwnership,
height: BlockHeight,
local_time: Timestamp,
fallback_owners: impl Iterator<Item = (PublicKey, u64)> + 'a,
) -> Result<(), ChainError>
pub fn reset<'a>( &mut self, ownership: &ChainOwnership, height: BlockHeight, local_time: Timestamp, fallback_owners: impl Iterator<Item = (PublicKey, u64)> + 'a, ) -> Result<(), ChainError>
Replaces self
with a new chain manager.
Sourcepub fn check_proposed_block(
&self,
proposal: &BlockProposal,
) -> Result<Outcome, ChainError>
pub fn check_proposed_block( &self, proposal: &BlockProposal, ) -> Result<Outcome, ChainError>
Verifies the safety of a proposed block with respect to voting rules.
Sourcepub fn vote_timeout(
&mut self,
chain_id: ChainId,
height: BlockHeight,
epoch: Epoch,
key_pair: Option<&KeyPair>,
local_time: Timestamp,
) -> bool
pub fn vote_timeout( &mut self, chain_id: ChainId, height: BlockHeight, epoch: Epoch, key_pair: Option<&KeyPair>, local_time: Timestamp, ) -> bool
Checks if the current round has timed out, and signs a Timeout
.
Sourcepub fn vote_fallback(
&mut self,
chain_id: ChainId,
height: BlockHeight,
epoch: Epoch,
key_pair: Option<&KeyPair>,
) -> bool
pub fn vote_fallback( &mut self, chain_id: ChainId, height: BlockHeight, epoch: Epoch, key_pair: Option<&KeyPair>, ) -> 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: &Certificate,
) -> Result<Outcome, ChainError>
pub fn check_validated_block( &self, certificate: &Certificate, ) -> Result<Outcome, ChainError>
Verifies that we can vote to confirm a validated block.
Sourcepub fn create_vote(
&mut self,
proposal: BlockProposal,
outcome: BlockExecutionOutcome,
key_pair: Option<&KeyPair>,
local_time: Timestamp,
)
pub fn create_vote( &mut self, proposal: BlockProposal, outcome: BlockExecutionOutcome, key_pair: Option<&KeyPair>, local_time: Timestamp, )
Signs a vote to validate the proposed block.
Sourcepub fn create_final_vote(
&mut self,
certificate: Certificate,
key_pair: Option<&KeyPair>,
local_time: Timestamp,
)
pub fn create_final_vote( &mut self, certificate: Certificate, key_pair: Option<&KeyPair>, local_time: Timestamp, )
Signs a vote to confirm the validated block.
Sourcepub fn handle_timeout_certificate(
&mut self,
certificate: Certificate,
local_time: Timestamp,
)
pub fn handle_timeout_certificate( &mut self, certificate: Certificate, 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: &BlockProposal) -> Option<PublicKey>
pub fn verify_owner(&self, proposal: &BlockProposal) -> Option<PublicKey>
Returns the public key of the block proposal’s signer, if they are a valid owner and allowed to propose a block in the proposal’s round.
Trait Implementations§
Source§impl Clone for ChainManager
impl Clone for ChainManager
Source§fn clone(&self) -> ChainManager
fn clone(&self) -> ChainManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ChainManager
impl Debug for ChainManager
Source§impl Default for ChainManager
impl Default for ChainManager
Source§fn default() -> ChainManager
fn default() -> ChainManager
Source§impl<'de> Deserialize<'de> for ChainManager
impl<'de> Deserialize<'de> for ChainManager
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&ChainManager> for ChainManagerInfo
impl From<&ChainManager> for ChainManagerInfo
Source§fn from(manager: &ChainManager) -> Self
fn from(manager: &ChainManager) -> Self
Source§impl InputType for ChainManager
impl InputType for ChainManager
Source§type RawValueType = ChainManager
type RawValueType = ChainManager
Source§fn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
Source§fn parse(value: Option<Value>) -> InputValueResult<Self>
fn parse(value: Option<Value>) -> InputValueResult<Self>
Value
. None represents undefined.Source§fn as_raw_value(&self) -> Option<&Self::RawValueType>
fn as_raw_value(&self) -> Option<&Self::RawValueType>
Source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
Source§impl OutputType for ChainManager
impl OutputType for ChainManager
Source§fn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
Source§async fn resolve(
&self,
_: &ContextSelectionSet<'_>,
_field: &Positioned<Field>,
) -> ServerResult<Value>
async fn resolve( &self, _: &ContextSelectionSet<'_>, _field: &Positioned<Field>, ) -> ServerResult<Value>
async_graphql::Value
.Source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
Source§impl ScalarType for ChainManager
impl ScalarType for ChainManager
Auto Trait Implementations§
impl Freeze for ChainManager
impl RefUnwindSafe for ChainManager
impl Send for ChainManager
impl Sync for ChainManager
impl Unpin for ChainManager
impl UnwindSafe for ChainManager
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
.