simplify ethcore machine by removing redundant traits (#10454)

This commit is contained in:
Marek Kotewicz
2019-03-11 11:37:48 +01:00
committed by Andrew Jones
parent ab27848dc4
commit 23d977ecce
6 changed files with 20 additions and 76 deletions

View File

@@ -15,7 +15,8 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use engines::{Engine, Seal};
use parity_machine::{Machine, Transactions, TotalScoredHeader};
use parity_machine::{Machine, Transactions};
use types::header::ExtendedHeader;
/// `InstantSeal` params.
#[derive(Default, Debug, PartialEq)]
@@ -48,11 +49,7 @@ impl<M> InstantSeal<M> {
}
}
impl<M: Machine> Engine<M> for InstantSeal<M>
where M::LiveBlock: Transactions,
M::ExtendedHeader: TotalScoredHeader,
<M::ExtendedHeader as TotalScoredHeader>::Value: Ord
{
impl<M: Machine> Engine<M> for InstantSeal<M> where M::LiveBlock: Transactions {
fn name(&self) -> &str {
"InstantSeal"
}
@@ -84,7 +81,7 @@ impl<M: Machine> Engine<M> for InstantSeal<M>
header_timestamp >= parent_timestamp
}
fn fork_choice(&self, new: &M::ExtendedHeader, current: &M::ExtendedHeader) -> super::ForkChoice {
fn fork_choice(&self, new: &ExtendedHeader, current: &ExtendedHeader) -> super::ForkChoice {
super::total_difficulty_fork_choice(new, current)
}
}

View File

@@ -44,13 +44,13 @@ use builtin::Builtin;
use vm::{EnvInfo, Schedule, CreateContractAddress, CallType, ActionValue};
use error::Error;
use types::BlockNumber;
use types::header::Header;
use types::header::{Header, ExtendedHeader};
use snapshot::SnapshotComponents;
use spec::CommonParams;
use types::transaction::{self, UnverifiedTransaction, SignedTransaction};
use ethkey::{Signature};
use parity_machine::{Machine, LocalizedMachine as Localized, TotalScoredHeader};
use parity_machine::{Machine, LocalizedMachine as Localized};
use ethereum_types::{H256, U256, Address};
use unexpected::{Mismatch, OutOfBounds};
use bytes::Bytes;
@@ -255,7 +255,7 @@ pub trait Engine<M: Machine>: Sync + Send {
&self,
_block: &mut M::LiveBlock,
_epoch_begin: bool,
_ancestry: &mut Iterator<Item=M::ExtendedHeader>,
_ancestry: &mut Iterator<Item = ExtendedHeader>,
) -> Result<(), M::Error> {
Ok(())
}
@@ -421,16 +421,16 @@ pub trait Engine<M: Machine>: Sync + Send {
/// Gather all ancestry actions. Called at the last stage when a block is committed. The Engine must guarantee that
/// the ancestry exists.
fn ancestry_actions(&self, _header: &M::Header, _ancestry: &mut Iterator<Item=M::ExtendedHeader>) -> Vec<AncestryAction> {
fn ancestry_actions(&self, _header: &M::Header, _ancestry: &mut Iterator<Item = ExtendedHeader>) -> Vec<AncestryAction> {
Vec::new()
}
/// Check whether the given new block is the best block, after finalization check.
fn fork_choice(&self, new: &M::ExtendedHeader, best: &M::ExtendedHeader) -> ForkChoice;
fn fork_choice(&self, new: &ExtendedHeader, best: &ExtendedHeader) -> ForkChoice;
}
/// Check whether a given block is the best block based on the default total difficulty rule.
pub fn total_difficulty_fork_choice<T: TotalScoredHeader>(new: &T, best: &T) -> ForkChoice where <T as TotalScoredHeader>::Value: Ord {
pub fn total_difficulty_fork_choice(new: &ExtendedHeader, best: &ExtendedHeader) -> ForkChoice {
if new.total_score() > best.total_score() {
ForkChoice::New
} else {

View File

@@ -18,8 +18,9 @@ use engines::Engine;
use engines::block_reward::{self, RewardKind};
use ethereum_types::U256;
use machine::WithRewards;
use parity_machine::{Machine, Header, LiveBlock, TotalScoredHeader};
use parity_machine::{Machine, Header, LiveBlock};
use types::BlockNumber;
use types::header::ExtendedHeader;
/// Params for a null engine.
#[derive(Clone, Default)]
@@ -58,10 +59,7 @@ impl<M: Default> Default for NullEngine<M> {
}
}
impl<M: Machine + WithRewards> Engine<M> for NullEngine<M>
where M::ExtendedHeader: TotalScoredHeader,
<M::ExtendedHeader as TotalScoredHeader>::Value: Ord
{
impl<M: Machine + WithRewards> Engine<M> for NullEngine<M> {
fn name(&self) -> &str {
"NullEngine"
}
@@ -105,7 +103,7 @@ impl<M: Machine + WithRewards> Engine<M> for NullEngine<M>
Some(Box::new(::snapshot::PowSnapshot::new(10000, 10000)))
}
fn fork_choice(&self, new: &M::ExtendedHeader, current: &M::ExtendedHeader) -> super::ForkChoice {
fn fork_choice(&self, new: &ExtendedHeader, current: &ExtendedHeader) -> super::ForkChoice {
super::total_difficulty_fork_choice(new, current)
}
}

View File

@@ -24,7 +24,7 @@ use ethereum_types::{U256, H256, Address};
use rlp::Rlp;
use types::transaction::{self, SYSTEM_ADDRESS, UNSIGNED_SENDER, UnverifiedTransaction, SignedTransaction};
use types::BlockNumber;
use types::header::{Header, ExtendedHeader};
use types::header::Header;
use vm::{CallType, ActionParams, ActionValue, ParamsType};
use vm::{EnvInfo, Schedule, CreateContractAddress};
@@ -430,7 +430,6 @@ pub enum AuxiliaryRequest {
impl ::parity_machine::Machine for EthereumMachine {
type Header = Header;
type ExtendedHeader = ExtendedHeader;
type LiveBlock = ExecutedBlock;
type EngineClient = ::client::EngineClient;