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

Commit

Permalink
Removed machine abstraction from ethcore (#10791)
Browse files Browse the repository at this point in the history
  • Loading branch information
debris authored and sorpaas committed Jun 26, 2019
1 parent 63221c5 commit 9c051ab
Show file tree
Hide file tree
Showing 32 changed files with 171 additions and 223 deletions.
4 changes: 2 additions & 2 deletions ethcore/benches/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
5 changes: 2 additions & 3 deletions ethcore/light/src/client/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -49,7 +48,7 @@ pub trait ChainDataFetcher: Send + Sync + 'static {
&self,
_hash: H256,
_engine: Arc<EthEngine>,
_checker: Arc<StateDependentProof<EthereumMachine>>
_checker: Arc<StateDependentProof>
) -> Self::Transition;
}

Expand Down Expand Up @@ -78,7 +77,7 @@ impl ChainDataFetcher for Unavailable {
&self,
_hash: H256,
_engine: Arc<EthEngine>,
_checker: Arc<StateDependentProof<EthereumMachine>>
_checker: Arc<StateDependentProof>
) -> Self::Transition {
Err("fetching epoch transition proofs unavailable")
}
Expand Down
5 changes: 2 additions & 3 deletions ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -468,7 +467,7 @@ impl<T: ChainDataFetcher> Client<T> {
true
}

fn check_epoch_signal(&self, verified_header: &Header) -> Result<Option<Proof<EthereumMachine>>, T::Error> {
fn check_epoch_signal(&self, verified_header: &Header) -> Result<Option<Proof>, T::Error> {
use ethcore::machine::{AuxiliaryRequest, AuxiliaryData};

let mut block: Option<Vec<u8>> = None;
Expand Down Expand Up @@ -514,7 +513,7 @@ impl<T: ChainDataFetcher> Client<T> {
}

// attempts to fetch the epoch proof from the network until successful.
fn write_pending_proof(&self, header: &Header, proof: Proof<EthereumMachine>) -> 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) => {
Expand Down
3 changes: 1 addition & 2 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1083,7 +1082,7 @@ pub struct Signal {
/// Consensus engine, used to check the proof.
pub engine: Arc<EthEngine>,
/// Special checker for the proof.
pub proof_check: Arc<StateDependentProof<EthereumMachine>>,
pub proof_check: Arc<StateDependentProof>,
}

impl Signal {
Expand Down
5 changes: 2 additions & 3 deletions ethcore/src/client/ancient_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use std::sync::Arc;

use engines::{EthEngine, EpochVerifier};
use machine::EthereumMachine;

use blockchain::BlockChain;
use parking_lot::RwLock;
Expand All @@ -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<Option<Box<dyn EpochVerifier<EthereumMachine>>>>,
cur_verifier: RwLock<Option<Box<dyn EpochVerifier>>>,
engine: Arc<dyn EthEngine>,
}

Expand Down Expand Up @@ -87,7 +86,7 @@ impl AncientVerifier {
}

fn initial_verifier(&self, header: &Header, chain: &BlockChain)
-> Result<Box<dyn EpochVerifier<EthereumMachine>>, ::error::Error>
-> Result<Box<dyn EpochVerifier>, ::error::Error>
{
trace!(target: "client", "Initializing ancient block restoration.");
let current_epoch_data = chain.epoch_transitions()
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ impl Client {
}

fn do_virtual_call(
machine: &::machine::EthereumMachine,
machine: &::machine::Machine,
env_info: &EnvInfo,
state: &mut State<StateDB>,
t: &SignedTransaction,
Expand All @@ -1257,7 +1257,7 @@ impl Client {
fn call<V, T>(
state: &mut State<StateDB>,
env_info: &EnvInfo,
machine: &::machine::EthereumMachine,
machine: &::machine::Machine,
state_diff: bool,
transaction: &SignedTransaction,
options: TransactOptions<T, V>,
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 11 additions & 10 deletions ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -450,7 +450,7 @@ struct EpochVerifier {
empty_steps_transition: u64,
}

impl super::EpochVerifier<EthereumMachine> 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)?)?;
Expand Down Expand Up @@ -671,7 +671,7 @@ impl<'a, A: ?Sized, B> Deref for CowLike<'a, A, B> where B: AsRef<A> {

impl AuthorityRound {
/// Create a new instance of AuthorityRound engine.
pub fn new(our_params: AuthorityRoundParams, machine: EthereumMachine) -> Result<Arc<Self>, Error> {
pub fn new(our_params: AuthorityRoundParams, machine: Machine) -> Result<Arc<Self>, 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")
Expand Down Expand Up @@ -941,10 +941,10 @@ impl IoHandler<()> for TransitionHandler {
}
}

impl Engine<EthereumMachine> 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)
Expand Down Expand Up @@ -1429,7 +1429,7 @@ impl Engine<EthereumMachine> for AuthorityRound {
}

fn signals_epoch_end(&self, header: &Header, aux: AuxiliaryData)
-> super::EpochChange<EthereumMachine>
-> super::EpochChange
{
if self.immediate_transitions { return super::EpochChange::No }

Expand Down Expand Up @@ -1551,7 +1551,7 @@ impl Engine<EthereumMachine> 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),
Expand Down Expand Up @@ -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: F) -> Arc<AuthorityRound> where
F: FnOnce(&mut AuthorityRoundParams),
Expand All @@ -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()
}

Expand Down
18 changes: 9 additions & 9 deletions ethcore/src/engines/basic_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -49,7 +49,7 @@ struct EpochVerifier {
list: SimpleList,
}

impl super::EpochVerifier<EthereumMachine> for EpochVerifier {
impl super::EpochVerifier for EpochVerifier {
fn verify_light(&self, header: &Header) -> Result<(), Error> {
verify_external(header, &self.list)
}
Expand All @@ -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<Option<Box<dyn EngineSigner>>>,
validators: Box<dyn ValidatorSet>,
}

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),
Expand All @@ -90,10 +90,10 @@ impl BasicAuthority {
}
}

impl Engine<EthereumMachine> 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 }
Expand Down Expand Up @@ -135,15 +135,15 @@ impl Engine<EthereumMachine> for BasicAuthority {

#[cfg(not(test))]
fn signals_epoch_end(&self, _header: &Header, _auxiliary: AuxiliaryData)
-> super::EpochChange<EthereumMachine>
-> super::EpochChange
{
// don't bother signalling even though a contract might try.
super::EpochChange::No
}

#[cfg(test)]
fn signals_epoch_end(&self, header: &Header, auxiliary: AuxiliaryData)
-> super::EpochChange<EthereumMachine>
-> super::EpochChange
{
// in test mode, always signal even though they don't be finalized.
let first = header.number() == 0;
Expand Down Expand Up @@ -172,7 +172,7 @@ impl Engine<EthereumMachine> 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) {
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/engines/block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<M: Machine>(
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)?;
}
Expand Down
12 changes: 6 additions & 6 deletions ethcore/src/engines/clique/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,7 +159,7 @@ impl VoteType {
pub struct Clique {
epoch_length: u64,
period: u64,
machine: EthereumMachine,
machine: Machine,
client: RwLock<Option<Weak<dyn EngineClient>>>,
block_state_by_hash: RwLock<LruCache<H256, CliqueBlockState>>,
proposals: RwLock<HashMap<Address, VoteType>>,
Expand All @@ -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<Option<Weak<dyn EngineClient>>>,
pub block_state_by_hash: RwLock<LruCache<H256, CliqueBlockState>>,
pub proposals: RwLock<HashMap<Address, VoteType>>,
Expand All @@ -180,7 +180,7 @@ pub struct Clique {

impl Clique {
/// Initialize Clique engine from empty state.
pub fn new(params: CliqueParams, machine: EthereumMachine) -> Result<Arc<Self>, Error> {
pub fn new(params: CliqueParams, machine: Machine) -> Result<Arc<Self>, Error> {
/// Step Clique at most every 2 seconds
const SEALING_FREQ: Duration = Duration::from_secs(2);

Expand Down Expand Up @@ -354,10 +354,10 @@ impl Clique {
}
}

impl Engine<EthereumMachine> 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 }
Expand Down
Loading

0 comments on commit 9c051ab

Please sign in to comment.