Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
removed EthEngine alias (#10805)
Browse files Browse the repository at this point in the history
  • Loading branch information
debris authored and ordian committed Jun 28, 2019
1 parent cff1bc8 commit 7f02a08
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 121 deletions.
6 changes: 3 additions & 3 deletions ethcore/light/src/client/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -47,7 +47,7 @@ pub trait ChainDataFetcher: Send + Sync + 'static {
fn epoch_transition(
&self,
_hash: H256,
_engine: Arc<EthEngine>,
_engine: Arc<Engine>,
_checker: Arc<StateDependentProof>
) -> Self::Transition;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ impl ChainDataFetcher for Unavailable {
fn epoch_transition(
&self,
_hash: H256,
_engine: Arc<EthEngine>,
_engine: Arc<Engine>,
_checker: Arc<StateDependentProof>
) -> Self::Transition {
Err("fetching epoch transition proofs unavailable")
Expand Down
10 changes: 5 additions & 5 deletions ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -114,7 +114,7 @@ pub trait LightChainClient: Send + Sync {
fn env_info(&self, id: BlockId) -> Option<EnvInfo>;

/// Get a handle to the consensus engine.
fn engine(&self) -> &Arc<EthEngine>;
fn engine(&self) -> &Arc<Engine>;

/// Query whether a block is known.
fn is_known(&self, hash: &H256) -> bool;
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<T: LightChainClient> AsLightClient for T {
/// Light client implementation.
pub struct Client<T> {
queue: HeaderQueue,
engine: Arc<EthEngine>,
engine: Arc<Engine>,
chain: HeaderChain,
report: RwLock<ClientReport>,
import_lock: Mutex<()>,
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<T: ChainDataFetcher> Client<T> {
}

/// Get a handle to the verification engine.
pub fn engine(&self) -> &Arc<EthEngine> {
pub fn engine(&self) -> &Arc<Engine> {
&self.engine
}

Expand Down Expand Up @@ -578,7 +578,7 @@ impl<T: ChainDataFetcher> LightChainClient for Client<T> {
Client::env_info(self, id)
}

fn engine(&self) -> &Arc<EthEngine> {
fn engine(&self) -> &Arc<Engine> {
Client::engine(self)
}

Expand Down
6 changes: 3 additions & 3 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<EthEngine>,
pub engine: Arc<Engine>,
}

impl TransactionProof {
Expand Down Expand Up @@ -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<EthEngine>,
pub engine: Arc<Engine>,
/// Special checker for the proof.
pub proof_check: Arc<StateDependentProof>,
}
Expand Down
22 changes: 11 additions & 11 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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<Item = ExtendedHeader>>(
engine: &'x dyn EthEngine,
engine: &'x dyn Engine,
factories: Factories,
tracing: bool,
db: StateDB,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Bytes>) -> Result<SealedBlock, Error> {
pub fn seal(self, engine: &dyn Engine, seal: Vec<Bytes>) -> Result<SealedBlock, Error> {
let expected_seal_fields = engine.seal_fields(&self.header);
let mut s = self;
if seal.len() != expected_seal_fields {
Expand All @@ -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<Bytes>,
) -> Result<SealedBlock, Error> {
let mut s = self;
Expand Down Expand Up @@ -472,7 +472,7 @@ pub(crate) fn enact(
header: Header,
transactions: Vec<SignedTransaction>,
uncles: Vec<Header>,
engine: &dyn EthEngine,
engine: &dyn Engine,
tracing: bool,
db: StateDB,
parent: &Header,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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<u8>,
engine: &dyn EthEngine,
engine: &dyn Engine,
tracing: bool,
db: StateDB,
parent: &Header,
Expand Down Expand Up @@ -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<u8>,
engine: &dyn EthEngine,
engine: &dyn Engine,
tracing: bool,
db: StateDB,
parent: &Header,
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/client/ancient_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::sync::Arc;

use engines::{EthEngine, EpochVerifier};
use engines::{Engine, EpochVerifier};

use blockchain::BlockChain;
use parking_lot::RwLock;
Expand All @@ -32,12 +32,12 @@ const HEAVY_VERIFY_RATE: f32 = 0.02;
/// epoch.
pub struct AncientVerifier {
cur_verifier: RwLock<Option<Box<dyn EpochVerifier>>>,
engine: Arc<dyn EthEngine>,
engine: Arc<dyn Engine>,
}

impl AncientVerifier {
/// Create a new ancient block verifier with the given engine.
pub fn new(engine: Arc<dyn EthEngine>) -> Self {
pub fn new(engine: Arc<dyn Engine>) -> Self {
AncientVerifier {
cur_verifier: RwLock::new(None),
engine,
Expand Down
12 changes: 6 additions & 6 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -165,7 +165,7 @@ struct Importer {
pub ancient_verifier: AncientVerifier,

/// Ethereum engine to be used during import
pub engine: Arc<dyn EthEngine>,
pub engine: Arc<dyn Engine>,

/// A lru cache of recently detected bad blocks
pub bad_blocks: bad_blocks::BadBlocks,
Expand All @@ -187,7 +187,7 @@ pub struct Client {

chain: RwLock<Arc<BlockChain>>,
tracedb: RwLock<TraceDB<BlockChain>>,
engine: Arc<dyn EthEngine>,
engine: Arc<dyn Engine>,

/// Client configuration
config: ClientConfig,
Expand Down Expand Up @@ -245,7 +245,7 @@ pub struct Client {
impl Importer {
pub fn new(
config: &ClientConfig,
engine: Arc<dyn EthEngine>,
engine: Arc<dyn Engine>,
message_channel: IoChannel<ClientIoMessage>,
miner: Arc<Miner>,
) -> Result<Importer, ::error::Error> {
Expand Down Expand Up @@ -857,7 +857,7 @@ impl Client {
}

/// Returns engine reference.
pub fn engine(&self) -> &dyn EthEngine {
pub fn engine(&self) -> &dyn Engine {
&*self.engine
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -627,7 +627,7 @@ impl StateClient for TestBlockChainClient {
}

impl EngineInfo for TestBlockChainClient {
fn engine(&self) -> &dyn EthEngine {
fn engine(&self) -> &dyn Engine {
unimplemented!()
}
}
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 }
Expand Down
25 changes: 8 additions & 17 deletions ethcore/src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,22 +475,7 @@ pub trait Engine: Sync + Send {
fn executive_author(&self, header: &Header) -> Result<Address, Error> {
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()
Expand Down Expand Up @@ -569,8 +554,14 @@ pub trait EthEngine: Engine {
}
}

// convenience wrappers for existing functions.
impl<T> 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 {
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,7 +245,7 @@ pub struct Miner {
options: MinerOptions,
// TODO [ToDr] Arc is only required because of price updater
transaction_queue: Arc<TransactionQueue>,
engine: Arc<dyn EthEngine>,
engine: Arc<dyn Engine>,
accounts: Arc<dyn LocalAccounts>,
io_channel: RwLock<Option<IoChannel<ClientIoMessage>>>,
service_transaction_checker: Option<ServiceTransactionChecker>,
Expand Down
Loading

0 comments on commit 7f02a08

Please sign in to comment.