From 9c051ab7569e2310caf2286efab2814dcaee5802 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 26 Jun 2019 20:16:05 +0800 Subject: [PATCH] Removed machine abstraction from ethcore (#10791) --- ethcore/benches/builtin.rs | 4 +- ethcore/light/src/client/fetch.rs | 5 +- ethcore/light/src/client/mod.rs | 5 +- ethcore/light/src/on_demand/request.rs | 3 +- ethcore/src/client/ancient_import.rs | 5 +- ethcore/src/client/client.rs | 6 +- ethcore/src/engines/authority_round/mod.rs | 21 +++--- ethcore/src/engines/basic_authority.rs | 18 ++--- ethcore/src/engines/block_reward.rs | 6 +- ethcore/src/engines/clique/mod.rs | 12 ++-- ethcore/src/engines/instant_seal.rs | 18 ++--- ethcore/src/engines/mod.rs | 65 ++++++++++--------- ethcore/src/engines/null_engine.rs | 27 ++++---- ethcore/src/engines/validator_set/contract.rs | 6 +- ethcore/src/engines/validator_set/mod.rs | 6 +- ethcore/src/engines/validator_set/multi.rs | 6 +- .../engines/validator_set/safe_contract.rs | 12 ++-- .../src/engines/validator_set/simple_list.rs | 6 +- ethcore/src/engines/validator_set/test.rs | 6 +- ethcore/src/ethereum/ethash.rs | 14 ++-- ethcore/src/ethereum/mod.rs | 20 +++--- ethcore/src/executive.rs | 8 +-- ethcore/src/externalities.rs | 4 +- ethcore/src/json_tests/executive.rs | 2 +- ethcore/src/{machine/impls.rs => machine.rs} | 31 +++++---- ethcore/src/machine/mod.rs | 7 -- ethcore/src/machine/traits.rs | 37 ----------- ethcore/src/snapshot/consensus/authority.rs | 5 +- ethcore/src/spec/spec.rs | 16 ++--- ethcore/src/state/mod.rs | 6 +- ethcore/src/verification/verification.rs | 4 +- parity/light_helpers/epoch_fetch.rs | 3 +- 32 files changed, 171 insertions(+), 223 deletions(-) rename ethcore/src/{machine/impls.rs => machine.rs} (96%) delete mode 100644 ethcore/src/machine/mod.rs delete mode 100644 ethcore/src/machine/traits.rs diff --git a/ethcore/benches/builtin.rs b/ethcore/benches/builtin.rs index 974284bb0..93158cb21 100644 --- a/ethcore/benches/builtin.rs +++ b/ethcore/benches/builtin.rs @@ -28,13 +28,13 @@ extern crate rustc_hex; use criterion::{Criterion, Bencher}; use bytes::BytesRef; use ethcore::builtin::Builtin; -use ethcore::machine::EthereumMachine; +use ethcore::machine::Machine; use ethereum_types::H160; use ethcore::ethereum::new_byzantium_test_machine; use rustc_hex::FromHex; lazy_static! { - static ref BYZANTIUM_MACHINE: EthereumMachine = new_byzantium_test_machine(); + static ref BYZANTIUM_MACHINE: Machine = new_byzantium_test_machine(); } struct BuiltinBenchmark<'a> { diff --git a/ethcore/light/src/client/fetch.rs b/ethcore/light/src/client/fetch.rs index 86a3770bf..dd052917f 100644 --- a/ethcore/light/src/client/fetch.rs +++ b/ethcore/light/src/client/fetch.rs @@ -22,7 +22,6 @@ use common_types::encoded; use common_types::header::Header; use common_types::receipt::Receipt; use ethcore::engines::{EthEngine, StateDependentProof}; -use ethcore::machine::EthereumMachine; use ethereum_types::H256; use futures::future::IntoFuture; @@ -49,7 +48,7 @@ pub trait ChainDataFetcher: Send + Sync + 'static { &self, _hash: H256, _engine: Arc, - _checker: Arc> + _checker: Arc ) -> Self::Transition; } @@ -78,7 +77,7 @@ impl ChainDataFetcher for Unavailable { &self, _hash: H256, _engine: Arc, - _checker: Arc> + _checker: Arc ) -> Self::Transition { Err("fetching epoch transition proofs unavailable") } diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index 6ed2b222e..c6e0925db 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -20,7 +20,6 @@ use std::sync::{Weak, Arc}; use ethcore::client::{ClientReport, EnvInfo, ClientIoMessage}; use ethcore::engines::{epoch, EthEngine, EpochChange, EpochTransition, Proof}; -use ethcore::machine::EthereumMachine; use ethcore::error::{Error, EthcoreResult}; use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::spec::{Spec, SpecHardcodedSync}; @@ -468,7 +467,7 @@ impl Client { true } - fn check_epoch_signal(&self, verified_header: &Header) -> Result>, T::Error> { + fn check_epoch_signal(&self, verified_header: &Header) -> Result, T::Error> { use ethcore::machine::{AuxiliaryRequest, AuxiliaryData}; let mut block: Option> = None; @@ -514,7 +513,7 @@ impl Client { } // attempts to fetch the epoch proof from the network until successful. - fn write_pending_proof(&self, header: &Header, proof: Proof) -> Result<(), T::Error> { + fn write_pending_proof(&self, header: &Header, proof: Proof) -> Result<(), T::Error> { let proof = match proof { Proof::Known(known) => known, Proof::WithState(state_dependent) => { diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index 09433ea23..380a7c933 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -25,7 +25,6 @@ use common_types::encoded; use common_types::receipt::Receipt; use common_types::transaction::SignedTransaction; use ethcore::engines::{EthEngine, StateDependentProof}; -use ethcore::machine::EthereumMachine; use ethcore::state::{self, ProvedExecution}; use ethereum_types::{H256, U256, Address}; use ethtrie::{TrieError, TrieDB}; @@ -1083,7 +1082,7 @@ pub struct Signal { /// Consensus engine, used to check the proof. pub engine: Arc, /// Special checker for the proof. - pub proof_check: Arc>, + pub proof_check: Arc, } impl Signal { diff --git a/ethcore/src/client/ancient_import.rs b/ethcore/src/client/ancient_import.rs index 46cd519a7..9dc5e97b9 100644 --- a/ethcore/src/client/ancient_import.rs +++ b/ethcore/src/client/ancient_import.rs @@ -19,7 +19,6 @@ use std::sync::Arc; use engines::{EthEngine, EpochVerifier}; -use machine::EthereumMachine; use blockchain::BlockChain; use parking_lot::RwLock; @@ -32,7 +31,7 @@ const HEAVY_VERIFY_RATE: f32 = 0.02; /// Ancient block verifier: import an ancient sequence of blocks in order from a starting /// epoch. pub struct AncientVerifier { - cur_verifier: RwLock>>>, + cur_verifier: RwLock>>, engine: Arc, } @@ -87,7 +86,7 @@ impl AncientVerifier { } fn initial_verifier(&self, header: &Header, chain: &BlockChain) - -> Result>, ::error::Error> + -> Result, ::error::Error> { trace!(target: "client", "Initializing ancient block restoration."); let current_epoch_data = chain.epoch_transitions() diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 0a755bbe0..26a58fc86 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -1248,7 +1248,7 @@ impl Client { } fn do_virtual_call( - machine: &::machine::EthereumMachine, + machine: &::machine::Machine, env_info: &EnvInfo, state: &mut State, t: &SignedTransaction, @@ -1257,7 +1257,7 @@ impl Client { fn call( state: &mut State, env_info: &EnvInfo, - machine: &::machine::EthereumMachine, + machine: &::machine::Machine, state_diff: bool, transaction: &SignedTransaction, options: TransactOptions, @@ -2561,7 +2561,7 @@ impl SnapshotClient for Client {} /// Returns `LocalizedReceipt` given `LocalizedTransaction` /// and a vector of receipts from given block up to transaction index. fn transaction_receipt( - machine: &::machine::EthereumMachine, + machine: &::machine::Machine, mut tx: LocalizedTransaction, receipt: Receipt, prior_gas_used: U256, diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 44c10b4c2..a62d744a4 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -31,7 +31,7 @@ use engines::block_reward; use engines::block_reward::{BlockRewardContract, RewardKind}; use error::{Error, BlockError}; use ethjson; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use machine::{AuxiliaryData, Call, Machine}; use hash::keccak; use super::signer::EngineSigner; use super::validator_set::{ValidatorSet, SimpleList, new_validator_set}; @@ -221,7 +221,7 @@ impl EpochManager { fn zoom_to_after( &mut self, client: &dyn EngineClient, - machine: &EthereumMachine, + machine: &Machine, validators: &dyn ValidatorSet, hash: H256 ) -> bool { @@ -440,7 +440,7 @@ pub struct AuthorityRound { empty_steps_transition: u64, strict_empty_steps_transition: u64, maximum_empty_steps: usize, - machine: EthereumMachine, + machine: Machine, } // header-chain validator. @@ -450,7 +450,7 @@ struct EpochVerifier { empty_steps_transition: u64, } -impl super::EpochVerifier for EpochVerifier { +impl super::EpochVerifier for EpochVerifier { fn verify_light(&self, header: &Header) -> Result<(), Error> { // Validate the timestamp verify_timestamp(&self.step.inner, header_step(header, self.empty_steps_transition)?)?; @@ -671,7 +671,7 @@ impl<'a, A: ?Sized, B> Deref for CowLike<'a, A, B> where B: AsRef { impl AuthorityRound { /// Create a new instance of AuthorityRound engine. - pub fn new(our_params: AuthorityRoundParams, machine: EthereumMachine) -> Result, Error> { + pub fn new(our_params: AuthorityRoundParams, machine: Machine) -> Result, Error> { if our_params.step_duration == 0 { error!(target: "engine", "Authority Round step duration can't be zero, aborting"); panic!("authority_round: step duration can't be zero") @@ -941,10 +941,10 @@ impl IoHandler<()> for TransitionHandler { } } -impl Engine for AuthorityRound { +impl Engine for AuthorityRound { fn name(&self) -> &str { "AuthorityRound" } - fn machine(&self) -> &EthereumMachine { &self.machine } + fn machine(&self) -> &Machine { &self.machine } /// Three fields - consensus step and the corresponding proposer signature, and a list of empty /// step messages (which should be empty if no steps are skipped) @@ -1429,7 +1429,7 @@ impl Engine for AuthorityRound { } fn signals_epoch_end(&self, header: &Header, aux: AuxiliaryData) - -> super::EpochChange + -> super::EpochChange { if self.immediate_transitions { return super::EpochChange::No } @@ -1551,7 +1551,7 @@ impl Engine for AuthorityRound { None } - fn epoch_verifier<'a>(&self, _header: &Header, proof: &'a [u8]) -> ConstructedVerifier<'a, EthereumMachine> { + fn epoch_verifier<'a>(&self, _header: &Header, proof: &'a [u8]) -> ConstructedVerifier<'a> { let (signal_number, set_proof, finality_proof) = match destructure_proofs(proof) { Ok(x) => x, Err(e) => return ConstructedVerifier::Err(e), @@ -1640,6 +1640,7 @@ mod tests { use engines::validator_set::{TestSet, SimpleList}; use error::Error; use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score}; + use machine::Machine; fn build_aura(f: F) -> Arc where F: FnOnce(&mut AuthorityRoundParams), @@ -1666,7 +1667,7 @@ mod tests { // create engine let mut c_params = ::spec::CommonParams::default(); c_params.gas_limit_bound_divisor = 5.into(); - let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); + let machine = Machine::regular(c_params, Default::default()); AuthorityRound::new(params, machine).unwrap() } diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 098c3f558..18afc51ce 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -26,7 +26,7 @@ use engines::signer::EngineSigner; use error::{BlockError, Error}; use ethjson; use client::EngineClient; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use machine::{AuxiliaryData, Call, Machine}; use types::header::{Header, ExtendedHeader}; use super::validator_set::{ValidatorSet, SimpleList, new_validator_set}; @@ -49,7 +49,7 @@ struct EpochVerifier { list: SimpleList, } -impl super::EpochVerifier for EpochVerifier { +impl super::EpochVerifier for EpochVerifier { fn verify_light(&self, header: &Header) -> Result<(), Error> { verify_external(header, &self.list) } @@ -74,14 +74,14 @@ fn verify_external(header: &Header, validators: &dyn ValidatorSet) -> Result<(), /// Engine using `BasicAuthority`, trivial proof-of-authority consensus. pub struct BasicAuthority { - machine: EthereumMachine, + machine: Machine, signer: RwLock>>, validators: Box, } impl BasicAuthority { /// Create a new instance of BasicAuthority engine - pub fn new(our_params: BasicAuthorityParams, machine: EthereumMachine) -> Self { + pub fn new(our_params: BasicAuthorityParams, machine: Machine) -> Self { BasicAuthority { machine: machine, signer: RwLock::new(None), @@ -90,10 +90,10 @@ impl BasicAuthority { } } -impl Engine for BasicAuthority { +impl Engine for BasicAuthority { fn name(&self) -> &str { "BasicAuthority" } - fn machine(&self) -> &EthereumMachine { &self.machine } + fn machine(&self) -> &Machine { &self.machine } // One field - the signature fn seal_fields(&self, _header: &Header) -> usize { 1 } @@ -135,7 +135,7 @@ impl Engine for BasicAuthority { #[cfg(not(test))] fn signals_epoch_end(&self, _header: &Header, _auxiliary: AuxiliaryData) - -> super::EpochChange + -> super::EpochChange { // don't bother signalling even though a contract might try. super::EpochChange::No @@ -143,7 +143,7 @@ impl Engine for BasicAuthority { #[cfg(test)] fn signals_epoch_end(&self, header: &Header, auxiliary: AuxiliaryData) - -> super::EpochChange + -> super::EpochChange { // in test mode, always signal even though they don't be finalized. let first = header.number() == 0; @@ -172,7 +172,7 @@ impl Engine for BasicAuthority { self.is_epoch_end(chain_head, &[], chain, transition_store) } - fn epoch_verifier<'a>(&self, header: &Header, proof: &'a [u8]) -> ConstructedVerifier<'a, EthereumMachine> { + fn epoch_verifier<'a>(&self, header: &Header, proof: &'a [u8]) -> ConstructedVerifier<'a> { let first = header.number() == 0; match self.validators.epoch_set(first, &self.machine, header.number(), proof) { diff --git a/ethcore/src/engines/block_reward.rs b/ethcore/src/engines/block_reward.rs index 42b08560f..c7266368d 100644 --- a/ethcore/src/engines/block_reward.rs +++ b/ethcore/src/engines/block_reward.rs @@ -153,11 +153,11 @@ impl BlockRewardContract { /// Applies the given block rewards, i.e. adds the given balance to each beneficiary' address. /// If tracing is enabled the operations are recorded. -pub fn apply_block_rewards( +pub fn apply_block_rewards( rewards: &[(Address, RewardKind, U256)], block: &mut ExecutedBlock, - machine: &M, -) -> Result<(), M::Error> { + machine: &Machine, +) -> Result<(), Error> { for &(ref author, _, ref block_reward) in rewards { machine.add_balance(block, author, block_reward)?; } diff --git a/ethcore/src/engines/clique/mod.rs b/ethcore/src/engines/clique/mod.rs index 158274778..9c8e1823f 100644 --- a/ethcore/src/engines/clique/mod.rs +++ b/ethcore/src/engines/clique/mod.rs @@ -76,7 +76,7 @@ use ethkey::Signature; use hash::KECCAK_EMPTY_LIST_RLP; use itertools::Itertools; use lru_cache::LruCache; -use machine::{Call, EthereumMachine}; +use machine::{Call, Machine}; use parking_lot::RwLock; use rand::Rng; use super::signer::EngineSigner; @@ -159,7 +159,7 @@ impl VoteType { pub struct Clique { epoch_length: u64, period: u64, - machine: EthereumMachine, + machine: Machine, client: RwLock>>, block_state_by_hash: RwLock>, proposals: RwLock>, @@ -171,7 +171,7 @@ pub struct Clique { pub struct Clique { pub epoch_length: u64, pub period: u64, - pub machine: EthereumMachine, + pub machine: Machine, pub client: RwLock>>, pub block_state_by_hash: RwLock>, pub proposals: RwLock>, @@ -180,7 +180,7 @@ pub struct Clique { impl Clique { /// Initialize Clique engine from empty state. - pub fn new(params: CliqueParams, machine: EthereumMachine) -> Result, Error> { + pub fn new(params: CliqueParams, machine: Machine) -> Result, Error> { /// Step Clique at most every 2 seconds const SEALING_FREQ: Duration = Duration::from_secs(2); @@ -354,10 +354,10 @@ impl Clique { } } -impl Engine for Clique { +impl Engine for Clique { fn name(&self) -> &str { "Clique" } - fn machine(&self) -> &EthereumMachine { &self.machine } + fn machine(&self) -> &Machine { &self.machine } // Clique use same fields, nonce + mixHash fn seal_fields(&self, _header: &Header) -> usize { 2 } diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 2daa0aa55..27f133424 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -18,6 +18,7 @@ use engines::{Engine, Seal, SealingState}; use machine::Machine; use types::header::{Header, ExtendedHeader}; use block::ExecutedBlock; +use error::Error; /// `InstantSeal` params. #[derive(Default, Debug, PartialEq)] @@ -36,26 +37,27 @@ impl From<::ethjson::spec::InstantSealParams> for InstantSealParams { /// An engine which does not provide any consensus mechanism, just seals blocks internally. /// Only seals blocks which have transactions. -pub struct InstantSeal { +pub struct InstantSeal { params: InstantSealParams, - machine: M, + machine: Machine, } -impl InstantSeal { +impl InstantSeal { /// Returns new instance of InstantSeal over the given state machine. - pub fn new(params: InstantSealParams, machine: M) -> Self { + pub fn new(params: InstantSealParams, machine: Machine) -> Self { InstantSeal { - params, machine, + params, + machine, } } } -impl Engine for InstantSeal { +impl Engine for InstantSeal { fn name(&self) -> &str { "InstantSeal" } - fn machine(&self) -> &M { &self.machine } + fn machine(&self) -> &Machine { &self.machine } fn sealing_state(&self) -> SealingState { SealingState::Ready } @@ -67,7 +69,7 @@ impl Engine for InstantSeal { } } - fn verify_local_seal(&self, _header: &Header) -> Result<(), M::Error> { + fn verify_local_seal(&self, _header: &Header) -> Result<(), Error> { Ok(()) } diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index da49e21ea..8dcc36de1 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -49,6 +49,7 @@ use types::header::{Header, ExtendedHeader}; use snapshot::SnapshotComponents; use spec::CommonParams; use types::transaction::{self, UnverifiedTransaction, SignedTransaction}; +use client::EngineClient; use ethkey::{Signature}; use machine::{self, Machine, AuxiliaryRequest, AuxiliaryData}; @@ -190,7 +191,7 @@ pub enum SystemOrCodeCallKind { } /// Default SystemOrCodeCall implementation. -pub fn default_system_or_code_call<'a>(machine: &'a ::machine::EthereumMachine, block: &'a mut ::block::ExecutedBlock) -> impl FnMut(SystemOrCodeCallKind, Vec) -> Result, String> + 'a { +pub fn default_system_or_code_call<'a>(machine: &'a ::machine::Machine, block: &'a mut ::block::ExecutedBlock) -> impl FnMut(SystemOrCodeCallKind, Vec) -> Result, String> + 'a { move |to, data| { let result = match to { SystemOrCodeCallKind::Address(address) => { @@ -226,38 +227,38 @@ pub type Headers<'a, H> = dyn Fn(H256) -> Option + 'a; pub type PendingTransitionStore<'a> = dyn Fn(H256) -> Option + 'a; /// Proof dependent on state. -pub trait StateDependentProof: Send + Sync { +pub trait StateDependentProof: Send + Sync { /// Generate a proof, given the state. fn generate_proof<'a>(&self, state: &machine::Call) -> Result, String>; /// Check a proof generated elsewhere (potentially by a peer). // `engine` needed to check state proofs, while really this should // just be state machine params. - fn check_proof(&self, machine: &M, proof: &[u8]) -> Result<(), String>; + fn check_proof(&self, machine: &Machine, proof: &[u8]) -> Result<(), String>; } /// Proof generated on epoch change. -pub enum Proof { +pub enum Proof { /// Known proof (extracted from signal) Known(Vec), /// State dependent proof. - WithState(Arc>), + WithState(Arc), } /// Generated epoch verifier. -pub enum ConstructedVerifier<'a, M: Machine> { +pub enum ConstructedVerifier<'a> { /// Fully trusted verifier. - Trusted(Box>), + Trusted(Box), /// Verifier unconfirmed. Check whether given finality proof finalizes given hash /// under previous epoch. - Unconfirmed(Box>, &'a [u8], H256), + Unconfirmed(Box, &'a [u8], H256), /// Error constructing verifier. Err(Error), } -impl<'a, M: Machine> ConstructedVerifier<'a, M> { +impl<'a> ConstructedVerifier<'a> { /// Convert to a result, indicating that any necessary confirmation has been done /// already. - pub fn known_confirmed(self) -> Result>, Error> { + pub fn known_confirmed(self) -> Result, Error> { match self { ConstructedVerifier::Trusted(v) | ConstructedVerifier::Unconfirmed(v, _, _) => Ok(v), ConstructedVerifier::Err(e) => Err(e), @@ -266,24 +267,24 @@ impl<'a, M: Machine> ConstructedVerifier<'a, M> { } /// Results of a query of whether an epoch change occurred at the given block. -pub enum EpochChange { +pub enum EpochChange { /// Cannot determine until more data is passed. Unsure(AuxiliaryRequest), /// No epoch change. No, /// The epoch will change, with proof. - Yes(Proof), + Yes(Proof), } /// 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: Sync + Send { +pub trait Engine: Sync + Send { /// The name of this engine. fn name(&self) -> &str; /// Get access to the underlying state machine. // TODO: decouple. - fn machine(&self) -> &M; + fn machine(&self) -> &Machine; /// The number of additional header fields required for this engine. fn seal_fields(&self, _header: &Header) -> usize { 0 } @@ -304,12 +305,12 @@ pub trait Engine: Sync + Send { _block: &mut ExecutedBlock, _epoch_begin: bool, _ancestry: &mut dyn Iterator, - ) -> Result<(), M::Error> { + ) -> Result<(), Error> { Ok(()) } /// Block transformation functions, after the transactions. - fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<(), M::Error> { + fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { Ok(()) } @@ -340,22 +341,22 @@ pub trait Engine: Sync + Send { /// /// It is fine to require access to state or a full client for this function, since /// light clients do not generate seals. - fn verify_local_seal(&self, header: &Header) -> Result<(), M::Error>; + fn verify_local_seal(&self, header: &Header) -> Result<(), 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. /// The verification module can optionally avoid checking the seal (`check_seal`), if seal verification is disabled this method won't be called. - fn verify_block_basic(&self, _header: &Header) -> Result<(), M::Error> { Ok(()) } + fn verify_block_basic(&self, _header: &Header) -> Result<(), Error> { Ok(()) } /// 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. - fn verify_block_unordered(&self, _header: &Header) -> Result<(), M::Error> { Ok(()) } + fn verify_block_unordered(&self, _header: &Header) -> Result<(), Error> { Ok(()) } /// 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_family(&self, _header: &Header, _parent: &Header) -> Result<(), M::Error> { Ok(()) } + fn verify_block_family(&self, _header: &Header, _parent: &Header) -> Result<(), Error> { Ok(()) } /// Phase 4 verification. Verify block header against potentially external data. /// Should only be called when `register_client` has been called previously. - fn verify_block_external(&self, _header: &Header) -> Result<(), M::Error> { Ok(()) } + fn verify_block_external(&self, _header: &Header) -> Result<(), Error> { Ok(()) } /// Genesis epoch data. fn genesis_epoch_data<'a>(&self, _header: &Header, _state: &machine::Call) -> Result, String> { Ok(Vec::new()) } @@ -370,7 +371,7 @@ pub trait Engine: Sync + Send { /// /// Should not interact with state. fn signals_epoch_end<'a>(&self, _header: &Header, _aux: AuxiliaryData<'a>) - -> EpochChange + -> EpochChange { EpochChange::No } @@ -413,7 +414,7 @@ pub trait Engine: Sync + Send { /// Create an epoch verifier from validation proof and a flag indicating /// whether finality is required. - 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> { ConstructedVerifier::Trusted(Box::new(NoOp)) } @@ -429,10 +430,10 @@ pub trait Engine: Sync + Send { fn set_signer(&self, _signer: Box) {} /// Sign using the EngineSigner, to be used for consensus tx signing. - fn sign(&self, _hash: H256) -> Result { unimplemented!() } + fn sign(&self, _hash: H256) -> Result { unimplemented!() } /// Add Client which can be used for sealing, potentially querying the state and sending messages. - fn register_client(&self, _client: Weak) {} + fn register_client(&self, _client: Weak) {} /// Trigger next step of the consensus engine. fn step(&self) {} @@ -489,7 +490,7 @@ pub fn total_difficulty_fork_choice(new: &ExtendedHeader, best: &ExtendedHeader) // TODO: make this a _trait_ alias when those exist. // fortunately the effect is largely the same since engines are mostly used // via trait objects. -pub trait EthEngine: Engine<::machine::EthereumMachine> { +pub trait EthEngine: Engine { /// Get the general parameters of the chain. fn params(&self) -> &CommonParams { self.machine().params() @@ -569,16 +570,16 @@ pub trait EthEngine: Engine<::machine::EthereumMachine> { } // convenience wrappers for existing functions. -impl EthEngine for T where T: Engine<::machine::EthereumMachine> { } +impl EthEngine for T where T: Engine { } /// Verifier for all blocks within an epoch with self-contained state. -pub trait EpochVerifier: Send + Sync { +pub trait EpochVerifier: Send + Sync { /// Lightly verify the next block header. /// This may not be a header belonging to a different epoch. - fn verify_light(&self, header: &Header) -> Result<(), M::Error>; + fn verify_light(&self, header: &Header) -> Result<(), Error>; /// Perform potentially heavier checks on the next block header. - fn verify_heavy(&self, header: &Header) -> Result<(), M::Error> { + fn verify_heavy(&self, header: &Header) -> Result<(), Error> { self.verify_light(header) } @@ -593,6 +594,6 @@ pub trait EpochVerifier: Send + Sync { /// Special "no-op" verifier for stateless, epoch-less engines. pub struct NoOp; -impl EpochVerifier for NoOp { - fn verify_light(&self, _header: &Header) -> Result<(), M::Error> { Ok(()) } +impl EpochVerifier for NoOp { + fn verify_light(&self, _header: &Header) -> Result<(), Error> { Ok(()) } } diff --git a/ethcore/src/engines/null_engine.rs b/ethcore/src/engines/null_engine.rs index 42cb9b5b4..a29196977 100644 --- a/ethcore/src/engines/null_engine.rs +++ b/ethcore/src/engines/null_engine.rs @@ -21,6 +21,7 @@ use machine::Machine; use types::BlockNumber; use types::header::{Header, ExtendedHeader}; use block::ExecutedBlock; +use error::Error; /// Params for a null engine. #[derive(Clone, Default)] @@ -38,35 +39,29 @@ impl From<::ethjson::spec::NullEngineParams> for NullEngineParams { } /// An engine which does not provide any consensus mechanism and does not seal blocks. -pub struct NullEngine { +pub struct NullEngine { params: NullEngineParams, - machine: M, + machine: Machine, } -impl NullEngine { +impl NullEngine { /// Returns new instance of NullEngine with default VM Factory - pub fn new(params: NullEngineParams, machine: M) -> Self { + pub fn new(params: NullEngineParams, machine: Machine) -> Self { NullEngine { - params: params, - machine: machine, + params, + machine, } } } -impl Default for NullEngine { - fn default() -> Self { - Self::new(Default::default(), Default::default()) - } -} - -impl Engine for NullEngine { +impl Engine for NullEngine { fn name(&self) -> &str { "NullEngine" } - fn machine(&self) -> &M { &self.machine } + fn machine(&self) -> &Machine { &self.machine } - fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), M::Error> { + fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> { use std::ops::Shr; let author = *block.header.author(); @@ -95,7 +90,7 @@ impl Engine for NullEngine { fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { 2 } - fn verify_local_seal(&self, _header: &Header) -> Result<(), M::Error> { + fn verify_local_seal(&self, _header: &Header) -> Result<(), Error> { Ok(()) } diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index 5560447c4..c1bf7a155 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -21,7 +21,7 @@ use std::sync::Weak; use bytes::Bytes; use ethereum_types::{H256, Address}; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use machine::{AuxiliaryData, Call, Machine}; use parking_lot::RwLock; use types::BlockNumber; use types::header::Header; @@ -89,11 +89,11 @@ impl ValidatorSet for ValidatorContract { first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange { + ) -> ::engines::EpochChange { self.validators.signals_epoch_end(first, header, aux) } - fn epoch_set(&self, first: bool, machine: &EthereumMachine, number: BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { + fn epoch_set(&self, first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { self.validators.epoch_set(first, machine, number, proof) } diff --git a/ethcore/src/engines/validator_set/mod.rs b/ethcore/src/engines/validator_set/mod.rs index 8d3193709..865c45484 100644 --- a/ethcore/src/engines/validator_set/mod.rs +++ b/ethcore/src/engines/validator_set/mod.rs @@ -28,7 +28,7 @@ use std::sync::Weak; use bytes::Bytes; use ethereum_types::{H256, Address}; use ethjson::spec::ValidatorSet as ValidatorSpec; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use machine::{AuxiliaryData, Call, Machine}; use types::BlockNumber; use types::header::Header; use types::ids::BlockId; @@ -113,7 +113,7 @@ pub trait ValidatorSet: Send + Sync + 'static { first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange; + ) -> ::engines::EpochChange; /// Recover the validator set from the given proof, the block number, and /// whether this header is first in its set. @@ -123,7 +123,7 @@ pub trait ValidatorSet: Send + Sync + 'static { /// /// Returns the set, along with a flag indicating whether finality of a specific /// hash should be proven. - fn epoch_set(&self, first: bool, machine: &EthereumMachine, number: BlockNumber, proof: &[u8]) + fn epoch_set(&self, first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option), ::error::Error>; /// Checks if a given address is a validator, with the given function diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 1d115bf5d..0f6dd41af 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -27,7 +27,7 @@ use types::header::Header; use types::ids::BlockId; use client::EngineClient; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use machine::{AuxiliaryData, Call, Machine}; use super::{SystemCall, ValidatorSet}; type BlockNumberLookup = Box Result + Send + Sync + 'static>; @@ -96,7 +96,7 @@ impl ValidatorSet for Multi { } fn signals_epoch_end(&self, _first: bool, header: &Header, aux: AuxiliaryData) - -> ::engines::EpochChange + -> ::engines::EpochChange { let (set_block, set) = self.correct_set_by_number(header.number()); let first = set_block == header.number(); @@ -104,7 +104,7 @@ impl ValidatorSet for Multi { set.signals_epoch_end(first, header, aux) } - fn epoch_set(&self, _first: bool, machine: &EthereumMachine, number: BlockNumber, proof: &[u8]) -> Result<(super::SimpleList, Option), ::error::Error> { + fn epoch_set(&self, _first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(super::SimpleList, Option), ::error::Error> { let (set_block, set) = self.correct_set_by_number(number); let first = set_block == number; diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 18477d64d..65f572355 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -33,7 +33,7 @@ use types::receipt::Receipt; use unexpected::Mismatch; use client::EngineClient; -use machine::{AuxiliaryData, Call, EthereumMachine, AuxiliaryRequest}; +use machine::{AuxiliaryData, Call, Machine, AuxiliaryRequest}; use super::{SystemCall, ValidatorSet}; use super::simple_list::SimpleList; @@ -55,12 +55,12 @@ struct StateProof { header: Header, } -impl ::engines::StateDependentProof for StateProof { +impl ::engines::StateDependentProof for StateProof { fn generate_proof(&self, caller: &Call) -> Result, String> { prove_initial(self.contract_address, &self.header, caller) } - fn check_proof(&self, machine: &EthereumMachine, proof: &[u8]) -> Result<(), String> { + fn check_proof(&self, machine: &Machine, proof: &[u8]) -> Result<(), String> { let (header, state_items) = decode_first_proof(&Rlp::new(proof)) .map_err(|e| format!("proof incorrectly encoded: {}", e))?; if &header != &self.header { @@ -90,7 +90,7 @@ fn encode_first_proof(header: &Header, state_items: &[Vec]) -> Bytes { } // check a first proof: fetch the validator set at the given block. -fn check_first_proof(machine: &EthereumMachine, contract_address: Address, old_header: Header, state_items: &[DBValue]) +fn check_first_proof(machine: &Machine, contract_address: Address, old_header: Header, state_items: &[DBValue]) -> Result, String> { use types::transaction::{Action, Transaction}; @@ -308,7 +308,7 @@ impl ValidatorSet for ValidatorSafeContract { } fn signals_epoch_end(&self, first: bool, header: &Header, aux: AuxiliaryData) - -> ::engines::EpochChange + -> ::engines::EpochChange { let receipts = aux.receipts; @@ -345,7 +345,7 @@ impl ValidatorSet for ValidatorSafeContract { } } - fn epoch_set(&self, first: bool, machine: &EthereumMachine, _number: ::types::BlockNumber, proof: &[u8]) + fn epoch_set(&self, first: bool, machine: &Machine, _number: ::types::BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { let rlp = Rlp::new(proof); diff --git a/ethcore/src/engines/validator_set/simple_list.rs b/ethcore/src/engines/validator_set/simple_list.rs index 80a34268e..613b10880 100644 --- a/ethcore/src/engines/validator_set/simple_list.rs +++ b/ethcore/src/engines/validator_set/simple_list.rs @@ -19,7 +19,7 @@ use parity_util_mem::MallocSizeOf; use ethereum_types::{H256, Address}; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use machine::{AuxiliaryData, Call, Machine}; use types::BlockNumber; use types::header::Header; use super::ValidatorSet; @@ -73,12 +73,12 @@ impl ValidatorSet for SimpleList { } fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) - -> ::engines::EpochChange + -> ::engines::EpochChange { ::engines::EpochChange::No } - fn epoch_set(&self, _first: bool, _: &EthereumMachine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { + fn epoch_set(&self, _first: bool, _: &Machine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { Ok((self.clone(), None)) } diff --git a/ethcore/src/engines/validator_set/test.rs b/ethcore/src/engines/validator_set/test.rs index b82bcfe12..dd84a84f8 100644 --- a/ethcore/src/engines/validator_set/test.rs +++ b/ethcore/src/engines/validator_set/test.rs @@ -26,7 +26,7 @@ use ethereum_types::{H256, Address}; use types::BlockNumber; use types::header::Header; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use machine::{AuxiliaryData, Call, Machine}; use super::{ValidatorSet, SimpleList}; /// Set used for testing with a single validator. @@ -67,12 +67,12 @@ impl ValidatorSet for TestSet { fn is_epoch_end(&self, _first: bool, _chain_head: &Header) -> Option> { None } fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) - -> ::engines::EpochChange + -> ::engines::EpochChange { ::engines::EpochChange::No } - fn epoch_set(&self, _: bool, _: &EthereumMachine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { + fn epoch_set(&self, _: bool, _: &Machine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { Ok((self.validator.clone(), None)) } diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 4fcf7f098..c29f960e5 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -32,7 +32,7 @@ use engines::block_reward::{self, BlockRewardContract, RewardKind}; use engines::{self, Engine}; use error::{BlockError, Error}; use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor}; -use machine::EthereumMachine; +use machine::Machine; /// Number of blocks in an ethash snapshot. // make dependent on difficulty incrment divisor? @@ -174,7 +174,7 @@ impl From for EthashParams { pub struct Ethash { ethash_params: EthashParams, pow: EthashManager, - machine: EthereumMachine, + machine: Machine, } impl Ethash { @@ -182,7 +182,7 @@ impl Ethash { pub fn new>>( cache_dir: &Path, ethash_params: EthashParams, - machine: EthereumMachine, + machine: Machine, optimize_for: T, ) -> Arc { let progpow_transition = ethash_params.progpow_transition; @@ -203,16 +203,16 @@ impl Ethash { // for any block in the chain. // in the future, we might move the Ethash epoch // caching onto this mechanism as well. -impl engines::EpochVerifier for Arc { +impl engines::EpochVerifier for Arc { fn verify_light(&self, _header: &Header) -> Result<(), Error> { Ok(()) } fn verify_heavy(&self, header: &Header) -> Result<(), Error> { self.verify_block_unordered(header) } } -impl Engine for Arc { +impl Engine for Arc { fn name(&self) -> &str { "Ethash" } - fn machine(&self) -> &EthereumMachine { &self.machine } + fn machine(&self) -> &Machine { &self.machine } // Two fields - nonce and mix. fn seal_fields(&self, _header: &Header) -> usize { 2 } @@ -373,7 +373,7 @@ impl Engine for Arc { Ok(()) } - fn epoch_verifier<'a>(&self, _header: &Header, _proof: &'a [u8]) -> engines::ConstructedVerifier<'a, EthereumMachine> { + fn epoch_verifier<'a>(&self, _header: &Header, _proof: &'a [u8]) -> engines::ConstructedVerifier<'a> { engines::ConstructedVerifier::Trusted(Box::new(self.clone())) } diff --git a/ethcore/src/ethereum/mod.rs b/ethcore/src/ethereum/mod.rs index 38bf970a8..01d1ccf80 100644 --- a/ethcore/src/ethereum/mod.rs +++ b/ethcore/src/ethereum/mod.rs @@ -27,7 +27,7 @@ pub mod denominations; pub use self::ethash::{Ethash}; pub use self::denominations::*; -use machine::EthereumMachine; +use machine::Machine; use super::spec::*; /// Load chain spec from `SpecParams` and JSON. @@ -38,7 +38,7 @@ pub fn load<'a, T: Into>>>(params: T, b: &[u8]) -> Spec { }.expect("chain spec is invalid") } -fn load_machine(b: &[u8]) -> EthereumMachine { +fn load_machine(b: &[u8]) -> Machine { Spec::load_machine(b).expect("chain spec is invalid") } @@ -162,28 +162,28 @@ pub fn new_mcip3_test() -> Spec { load(None, include_bytes!("../../res/ethereum/ // For tests /// Create a new Foundation Frontier-era chain spec as though it never changes to Homestead. -pub fn new_frontier_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/frontier_test.json")) } +pub fn new_frontier_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/frontier_test.json")) } /// Create a new Foundation Homestead-era chain spec as though it never changed from Frontier. -pub fn new_homestead_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/homestead_test.json")) } +pub fn new_homestead_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/homestead_test.json")) } /// Create a new Foundation Homestead-EIP210-era chain spec as though it never changed from Homestead/Frontier. -pub fn new_eip210_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/eip210_test.json")) } +pub fn new_eip210_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/eip210_test.json")) } /// Create a new Foundation Byzantium era spec. -pub fn new_byzantium_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/byzantium_test.json")) } +pub fn new_byzantium_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/byzantium_test.json")) } /// Create a new Foundation Constantinople era spec. -pub fn new_constantinople_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/constantinople_test.json")) } +pub fn new_constantinople_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/constantinople_test.json")) } /// Create a new Foundation St. Peter's (Contantinople Fix) era spec. -pub fn new_constantinople_fix_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/st_peters_test.json")) } +pub fn new_constantinople_fix_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/st_peters_test.json")) } /// Create a new Musicoin-MCIP3-era spec. -pub fn new_mcip3_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/mcip3_test.json")) } +pub fn new_mcip3_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/mcip3_test.json")) } /// Create new Kovan spec with wasm activated at certain block -pub fn new_kovan_wasm_test_machine() -> EthereumMachine { load_machine(include_bytes!("../../res/ethereum/kovan_wasm_test.json")) } +pub fn new_kovan_wasm_test_machine() -> Machine { load_machine(include_bytes!("../../res/ethereum/kovan_wasm_test.json")) } #[cfg(test)] mod tests { diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index e14a43787..8c8ace25c 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -23,7 +23,7 @@ use ethereum_types::{H256, U256, U512, Address}; use bytes::{Bytes, BytesRef}; use state::{Backend as StateBackend, State, Substate, CleanupMode}; use executed::ExecutionError; -use machine::EthereumMachine as Machine; +use machine::Machine; use evm::{CallType, Finalize, FinalizationResult}; use vm::{ self, EnvInfo, CreateContractAddress, ReturnData, CleanDustMode, ActionParams, @@ -1179,7 +1179,7 @@ mod tests { use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress}; use evm::{Factory, VMType}; use error::ExecutionError; - use machine::EthereumMachine; + use machine::Machine; use state::{Substate, CleanupMode}; use test_helpers::{get_temp_state_with_factory, get_temp_state}; use trace::trace; @@ -1187,13 +1187,13 @@ mod tests { use trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, VMTracer, NoopVMTracer, ExecutiveVMTracer}; use types::transaction::{Action, Transaction}; - fn make_frontier_machine(max_depth: usize) -> EthereumMachine { + fn make_frontier_machine(max_depth: usize) -> Machine { let mut machine = ::ethereum::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } - fn make_byzantium_machine(max_depth: usize) -> EthereumMachine { + fn make_byzantium_machine(max_depth: usize) -> Machine { let mut machine = ::ethereum::new_byzantium_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 2d831290a..d5ffb5dbc 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use ethereum_types::{H256, U256, Address, BigEndianHash}; use bytes::Bytes; use state::{Backend as StateBackend, State, Substate, CleanupMode}; -use machine::EthereumMachine as Machine; +use machine::Machine; use executive::*; use vm::{ self, ActionParams, ActionValue, EnvInfo, CallType, Schedule, @@ -458,7 +458,7 @@ mod tests { struct TestSetup { state: State<::state_db::StateDB>, - machine: ::machine::EthereumMachine, + machine: ::machine::Machine, schedule: Schedule, sub_state: Substate, env_info: EnvInfo diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index dafc29e41..3c2792740 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -34,7 +34,7 @@ use bytes::Bytes; use ethtrie; use rlp::RlpStream; use hash::keccak; -use machine::EthereumMachine as Machine; +use machine::Machine; use ethereum_types::BigEndianHash; use super::HookType; diff --git a/ethcore/src/machine/impls.rs b/ethcore/src/machine.rs similarity index 96% rename from ethcore/src/machine/impls.rs rename to ethcore/src/machine.rs index ec14f1f95..10f3078c6 100644 --- a/ethcore/src/machine/impls.rs +++ b/ethcore/src/machine.rs @@ -70,7 +70,7 @@ impl From<::ethjson::spec::EthashParams> for EthashExtensions { pub type ScheduleCreationRules = dyn Fn(&mut Schedule, BlockNumber) + Sync + Send; /// An ethereum-like state machine. -pub struct EthereumMachine { +pub struct Machine { params: CommonParams, builtins: Arc>, tx_filter: Option>, @@ -78,11 +78,11 @@ pub struct EthereumMachine { schedule_rules: Option>, } -impl EthereumMachine { +impl Machine { /// Regular ethereum machine. - pub fn regular(params: CommonParams, builtins: BTreeMap) -> EthereumMachine { + pub fn regular(params: CommonParams, builtins: BTreeMap) -> Machine { let tx_filter = TransactionFilter::from_params(¶ms).map(Arc::new); - EthereumMachine { + Machine { params: params, builtins: Arc::new(builtins), tx_filter: tx_filter, @@ -93,8 +93,8 @@ impl EthereumMachine { /// Ethereum machine with ethash extensions. // TODO: either unify or specify to mainnet specifically and include other specific-chain HFs? - pub fn with_ethash_extensions(params: CommonParams, builtins: BTreeMap, extensions: EthashExtensions) -> EthereumMachine { - let mut machine = EthereumMachine::regular(params, builtins); + pub fn with_ethash_extensions(params: CommonParams, builtins: BTreeMap, extensions: EthashExtensions) -> Machine { + let mut machine = Machine::regular(params, builtins); machine.ethash_extensions = Some(extensions); machine } @@ -110,7 +110,7 @@ impl EthereumMachine { } } -impl EthereumMachine { +impl Machine { /// Execute a call as the system address. Block environment information passed to the /// VM is modified to have its gas limit bounded at the upper limit of possible used /// gases including this system call, capped at the maximum value able to be @@ -428,16 +428,15 @@ pub enum AuxiliaryRequest { Both, } -impl super::Machine for EthereumMachine { - type EngineClient = dyn (::client::EngineClient); - - type Error = Error; - - fn balance(&self, live: &ExecutedBlock, address: &Address) -> Result { +impl Machine { + /// Get the balance, in base units, associated with an account. + /// Extracts data from the live block. + pub fn balance(&self, live: &ExecutedBlock, address: &Address) -> Result { live.state.balance(address).map_err(Into::into) } - fn add_balance(&self, live: &mut ExecutedBlock, address: &Address, amount: &U256) -> Result<(), Error> { + /// Increment the balance of an account in the state of the live block. + pub fn add_balance(&self, live: &mut ExecutedBlock, address: &Address, amount: &U256) -> Result<(), Error> { live.state_mut().add_balance(address, amount, CleanupMode::NoEmpty).map_err(Into::into) } } @@ -480,7 +479,7 @@ mod tests { let spec = ::ethereum::new_ropsten_test(); let ethparams = get_default_ethash_extensions(); - let machine = EthereumMachine::with_ethash_extensions( + let machine = Machine::with_ethash_extensions( spec.params().clone(), Default::default(), ethparams, @@ -499,7 +498,7 @@ mod tests { let spec = ::ethereum::new_homestead_test(); let ethparams = get_default_ethash_extensions(); - let machine = EthereumMachine::with_ethash_extensions( + let machine = Machine::with_ethash_extensions( spec.params().clone(), Default::default(), ethparams, diff --git a/ethcore/src/machine/mod.rs b/ethcore/src/machine/mod.rs deleted file mode 100644 index 882dc011a..000000000 --- a/ethcore/src/machine/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! Generalization of a state machine for a consensus engine. - -mod impls; -mod traits; - -pub use self::impls::*; -pub use self::traits::*; diff --git a/ethcore/src/machine/traits.rs b/ethcore/src/machine/traits.rs deleted file mode 100644 index 1523885e0..000000000 --- a/ethcore/src/machine/traits.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Generalization of a state machine for a consensus engine. -//! This will define traits for the header, block, and state of a blockchain. - -use ethereum_types::{U256, Address}; -use block::ExecutedBlock; - -/// Generalization of types surrounding blockchain-suitable state machines. -pub trait Machine: Send + Sync { - /// A handle to a blockchain client for this machine. - type EngineClient: ?Sized; - - /// Errors which can occur when querying or interacting with the machine. - type Error; - - /// Get the balance, in base units, associated with an account. - /// Extracts data from the live block. - fn balance(&self, live: &ExecutedBlock, address: &Address) -> Result; - - /// Increment the balance of an account in the state of the live block. - fn add_balance(&self, live: &mut ExecutedBlock, address: &Address, amount: &U256) -> Result<(), Self::Error>; -} diff --git a/ethcore/src/snapshot/consensus/authority.rs b/ethcore/src/snapshot/consensus/authority.rs index 08a1f8afe..621d98451 100644 --- a/ethcore/src/snapshot/consensus/authority.rs +++ b/ethcore/src/snapshot/consensus/authority.rs @@ -25,7 +25,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use engines::{EthEngine, EpochVerifier, EpochTransition}; -use machine::EthereumMachine; use snapshot::{Error, ManifestData, Progress}; use blockchain::{BlockChain, BlockChainDB, BlockProvider}; @@ -171,7 +170,7 @@ struct ChunkRebuilder { // and epoch data from last blocks in chunks. // verification for these will be done at the end. unverified_firsts: Vec<(Header, Bytes, H256)>, - last_epochs: Vec<(Header, Box>)>, + last_epochs: Vec<(Header, Box)>, } // verified data. @@ -183,7 +182,7 @@ struct Verified { impl ChunkRebuilder { fn verify_transition( &mut self, - last_verifier: &mut Option>>, + last_verifier: &mut Option>, transition_rlp: Rlp, engine: &dyn EthEngine, ) -> Result { diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index c09bbc8d1..140bd8264 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -41,7 +41,7 @@ use engines::{ use error::Error; use executive::Executive; use factory::Factories; -use machine::EthereumMachine; +use machine::Machine; use pod_state::PodState; use spec::Genesis; use spec::seal::Generic as GenericSeal; @@ -488,7 +488,7 @@ impl From for ethjson::spec::HardcodedSync { } } -fn load_machine_from(s: ethjson::spec::Spec) -> EthereumMachine { +fn load_machine_from(s: ethjson::spec::Spec) -> Machine { let builtins = s.accounts.builtins().into_iter().map(|p| (p.0.into(), From::from(p.1))).collect(); let params = CommonParams::from(s.params); @@ -586,11 +586,11 @@ impl Spec { engine_spec: ðjson::spec::Engine, params: CommonParams, builtins: BTreeMap, - ) -> EthereumMachine { + ) -> Machine { if let ethjson::spec::Engine::Ethash(ref ethash) = *engine_spec { - EthereumMachine::with_ethash_extensions(params, builtins, ethash.params.clone().into()) + Machine::with_ethash_extensions(params, builtins, ethash.params.clone().into()) } else { - EthereumMachine::regular(params, builtins) + Machine::regular(params, builtins) } } @@ -824,7 +824,7 @@ impl Spec { } /// Loads just the state machine from a json file. - pub fn load_machine(reader: R) -> Result { + pub fn load_machine(reader: R) -> Result { ethjson::spec::Spec::load(reader) .map_err(fmt_err) .map(load_machine_from) @@ -912,9 +912,9 @@ impl Spec { load_bundled!("null_morden") } - /// Create the EthereumMachine corresponding to Spec::new_test. + /// Create the Machine corresponding to Spec::new_test. #[cfg(any(test, feature = "test-helpers"))] - pub fn new_test_machine() -> EthereumMachine { load_machine_bundled!("null_morden") } + pub fn new_test_machine() -> Machine { load_machine_bundled!("null_morden") } /// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus with applying reward on block close. #[cfg(any(test, feature = "test-helpers"))] diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index a2f07e141..62e2465d4 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -27,7 +27,7 @@ use std::sync::Arc; use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY}; use types::receipt::{Receipt, TransactionOutcome}; -use machine::EthereumMachine as Machine; +use machine::Machine; use vm::EnvInfo; use error::Error; use executive::{Executive, TransactOptions}; @@ -1345,7 +1345,7 @@ mod tests { use ethkey::Secret; use ethereum_types::{H256, U256, Address, BigEndianHash}; use test_helpers::{get_temp_state, get_temp_state_db}; - use machine::EthereumMachine; + use machine::Machine; use vm::EnvInfo; use spec::*; use types::transaction::*; @@ -1356,7 +1356,7 @@ mod tests { keccak("").into() } - fn make_frontier_machine(max_depth: usize) -> EthereumMachine { + fn make_frontier_machine(max_depth: usize) -> Machine { let mut machine = ::ethereum::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index beebb155a..87a19697c 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -788,7 +788,7 @@ mod tests { fn dust_protection() { use ethkey::{Generator, Random}; use types::transaction::{Transaction, Action}; - use machine::EthereumMachine; + use machine::Machine; use engines::NullEngine; let mut params = CommonParams::default(); @@ -810,7 +810,7 @@ mod tests { let good_transactions = [bad_transactions[0].clone(), bad_transactions[1].clone()]; - let machine = EthereumMachine::regular(params, BTreeMap::new()); + let machine = Machine::regular(params, BTreeMap::new()); let engine = NullEngine::new(Default::default(), machine); check_fail(unordered_test(&create_test_block_with_data(&header, &bad_transactions, &[]), &engine), TooManyTransactions(keypair.address())); unordered_test(&create_test_block_with_data(&header, &good_transactions, &[]), &engine).unwrap(); diff --git a/parity/light_helpers/epoch_fetch.rs b/parity/light_helpers/epoch_fetch.rs index 9c7fd6a8e..38c277cb6 100644 --- a/parity/light_helpers/epoch_fetch.rs +++ b/parity/light_helpers/epoch_fetch.rs @@ -17,7 +17,6 @@ use std::sync::{Arc, Weak}; use ethcore::engines::{EthEngine, StateDependentProof}; -use ethcore::machine::EthereumMachine; use sync::{LightSync, LightNetworkDispatcher}; use types::encoded; use types::header::Header; @@ -82,7 +81,7 @@ impl ChainDataFetcher for EpochFetch { } /// Fetch epoch transition proof at given header. - fn epoch_transition(&self, hash: H256, engine: Arc, checker: Arc>) + fn epoch_transition(&self, hash: H256, engine: Arc, checker: Arc) -> Self::Transition { self.request(request::Signal {