further simplify machine (#10472)
* removed AuxiliaryRequest from Machin trait * removed AncestryAction from Machine trait * removed AuxiliaryData from Machine trait * removed LocalizedMachine trait
This commit is contained in:
parent
a16bad4175
commit
c9db8ea21d
@ -49,13 +49,12 @@ use spec::CommonParams;
|
||||
use types::transaction::{self, UnverifiedTransaction, SignedTransaction};
|
||||
|
||||
use ethkey::{Signature};
|
||||
use machine::{Machine, LocalizedMachine as Localized};
|
||||
use machine::{self, Machine, AuxiliaryRequest, AuxiliaryData};
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use unexpected::{Mismatch, OutOfBounds};
|
||||
use bytes::Bytes;
|
||||
use types::ancestry_action::AncestryAction;
|
||||
use block::ExecutedBlock;
|
||||
use machine;
|
||||
|
||||
/// Default EIP-210 contract code.
|
||||
/// As defined in https://github.com/ethereum/EIPs/pull/210
|
||||
@ -177,8 +176,7 @@ pub type PendingTransitionStore<'a> = Fn(H256) -> Option<epoch::PendingTransitio
|
||||
/// Proof dependent on state.
|
||||
pub trait StateDependentProof<M: Machine>: Send + Sync {
|
||||
/// Generate a proof, given the state.
|
||||
// TODO: make this into an &M::StateContext
|
||||
fn generate_proof<'a>(&self, state: &<M as Localized<'a>>::StateContext) -> Result<Vec<u8>, String>;
|
||||
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.
|
||||
@ -218,7 +216,7 @@ 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> {
|
||||
/// Cannot determine until more data is passed.
|
||||
Unsure(M::AuxiliaryRequest),
|
||||
Unsure(AuxiliaryRequest),
|
||||
/// No epoch change.
|
||||
No,
|
||||
/// The epoch will change, with proof.
|
||||
@ -310,7 +308,7 @@ pub trait Engine<M: Machine>: Sync + Send {
|
||||
fn verify_block_external(&self, _header: &Header) -> Result<(), M::Error> { Ok(()) }
|
||||
|
||||
/// Genesis epoch data.
|
||||
fn genesis_epoch_data<'a>(&self, _header: &Header, _state: &<M as Localized<'a>>::StateContext) -> Result<Vec<u8>, String> { Ok(Vec::new()) }
|
||||
fn genesis_epoch_data<'a>(&self, _header: &Header, _state: &machine::Call) -> Result<Vec<u8>, String> { Ok(Vec::new()) }
|
||||
|
||||
/// Whether an epoch change is signalled at the given header but will require finality.
|
||||
/// If a change can be enacted immediately then return `No` from this function but
|
||||
@ -321,7 +319,7 @@ pub trait Engine<M: Machine>: 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: <M as Localized<'a>>::AuxiliaryData)
|
||||
fn signals_epoch_end<'a>(&self, _header: &Header, _aux: AuxiliaryData<'a>)
|
||||
-> EpochChange<M>
|
||||
{
|
||||
EpochChange::No
|
||||
|
@ -430,8 +430,6 @@ pub enum AuxiliaryRequest {
|
||||
|
||||
impl super::Machine for EthereumMachine {
|
||||
type EngineClient = ::client::EngineClient;
|
||||
type AuxiliaryRequest = AuxiliaryRequest;
|
||||
type AncestryAction = ::types::ancestry_action::AncestryAction;
|
||||
|
||||
type Error = Error;
|
||||
|
||||
@ -444,11 +442,6 @@ impl super::Machine for EthereumMachine {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> super::LocalizedMachine<'a> for EthereumMachine {
|
||||
type StateContext = Call<'a>;
|
||||
type AuxiliaryData = AuxiliaryData<'a>;
|
||||
}
|
||||
|
||||
// Try to round gas_limit a bit so that:
|
||||
// 1) it will still be in desired range
|
||||
// 2) it will be a nearest (with tendency to increase) multiple of PARITY_GAS_LIMIT_DETERMINANT
|
||||
|
@ -21,13 +21,9 @@ use ethereum_types::{U256, Address};
|
||||
use block::ExecutedBlock;
|
||||
|
||||
/// Generalization of types surrounding blockchain-suitable state machines.
|
||||
pub trait Machine: for<'a> LocalizedMachine<'a> {
|
||||
pub trait Machine: Send + Sync {
|
||||
/// A handle to a blockchain client for this machine.
|
||||
type EngineClient: ?Sized;
|
||||
/// A description of needed auxiliary data.
|
||||
type AuxiliaryRequest;
|
||||
/// Actions taken on ancestry blocks when commiting a new block.
|
||||
type AncestryAction;
|
||||
|
||||
/// Errors which can occur when querying or interacting with the machine.
|
||||
type Error;
|
||||
@ -39,13 +35,3 @@ pub trait Machine: for<'a> LocalizedMachine<'a> {
|
||||
/// 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>;
|
||||
}
|
||||
|
||||
/// Machine-related types localized to a specific lifetime.
|
||||
// TODO: this is a workaround for a lack of associated type constructors in the language.
|
||||
pub trait LocalizedMachine<'a>: Sync + Send {
|
||||
/// Definition of auxiliary data associated to a specific block.
|
||||
type AuxiliaryData: 'a;
|
||||
/// A context providing access to the state in a controlled capacity.
|
||||
/// Generally also provides verifiable proofs.
|
||||
type StateContext: ?Sized + 'a;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user