diff --git a/ethcore/engine/src/engine.rs b/ethcore/engine/src/engine.rs index 3fa13a07472..405bd4379a0 100644 --- a/ethcore/engine/src/engine.rs +++ b/ethcore/engine/src/engine.rs @@ -28,9 +28,9 @@ use common_types::{ Seal, SealingState, Headers, PendingTransitionStore, params::CommonParams, machine as machine_types, - machine::{AuxiliaryData, AuxiliaryRequest}, }, errors::{EthcoreError as Error, EngineError}, + receipt::Receipt, snapshot::Snapshotting, transaction::{self, SignedTransaction, UnverifiedTransaction}, }; @@ -134,7 +134,7 @@ impl<'a> ConstructedVerifier<'a> { /// Results of a query of whether an epoch change occurred at the given block. pub enum EpochChange { /// Cannot determine until more data is passed. - Unsure(AuxiliaryRequest), + Unsure, /// No epoch change. No, /// The epoch will change, with proof. @@ -254,7 +254,7 @@ pub trait Engine: Sync + Send { /// Return `Yes` or `No` when the answer is definitively known. /// /// Should not interact with state. - fn signals_epoch_end<'a>(&self, _header: &Header, _aux: AuxiliaryData<'a>) -> EpochChange { + fn signals_epoch_end<'a>(&self, _header: &Header, _receipts: Option<&'a [Receipt]>) -> EpochChange { EpochChange::No } diff --git a/ethcore/engines/authority-round/src/lib.rs b/ethcore/engines/authority-round/src/lib.rs index 588b239873d..0ac158b6832 100644 --- a/ethcore/engines/authority-round/src/lib.rs +++ b/ethcore/engines/authority-round/src/lib.rs @@ -71,10 +71,11 @@ use common_types::{ PendingTransitionStore, Seal, SealingState, - machine::{Call, AuxiliaryData}, + machine::Call, }, errors::{BlockError, EthcoreError as Error, EngineError}, ids::BlockId, + receipt::Receipt, snapshot::Snapshotting, transaction::SignedTransaction, }; @@ -1766,11 +1767,11 @@ impl Engine for AuthorityRound { .map(|set_proof| combine_proofs(0, &set_proof, &[])) } - fn signals_epoch_end(&self, header: &Header, aux: AuxiliaryData) -> engine::EpochChange { + fn signals_epoch_end(&self, header: &Header, receipts: Option<&[Receipt]>) -> engine::EpochChange { if self.immediate_transitions { return engine::EpochChange::No } let first = header.number() == 0; - self.validators.signals_epoch_end(first, header, aux) + self.validators.signals_epoch_end(first, header, receipts) } fn is_epoch_end_light( diff --git a/ethcore/engines/basic-authority/src/lib.rs b/ethcore/engines/basic-authority/src/lib.rs index 5c5efc88e17..38ca8f97213 100644 --- a/ethcore/engines/basic-authority/src/lib.rs +++ b/ethcore/engines/basic-authority/src/lib.rs @@ -26,9 +26,10 @@ use common_types::{ SealingState, Seal, params::CommonParams, - machine::{AuxiliaryData, Call}, + machine::Call, }, errors::{EngineError, BlockError, EthcoreError as Error}, + receipt::Receipt, }; use client_traits::EngineClient; use ethereum_types::{H256, H520}; @@ -142,16 +143,16 @@ impl Engine for BasicAuthority { } #[cfg(not(any(test, feature = "test-helpers")))] - fn signals_epoch_end(&self, _header: &Header, _auxiliary: AuxiliaryData) -> engine::EpochChange { + fn signals_epoch_end(&self, _header: &Header, _receipts: Option<&[Receipt]>) -> engine::EpochChange { // don't bother signalling even though a contract might try. engine::EpochChange::No } #[cfg(any(test, feature = "test-helpers"))] - fn signals_epoch_end(&self, header: &Header, auxiliary: AuxiliaryData) -> engine::EpochChange { + fn signals_epoch_end(&self, header: &Header, receipts: Option<&[Receipt]>) -> engine::EpochChange { // in test mode, always signal even though they don't be finalized. let first = header.number() == 0; - self.validators.signals_epoch_end(first, header, auxiliary) + self.validators.signals_epoch_end(first, header, receipts) } fn is_epoch_end( diff --git a/ethcore/engines/validator-set/src/contract.rs b/ethcore/engines/validator-set/src/contract.rs index bcc2fd176cb..295ce32f07d 100644 --- a/ethcore/engines/validator-set/src/contract.rs +++ b/ethcore/engines/validator-set/src/contract.rs @@ -30,7 +30,8 @@ use common_types::{ ids::BlockId, header::Header, errors::EthcoreError, - engines::machine::{Call, AuxiliaryData}, + engines::machine::Call, + receipt::Receipt, transaction, }; @@ -141,9 +142,9 @@ impl ValidatorSet for ValidatorContract { &self, first: bool, header: &Header, - aux: AuxiliaryData, + receipts: Option<&[Receipt]>, ) -> engine::EpochChange { - self.validators.signals_epoch_end(first, header, aux) + self.validators.signals_epoch_end(first, header, receipts) } fn epoch_set(&self, first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option), EthcoreError> { diff --git a/ethcore/engines/validator-set/src/lib.rs b/ethcore/engines/validator-set/src/lib.rs index aa6bbd7545d..5b649182b05 100644 --- a/ethcore/engines/validator-set/src/lib.rs +++ b/ethcore/engines/validator-set/src/lib.rs @@ -31,7 +31,8 @@ use common_types::{ header::Header, ids::BlockId, errors::EthcoreError, - engines::machine::{Call, AuxiliaryData}, + engines::machine::Call, + receipt::Receipt, }; use engine::SystemCall; use ethereum_types::{H256, Address}; @@ -144,7 +145,7 @@ pub trait ValidatorSet: Send + Sync + 'static { &self, first: bool, header: &Header, - aux: AuxiliaryData, + receipts: Option<&[Receipt]>, ) -> engine::EpochChange; /// Recover the validator set from the given proof, the block number, and diff --git a/ethcore/engines/validator-set/src/multi.rs b/ethcore/engines/validator-set/src/multi.rs index 9a3c7778ea9..7ee962c81f5 100644 --- a/ethcore/engines/validator-set/src/multi.rs +++ b/ethcore/engines/validator-set/src/multi.rs @@ -24,7 +24,8 @@ use common_types::{ header::Header, ids::BlockId, errors::EthcoreError, - engines::machine::{Call, AuxiliaryData}, + engines::machine::Call, + receipt::Receipt, }; use client_traits::EngineClient; use ethereum_types::{H256, Address}; @@ -117,13 +118,13 @@ impl ValidatorSet for Multi { set.is_epoch_end(first, chain_head) } - fn signals_epoch_end(&self, _first: bool, header: &Header, aux: AuxiliaryData) + fn signals_epoch_end(&self, _first: bool, header: &Header, receipts: Option<&[Receipt]>) -> engine::EpochChange { let (set_block, set) = self.correct_set_by_number(header.number()); let first = set_block == header.number(); - set.signals_epoch_end(first, header, aux) + set.signals_epoch_end(first, header, receipts) } fn epoch_set(&self, _first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(super::SimpleList, Option), EthcoreError> { diff --git a/ethcore/engines/validator-set/src/safe_contract.rs b/ethcore/engines/validator-set/src/safe_contract.rs index c0f05620450..fb73a9ec35e 100644 --- a/ethcore/engines/validator-set/src/safe_contract.rs +++ b/ethcore/engines/validator-set/src/safe_contract.rs @@ -26,7 +26,7 @@ use common_types::{ errors::{EngineError, EthcoreError, BlockError}, ids::BlockId, log_entry::LogEntry, - engines::machine::{Call, AuxiliaryData, AuxiliaryRequest}, + engines::machine::Call, receipt::Receipt, transaction::{self, Action, Transaction}, }; @@ -438,11 +438,9 @@ impl ValidatorSet for ValidatorSafeContract { None // no immediate transitions to contract. } - fn signals_epoch_end(&self, first: bool, header: &Header, aux: AuxiliaryData) + fn signals_epoch_end(&self, first: bool, header: &Header, receipts: Option<&[Receipt]>) -> engine::EpochChange { - let receipts = aux.receipts; - // transition to the first block of a contract requires finality but has no log event. if first { debug!(target: "engine", "signalling transition to fresh contract."); @@ -462,7 +460,7 @@ impl ValidatorSet for ValidatorSafeContract { trace!(target: "engine", "detected epoch change event bloom"); match receipts { - None => engine::EpochChange::Unsure(AuxiliaryRequest::Receipts), + None => engine::EpochChange::Unsure, Some(receipts) => match self.extract_from_event(bloom, header, receipts) { None => engine::EpochChange::No, Some(list) => { @@ -642,7 +640,6 @@ mod tests { use accounts::AccountProvider; use common_types::{ ids::BlockId, - engines::machine::AuxiliaryRequest, header::Header, log_entry::LogEntry, transaction::{Transaction, Action}, @@ -774,7 +771,7 @@ mod tests { new_header.set_log_bloom(event.bloom()); match engine.signals_epoch_end(&new_header, Default::default()) { - EpochChange::Unsure(AuxiliaryRequest::Receipts) => {}, + EpochChange::Unsure => {}, _ => panic!("Expected bloom to be recognized."), }; } diff --git a/ethcore/engines/validator-set/src/simple_list.rs b/ethcore/engines/validator-set/src/simple_list.rs index def51ccb949..226fab4706d 100644 --- a/ethcore/engines/validator-set/src/simple_list.rs +++ b/ethcore/engines/validator-set/src/simple_list.rs @@ -21,7 +21,8 @@ use common_types::{ ids::BlockId, header::Header, errors::EthcoreError, - engines::machine::{Call, AuxiliaryData}, + engines::machine::Call, + receipt::Receipt, }; use ethereum_types::{H256, Address}; use log::warn; @@ -89,9 +90,7 @@ impl ValidatorSet for SimpleList { } } - fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) - -> engine::EpochChange - { + fn signals_epoch_end(&self, _: bool, _: &Header, _: Option<&[Receipt]>) -> engine::EpochChange { engine::EpochChange::No } diff --git a/ethcore/engines/validator-set/src/test.rs b/ethcore/engines/validator-set/src/test.rs index e2658ac1749..6ab5bc5193f 100644 --- a/ethcore/engines/validator-set/src/test.rs +++ b/ethcore/engines/validator-set/src/test.rs @@ -27,7 +27,8 @@ use common_types::{ ids::BlockId, header::Header, errors::EthcoreError, - engines::machine::{Call, AuxiliaryData}, + engines::machine::Call, + receipt::Receipt, }; use ethereum_types::{H256, Address}; use machine::Machine; @@ -94,9 +95,7 @@ impl ValidatorSet for TestSet { fn is_epoch_end(&self, _first: bool, _chain_head: &Header) -> Option> { None } - fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) - -> engine::EpochChange - { + fn signals_epoch_end(&self, _: bool, _: &Header, _: Option<&[Receipt]>) -> engine::EpochChange { engine::EpochChange::No } diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index e835711e5ba..073d1dbfda4 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -474,45 +474,20 @@ impl Client { } fn check_epoch_signal(&self, verified_header: &Header) -> Result, T::Error> { - use common_types::engines::machine::{AuxiliaryRequest, AuxiliaryData}; - - let mut block: Option> = None; let mut receipts: Option> = None; loop { - let is_signal = { - let auxiliary = AuxiliaryData { - bytes: block.as_ref().map(|x| &x[..]), - receipts: receipts.as_ref().map(|x| &x[..]), - }; - - self.engine.signals_epoch_end(verified_header, auxiliary) + let is_transition = { + self.engine.signals_epoch_end(verified_header, receipts.as_ref().map(|x| &x[..])) }; - // check with any auxiliary data fetched so far - match is_signal { + // check if we need to fetch receipts + match is_transition { EpochChange::No => return Ok(None), EpochChange::Yes(proof) => return Ok(Some(proof)), - EpochChange::Unsure(unsure) => { - let (b, r) = match unsure { - AuxiliaryRequest::Body => - (Some(self.fetcher.block_body(verified_header)), None), - AuxiliaryRequest::Receipts => - (None, Some(self.fetcher.block_receipts(verified_header))), - AuxiliaryRequest::Both => ( - Some(self.fetcher.block_body(verified_header)), - Some(self.fetcher.block_receipts(verified_header)), - ), - }; - - if let Some(b) = b { - block = Some(b.into_future().wait()?.into_inner()); - } - - if let Some(r) = r { - receipts = Some(r.into_future().wait()?); - } + EpochChange::Unsure => { + receipts = Some(self.fetcher.block_receipts(verified_header).into_future().wait()?); } } } diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 55e0b1889df..7fbcaedf38a 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -114,7 +114,7 @@ use types::{ engines::{ epoch::{PendingTransition, Transition as EpochTransition}, ForkChoice, - machine::{AuxiliaryData, Call as MachineCall}, + machine::Call as MachineCall, MAX_UNCLE_AGE, SealingState, }, @@ -308,7 +308,7 @@ impl Importer { continue; } - match self.check_and_lock_block(&bytes, block, client) { + match self.check_and_lock_block(block, client) { Ok((closed_block, pending)) => { imported_blocks.push(hash); let transactions_len = closed_block.transactions.len(); @@ -362,7 +362,7 @@ impl Importer { imported } - fn check_and_lock_block(&self, bytes: &[u8], block: PreverifiedBlock, client: &Client) -> EthcoreResult<(LockedBlock, Option)> { + fn check_and_lock_block(&self, block: PreverifiedBlock, client: &Client) -> EthcoreResult<(LockedBlock, Option)> { let engine = &*self.engine; let header = block.header.clone(); @@ -448,7 +448,6 @@ impl Importer { let pending = self.check_epoch_end_signal( &header, - bytes, &locked_block.receipts, locked_block.state.db(), client @@ -596,7 +595,6 @@ impl Importer { fn check_epoch_end_signal( &self, header: &Header, - block_bytes: &[u8], receipts: &[Receipt], state_db: &StateDB, client: &Client, @@ -604,12 +602,7 @@ impl Importer { use engine::EpochChange; let hash = header.hash(); - let auxiliary = AuxiliaryData { - bytes: Some(block_bytes), - receipts: Some(&receipts), - }; - - match self.engine.signals_epoch_end(header, auxiliary) { + match self.engine.signals_epoch_end(header, Some(&receipts)) { EpochChange::Yes(proof) => { use engine::Proof; @@ -671,7 +664,7 @@ impl Importer { Ok(Some(PendingTransition { proof })) }, EpochChange::No => Ok(None), - EpochChange::Unsure(_) => { + EpochChange::Unsure => { warn!(target: "client", "Detected invalid engine implementation."); warn!(target: "client", "Engine claims to require more block data, but everything provided."); Err(EngineError::InvalidEngine.into()) @@ -2402,7 +2395,6 @@ impl ImportSealedBlock for Client { let pending = self.importer.check_epoch_end_signal( &header, - &block_bytes, &block.receipts, block.state.db(), self diff --git a/ethcore/types/src/engines/machine.rs b/ethcore/types/src/engines/machine.rs index 80b9bf6222b..2927e522182 100644 --- a/ethcore/types/src/engines/machine.rs +++ b/ethcore/types/src/engines/machine.rs @@ -21,7 +21,6 @@ use bytes::Bytes; use crate::{ log_entry::LogEntry, - receipt, state_diff::StateDiff, }; @@ -29,28 +28,6 @@ use crate::{ /// Returns the call result and state proof for each call. pub type Call<'a> = dyn Fn(Address, Vec) -> Result<(Vec, Vec>), String> + 'a; -/// Request for auxiliary data of a block. -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum AuxiliaryRequest { - /// Needs the body. - Body, - /// Needs the receipts. - Receipts, - /// Needs both body and receipts. - Both, -} - -/// Auxiliary data fetcher for an Ethereum machine. In Ethereum-like machines -/// there are two kinds of auxiliary data: bodies and receipts. -#[derive(Default, Clone)] -pub struct AuxiliaryData<'a> { - /// The full block bytes, including the header. - pub bytes: Option<&'a [u8]>, - /// The block receipts. - pub receipts: Option<&'a [receipt::Receipt]>, -} - - /// Transaction execution receipt. #[derive(Debug, PartialEq, Clone)] pub struct Executed {