openethereum/src/engine.rs

69 lines
3.3 KiB
Rust
Raw Normal View History

use std::collections::hash_map::*;
use util::bytes::*;
use util::uint::*;
use util::rlp::*;
use util::semantic_version::*;
use util::error::*;
2015-12-20 16:12:53 +01:00
use header::Header;
use transaction::Transaction;
use spec::Spec;
use evm_schedule::EvmSchedule;
use env_info::EnvInfo;
/// 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.
pub trait Engine {
/// The name of this engine.
fn name(&self) -> &str;
/// The version of this engine. Should be of the form
2015-12-20 16:12:53 +01:00
fn version(&self) -> SemanticVersion { SemanticVersion::new(0, 0, 0) }
/// The number of additional header fields required for this engine.
fn seal_fields(&self) -> u32 { 0 }
/// Default values of the additional fields RLP-encoded in a raw (non-list) harness.
fn seal_rlp(&self) -> Bytes { vec![] }
/// Additional engine-specific information for the user/developer concerning `header`.
fn extra_info(&self, _header: &Header) -> HashMap<String, String> { HashMap::new() }
2015-12-20 16:12:53 +01:00
/// Get the general parameters of the chain.
fn spec(&self) -> &Spec;
2015-12-20 16:12:53 +01:00
2015-12-23 12:56:38 +01:00
/// Get the EVM schedule for the given `env_info`.
fn evm_schedule(&self, env_info: &EnvInfo) -> EvmSchedule;
2015-12-20 16:12:53 +01:00
/// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`.
fn maximum_extra_data_size(&self, _env_info: &EnvInfo) -> usize { decode(&self.spec().engine_params.get("maximum_extra_data_size").unwrap()) }
fn account_start_nonce(&self, _env_info: &EnvInfo) -> U256 { decode(&self.spec().engine_params.get("account_start_nonce").unwrap()) }
// TODO: refactor in terms of `on_preseal_block`
fn block_reward(&self, _env_info: &EnvInfo) -> U256 { decode(&self.spec().engine_params.get("block_reward").unwrap()) }
/// Block transformation functions, before and after the transactions.
// fn on_new_block(&self, _env_info: &EnvInfo, _block: &mut Block) -> Result<(), EthcoreError> {}
// fn on_preseal_block(&self, _env_info: &EnvInfo, _block: &mut Block) -> Result<(), EthcoreError> {}
/// Verify that `header` is valid.
/// `parent` (the parent header) and `block` (the header's full block) may be provided for additional
/// checks. Returns either a null `Ok` or a general error detailing the problem with import.
2015-12-23 12:56:38 +01:00
// TODO: consider including State in the params.
fn verify(&self, _header: &Header, _parent: Option<&Header>, _block: Option<&[u8]>) -> Result<(), EthcoreError> { Ok(()) }
2015-12-20 16:12:53 +01:00
/// Additional verification for transactions in blocks.
2015-12-20 16:12:53 +01:00
// TODO: Add flags for which bits of the transaction to check.
2015-12-23 12:56:38 +01:00
// TODO: consider including State in the params.
2015-12-20 16:12:53 +01:00
fn verify_transaction(&self, _t: &Transaction, _header: &Header) -> Result<(), EthcoreError> { Ok(()) }
2015-12-20 16:12:53 +01:00
/// Don't forget to call Super::populateFromParent when subclassing & overriding.
2015-12-23 12:56:38 +01:00
// TODO: consider including State in the params.
2015-12-20 16:12:53 +01:00
fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) -> Result<(), EthcoreError> { Ok(()) }
2016-01-07 23:55:14 +01:00
// TODO: builtin contract routing - to do this properly, it will require removing the built-in configuration-reading logic
// from Spec into here and removing the Spec::builtins field.
/* fn is_builtin(&self, a: Address) -> bool;
fn cost_of_builtin(&self, a: Address, in: &[u8]) -> bignum;
fn execute_builtin(&self, a: Address, in: &[u8], out: &mut [u8]);
*/
2015-12-23 12:56:38 +01:00
// TODO: sealing stuff - though might want to leave this for later.
}