Remove AuxiliaryData/AuxiliaryRequest (#11533)

* Remove AuxiliaryRequest
Remove bytes member from AuxiliaryData

* Remove AuxiliaryData

* Address review grumbles
This commit is contained in:
David 2020-03-03 15:17:37 +01:00 committed by GitHub
parent 0c385de921
commit 7d54e9258d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 44 additions and 100 deletions

View File

@ -28,9 +28,9 @@ use common_types::{
Seal, SealingState, Headers, PendingTransitionStore, Seal, SealingState, Headers, PendingTransitionStore,
params::CommonParams, params::CommonParams,
machine as machine_types, machine as machine_types,
machine::{AuxiliaryData, AuxiliaryRequest},
}, },
errors::{EthcoreError as Error, EngineError}, errors::{EthcoreError as Error, EngineError},
receipt::Receipt,
snapshot::Snapshotting, snapshot::Snapshotting,
transaction::{self, SignedTransaction, UnverifiedTransaction}, 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. /// Results of a query of whether an epoch change occurred at the given block.
pub enum EpochChange { pub enum EpochChange {
/// Cannot determine until more data is passed. /// Cannot determine until more data is passed.
Unsure(AuxiliaryRequest), Unsure,
/// No epoch change. /// No epoch change.
No, No,
/// The epoch will change, with proof. /// 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. /// Return `Yes` or `No` when the answer is definitively known.
/// ///
/// Should not interact with state. /// 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 EpochChange::No
} }

View File

@ -71,10 +71,11 @@ use common_types::{
PendingTransitionStore, PendingTransitionStore,
Seal, Seal,
SealingState, SealingState,
machine::{Call, AuxiliaryData}, machine::Call,
}, },
errors::{BlockError, EthcoreError as Error, EngineError}, errors::{BlockError, EthcoreError as Error, EngineError},
ids::BlockId, ids::BlockId,
receipt::Receipt,
snapshot::Snapshotting, snapshot::Snapshotting,
transaction::SignedTransaction, transaction::SignedTransaction,
}; };
@ -1766,11 +1767,11 @@ impl Engine for AuthorityRound {
.map(|set_proof| combine_proofs(0, &set_proof, &[])) .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 } if self.immediate_transitions { return engine::EpochChange::No }
let first = header.number() == 0; 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( fn is_epoch_end_light(

View File

@ -26,9 +26,10 @@ use common_types::{
SealingState, SealingState,
Seal, Seal,
params::CommonParams, params::CommonParams,
machine::{AuxiliaryData, Call}, machine::Call,
}, },
errors::{EngineError, BlockError, EthcoreError as Error}, errors::{EngineError, BlockError, EthcoreError as Error},
receipt::Receipt,
}; };
use client_traits::EngineClient; use client_traits::EngineClient;
use ethereum_types::{H256, H520}; use ethereum_types::{H256, H520};
@ -142,16 +143,16 @@ impl Engine for BasicAuthority {
} }
#[cfg(not(any(test, feature = "test-helpers")))] #[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. // don't bother signalling even though a contract might try.
engine::EpochChange::No engine::EpochChange::No
} }
#[cfg(any(test, feature = "test-helpers"))] #[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. // in test mode, always signal even though they don't be finalized.
let first = header.number() == 0; 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( fn is_epoch_end(

View File

@ -30,7 +30,8 @@ use common_types::{
ids::BlockId, ids::BlockId,
header::Header, header::Header,
errors::EthcoreError, errors::EthcoreError,
engines::machine::{Call, AuxiliaryData}, engines::machine::Call,
receipt::Receipt,
transaction, transaction,
}; };
@ -141,9 +142,9 @@ impl ValidatorSet for ValidatorContract {
&self, &self,
first: bool, first: bool,
header: &Header, header: &Header,
aux: AuxiliaryData, receipts: Option<&[Receipt]>,
) -> engine::EpochChange { ) -> 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> { fn epoch_set(&self, first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option<H256>), EthcoreError> {

View File

@ -31,7 +31,8 @@ use common_types::{
header::Header, header::Header,
ids::BlockId, ids::BlockId,
errors::EthcoreError, errors::EthcoreError,
engines::machine::{Call, AuxiliaryData}, engines::machine::Call,
receipt::Receipt,
}; };
use engine::SystemCall; use engine::SystemCall;
use ethereum_types::{H256, Address}; use ethereum_types::{H256, Address};
@ -144,7 +145,7 @@ pub trait ValidatorSet: Send + Sync + 'static {
&self, &self,
first: bool, first: bool,
header: &Header, header: &Header,
aux: AuxiliaryData, receipts: Option<&[Receipt]>,
) -> engine::EpochChange; ) -> engine::EpochChange;
/// Recover the validator set from the given proof, the block number, and /// Recover the validator set from the given proof, the block number, and

View File

@ -24,7 +24,8 @@ use common_types::{
header::Header, header::Header,
ids::BlockId, ids::BlockId,
errors::EthcoreError, errors::EthcoreError,
engines::machine::{Call, AuxiliaryData}, engines::machine::Call,
receipt::Receipt,
}; };
use client_traits::EngineClient; use client_traits::EngineClient;
use ethereum_types::{H256, Address}; use ethereum_types::{H256, Address};
@ -117,13 +118,13 @@ impl ValidatorSet for Multi {
set.is_epoch_end(first, chain_head) 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 -> engine::EpochChange
{ {
let (set_block, set) = self.correct_set_by_number(header.number()); let (set_block, set) = self.correct_set_by_number(header.number());
let first = set_block == 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> { fn epoch_set(&self, _first: bool, machine: &Machine, number: BlockNumber, proof: &[u8]) -> Result<(super::SimpleList, Option<H256>), EthcoreError> {

View File

@ -26,7 +26,7 @@ use common_types::{
errors::{EngineError, EthcoreError, BlockError}, errors::{EngineError, EthcoreError, BlockError},
ids::BlockId, ids::BlockId,
log_entry::LogEntry, log_entry::LogEntry,
engines::machine::{Call, AuxiliaryData, AuxiliaryRequest}, engines::machine::Call,
receipt::Receipt, receipt::Receipt,
transaction::{self, Action, Transaction}, transaction::{self, Action, Transaction},
}; };
@ -438,11 +438,9 @@ impl ValidatorSet for ValidatorSafeContract {
None // no immediate transitions to contract. 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 -> engine::EpochChange
{ {
let receipts = aux.receipts;
// transition to the first block of a contract requires finality but has no log event. // transition to the first block of a contract requires finality but has no log event.
if first { if first {
debug!(target: "engine", "signalling transition to fresh contract."); debug!(target: "engine", "signalling transition to fresh contract.");
@ -462,7 +460,7 @@ impl ValidatorSet for ValidatorSafeContract {
trace!(target: "engine", "detected epoch change event bloom"); trace!(target: "engine", "detected epoch change event bloom");
match receipts { match receipts {
None => engine::EpochChange::Unsure(AuxiliaryRequest::Receipts), None => engine::EpochChange::Unsure,
Some(receipts) => match self.extract_from_event(bloom, header, receipts) { Some(receipts) => match self.extract_from_event(bloom, header, receipts) {
None => engine::EpochChange::No, None => engine::EpochChange::No,
Some(list) => { Some(list) => {
@ -642,7 +640,6 @@ mod tests {
use accounts::AccountProvider; use accounts::AccountProvider;
use common_types::{ use common_types::{
ids::BlockId, ids::BlockId,
engines::machine::AuxiliaryRequest,
header::Header, header::Header,
log_entry::LogEntry, log_entry::LogEntry,
transaction::{Transaction, Action}, transaction::{Transaction, Action},
@ -774,7 +771,7 @@ mod tests {
new_header.set_log_bloom(event.bloom()); new_header.set_log_bloom(event.bloom());
match engine.signals_epoch_end(&new_header, Default::default()) { match engine.signals_epoch_end(&new_header, Default::default()) {
EpochChange::Unsure(AuxiliaryRequest::Receipts) => {}, EpochChange::Unsure => {},
_ => panic!("Expected bloom to be recognized."), _ => panic!("Expected bloom to be recognized."),
}; };
} }

View File

@ -21,7 +21,8 @@ use common_types::{
ids::BlockId, ids::BlockId,
header::Header, header::Header,
errors::EthcoreError, errors::EthcoreError,
engines::machine::{Call, AuxiliaryData}, engines::machine::Call,
receipt::Receipt,
}; };
use ethereum_types::{H256, Address}; use ethereum_types::{H256, Address};
use log::warn; use log::warn;
@ -89,9 +90,7 @@ impl ValidatorSet for SimpleList {
} }
} }
fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) fn signals_epoch_end(&self, _: bool, _: &Header, _: Option<&[Receipt]>) -> engine::EpochChange {
-> engine::EpochChange
{
engine::EpochChange::No engine::EpochChange::No
} }

View File

@ -27,7 +27,8 @@ use common_types::{
ids::BlockId, ids::BlockId,
header::Header, header::Header,
errors::EthcoreError, errors::EthcoreError,
engines::machine::{Call, AuxiliaryData}, engines::machine::Call,
receipt::Receipt,
}; };
use ethereum_types::{H256, Address}; use ethereum_types::{H256, Address};
use machine::Machine; use machine::Machine;
@ -94,9 +95,7 @@ impl ValidatorSet for TestSet {
fn is_epoch_end(&self, _first: bool, _chain_head: &Header) -> Option<Vec<u8>> { None } fn is_epoch_end(&self, _first: bool, _chain_head: &Header) -> Option<Vec<u8>> { None }
fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) fn signals_epoch_end(&self, _: bool, _: &Header, _: Option<&[Receipt]>) -> engine::EpochChange {
-> engine::EpochChange
{
engine::EpochChange::No engine::EpochChange::No
} }

View File

@ -474,45 +474,20 @@ impl<T: ChainDataFetcher> Client<T> {
} }
fn check_epoch_signal(&self, verified_header: &Header) -> Result<Option<Proof>, T::Error> { 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; let mut receipts: Option<Vec<_>> = None;
loop { loop {
let is_signal = { let is_transition = {
let auxiliary = AuxiliaryData { self.engine.signals_epoch_end(verified_header, receipts.as_ref().map(|x| &x[..]))
bytes: block.as_ref().map(|x| &x[..]),
receipts: receipts.as_ref().map(|x| &x[..]),
};
self.engine.signals_epoch_end(verified_header, auxiliary)
}; };
// check with any auxiliary data fetched so far // check if we need to fetch receipts
match is_signal { match is_transition {
EpochChange::No => return Ok(None), EpochChange::No => return Ok(None),
EpochChange::Yes(proof) => return Ok(Some(proof)), EpochChange::Yes(proof) => return Ok(Some(proof)),
EpochChange::Unsure(unsure) => { EpochChange::Unsure => {
let (b, r) = match unsure { receipts = Some(self.fetcher.block_receipts(verified_header).into_future().wait()?);
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()?);
}
} }
} }
} }

View File

@ -114,7 +114,7 @@ use types::{
engines::{ engines::{
epoch::{PendingTransition, Transition as EpochTransition}, epoch::{PendingTransition, Transition as EpochTransition},
ForkChoice, ForkChoice,
machine::{AuxiliaryData, Call as MachineCall}, machine::Call as MachineCall,
MAX_UNCLE_AGE, MAX_UNCLE_AGE,
SealingState, SealingState,
}, },
@ -308,7 +308,7 @@ impl Importer {
continue; continue;
} }
match self.check_and_lock_block(&bytes, block, client) { match self.check_and_lock_block(block, client) {
Ok((closed_block, pending)) => { Ok((closed_block, pending)) => {
imported_blocks.push(hash); imported_blocks.push(hash);
let transactions_len = closed_block.transactions.len(); let transactions_len = closed_block.transactions.len();
@ -362,7 +362,7 @@ impl Importer {
imported 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 engine = &*self.engine;
let header = block.header.clone(); let header = block.header.clone();
@ -448,7 +448,6 @@ impl Importer {
let pending = self.check_epoch_end_signal( let pending = self.check_epoch_end_signal(
&header, &header,
bytes,
&locked_block.receipts, &locked_block.receipts,
locked_block.state.db(), locked_block.state.db(),
client client
@ -596,7 +595,6 @@ impl Importer {
fn check_epoch_end_signal( fn check_epoch_end_signal(
&self, &self,
header: &Header, header: &Header,
block_bytes: &[u8],
receipts: &[Receipt], receipts: &[Receipt],
state_db: &StateDB, state_db: &StateDB,
client: &Client, client: &Client,
@ -604,12 +602,7 @@ impl Importer {
use engine::EpochChange; use engine::EpochChange;
let hash = header.hash(); let hash = header.hash();
let auxiliary = AuxiliaryData { match self.engine.signals_epoch_end(header, Some(&receipts)) {
bytes: Some(block_bytes),
receipts: Some(&receipts),
};
match self.engine.signals_epoch_end(header, auxiliary) {
EpochChange::Yes(proof) => { EpochChange::Yes(proof) => {
use engine::Proof; use engine::Proof;
@ -671,7 +664,7 @@ impl Importer {
Ok(Some(PendingTransition { proof })) Ok(Some(PendingTransition { proof }))
}, },
EpochChange::No => Ok(None), EpochChange::No => Ok(None),
EpochChange::Unsure(_) => { EpochChange::Unsure => {
warn!(target: "client", "Detected invalid engine implementation."); warn!(target: "client", "Detected invalid engine implementation.");
warn!(target: "client", "Engine claims to require more block data, but everything provided."); warn!(target: "client", "Engine claims to require more block data, but everything provided.");
Err(EngineError::InvalidEngine.into()) Err(EngineError::InvalidEngine.into())
@ -2402,7 +2395,6 @@ impl ImportSealedBlock for Client {
let pending = self.importer.check_epoch_end_signal( let pending = self.importer.check_epoch_end_signal(
&header, &header,
&block_bytes,
&block.receipts, &block.receipts,
block.state.db(), block.state.db(),
self self

View File

@ -21,7 +21,6 @@ use bytes::Bytes;
use crate::{ use crate::{
log_entry::LogEntry, log_entry::LogEntry,
receipt,
state_diff::StateDiff, state_diff::StateDiff,
}; };
@ -29,28 +28,6 @@ use crate::{
/// Returns the call result and state proof for each call. /// Returns the call result and state proof for each call.
pub type Call<'a> = dyn Fn(Address, Vec<u8>) -> Result<(Vec<u8>, Vec<Vec<u8>>), String> + 'a; pub type Call<'a> = dyn Fn(Address, Vec<u8>) -> Result<(Vec<u8>, Vec<Vec<u8>>), 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. /// Transaction execution receipt.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct Executed<T, V> { pub struct Executed<T, V> {