pub trait Engine<M: Machine>: Sync + Send {
Show 37 methods
fn name(&self) -> &str;
fn machine(&self) -> &M;
fn verify_local_seal(&self, header: &Header) -> Result<(), M::Error>;
fn fork_choice(
&self,
new: &ExtendedHeader,
best: &ExtendedHeader
) -> ForkChoice;
fn seal_fields(&self, _header: &Header) -> usize { ... }
fn extra_info(&self, _header: &Header) -> BTreeMap<String, String> { ... }
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { ... }
fn maximum_gas_limit(&self) -> Option<U256> { ... }
fn on_new_block(
&self,
_block: &mut ExecutedBlock,
_epoch_begin: bool,
_ancestry: &mut dyn Iterator<Item = ExtendedHeader>
) -> Result<(), M::Error> { ... }
fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<(), M::Error> { ... }
fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { ... }
fn sealing_state(&self) -> SealingState { ... }
fn should_reseal_on_update(&self) -> bool { ... }
fn generate_seal(&self, _block: &ExecutedBlock, _parent: &Header) -> Seal { ... }
fn verify_block_basic(&self, _header: &Header) -> Result<(), M::Error> { ... }
fn verify_block_unordered(&self, _header: &Header) -> Result<(), M::Error> { ... }
fn verify_block_family(
&self,
_header: &Header,
_parent: &Header
) -> Result<(), M::Error> { ... }
fn verify_block_external(&self, _header: &Header) -> Result<(), M::Error> { ... }
fn genesis_epoch_data<'a>(
&self,
_header: &Header,
_state: &Call<'_>
) -> Result<Vec<u8>, String> { ... }
fn signals_epoch_end<'a>(
&self,
_header: &Header,
_aux: AuxiliaryData<'a>
) -> EpochChange<M> { ... }
fn is_epoch_end(
&self,
_chain_head: &Header,
_finalized: &[H256],
_chain: &Headers<'_, Header>,
_transition_store: &PendingTransitionStore<'_>
) -> Option<Vec<u8>> { ... }
fn epoch_verifier<'a>(
&self,
_header: &Header,
_proof: &'a [u8]
) -> ConstructedVerifier<'a, M> { ... }
fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) { ... }
fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError> { ... }
fn set_signer(&self, _signer: Option<Box<dyn EngineSigner>>) { ... }
fn is_allowed_to_seal(&self) -> bool { ... }
fn sign(&self, _hash: H256) -> Result<Signature, M::Error> { ... }
fn register_client(&self, _client: Weak<M::EngineClient>) { ... }
fn step(&self) { ... }
fn snapshot_components(&self) -> Option<Box<dyn SnapshotComponents>> { ... }
fn supports_warp(&self) -> bool { ... }
fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64 { ... }
fn is_timestamp_valid(
&self,
header_timestamp: u64,
parent_timestamp: u64
) -> bool { ... }
fn ancestry_actions(
&self,
_header: &Header,
_ancestry: &mut dyn Iterator<Item = ExtendedHeader>
) -> Vec<AncestryAction>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
{ ... }
fn executive_author(&self, header: &Header) -> Result<Address, Error> { ... }
fn generate_engine_transactions(
&self,
_block: &ExecutedBlock
) -> Result<Vec<SignedTransaction>, Error> { ... }
fn gas_limit_override(&self, _header: &Header) -> Option<U256> { ... }
}
Expand description
A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based. Provides hooks into each of the major parts of block import.
Required methods
Verify a locally-generated seal of a header.
If this engine seals internally, no checks have to be done here, since all internally generated seals should be valid.
Externally-generated seals (e.g. PoW) will need to be checked for validity.
It is fine to require access to state or a full client for this function, since light clients do not generate seals.
fn fork_choice(&self, new: &ExtendedHeader, best: &ExtendedHeader) -> ForkChoice
fn fork_choice(&self, new: &ExtendedHeader, best: &ExtendedHeader) -> ForkChoice
Check whether the given new block is the best block, after finalization check.
Provided methods
fn seal_fields(&self, _header: &Header) -> usize
fn seal_fields(&self, _header: &Header) -> usize
The number of additional header fields required for this engine.
Additional engine-specific information for the user/developer concerning header
.
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize
Maximum number of uncles a block is allowed to declare.
fn maximum_gas_limit(&self) -> Option<U256>
fn maximum_gas_limit(&self) -> Option<U256>
Optional maximum gas limit.
fn on_new_block(
&self,
_block: &mut ExecutedBlock,
_epoch_begin: bool,
_ancestry: &mut dyn Iterator<Item = ExtendedHeader>
) -> Result<(), M::Error>
fn on_new_block(
&self,
_block: &mut ExecutedBlock,
_epoch_begin: bool,
_ancestry: &mut dyn Iterator<Item = ExtendedHeader>
) -> Result<(), M::Error>
Block transformation functions, before the transactions.
epoch_begin
set to true if this block kicks off an epoch.
fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<(), M::Error>
fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<(), M::Error>
Block transformation functions, after the transactions.
fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error>
fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error>
Allow mutating the header during seal generation. Currently only used by Clique.
fn sealing_state(&self) -> SealingState
fn sealing_state(&self) -> SealingState
Returns the engine’s current sealing state.
fn should_reseal_on_update(&self) -> bool
fn should_reseal_on_update(&self) -> bool
Called in miner.chain_new_blocks
if the engine wishes to update_sealing
after a block was recently sealed.
returns false by default
fn generate_seal(&self, _block: &ExecutedBlock, _parent: &Header) -> Seal
fn generate_seal(&self, _block: &ExecutedBlock, _parent: &Header) -> Seal
Attempt to seal the block internally.
If Some
is returned, then you get a valid seal.
This operation is synchronous and may (quite reasonably) not be available, in which None will be returned.
It is fine to require access to state or a full client for this function, since light clients do not generate seals.
Phase 1 quick block verification. Only does checks that are cheap. Returns either a null Ok
or a general error detailing the problem with import.
The verification module can optionally avoid checking the seal (check_seal
), if seal verification is disabled this method won’t be called.
Phase 2 verification. Perform costly checks such as transaction signatures. Returns either a null Ok
or a general error detailing the problem with import.
The verification module can optionally avoid checking the seal (check_seal
), if seal verification is disabled this method won’t be called.
Phase 3 verification. Check block information against parent. Returns either a null Ok
or a general error detailing the problem with import.
Phase 4 verification. Verify block header against potentially external data.
Should only be called when register_client
has been called previously.
Genesis epoch data.
fn signals_epoch_end<'a>(
&self,
_header: &Header,
_aux: AuxiliaryData<'a>
) -> EpochChange<M>
fn signals_epoch_end<'a>(
&self,
_header: &Header,
_aux: AuxiliaryData<'a>
) -> EpochChange<M>
Whether an epoch change is signalled at the given header but will require finality.
If a change can be enacted immediately then return No
from this function but
Yes
from is_epoch_end
.
If auxiliary data of the block is required, return an auxiliary request and the function will be
called again with them.
Return Yes
or No
when the answer is definitively known.
Should not interact with state.
Whether a block is the end of an epoch.
This either means that an immediate transition occurs or a block signalling transition
has reached finality. The Headers
given are not guaranteed to return any blocks
from any epoch other than the current. The client must keep track of finality and provide
the latest finalized headers to check against the transition store.
Return optional transition proof.
fn epoch_verifier<'a>(
&self,
_header: &Header,
_proof: &'a [u8]
) -> ConstructedVerifier<'a, M>
fn epoch_verifier<'a>(
&self,
_header: &Header,
_proof: &'a [u8]
) -> ConstructedVerifier<'a, M>
Create an epoch verifier from validation proof and a flag indicating whether finality is required.
fn populate_from_parent(&self, _header: &mut Header, _parent: &Header)
fn populate_from_parent(&self, _header: &mut Header, _parent: &Header)
Populate a header’s fields based on its parent’s header. Usually implements the chain scoring rule based on weight.
fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError>
fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError>
Handle any potential consensus messages; updating consensus state and potentially issuing a new one.
fn set_signer(&self, _signer: Option<Box<dyn EngineSigner>>)
fn set_signer(&self, _signer: Option<Box<dyn EngineSigner>>)
Register a component which signs consensus messages.
fn is_allowed_to_seal(&self) -> bool
fn is_allowed_to_seal(&self) -> bool
Returns whether the current node is a validator and actually may seal a block if AuRa engine is used.
Used by eth_mining
rpc call.
Sign using the EngineSigner, to be used for consensus tx signing.
fn register_client(&self, _client: Weak<M::EngineClient>)
fn register_client(&self, _client: Weak<M::EngineClient>)
Add Client which can be used for sealing, potentially querying the state and sending messages.
fn snapshot_components(&self) -> Option<Box<dyn SnapshotComponents>>
fn snapshot_components(&self) -> Option<Box<dyn SnapshotComponents>>
Create a factory for building snapshot chunks and restoring from them.
Returning None
indicates that this engine doesn’t support snapshot creation.
fn supports_warp(&self) -> bool
fn supports_warp(&self) -> bool
Whether this engine supports warp sync.
fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64
fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64
Return a new open block header timestamp based on the parent timestamp.
fn is_timestamp_valid(
&self,
header_timestamp: u64,
parent_timestamp: u64
) -> bool
fn is_timestamp_valid(
&self,
header_timestamp: u64,
parent_timestamp: u64
) -> bool
Check whether the parent timestamp is valid.
fn ancestry_actions(
&self,
_header: &Header,
_ancestry: &mut dyn Iterator<Item = ExtendedHeader>
) -> Vec<AncestryAction>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn ancestry_actions(
&self,
_header: &Header,
_ancestry: &mut dyn Iterator<Item = ExtendedHeader>
) -> Vec<AncestryAction>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
the ancestry exists.
Returns author should used when executing tx’s for this block.
fn generate_engine_transactions(
&self,
_block: &ExecutedBlock
) -> Result<Vec<SignedTransaction>, Error>
fn generate_engine_transactions(
&self,
_block: &ExecutedBlock
) -> Result<Vec<SignedTransaction>, Error>
Returns a list of transactions for a new block if we are the author.
This is called when the miner prepares a new block that this node will author and seal. It returns a list of transactions that will be added to the block before any other transactions from the queue. Added for AuRa needs.
fn gas_limit_override(&self, _header: &Header) -> Option<U256>
fn gas_limit_override(&self, _header: &Header) -> Option<U256>
Overrides the block gas limit. Whenever this returns Some
for a header, the next block’s gas limit must be
exactly that value. used by AuRa engine.
Implementations on Foreign Types
sourceimpl Engine<EthereumMachine> for Arc<Ethash>
impl Engine<EthereumMachine> for Arc<Ethash>
sourcefn extra_info(&self, header: &Header) -> BTreeMap<String, String>
fn extra_info(&self, header: &Header) -> BTreeMap<String, String>
Additional engine-specific information for the user/developer concerning header
.
sourcefn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error>
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error>
Apply the block reward on finalisation of the block. This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).