Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ethcore/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions ethcore/engines/authority-round/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 5 additions & 4 deletions ethcore/engines/basic-authority/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions ethcore/engines/validator-set/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use common_types::{
ids::BlockId,
header::Header,
errors::EthcoreError,
engines::machine::{Call, AuxiliaryData},
engines::machine::Call,
receipt::Receipt,
transaction,
};

Expand Down Expand Up @@ -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<H256>), EthcoreError> {
Expand Down
5 changes: 3 additions & 2 deletions ethcore/engines/validator-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions ethcore/engines/validator-set/src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<H256>), EthcoreError> {
Expand Down
11 changes: 4 additions & 7 deletions ethcore/engines/validator-set/src/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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.");
Expand All @@ -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) => {
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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."),
};
}
Expand Down
7 changes: 3 additions & 4 deletions ethcore/engines/validator-set/src/simple_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 3 additions & 4 deletions ethcore/engines/validator-set/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,9 +95,7 @@ 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)
-> engine::EpochChange
{
fn signals_epoch_end(&self, _: bool, _: &Header, _: Option<&[Receipt]>) -> engine::EpochChange {
engine::EpochChange::No
}

Expand Down
37 changes: 6 additions & 31 deletions ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,45 +474,20 @@ impl<T: ChainDataFetcher> Client<T> {
}

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

let mut block: Option<Vec<u8>> = None;
let mut receipts: Option<Vec<_>> = 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()?);
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -362,7 +362,7 @@ impl Importer {
imported
}

fn check_and_lock_block(&self, bytes: &[u8], block: PreverifiedBlock, client: &Client) -> EthcoreResult<(LockedBlock, Option<PendingTransition>)> {
fn check_and_lock_block(&self, block: PreverifiedBlock, client: &Client) -> EthcoreResult<(LockedBlock, Option<PendingTransition>)> {
let engine = &*self.engine;
let header = block.header.clone();

Expand Down Expand Up @@ -448,7 +448,6 @@ impl Importer {

let pending = self.check_epoch_end_signal(
&header,
bytes,
&locked_block.receipts,
locked_block.state.db(),
client
Expand Down Expand Up @@ -596,20 +595,14 @@ impl Importer {
fn check_epoch_end_signal(
&self,
header: &Header,
block_bytes: &[u8],
receipts: &[Receipt],
state_db: &StateDB,
client: &Client,
) -> EthcoreResult<Option<PendingTransition>> {
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;

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
Loading