Trait ethcore::engines::Engine
[−]
[src]
pub trait Engine<M: Machine>: Sync + Send { fn name(&self) -> &str; fn machine(&self) -> &M; fn verify_local_seal(&self, header: &M::Header) -> Result<(), M::Error>; fn fork_choice(
&self,
new: &M::ExtendedHeader,
best: &M::ExtendedHeader
) -> ForkChoice; fn seal_fields(&self, _header: &M::Header) -> usize { ... } fn extra_info(&self, _header: &M::Header) -> BTreeMap<String, String> { ... } fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { ... } fn maximum_uncle_age(&self) -> usize { ... } fn on_new_block(
&self,
_block: &mut M::LiveBlock,
_epoch_begin: bool,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Result<(), M::Error> { ... } fn on_close_block(&self, _block: &mut M::LiveBlock) -> Result<(), M::Error> { ... } fn seals_internally(&self) -> Option<bool> { ... } fn generate_seal(&self, _block: &M::LiveBlock, _parent: &M::Header) -> Seal { ... } fn verify_block_basic(&self, _header: &M::Header) -> Result<(), M::Error> { ... } fn verify_block_unordered(
&self,
_header: &M::Header
) -> Result<(), M::Error> { ... } fn verify_block_family(
&self,
_header: &M::Header,
_parent: &M::Header
) -> Result<(), M::Error> { ... } fn verify_block_external(&self, _header: &M::Header) -> Result<(), M::Error> { ... } fn genesis_epoch_data<'a>(
&self,
_header: &M::Header,
_state: &<M as Localized<'a>>::StateContext
) -> Result<Vec<u8>, String> { ... } fn signals_epoch_end<'a>(
&self,
_header: &M::Header,
_aux: <M as Localized<'a>>::AuxiliaryData
) -> EpochChange<M> { ... } fn is_epoch_end(
&self,
_chain_head: &M::Header,
_chain: &Headers<M::Header>,
_transition_store: &PendingTransitionStore
) -> Option<Vec<u8>> { ... } fn epoch_verifier<'a>(
&self,
_header: &M::Header,
_proof: &'a [u8]
) -> ConstructedVerifier<'a, M> { ... } fn populate_from_parent(&self, _header: &mut M::Header, _parent: &M::Header) { ... } fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError> { ... } fn is_proposal(&self, _verified_header: &M::Header) -> bool { ... } fn set_signer(
&self,
_account_provider: Arc<AccountProvider>,
_address: Address,
_password: String
) { ... } fn sign(&self, _hash: H256) -> Result<Signature, M::Error> { ... } fn register_client(&self, _client: Weak<M::EngineClient>) { ... } fn step(&self) { ... } fn stop(&self) { ... } fn snapshot_components(&self) -> Option<Box<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,
_block: &M::LiveBlock,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Vec<AncestryAction> { ... } }
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
fn name(&self) -> &str
The name of this engine.
fn machine(&self) -> &M
Get access to the underlying state machine.
fn verify_local_seal(&self, header: &M::Header) -> Result<(), M::Error>
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: &M::ExtendedHeader,
best: &M::ExtendedHeader
) -> ForkChoice
&self,
new: &M::ExtendedHeader,
best: &M::ExtendedHeader
) -> ForkChoice
Check whether the given new block is the best block, after finalization check.
Provided Methods
fn seal_fields(&self, _header: &M::Header) -> usize
The number of additional header fields required for this engine.
fn extra_info(&self, _header: &M::Header) -> BTreeMap<String, String>
Additional engine-specific information for the user/developer concerning header
.
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize
Maximum number of uncles a block is allowed to declare.
fn maximum_uncle_age(&self) -> usize
The number of generations back that uncles can be.
fn on_new_block(
&self,
_block: &mut M::LiveBlock,
_epoch_begin: bool,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Result<(), M::Error>
&self,
_block: &mut M::LiveBlock,
_epoch_begin: bool,
_ancestry: &mut Iterator<Item = M::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 M::LiveBlock) -> Result<(), M::Error>
Block transformation functions, after the transactions.
fn seals_internally(&self) -> Option<bool>
None means that it requires external input (e.g. PoW) to seal a block. Some(true) means the engine is currently prime for seal generation (i.e. node is the current validator). Some(false) means that the node might seal internally but is not qualified now.
fn generate_seal(&self, _block: &M::LiveBlock, _parent: &M::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.
fn verify_block_basic(&self, _header: &M::Header) -> Result<(), M::Error>
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.
fn verify_block_unordered(&self, _header: &M::Header) -> Result<(), M::Error>
Phase 2 verification. Perform costly checks such as transaction signatures. Returns either a null Ok
or a general error detailing the problem with import.
fn verify_block_family(
&self,
_header: &M::Header,
_parent: &M::Header
) -> Result<(), M::Error>
&self,
_header: &M::Header,
_parent: &M::Header
) -> Result<(), M::Error>
Phase 3 verification. Check block information against parent. Returns either a null Ok
or a general error detailing the problem with import.
fn verify_block_external(&self, _header: &M::Header) -> Result<(), M::Error>
Phase 4 verification. Verify block header against potentially external data.
Should only be called when register_client
has been called previously.
fn genesis_epoch_data<'a>(
&self,
_header: &M::Header,
_state: &<M as Localized<'a>>::StateContext
) -> Result<Vec<u8>, String>
&self,
_header: &M::Header,
_state: &<M as Localized<'a>>::StateContext
) -> Result<Vec<u8>, String>
Genesis epoch data.
fn signals_epoch_end<'a>(
&self,
_header: &M::Header,
_aux: <M as Localized<'a>>::AuxiliaryData
) -> EpochChange<M>
&self,
_header: &M::Header,
_aux: <M as Localized<'a>>::AuxiliaryData
) -> 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.
fn is_epoch_end(
&self,
_chain_head: &M::Header,
_chain: &Headers<M::Header>,
_transition_store: &PendingTransitionStore
) -> Option<Vec<u8>>
&self,
_chain_head: &M::Header,
_chain: &Headers<M::Header>,
_transition_store: &PendingTransitionStore
) -> Option<Vec<u8>>
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.
Return optional transition proof.
fn epoch_verifier<'a>(
&self,
_header: &M::Header,
_proof: &'a [u8]
) -> ConstructedVerifier<'a, M>
&self,
_header: &M::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 M::Header, _parent: &M::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>
Handle any potential consensus messages; updating consensus state and potentially issuing a new one.
fn is_proposal(&self, _verified_header: &M::Header) -> bool
Find out if the block is a proposal block and should not be inserted into the DB. Takes a header of a fully verified block.
fn set_signer(
&self,
_account_provider: Arc<AccountProvider>,
_address: Address,
_password: String
)
&self,
_account_provider: Arc<AccountProvider>,
_address: Address,
_password: String
)
Register an account which signs consensus messages.
fn sign(&self, _hash: H256) -> Result<Signature, M::Error>
Sign using the EngineSigner, to be used for consensus tx signing.
fn register_client(&self, _client: Weak<M::EngineClient>)
Add Client which can be used for sealing, potentially querying the state and sending messages.
fn step(&self)
Trigger next step of the consensus engine.
fn stop(&self)
Stops any services that the may hold the Engine and makes it safe to drop.
fn snapshot_components(&self) -> Option<Box<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
Whether this engine supports warp sync.
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
&self,
header_timestamp: u64,
parent_timestamp: u64
) -> bool
Check whether the parent timestamp is valid.
fn ancestry_actions(
&self,
_block: &M::LiveBlock,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Vec<AncestryAction>
&self,
_block: &M::LiveBlock,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Vec<AncestryAction>
Gather all ancestry actions. Called at the last stage when a block is committed. The Engine must guarantee that the ancestry exists.
Implementations on Foreign Types
impl Engine<EthereumMachine> for Arc<Ethash>
[src]
impl Engine<EthereumMachine> for Arc<Ethash>
fn name(&self) -> &str
[src]
fn name(&self) -> &str
fn machine(&self) -> &EthereumMachine
[src]
fn machine(&self) -> &EthereumMachine
fn seal_fields(&self, _header: &Header) -> usize
[src]
fn seal_fields(&self, _header: &Header) -> usize
fn extra_info(&self, header: &Header) -> BTreeMap<String, String>
[src]
fn extra_info(&self, header: &Header) -> BTreeMap<String, String>
Additional engine-specific information for the user/developer concerning header
.
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize
[src]
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize
fn populate_from_parent(&self, header: &mut Header, parent: &Header)
[src]
fn populate_from_parent(&self, header: &mut Header, parent: &Header)
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error>
[src]
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).
fn verify_local_seal(&self, header: &Header) -> Result<(), Error>
[src]
fn verify_local_seal(&self, header: &Header) -> Result<(), Error>
fn verify_block_basic(&self, header: &Header) -> Result<(), Error>
[src]
fn verify_block_basic(&self, header: &Header) -> Result<(), Error>
fn verify_block_unordered(&self, header: &Header) -> Result<(), Error>
[src]
fn verify_block_unordered(&self, header: &Header) -> Result<(), Error>
fn verify_block_family(
&self,
header: &Header,
parent: &Header
) -> Result<(), Error>
[src]
fn verify_block_family(
&self,
header: &Header,
parent: &Header
) -> Result<(), Error>
fn epoch_verifier<'a>(
&self,
_header: &Header,
_proof: &'a [u8]
) -> ConstructedVerifier<'a, EthereumMachine>
[src]
fn epoch_verifier<'a>(
&self,
_header: &Header,
_proof: &'a [u8]
) -> ConstructedVerifier<'a, EthereumMachine>
fn snapshot_components(&self) -> Option<Box<SnapshotComponents>>
[src]
fn snapshot_components(&self) -> Option<Box<SnapshotComponents>>
fn fork_choice(
&self,
new: &ExtendedHeader,
current: &ExtendedHeader
) -> ForkChoice
[src]
fn fork_choice(
&self,
new: &ExtendedHeader,
current: &ExtendedHeader
) -> ForkChoice
fn maximum_uncle_age(&self) -> usize
[src]
fn maximum_uncle_age(&self) -> usize
fn on_new_block(
&self,
_block: &mut M::LiveBlock,
_epoch_begin: bool,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Result<(), M::Error>
[src]
fn on_new_block(
&self,
_block: &mut M::LiveBlock,
_epoch_begin: bool,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Result<(), M::Error>
fn seals_internally(&self) -> Option<bool>
[src]
fn seals_internally(&self) -> Option<bool>
fn generate_seal(&self, _block: &M::LiveBlock, _parent: &M::Header) -> Seal
[src]
fn generate_seal(&self, _block: &M::LiveBlock, _parent: &M::Header) -> Seal
fn verify_block_external(&self, _header: &M::Header) -> Result<(), M::Error>
[src]
fn verify_block_external(&self, _header: &M::Header) -> Result<(), M::Error>
fn genesis_epoch_data<'a>(
&self,
_header: &M::Header,
_state: &<M as Localized<'a>>::StateContext
) -> Result<Vec<u8>, String>
[src]
fn genesis_epoch_data<'a>(
&self,
_header: &M::Header,
_state: &<M as Localized<'a>>::StateContext
) -> Result<Vec<u8>, String>
fn signals_epoch_end<'a>(
&self,
_header: &M::Header,
_aux: <M as Localized<'a>>::AuxiliaryData
) -> EpochChange<M>
[src]
fn signals_epoch_end<'a>(
&self,
_header: &M::Header,
_aux: <M as Localized<'a>>::AuxiliaryData
) -> EpochChange<M>
fn is_epoch_end(
&self,
_chain_head: &M::Header,
_chain: &Headers<M::Header>,
_transition_store: &PendingTransitionStore
) -> Option<Vec<u8>>
[src]
fn is_epoch_end(
&self,
_chain_head: &M::Header,
_chain: &Headers<M::Header>,
_transition_store: &PendingTransitionStore
) -> Option<Vec<u8>>
fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError>
[src]
fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError>
fn is_proposal(&self, _verified_header: &M::Header) -> bool
[src]
fn is_proposal(&self, _verified_header: &M::Header) -> bool
fn set_signer(
&self,
_account_provider: Arc<AccountProvider>,
_address: Address,
_password: String
)
[src]
fn set_signer(
&self,
_account_provider: Arc<AccountProvider>,
_address: Address,
_password: String
)
fn sign(&self, _hash: H256) -> Result<Signature, M::Error>
[src]
fn sign(&self, _hash: H256) -> Result<Signature, M::Error>
fn register_client(&self, _client: Weak<M::EngineClient>)
[src]
fn register_client(&self, _client: Weak<M::EngineClient>)
fn step(&self)
[src]
fn step(&self)
fn stop(&self)
[src]
fn stop(&self)
fn supports_warp(&self) -> bool
[src]
fn supports_warp(&self) -> bool
fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64
[src]
fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64
fn is_timestamp_valid(
&self,
header_timestamp: u64,
parent_timestamp: u64
) -> bool
[src]
fn is_timestamp_valid(
&self,
header_timestamp: u64,
parent_timestamp: u64
) -> bool
fn ancestry_actions(
&self,
_block: &M::LiveBlock,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Vec<AncestryAction>
[src]
fn ancestry_actions(
&self,
_block: &M::LiveBlock,
_ancestry: &mut Iterator<Item = M::ExtendedHeader>
) -> Vec<AncestryAction>
Implementors
impl Engine<EthereumMachine> for AuthorityRound
impl Engine<EthereumMachine> for BasicAuthority
impl<M: Machine> Engine<M> for InstantSeal<M> where
M::LiveBlock: Transactions,
M::ExtendedHeader: TotalScoredHeader,
<M::ExtendedHeader as TotalScoredHeader>::Value: Ord,impl<M: WithBalances + WithRewards> Engine<M> for NullEngine<M> where
M::ExtendedHeader: TotalScoredHeader,
<M::ExtendedHeader as TotalScoredHeader>::Value: Ord,impl Engine<EthereumMachine> for Tendermint