Removed machine abstraction from ethcore (#10791)

This commit is contained in:
Marek Kotewicz 2019-06-26 20:16:05 +08:00 committed by Wei Tang
parent 63221c5152
commit 9c051ab756
32 changed files with 171 additions and 223 deletions

View File

@ -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> {

View File

@ -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<EthEngine>,
_checker: Arc<StateDependentProof<EthereumMachine>>
_checker: Arc<StateDependentProof>
) -> Self::Transition;
}
@ -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")
}

View File

@ -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<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;
@ -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) => {

View File

@ -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<EthEngine>,
/// Special checker for the proof.
pub proof_check: Arc<StateDependentProof<EthereumMachine>>,
pub proof_check: Arc<StateDependentProof>,
}
impl Signal {

View File

@ -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<Option<Box<dyn EpochVerifier<EthereumMachine>>>>,
cur_verifier: RwLock<Option<Box<dyn EpochVerifier>>>,
engine: Arc<dyn EthEngine>,
}
@ -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()

View File

@ -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,
@ -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>,
@ -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,

View File

@ -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<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)?)?;
@ -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")
@ -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)
@ -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 }
@ -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),
@ -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),
@ -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()
}

View File

@ -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<EthereumMachine> 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<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),
@ -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 }
@ -135,7 +135,7 @@ 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
@ -143,7 +143,7 @@ impl Engine<EthereumMachine> for BasicAuthority {
#[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;
@ -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) {

View File

@ -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)?;
}

View File

@ -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<Option<Weak<dyn EngineClient>>>,
block_state_by_hash: RwLock<LruCache<H256, CliqueBlockState>>,
proposals: RwLock<HashMap<Address, VoteType>>,
@ -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>>,
@ -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);
@ -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 }

View File

@ -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<M> {
pub struct InstantSeal {
params: InstantSealParams,
machine: M,
machine: Machine,
}
impl<M> InstantSeal<M> {
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<M: Machine> Engine<M> for InstantSeal<M> {
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<M: Machine> Engine<M> for InstantSeal<M> {
}
}
fn verify_local_seal(&self, _header: &Header) -> Result<(), M::Error> {
fn verify_local_seal(&self, _header: &Header) -> Result<(), Error> {
Ok(())
}

View File

@ -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<u8>) -> Result<Vec<u8>, String> + 'a {
pub fn default_system_or_code_call<'a>(machine: &'a ::machine::Machine, block: &'a mut ::block::ExecutedBlock) -> impl FnMut(SystemOrCodeCallKind, Vec<u8>) -> Result<Vec<u8>, 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<H> + 'a;
pub type PendingTransitionStore<'a> = dyn Fn(H256) -> Option<epoch::PendingTransition> + 'a;
/// Proof dependent on state.
pub trait StateDependentProof<M: Machine>: Send + Sync {
pub trait StateDependentProof: Send + Sync {
/// Generate a proof, given the state.
fn generate_proof<'a>(&self, state: &machine::Call) -> Result<Vec<u8>, 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<M: Machine> {
pub enum Proof {
/// Known proof (extracted from signal)
Known(Vec<u8>),
/// State dependent proof.
WithState(Arc<dyn StateDependentProof<M>>),
WithState(Arc<dyn StateDependentProof>),
}
/// Generated epoch verifier.
pub enum ConstructedVerifier<'a, M: Machine> {
pub enum ConstructedVerifier<'a> {
/// Fully trusted verifier.
Trusted(Box<dyn EpochVerifier<M>>),
Trusted(Box<dyn EpochVerifier>),
/// Verifier unconfirmed. Check whether given finality proof finalizes given hash
/// under previous epoch.
Unconfirmed(Box<dyn EpochVerifier<M>>, &'a [u8], H256),
Unconfirmed(Box<dyn EpochVerifier>, &'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<Box<dyn EpochVerifier<M>>, Error> {
pub fn known_confirmed(self) -> Result<Box<dyn EpochVerifier>, 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<M: Machine> {
pub enum EpochChange {
/// Cannot determine until more data is passed.
Unsure(AuxiliaryRequest),
/// No epoch change.
No,
/// The epoch will change, with proof.
Yes(Proof<M>),
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<M: Machine>: 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<M: Machine>: Sync + Send {
_block: &mut ExecutedBlock,
_epoch_begin: bool,
_ancestry: &mut dyn Iterator<Item = ExtendedHeader>,
) -> 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<M: Machine>: 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<Vec<u8>, String> { Ok(Vec::new()) }
@ -370,7 +371,7 @@ pub trait Engine<M: Machine>: Sync + Send {
///
/// Should not interact with state.
fn signals_epoch_end<'a>(&self, _header: &Header, _aux: AuxiliaryData<'a>)
-> EpochChange<M>
-> EpochChange
{
EpochChange::No
}
@ -413,7 +414,7 @@ pub trait Engine<M: Machine>: 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<M: Machine>: Sync + Send {
fn set_signer(&self, _signer: Box<dyn EngineSigner>) {}
/// Sign using the EngineSigner, to be used for consensus tx signing.
fn sign(&self, _hash: H256) -> Result<Signature, M::Error> { unimplemented!() }
fn sign(&self, _hash: H256) -> Result<Signature, Error> { unimplemented!() }
/// Add Client which can be used for sealing, potentially querying the state and sending messages.
fn register_client(&self, _client: Weak<M::EngineClient>) {}
fn register_client(&self, _client: Weak<dyn EngineClient>) {}
/// 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<T> EthEngine for T where T: Engine<::machine::EthereumMachine> { }
impl<T> EthEngine for T where T: Engine { }
/// Verifier for all blocks within an epoch with self-contained state.
pub trait EpochVerifier<M: machine::Machine>: 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<M: machine::Machine>: Send + Sync {
/// Special "no-op" verifier for stateless, epoch-less engines.
pub struct NoOp;
impl<M: machine::Machine> EpochVerifier<M> 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(()) }
}

View File

@ -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<M> {
pub struct NullEngine {
params: NullEngineParams,
machine: M,
machine: Machine,
}
impl<M> NullEngine<M> {
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<M: Default> Default for NullEngine<M> {
fn default() -> Self {
Self::new(Default::default(), Default::default())
}
}
impl<M: Machine> Engine<M> for NullEngine<M> {
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<M: Machine> Engine<M> for NullEngine<M> {
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(())
}

View File

@ -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<EthereumMachine> {
) -> ::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<H256>), ::error::Error> {
fn epoch_set(&self, first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option<H256>), ::error::Error> {
self.validators.epoch_set(first, machine, number, proof)
}

View File

@ -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<EthereumMachine>;
) -> ::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<H256>), ::error::Error>;
/// Checks if a given address is a validator, with the given function

View File

@ -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<dyn Fn(BlockId) -> Result<BlockNumber, String> + Send + Sync + 'static>;
@ -96,7 +96,7 @@ impl ValidatorSet for Multi {
}
fn signals_epoch_end(&self, _first: bool, header: &Header, aux: AuxiliaryData)
-> ::engines::EpochChange<EthereumMachine>
-> ::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<H256>), ::error::Error> {
fn epoch_set(&self, _first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(super::SimpleList, Option<H256>), ::error::Error> {
let (set_block, set) = self.correct_set_by_number(number);
let first = set_block == number;

View File

@ -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<EthereumMachine> for StateProof {
impl ::engines::StateDependentProof for StateProof {
fn generate_proof(&self, caller: &Call) -> Result<Vec<u8>, 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<u8>]) -> 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<Vec<Address>, 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<EthereumMachine>
-> ::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<H256>), ::error::Error>
{
let rlp = Rlp::new(proof);

View File

@ -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<EthereumMachine>
-> ::engines::EpochChange
{
::engines::EpochChange::No
}
fn epoch_set(&self, _first: bool, _: &EthereumMachine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option<H256>), ::error::Error> {
fn epoch_set(&self, _first: bool, _: &Machine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option<H256>), ::error::Error> {
Ok((self.clone(), None))
}

View File

@ -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<Vec<u8>> { None }
fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData)
-> ::engines::EpochChange<EthereumMachine>
-> ::engines::EpochChange
{
::engines::EpochChange::No
}
fn epoch_set(&self, _: bool, _: &EthereumMachine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option<H256>), ::error::Error> {
fn epoch_set(&self, _: bool, _: &Machine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option<H256>), ::error::Error> {
Ok((self.validator.clone(), None))
}

View File

@ -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<ethjson::spec::EthashParams> 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<T: Into<Option<OptimizeFor>>>(
cache_dir: &Path,
ethash_params: EthashParams,
machine: EthereumMachine,
machine: Machine,
optimize_for: T,
) -> Arc<Self> {
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<EthereumMachine> for Arc<Ethash> {
impl engines::EpochVerifier for Arc<Ethash> {
fn verify_light(&self, _header: &Header) -> Result<(), Error> { Ok(()) }
fn verify_heavy(&self, header: &Header) -> Result<(), Error> {
self.verify_block_unordered(header)
}
}
impl Engine<EthereumMachine> for Arc<Ethash> {
impl Engine for Arc<Ethash> {
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<EthereumMachine> for Arc<Ethash> {
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()))
}

View File

@ -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<Option<SpecParams<'a>>>>(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 {

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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<BTreeMap<Address, Builtin>>,
tx_filter: Option<Arc<TransactionFilter>>,
@ -78,11 +78,11 @@ pub struct EthereumMachine {
schedule_rules: Option<Box<ScheduleCreationRules>>,
}
impl EthereumMachine {
impl Machine {
/// Regular ethereum machine.
pub fn regular(params: CommonParams, builtins: BTreeMap<Address, Builtin>) -> EthereumMachine {
pub fn regular(params: CommonParams, builtins: BTreeMap<Address, Builtin>) -> Machine {
let tx_filter = TransactionFilter::from_params(&params).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<Address, Builtin>, extensions: EthashExtensions) -> EthereumMachine {
let mut machine = EthereumMachine::regular(params, builtins);
pub fn with_ethash_extensions(params: CommonParams, builtins: BTreeMap<Address, Builtin>, 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<U256, Error> {
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<U256, Error> {
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,

View File

@ -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::*;

View File

@ -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 <http://www.gnu.org/licenses/>.
//! 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<U256, Self::Error>;
/// 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>;
}

View File

@ -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<dyn EpochVerifier<EthereumMachine>>)>,
last_epochs: Vec<(Header, Box<dyn EpochVerifier>)>,
}
// verified data.
@ -183,7 +182,7 @@ struct Verified {
impl ChunkRebuilder {
fn verify_transition(
&mut self,
last_verifier: &mut Option<Box<dyn EpochVerifier<EthereumMachine>>>,
last_verifier: &mut Option<Box<dyn EpochVerifier>>,
transition_rlp: Rlp,
engine: &dyn EthEngine,
) -> Result<Verified, ::error::Error> {

View File

@ -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<SpecHardcodedSync> 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: &ethjson::spec::Engine,
params: CommonParams,
builtins: BTreeMap<Address, Builtin>,
) -> 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<R: Read>(reader: R) -> Result<EthereumMachine, String> {
pub fn load_machine<R: Read>(reader: R) -> Result<Machine, String> {
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"))]

View File

@ -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

View File

@ -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();

View File

@ -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<EthEngine>, checker: Arc<StateDependentProof<EthereumMachine>>)
fn epoch_transition(&self, hash: H256, engine: Arc<EthEngine>, checker: Arc<StateDependentProof>)
-> Self::Transition
{
self.request(request::Signal {