diff --git a/ethcore/light/src/client/fetch.rs b/ethcore/light/src/client/fetch.rs index dd052917fc5..373f6f0bd0b 100644 --- a/ethcore/light/src/client/fetch.rs +++ b/ethcore/light/src/client/fetch.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use common_types::encoded; use common_types::header::Header; use common_types::receipt::Receipt; -use ethcore::engines::{EthEngine, StateDependentProof}; +use ethcore::engines::{Engine, StateDependentProof}; use ethereum_types::H256; use futures::future::IntoFuture; @@ -47,7 +47,7 @@ pub trait ChainDataFetcher: Send + Sync + 'static { fn epoch_transition( &self, _hash: H256, - _engine: Arc, + _engine: Arc, _checker: Arc ) -> Self::Transition; } @@ -76,7 +76,7 @@ impl ChainDataFetcher for Unavailable { fn epoch_transition( &self, _hash: H256, - _engine: Arc, + _engine: 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 c6e0925dbac..bcabd809c5c 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -19,7 +19,7 @@ use std::sync::{Weak, Arc}; use ethcore::client::{ClientReport, EnvInfo, ClientIoMessage}; -use ethcore::engines::{epoch, EthEngine, EpochChange, EpochTransition, Proof}; +use ethcore::engines::{epoch, Engine, EpochChange, EpochTransition, Proof}; use ethcore::error::{Error, EthcoreResult}; use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::spec::{Spec, SpecHardcodedSync}; @@ -114,7 +114,7 @@ pub trait LightChainClient: Send + Sync { fn env_info(&self, id: BlockId) -> Option; /// Get a handle to the consensus engine. - fn engine(&self) -> &Arc; + fn engine(&self) -> &Arc; /// Query whether a block is known. fn is_known(&self, hash: &H256) -> bool; @@ -159,7 +159,7 @@ impl AsLightClient for T { /// Light client implementation. pub struct Client { queue: HeaderQueue, - engine: Arc, + engine: Arc, chain: HeaderChain, report: RwLock, import_lock: Mutex<()>, @@ -375,7 +375,7 @@ impl Client { } /// Get a handle to the verification engine. - pub fn engine(&self) -> &Arc { + pub fn engine(&self) -> &Arc { &self.engine } @@ -578,7 +578,7 @@ impl LightChainClient for Client { Client::env_info(self, id) } - fn engine(&self) -> &Arc { + fn engine(&self) -> &Arc { Client::engine(self) } diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index 380a7c93335..b2bf39951f3 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -24,7 +24,7 @@ use common_types::basic_account::BasicAccount; use common_types::encoded; use common_types::receipt::Receipt; use common_types::transaction::SignedTransaction; -use ethcore::engines::{EthEngine, StateDependentProof}; +use ethcore::engines::{Engine, StateDependentProof}; use ethcore::state::{self, ProvedExecution}; use ethereum_types::{H256, U256, Address}; use ethtrie::{TrieError, TrieDB}; @@ -1037,7 +1037,7 @@ pub struct TransactionProof { // TODO: it's not really possible to provide this if the header is unknown. pub env_info: EnvInfo, /// Consensus engine. - pub engine: Arc, + pub engine: Arc, } impl TransactionProof { @@ -1080,7 +1080,7 @@ pub struct Signal { /// Block hash and number to fetch proof for. pub hash: H256, /// Consensus engine, used to check the proof. - pub engine: Arc, + pub engine: Arc, /// Special checker for the proof. pub proof_check: Arc, } diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index d672668f733..d2cb128c48c 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -38,7 +38,7 @@ use std::sync::Arc; use bytes::Bytes; use ethereum_types::{H256, U256, Address, Bloom}; -use engines::EthEngine; +use engines::Engine; use error::{Error, BlockError}; use factory::Factories; use state_db::StateDB; @@ -61,7 +61,7 @@ use types::receipt::{Receipt, TransactionOutcome}; /// maintain the system `state()`. We also archive execution receipts in preparation for later block creation. pub struct OpenBlock<'x> { block: ExecutedBlock, - engine: &'x dyn EthEngine, + engine: &'x dyn Engine, } /// Just like `OpenBlock`, except that we've applied `Engine::on_close_block`, finished up the non-seal header fields, @@ -163,7 +163,7 @@ pub trait Drain { impl<'x> OpenBlock<'x> { /// Create a new `OpenBlock` ready for transaction pushing. pub fn new<'a, I: IntoIterator>( - engine: &'x dyn EthEngine, + engine: &'x dyn Engine, factories: Factories, tracing: bool, db: StateDB, @@ -374,7 +374,7 @@ impl ClosedBlock { } /// Given an engine reference, reopen the `ClosedBlock` into an `OpenBlock`. - pub fn reopen(self, engine: &dyn EthEngine) -> OpenBlock { + pub fn reopen(self, engine: &dyn Engine) -> OpenBlock { // revert rewards (i.e. set state back at last transaction's state). let mut block = self.block; block.state = self.unclosed_state; @@ -404,7 +404,7 @@ impl LockedBlock { /// Provide a valid seal in order to turn this into a `SealedBlock`. /// /// NOTE: This does not check the validity of `seal` with the engine. - pub fn seal(self, engine: &dyn EthEngine, seal: Vec) -> Result { + pub fn seal(self, engine: &dyn Engine, seal: Vec) -> Result { let expected_seal_fields = engine.seal_fields(&self.header); let mut s = self; if seal.len() != expected_seal_fields { @@ -429,7 +429,7 @@ impl LockedBlock { /// TODO(https://github.com/paritytech/parity-ethereum/issues/10407): This is currently only used in POW chain call paths, we should really merge it with seal() above. pub fn try_seal( self, - engine: &dyn EthEngine, + engine: &dyn Engine, seal: Vec, ) -> Result { let mut s = self; @@ -472,7 +472,7 @@ pub(crate) fn enact( header: Header, transactions: Vec, uncles: Vec
, - engine: &dyn EthEngine, + engine: &dyn Engine, tracing: bool, db: StateDB, parent: &Header, @@ -525,7 +525,7 @@ pub(crate) fn enact( /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header pub fn enact_verified( block: PreverifiedBlock, - engine: &dyn EthEngine, + engine: &dyn Engine, tracing: bool, db: StateDB, parent: &Header, @@ -554,7 +554,7 @@ pub fn enact_verified( mod tests { use test_helpers::get_temp_state_db; use super::*; - use engines::EthEngine; + use engines::Engine; use vm::LastHashes; use error::Error; use factory::Factories; @@ -571,7 +571,7 @@ mod tests { /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header fn enact_bytes( block_bytes: Vec, - engine: &dyn EthEngine, + engine: &dyn Engine, tracing: bool, db: StateDB, parent: &Header, @@ -624,7 +624,7 @@ mod tests { /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header. Seal the block aferwards fn enact_and_seal( block_bytes: Vec, - engine: &dyn EthEngine, + engine: &dyn Engine, tracing: bool, db: StateDB, parent: &Header, diff --git a/ethcore/src/client/ancient_import.rs b/ethcore/src/client/ancient_import.rs index 9dc5e97b9f8..f89afa13a3f 100644 --- a/ethcore/src/client/ancient_import.rs +++ b/ethcore/src/client/ancient_import.rs @@ -18,7 +18,7 @@ use std::sync::Arc; -use engines::{EthEngine, EpochVerifier}; +use engines::{Engine, EpochVerifier}; use blockchain::BlockChain; use parking_lot::RwLock; @@ -32,12 +32,12 @@ const HEAVY_VERIFY_RATE: f32 = 0.02; /// epoch. pub struct AncientVerifier { cur_verifier: RwLock>>, - engine: Arc, + engine: Arc, } impl AncientVerifier { /// Create a new ancient block verifier with the given engine. - pub fn new(engine: Arc) -> Self { + pub fn new(engine: Arc) -> Self { AncientVerifier { cur_verifier: RwLock::new(None), engine, diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 26a58fc867e..2aa6cfddea7 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -60,7 +60,7 @@ use client::{ IoClient, BadBlocks, }; use client::bad_blocks; -use engines::{MAX_UNCLE_AGE, EthEngine, EpochTransition, ForkChoice, EngineError, SealingState}; +use engines::{MAX_UNCLE_AGE, Engine, EpochTransition, ForkChoice, EngineError, SealingState}; use engines::epoch::PendingTransition; use error::{ ImportError, ExecutionError, CallError, BlockError, @@ -165,7 +165,7 @@ struct Importer { pub ancient_verifier: AncientVerifier, /// Ethereum engine to be used during import - pub engine: Arc, + pub engine: Arc, /// A lru cache of recently detected bad blocks pub bad_blocks: bad_blocks::BadBlocks, @@ -187,7 +187,7 @@ pub struct Client { chain: RwLock>, tracedb: RwLock>, - engine: Arc, + engine: Arc, /// Client configuration config: ClientConfig, @@ -245,7 +245,7 @@ pub struct Client { impl Importer { pub fn new( config: &ClientConfig, - engine: Arc, + engine: Arc, message_channel: IoChannel, miner: Arc, ) -> Result { @@ -857,7 +857,7 @@ impl Client { } /// Returns engine reference. - pub fn engine(&self) -> &dyn EthEngine { + pub fn engine(&self) -> &dyn Engine { &*self.engine } @@ -1661,7 +1661,7 @@ impl Call for Client { } impl EngineInfo for Client { - fn engine(&self) -> &dyn EthEngine { + fn engine(&self) -> &dyn Engine { Client::engine(self) } } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 1b28ca2cdbd..cefa2a193b9 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -59,7 +59,7 @@ use client::{ Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, IoClient, BadBlocks }; -use engines::EthEngine; +use engines::Engine; use error::{Error, EthcoreResult}; use executed::CallError; use executive::Executed; @@ -627,7 +627,7 @@ impl StateClient for TestBlockChainClient { } impl EngineInfo for TestBlockChainClient { - fn engine(&self) -> &dyn EthEngine { + fn engine(&self) -> &dyn Engine { unimplemented!() } } diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 9d0b27fc709..6f1bd595e90 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -43,7 +43,7 @@ use vm::LastHashes; use block::{OpenBlock, SealedBlock, ClosedBlock}; use client::Mode; -use engines::EthEngine; +use engines::Engine; use error::{Error, EthcoreResult}; use executed::CallError; use executive::Executed; @@ -184,7 +184,7 @@ pub trait Call { /// Provides `engine` method pub trait EngineInfo { /// Get underlying engine object - fn engine(&self) -> &dyn EthEngine; + fn engine(&self) -> &dyn Engine; } /// IO operations that should off-load heavy work to another thread. diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index a62d744a464..97305efad84 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -1636,7 +1636,7 @@ mod tests { }; use spec::Spec; use types::transaction::{Action, Transaction}; - use engines::{Seal, Engine, EngineError, EthEngine}; + use engines::{Seal, Engine, EngineError}; use engines::validator_set::{TestSet, SimpleList}; use error::Error; use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score}; @@ -1942,14 +1942,14 @@ mod tests { (spec, tap, accounts) } - fn empty_step(engine: &dyn EthEngine, step: u64, parent_hash: &H256) -> EmptyStep { + fn empty_step(engine: &dyn Engine, step: u64, parent_hash: &H256) -> EmptyStep { let empty_step_rlp = super::empty_step_rlp(step, parent_hash); let signature = engine.sign(keccak(&empty_step_rlp)).unwrap().into(); let parent_hash = parent_hash.clone(); EmptyStep { step, signature, parent_hash } } - fn sealed_empty_step(engine: &dyn EthEngine, step: u64, parent_hash: &H256) -> SealedEmptyStep { + fn sealed_empty_step(engine: &dyn Engine, step: u64, parent_hash: &H256) -> SealedEmptyStep { let empty_step_rlp = super::empty_step_rlp(step, parent_hash); let signature = engine.sign(keccak(&empty_step_rlp)).unwrap().into(); SealedEmptyStep { signature, step } diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 8dcc36de158..9edd5814a4b 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -475,22 +475,7 @@ pub trait Engine: Sync + Send { fn executive_author(&self, header: &Header) -> Result { Ok(*header.author()) } -} - -/// Check whether a given block is the best block based on the default total difficulty rule. -pub fn total_difficulty_fork_choice(new: &ExtendedHeader, best: &ExtendedHeader) -> ForkChoice { - if new.total_score() > best.total_score() { - ForkChoice::New - } else { - ForkChoice::Old - } -} -/// Common type alias for an engine coupled with an Ethereum-like state machine. -// 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 { /// Get the general parameters of the chain. fn params(&self) -> &CommonParams { self.machine().params() @@ -569,8 +554,14 @@ pub trait EthEngine: Engine { } } -// convenience wrappers for existing functions. -impl EthEngine for T where T: Engine { } +/// Check whether a given block is the best block based on the default total difficulty rule. +pub fn total_difficulty_fork_choice(new: &ExtendedHeader, best: &ExtendedHeader) -> ForkChoice { + if new.total_score() > best.total_score() { + ForkChoice::New + } else { + ForkChoice::Old + } +} /// Verifier for all blocks within an epoch with self-contained state. pub trait EpochVerifier: Send + Sync { diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 0bd40d1c8d1..2cba11b65b3 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -53,7 +53,7 @@ use client::{ BlockChain, ChainInfo, BlockProducer, SealedBlockImporter, Nonce, TransactionInfo, TransactionId }; use client::{BlockId, ClientIoMessage}; -use engines::{EthEngine, Seal, SealingState, EngineSigner}; +use engines::{Engine, Seal, SealingState, EngineSigner}; use error::Error; use executed::ExecutionError; use executive::contract_address; @@ -245,7 +245,7 @@ pub struct Miner { options: MinerOptions, // TODO [ToDr] Arc is only required because of price updater transaction_queue: Arc, - engine: Arc, + engine: Arc, accounts: Arc, io_channel: RwLock>>, service_transaction_checker: Option, diff --git a/ethcore/src/miner/pool_client.rs b/ethcore/src/miner/pool_client.rs index 98431b45852..b197e56f6c4 100644 --- a/ethcore/src/miner/pool_client.rs +++ b/ethcore/src/miner/pool_client.rs @@ -37,7 +37,7 @@ use parking_lot::RwLock; use call_contract::CallContract; use client::{TransactionId, BlockInfo, Nonce}; -use engines::EthEngine; +use engines::Engine; use miner; use transaction_ext::Transaction; @@ -72,7 +72,7 @@ impl NonceCache { pub struct PoolClient<'a, C: 'a> { chain: &'a C, cached_nonces: CachedNonceClient<'a, C>, - engine: &'a dyn EthEngine, + engine: &'a dyn Engine, accounts: &'a dyn LocalAccounts, best_block_header: Header, service_transaction_checker: Option<&'a ServiceTransactionChecker>, @@ -98,7 +98,7 @@ impl<'a, C: 'a> PoolClient<'a, C> where pub fn new( chain: &'a C, cache: &'a NonceCache, - engine: &'a dyn EthEngine, + engine: &'a dyn Engine, accounts: &'a dyn LocalAccounts, service_transaction_checker: Option<&'a ServiceTransactionChecker>, ) -> Self { diff --git a/ethcore/src/snapshot/consensus/authority.rs b/ethcore/src/snapshot/consensus/authority.rs index 621d9845121..4ff812bdb54 100644 --- a/ethcore/src/snapshot/consensus/authority.rs +++ b/ethcore/src/snapshot/consensus/authority.rs @@ -24,7 +24,7 @@ use super::{SnapshotComponents, Rebuilder, ChunkSink}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use engines::{EthEngine, EpochVerifier, EpochTransition}; +use engines::{Engine, EpochVerifier, EpochTransition}; use snapshot::{Error, ManifestData, Progress}; use blockchain::{BlockChain, BlockChainDB, BlockProvider}; @@ -184,7 +184,7 @@ impl ChunkRebuilder { &mut self, last_verifier: &mut Option>, transition_rlp: Rlp, - engine: &dyn EthEngine, + engine: &dyn Engine, ) -> Result { use engines::ConstructedVerifier; @@ -240,7 +240,7 @@ impl Rebuilder for ChunkRebuilder { fn feed( &mut self, chunk: &[u8], - engine: &dyn EthEngine, + engine: &dyn Engine, abort_flag: &AtomicBool, ) -> Result<(), ::error::Error> { let rlp = Rlp::new(chunk); @@ -348,7 +348,7 @@ impl Rebuilder for ChunkRebuilder { Ok(()) } - fn finalize(&mut self, _engine: &dyn EthEngine) -> Result<(), ::error::Error> { + fn finalize(&mut self, _engine: &dyn Engine) -> Result<(), ::error::Error> { if !self.had_genesis { return Err(Error::WrongChunkFormat("No genesis transition included.".into()).into()); } diff --git a/ethcore/src/snapshot/consensus/mod.rs b/ethcore/src/snapshot/consensus/mod.rs index 670700c10cf..4262248b1db 100644 --- a/ethcore/src/snapshot/consensus/mod.rs +++ b/ethcore/src/snapshot/consensus/mod.rs @@ -21,7 +21,7 @@ use std::sync::atomic::AtomicBool; use std::sync::Arc; use blockchain::{BlockChain, BlockChainDB}; -use engines::EthEngine; +use engines::Engine; use snapshot::{Error, ManifestData, Progress}; use ethereum_types::H256; @@ -83,7 +83,7 @@ pub trait Rebuilder: Send { fn feed( &mut self, chunk: &[u8], - engine: &dyn EthEngine, + engine: &dyn Engine, abort_flag: &AtomicBool, ) -> Result<(), ::error::Error>; @@ -92,5 +92,5 @@ pub trait Rebuilder: Send { /// /// This should apply the necessary "glue" between chunks, /// and verify against the restored state. - fn finalize(&mut self, engine: &dyn EthEngine) -> Result<(), ::error::Error>; + fn finalize(&mut self, engine: &dyn Engine) -> Result<(), ::error::Error>; } diff --git a/ethcore/src/snapshot/consensus/work.rs b/ethcore/src/snapshot/consensus/work.rs index 201d528d140..4bb0c758a7f 100644 --- a/ethcore/src/snapshot/consensus/work.rs +++ b/ethcore/src/snapshot/consensus/work.rs @@ -27,7 +27,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use blockchain::{BlockChain, BlockChainDB, BlockProvider}; -use engines::EthEngine; +use engines::Engine; use snapshot::{Error, ManifestData, Progress}; use snapshot::block::AbridgedBlock; use ethereum_types::H256; @@ -224,7 +224,7 @@ impl PowRebuilder { impl Rebuilder for PowRebuilder { /// Feed the rebuilder an uncompressed block chunk. /// Returns the number of blocks fed or any errors. - fn feed(&mut self, chunk: &[u8], engine: &dyn EthEngine, abort_flag: &AtomicBool) -> Result<(), ::error::Error> { + fn feed(&mut self, chunk: &[u8], engine: &dyn Engine, abort_flag: &AtomicBool) -> Result<(), ::error::Error> { use snapshot::verify_old_block; use ethereum_types::U256; use triehash::ordered_trie_root; @@ -298,7 +298,7 @@ impl Rebuilder for PowRebuilder { } /// Glue together any disconnected chunks and check that the chain is complete. - fn finalize(&mut self, _: &dyn EthEngine) -> Result<(), ::error::Error> { + fn finalize(&mut self, _: &dyn Engine) -> Result<(), ::error::Error> { let mut batch = self.db.transaction(); for (first_num, first_hash) in self.disconnected.drain(..) { diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 96136b042fd..d5ce8c2b179 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -27,7 +27,7 @@ use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY}; use account_db::{AccountDB, AccountDBMut}; use blockchain::{BlockChain, BlockProvider}; -use engines::EthEngine; +use engines::Engine; use types::header::Header; use types::ids::BlockId; @@ -578,7 +578,7 @@ const POW_VERIFY_RATE: f32 = 0.02; /// Verify an old block with the given header, engine, blockchain, body. If `always` is set, it will perform /// the fullest verification possible. If not, it will take a random sample to determine whether it will /// do heavy or light verification. -pub fn verify_old_block(rng: &mut OsRng, header: &Header, engine: &dyn EthEngine, chain: &BlockChain, always: bool) -> Result<(), ::error::Error> { +pub fn verify_old_block(rng: &mut OsRng, header: &Header, engine: &dyn Engine, chain: &BlockChain, always: bool) -> Result<(), ::error::Error> { engine.verify_block_basic(header)?; if always || rng.gen::() <= POW_VERIFY_RATE { diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index a9ff866ebed..3e914035e90 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -29,7 +29,7 @@ use super::io::{SnapshotReader, LooseReader, SnapshotWriter, LooseWriter}; use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler}; use client::{BlockInfo, BlockChainClient, Client, ChainInfo, ClientIoMessage}; -use engines::EthEngine; +use engines::Engine; use error::Error; use snapshot::{Error as SnapshotError}; use hash::keccak; @@ -91,7 +91,7 @@ struct RestorationParams<'a> { writer: Option, // writer for recovered snapshot. genesis: &'a [u8], // genesis block of the chain. guard: Guard, // guard for the restoration directory. - engine: &'a dyn EthEngine, + engine: &'a dyn Engine, } impl Restoration { @@ -149,7 +149,7 @@ impl Restoration { } // feeds a block chunk - fn feed_blocks(&mut self, hash: H256, chunk: &[u8], engine: &dyn EthEngine, flag: &AtomicBool) -> Result<(), Error> { + fn feed_blocks(&mut self, hash: H256, chunk: &[u8], engine: &dyn Engine, flag: &AtomicBool) -> Result<(), Error> { if self.block_chunks_left.contains(&hash) { let expected_len = snappy::decompressed_len(chunk)?; if expected_len > MAX_CHUNK_SIZE { @@ -170,7 +170,7 @@ impl Restoration { } // finish up restoration. - fn finalize(mut self, engine: &dyn EthEngine) -> Result<(), Error> { + fn finalize(mut self, engine: &dyn Engine) -> Result<(), Error> { use trie::TrieError; if !self.is_done() { return Ok(()) } @@ -211,7 +211,7 @@ pub trait SnapshotClient: BlockChainClient + BlockInfo + DatabaseRestore {} /// Snapshot service parameters. pub struct ServiceParams { /// The consensus engine this is built on. - pub engine: Arc, + pub engine: Arc, /// The chain's genesis block. pub genesis_block: Bytes, /// State pruning algorithm. @@ -237,7 +237,7 @@ pub struct Service { pruning: Algorithm, status: Mutex, reader: RwLock>, - engine: Arc, + engine: Arc, genesis_block: Bytes, state_chunks: AtomicUsize, block_chunks: AtomicUsize, diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index 96c5c51b023..1873d05b7f9 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -26,7 +26,7 @@ use account_db::AccountDBMut; use types::basic_account::BasicAccount; use blockchain::{BlockChain, BlockChainDB}; use client::{Client, ChainInfo}; -use engines::EthEngine; +use engines::Engine; use snapshot::{StateRebuilder}; use snapshot::io::{SnapshotReader, PackedWriter, PackedReader}; @@ -152,7 +152,7 @@ pub fn snap(client: &Client) -> (Box, TempDir) { /// write into the given database. pub fn restore( db: Arc, - engine: &dyn EthEngine, + engine: &dyn Engine, reader: &dyn SnapshotReader, genesis: &[u8], ) -> Result<(), ::error::Error> { diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 140bd8264f6..9b8c20ea59b 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -35,7 +35,7 @@ use vm::{EnvInfo, CallType, ActionValue, ActionParams, ParamsType}; use builtin::Builtin; use engines::{ - EthEngine, NullEngine, InstantSeal, InstantSealParams, BasicAuthority, Clique, + Engine, NullEngine, InstantSeal, InstantSealParams, BasicAuthority, Clique, AuthorityRound, DEFAULT_BLOCKHASH_CONTRACT }; use error::Error; @@ -382,7 +382,7 @@ pub struct Spec { /// User friendly spec name pub name: String, /// What engine are we using for this? - pub engine: Arc, + pub engine: Arc, /// Name of the subdir inside the main data dir to use for chain data and settings. pub data_dir: String, @@ -601,7 +601,7 @@ impl Spec { engine_spec: ethjson::spec::Engine, params: CommonParams, builtins: BTreeMap, - ) -> Arc { + ) -> Arc { let machine = Self::machine(&engine_spec, params, builtins); match engine_spec { diff --git a/ethcore/src/verification/canon_verifier.rs b/ethcore/src/verification/canon_verifier.rs index 76f37c19df0..230521c305b 100644 --- a/ethcore/src/verification/canon_verifier.rs +++ b/ethcore/src/verification/canon_verifier.rs @@ -18,7 +18,7 @@ use call_contract::CallContract; use client::BlockInfo; -use engines::EthEngine; +use engines::Engine; use error::Error; use types::header::Header; use super::Verifier; @@ -32,7 +32,7 @@ impl Verifier for CanonVerifier { &self, header: &Header, parent: &Header, - engine: &dyn EthEngine, + engine: &dyn Engine, do_full: Option>, ) -> Result<(), Error> { verification::verify_block_family(header, parent, engine, do_full) @@ -42,7 +42,7 @@ impl Verifier for CanonVerifier { verification::verify_block_final(expected, got) } - fn verify_block_external(&self, header: &Header, engine: &dyn EthEngine) -> Result<(), Error> { + fn verify_block_external(&self, header: &Header, engine: &dyn Engine) -> Result<(), Error> { engine.verify_block_external(header) } } diff --git a/ethcore/src/verification/noop_verifier.rs b/ethcore/src/verification/noop_verifier.rs index 3b646ed9e40..f503caa2f16 100644 --- a/ethcore/src/verification/noop_verifier.rs +++ b/ethcore/src/verification/noop_verifier.rs @@ -18,7 +18,7 @@ use call_contract::CallContract; use client::BlockInfo; -use engines::EthEngine; +use engines::Engine; use error::Error; use types::header::Header; use super::{verification, Verifier}; @@ -32,7 +32,7 @@ impl Verifier for NoopVerifier { &self, _: &Header, _t: &Header, - _: &dyn EthEngine, + _: &dyn Engine, _: Option> ) -> Result<(), Error> { Ok(()) @@ -42,7 +42,7 @@ impl Verifier for NoopVerifier { Ok(()) } - fn verify_block_external(&self, _header: &Header, _engine: &dyn EthEngine) -> Result<(), Error> { + fn verify_block_external(&self, _header: &Header, _engine: &dyn Engine) -> Result<(), Error> { Ok(()) } } diff --git a/ethcore/src/verification/queue/kind.rs b/ethcore/src/verification/queue/kind.rs index 508503a04b0..0ac0b4f34fc 100644 --- a/ethcore/src/verification/queue/kind.rs +++ b/ethcore/src/verification/queue/kind.rs @@ -16,7 +16,7 @@ //! Definition of valid items for the verification queue. -use engines::EthEngine; +use engines::Engine; use error::Error; use parity_util_mem::MallocSizeOf; @@ -58,17 +58,17 @@ pub trait Kind: 'static + Sized + Send + Sync { type Verified: Sized + Send + BlockLike + MallocSizeOf; /// Attempt to create the `Unverified` item from the input. - fn create(input: Self::Input, engine: &dyn EthEngine, check_seal: bool) -> Result; + fn create(input: Self::Input, engine: &dyn Engine, check_seal: bool) -> Result; /// Attempt to verify the `Unverified` item using the given engine. - fn verify(unverified: Self::Unverified, engine: &dyn EthEngine, check_seal: bool) -> Result; + fn verify(unverified: Self::Unverified, engine: &dyn Engine, check_seal: bool) -> Result; } /// The blocks verification module. pub mod blocks { use super::{Kind, BlockLike}; - use engines::EthEngine; + use engines::Engine; use error::{Error, BlockError}; use types::header::Header; use verification::{PreverifiedBlock, verify_block_basic, verify_block_unordered}; @@ -86,7 +86,7 @@ pub mod blocks { type Unverified = Unverified; type Verified = PreverifiedBlock; - fn create(input: Self::Input, engine: &dyn EthEngine, check_seal: bool) -> Result { + fn create(input: Self::Input, engine: &dyn Engine, check_seal: bool) -> Result { match verify_block_basic(&input, engine, check_seal) { Ok(()) => Ok(input), Err(Error::Block(BlockError::TemporarilyInvalid(oob))) => { @@ -100,7 +100,7 @@ pub mod blocks { } } - fn verify(un: Self::Unverified, engine: &dyn EthEngine, check_seal: bool) -> Result { + fn verify(un: Self::Unverified, engine: &dyn Engine, check_seal: bool) -> Result { let hash = un.hash(); match verify_block_unordered(un, engine, check_seal) { Ok(verified) => Ok(verified), @@ -179,7 +179,7 @@ pub mod blocks { pub mod headers { use super::{Kind, BlockLike}; - use engines::EthEngine; + use engines::Engine; use error::Error; use types::header::Header; use verification::verify_header_params; @@ -200,14 +200,14 @@ pub mod headers { type Unverified = Header; type Verified = Header; - fn create(input: Self::Input, engine: &dyn EthEngine, check_seal: bool) -> Result { + fn create(input: Self::Input, engine: &dyn Engine, check_seal: bool) -> Result { match verify_header_params(&input, engine, true, check_seal) { Ok(_) => Ok(input), Err(err) => Err((input, err)) } } - fn verify(unverified: Self::Unverified, engine: &dyn EthEngine, check_seal: bool) -> Result { + fn verify(unverified: Self::Unverified, engine: &dyn Engine, check_seal: bool) -> Result { match check_seal { true => engine.verify_block_unordered(&unverified,).map(|_| unverified), false => Ok(unverified), diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 7acc496ebb8..21e9f92ef90 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -27,7 +27,7 @@ use ethereum_types::{H256, U256}; use parking_lot::{Condvar, Mutex, RwLock}; use io::*; use error::{BlockError, ImportError, Error}; -use engines::EthEngine; +use engines::Engine; use client::ClientIoMessage; use len_caching_lock::LenCachingMutex; @@ -133,7 +133,7 @@ struct Sizes { /// A queue of items to be verified. Sits between network or other I/O and the `BlockChain`. /// Keeps them in the same order as inserted, minus invalid items. pub struct VerificationQueue { - engine: Arc, + engine: Arc, more_to_verify: Arc, verification: Arc>, deleting: Arc, @@ -201,7 +201,7 @@ struct Verification { impl VerificationQueue { /// Creates a new queue instance. - pub fn new(config: Config, engine: Arc, message_channel: IoChannel, check_seal: bool) -> Self { + pub fn new(config: Config, engine: Arc, message_channel: IoChannel, check_seal: bool) -> Self { let verification = Arc::new(Verification { unverified: LenCachingMutex::new(VecDeque::new()), verifying: LenCachingMutex::new(VecDeque::new()), @@ -288,7 +288,7 @@ impl VerificationQueue { fn verify( verification: Arc>, - engine: Arc, + engine: Arc, wait: Arc, ready: Arc, empty: Arc, diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 87a19697c45..664926374f4 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -34,7 +34,7 @@ use unexpected::{Mismatch, OutOfBounds}; use blockchain::*; use call_contract::CallContract; use client::BlockInfo; -use engines::{EthEngine, MAX_UNCLE_AGE}; +use engines::{Engine, MAX_UNCLE_AGE}; use error::{BlockError, Error}; use types::{BlockNumber, header::Header}; use types::transaction::SignedTransaction; @@ -56,7 +56,7 @@ pub struct PreverifiedBlock { } /// Phase 1 quick block verification. Only does checks that are cheap. Operates on a single block -pub fn verify_block_basic(block: &Unverified, engine: &dyn EthEngine, check_seal: bool) -> Result<(), Error> { +pub fn verify_block_basic(block: &Unverified, engine: &dyn Engine, check_seal: bool) -> Result<(), Error> { verify_header_params(&block.header, engine, true, check_seal)?; verify_block_integrity(block)?; @@ -81,7 +81,7 @@ pub fn verify_block_basic(block: &Unverified, engine: &dyn EthEngine, check_seal /// Phase 2 verification. Perform costly checks such as transaction signatures and block nonce for ethash. /// Still operates on a individual block /// Returns a `PreverifiedBlock` structure populated with transactions -pub fn verify_block_unordered(block: Unverified, engine: &dyn EthEngine, check_seal: bool) -> Result { +pub fn verify_block_unordered(block: Unverified, engine: &dyn Engine, check_seal: bool) -> Result { let header = block.header; if check_seal { engine.verify_block_unordered(&header)?; @@ -130,7 +130,7 @@ pub struct FullFamilyParams<'a, C: BlockInfo + CallContract + 'a> { } /// Phase 3 verification. Check block information against parent and uncles. -pub fn verify_block_family(header: &Header, parent: &Header, engine: &dyn EthEngine, do_full: Option>) -> Result<(), Error> { +pub fn verify_block_family(header: &Header, parent: &Header, engine: &dyn Engine, do_full: Option>) -> Result<(), Error> { // TODO: verify timestamp verify_parent(&header, &parent, engine)?; engine.verify_block_family(&header, &parent)?; @@ -151,7 +151,7 @@ pub fn verify_block_family(header: &Header, parent: Ok(()) } -fn verify_uncles(block: &PreverifiedBlock, bc: &dyn BlockProvider, engine: &dyn EthEngine) -> Result<(), Error> { +fn verify_uncles(block: &PreverifiedBlock, bc: &dyn BlockProvider, engine: &dyn Engine) -> Result<(), Error> { let header = &block.header; let num_uncles = block.uncles.len(); let max_uncles = engine.maximum_uncle_count(header.number()); @@ -259,7 +259,7 @@ pub fn verify_block_final(expected: &Header, got: &Header) -> Result<(), Error> } /// Check basic header parameters. -pub fn verify_header_params(header: &Header, engine: &dyn EthEngine, is_full: bool, check_seal: bool) -> Result<(), Error> { +pub fn verify_header_params(header: &Header, engine: &dyn Engine, is_full: bool, check_seal: bool) -> Result<(), Error> { if check_seal { let expected_seal_fields = engine.seal_fields(header); if header.seal().len() != expected_seal_fields { @@ -318,7 +318,7 @@ pub fn verify_header_params(header: &Header, engine: &dyn EthEngine, is_full: bo } /// Check header parameters agains parent header. -fn verify_parent(header: &Header, parent: &Header, engine: &dyn EthEngine) -> Result<(), Error> { +fn verify_parent(header: &Header, parent: &Header, engine: &dyn Engine) -> Result<(), Error> { assert!(header.parent_hash().is_zero() || &parent.hash() == header.parent_hash(), "Parent hash should already have been verified; qed"); @@ -381,7 +381,7 @@ mod tests { use blockchain::{BlockDetails, TransactionAddress, BlockReceipts}; use types::encoded; use hash::keccak; - use engines::EthEngine; + use engines::Engine; use error::BlockError::*; use ethkey::{Random, Generator}; use spec::{CommonParams, Spec}; @@ -508,12 +508,12 @@ mod tests { } } - fn basic_test(bytes: &[u8], engine: &dyn EthEngine) -> Result<(), Error> { + fn basic_test(bytes: &[u8], engine: &dyn Engine) -> Result<(), Error> { let unverified = Unverified::from_rlp(bytes.to_vec())?; verify_block_basic(&unverified, engine, true) } - fn family_test(bytes: &[u8], engine: &dyn EthEngine, bc: &BC) -> Result<(), Error> where BC: BlockProvider { + fn family_test(bytes: &[u8], engine: &dyn Engine, bc: &BC) -> Result<(), Error> where BC: BlockProvider { let block = Unverified::from_rlp(bytes.to_vec()).unwrap(); let header = block.header; let transactions: Vec<_> = block.transactions @@ -545,7 +545,7 @@ mod tests { verify_block_family(&block.header, &parent, engine, Some(full_params)) } - fn unordered_test(bytes: &[u8], engine: &dyn EthEngine) -> Result<(), Error> { + fn unordered_test(bytes: &[u8], engine: &dyn Engine) -> Result<(), Error> { let un = Unverified::from_rlp(bytes.to_vec())?; verify_block_unordered(un, engine, false)?; Ok(()) diff --git a/ethcore/src/verification/verifier.rs b/ethcore/src/verification/verifier.rs index 309e596aa78..b5c2782a6f4 100644 --- a/ethcore/src/verification/verifier.rs +++ b/ethcore/src/verification/verifier.rs @@ -18,7 +18,7 @@ use call_contract::CallContract; use client::BlockInfo; -use engines::EthEngine; +use engines::Engine; use error::Error; use types::header::Header; use super::verification; @@ -32,12 +32,12 @@ pub trait Verifier: Send + Sync &self, header: &Header, parent: &Header, - engine: &dyn EthEngine, + engine: &dyn Engine, do_full: Option> ) -> Result<(), Error>; /// Do a final verification check for an enacted header vs its expected counterpart. fn verify_block_final(&self, expected: &Header, got: &Header) -> Result<(), Error>; /// Verify a block, inspecting external state. - fn verify_block_external(&self, header: &Header, engine: &dyn EthEngine) -> Result<(), Error>; + fn verify_block_external(&self, header: &Header, engine: &dyn Engine) -> Result<(), Error>; } diff --git a/parity/light_helpers/epoch_fetch.rs b/parity/light_helpers/epoch_fetch.rs index 38c277cb61e..95eea58586d 100644 --- a/parity/light_helpers/epoch_fetch.rs +++ b/parity/light_helpers/epoch_fetch.rs @@ -16,7 +16,7 @@ use std::sync::{Arc, Weak}; -use ethcore::engines::{EthEngine, StateDependentProof}; +use ethcore::engines::{Engine, StateDependentProof}; use sync::{LightSync, LightNetworkDispatcher}; use types::encoded; use types::header::Header; @@ -81,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 { diff --git a/rpc/src/v1/helpers/light_fetch.rs b/rpc/src/v1/helpers/light_fetch.rs index 92b7f2ac0bc..5c6696e4328 100644 --- a/rpc/src/v1/helpers/light_fetch.rs +++ b/rpc/src/v1/helpers/light_fetch.rs @@ -737,7 +737,7 @@ where tx: EthTransaction, hdr: encoded::Header, env_info: ::vm::EnvInfo, - engine: Arc<::ethcore::engines::EthEngine>, + engine: Arc<::ethcore::engines::Engine>, on_demand: Arc, sync: Arc, } diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index b16651bd9c5..3d755245689 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -22,7 +22,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use bytes::Bytes; use ethcore::block::SealedBlock; use ethcore::client::{Nonce, PrepareOpenBlock, StateClient, EngineInfo}; -use ethcore::engines::{EthEngine, signer::EngineSigner}; +use ethcore::engines::{Engine, signer::EngineSigner}; use ethcore::error::Error; use ethcore::miner::{self, MinerService, AuthoringParams}; use ethereum_types::{H256, U256, Address}; @@ -99,7 +99,7 @@ impl StateClient for TestMinerService { } impl EngineInfo for TestMinerService { - fn engine(&self) -> &EthEngine { + fn engine(&self) -> &Engine { unimplemented!() } }