Move EvmSchedule -> evm::Schedule

This commit is contained in:
Gav Wood 2016-01-11 16:28:30 +01:00
parent f19a6e54bf
commit 85ac9af832
10 changed files with 23 additions and 22 deletions

View File

@ -2,7 +2,6 @@ pub use util::*;
pub use basic_types::*; pub use basic_types::*;
pub use error::*; pub use error::*;
pub use env_info::*; pub use env_info::*;
pub use evm_schedule::*;
pub use views::*; pub use views::*;
pub use builtin::*; pub use builtin::*;
pub use header::*; pub use header::*;

View File

@ -1,6 +1,7 @@
use common::*; use common::*;
use block::Block; use block::Block;
use spec::Spec; use spec::Spec;
use evm::Schedule;
/// A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based. /// A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based.
/// Provides hooks into each of the major parts of block import. /// Provides hooks into each of the major parts of block import.
@ -22,7 +23,7 @@ pub trait Engine : Sync + Send {
fn spec(&self) -> &Spec; fn spec(&self) -> &Spec;
/// Get the EVM schedule for the given `env_info`. /// Get the EVM schedule for the given `env_info`.
fn evm_schedule(&self, env_info: &EnvInfo) -> EvmSchedule; fn schedule(&self, env_info: &EnvInfo) -> Schedule;
/// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`. /// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`.
fn maximum_extra_data_size(&self) -> usize { decode(&self.spec().engine_params.get("maximumExtraDataSize").unwrap()) } fn maximum_extra_data_size(&self) -> usize { decode(&self.spec().engine_params.get("maximumExtraDataSize").unwrap()) }

View File

@ -2,6 +2,7 @@ use common::*;
use block::*; use block::*;
use spec::*; use spec::*;
use engine::*; use engine::*;
use evm::*;
/// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum /// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum
/// mainnet chains in the Olympic, Frontier and Homestead eras. /// mainnet chains in the Olympic, Frontier and Homestead eras.
@ -26,7 +27,7 @@ impl Engine for Ethash {
/// Additional engine-specific information for the user/developer concerning `header`. /// Additional engine-specific information for the user/developer concerning `header`.
fn extra_info(&self, _header: &Header) -> HashMap<String, String> { HashMap::new() } fn extra_info(&self, _header: &Header) -> HashMap<String, String> { HashMap::new() }
fn spec(&self) -> &Spec { &self.spec } fn spec(&self) -> &Spec { &self.spec }
fn evm_schedule(&self, _env_info: &EnvInfo) -> EvmSchedule { EvmSchedule::new_frontier() } fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() }
/// Apply the block reward on finalisation of the block. /// Apply the block reward on finalisation of the block.
/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current). /// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).

View File

@ -9,11 +9,10 @@ use util::sha3::*;
use util::bytes::*; use util::bytes::*;
use state::*; use state::*;
use env_info::*; use env_info::*;
use evm_schedule::*;
use engine::*; use engine::*;
use transaction::*; use transaction::*;
use log_entry::*; use log_entry::*;
use evm::{VmFactory, Ext, EvmParams, EvmResult, EvmError}; use evm::{Schedule, VmFactory, Ext, EvmParams, EvmResult, EvmError};
/// Returns new address created from address and given nonce. /// Returns new address created from address and given nonce.
pub fn contract_address(address: &Address, nonce: &U256) -> Address { pub fn contract_address(address: &Address, nonce: &U256) -> Address {
@ -242,7 +241,7 @@ impl<'a> Executive<'a> {
Err(ExecutionError::OutOfGas) Err(ExecutionError::OutOfGas)
}, },
Ok(gas_left) => { Ok(gas_left) => {
let schedule = self.engine.evm_schedule(self.info); let schedule = self.engine.schedule(self.info);
// refunds from SSTORE nonzero -> zero // refunds from SSTORE nonzero -> zero
let sstore_refunds = U256::from(schedule.sstore_refund_gas) * substate.refunds_count; let sstore_refunds = U256::from(schedule.sstore_refund_gas) * substate.refunds_count;
@ -294,7 +293,7 @@ pub struct Externalities<'a> {
depth: usize, depth: usize,
params: &'a EvmParams, params: &'a EvmParams,
substate: &'a mut Substate, substate: &'a mut Substate,
schedule: EvmSchedule, schedule: Schedule,
output: OutputPolicy<'a> output: OutputPolicy<'a>
} }
@ -314,7 +313,7 @@ impl<'a> Externalities<'a> {
depth: depth, depth: depth,
params: params, params: params,
substate: substate, substate: substate,
schedule: engine.evm_schedule(info), schedule: engine.schedule(info),
output: output output: output
} }
} }
@ -459,7 +458,7 @@ impl<'a> Ext for Externalities<'a> {
self.substate.suicides.insert(address); self.substate.suicides.insert(address);
} }
fn schedule(&self) -> &EvmSchedule { fn schedule(&self) -> &Schedule {
&self.schedule &self.schedule
} }
} }

View File

@ -3,7 +3,7 @@
use util::hash::*; use util::hash::*;
use util::uint::*; use util::uint::*;
use util::bytes::*; use util::bytes::*;
use evm_schedule::*; use evm::Schedule;
use evm::EvmError; use evm::EvmError;
// TODO: replace all u64 with u256 // TODO: replace all u64 with u256
@ -54,5 +54,5 @@ pub trait Ext {
fn suicide(&mut self); fn suicide(&mut self);
/// Returns schedule. /// Returns schedule.
fn schedule(&self) -> &EvmSchedule; fn schedule(&self) -> &Schedule;
} }

View File

@ -375,7 +375,7 @@ mod tests {
use state::*; use state::*;
use env_info::*; use env_info::*;
use engine::*; use engine::*;
use evm_schedule::*; use schedule::*;
use spec::*; use spec::*;
struct TestEngine; struct TestEngine;
@ -387,7 +387,7 @@ mod tests {
impl Engine for TestEngine { impl Engine for TestEngine {
fn name(&self) -> &str { "TestEngine" } fn name(&self) -> &str { "TestEngine" }
fn spec(&self) -> &Spec { unimplemented!() } fn spec(&self) -> &Spec { unimplemented!() }
fn evm_schedule(&self, _env_info: &EnvInfo) -> EvmSchedule { EvmSchedule::new_frontier() } fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() }
} }
#[test] #[test]

View File

@ -6,6 +6,7 @@ pub mod vmfactory;
//pub mod logentry; //pub mod logentry;
pub mod executive; pub mod executive;
pub mod params; pub mod params;
pub mod schedule;
#[cfg(feature = "jit" )] #[cfg(feature = "jit" )]
mod jit; mod jit;
@ -16,3 +17,4 @@ pub use self::vmfactory::VmFactory;
// TODO: reduce this to absolutely necessary things // TODO: reduce this to absolutely necessary things
pub use self::executive::{Executive, ExecutionResult, Externalities, Substate, OutputPolicy}; pub use self::executive::{Executive, ExecutionResult, Externalities, Substate, OutputPolicy};
pub use self::params::EvmParams; pub use self::params::EvmParams;
pub use self::schedule::Schedule;

View File

@ -1,5 +1,5 @@
/// Definition of the cost schedule and other parameterisations for the EVM. /// Definition of the cost schedule and other parameterisations for the EVM.
pub struct EvmSchedule { pub struct Schedule {
pub exceptional_failed_code_deposit: bool, pub exceptional_failed_code_deposit: bool,
pub have_delegate_call: bool, pub have_delegate_call: bool,
pub stack_limit: usize, pub stack_limit: usize,
@ -32,19 +32,19 @@ pub struct EvmSchedule {
pub copy_gas: usize, pub copy_gas: usize,
} }
impl EvmSchedule { impl Schedule {
/// Schedule for the Frontier-era of the Ethereum main net. /// Schedule for the Frontier-era of the Ethereum main net.
pub fn new_frontier() -> EvmSchedule { pub fn new_frontier() -> Schedule {
Self::new(false, false, 21000) Self::new(false, false, 21000)
} }
/// Schedule for the Homestead-era of the Ethereum main net. /// Schedule for the Homestead-era of the Ethereum main net.
pub fn new_homestead() -> EvmSchedule { pub fn new_homestead() -> Schedule {
Self::new(true, true, 53000) Self::new(true, true, 53000)
} }
fn new(efcd: bool, hdc: bool, tcg: usize) -> EvmSchedule { fn new(efcd: bool, hdc: bool, tcg: usize) -> Schedule {
EvmSchedule{ Schedule{
exceptional_failed_code_deposit: efcd, exceptional_failed_code_deposit: efcd,
have_delegate_call: hdc, have_delegate_call: hdc,
stack_limit: 1024, stack_limit: 1024,

View File

@ -98,7 +98,6 @@ pub mod header;
pub mod transaction; pub mod transaction;
pub mod receipt; pub mod receipt;
pub mod null_engine; pub mod null_engine;
pub mod evm_schedule;
pub mod builtin; pub mod builtin;
pub mod spec; pub mod spec;
pub mod views; pub mod views;

View File

@ -1,6 +1,6 @@
use engine::Engine; use engine::Engine;
use spec::Spec; use spec::Spec;
use evm_schedule::EvmSchedule; use evm::Schedule;
use env_info::EnvInfo; use env_info::EnvInfo;
/// An engine which does not provide any consensus mechanism. /// An engine which does not provide any consensus mechanism.
@ -17,5 +17,5 @@ impl NullEngine {
impl Engine for NullEngine { impl Engine for NullEngine {
fn name(&self) -> &str { "NullEngine" } fn name(&self) -> &str { "NullEngine" }
fn spec(&self) -> &Spec { &self.spec } fn spec(&self) -> &Spec { &self.spec }
fn evm_schedule(&self, _env_info: &EnvInfo) -> EvmSchedule { EvmSchedule::new_frontier() } fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() }
} }