Merge with master

This commit is contained in:
Anton Gavrilov
2017-08-02 17:24:34 +02:00
158 changed files with 14603 additions and 959 deletions

View File

@@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! DB backend wrapper for Account trie
use std::collections::HashMap;
use util::*;
use rlp::NULL_RLP;

View File

@@ -25,7 +25,7 @@ use util::{Bytes, Address, Hashable, U256, H256, ordered_trie_root, SHA3_NULL_RL
use util::error::{Mismatch, OutOfBounds};
use basic_types::{LogBloom, Seal};
use evm::env_info::{EnvInfo, LastHashes};
use vm::{EnvInfo, LastHashes};
use engines::Engine;
use error::{Error, BlockError, TransactionError};
use factory::Factories;
@@ -680,7 +680,7 @@ mod tests {
use tests::helpers::*;
use super::*;
use engines::Engine;
use evm::env_info::LastHashes;
use vm::LastHashes;
use error::Error;
use header::Header;
use factory::Factories;

View File

@@ -16,6 +16,9 @@
//! Blockchain database.
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use std::mem;
use bloomchain as bc;
use util::*;
use rlp::*;

View File

@@ -16,6 +16,8 @@
//! Blockchain DB extras.
use std::ops;
use std::io::Write;
use bloomchain;
use blooms::{GroupPosition, BloomGroup};
use db::Key;
@@ -56,7 +58,7 @@ fn with_index(hash: &H256, i: ExtrasIndex) -> H264 {
pub struct BlockNumberKey([u8; 5]);
impl Deref for BlockNumberKey {
impl ops::Deref for BlockNumberKey {
type Target = [u8];
fn deref(&self) -> &Self::Target {
@@ -88,7 +90,7 @@ impl Key<BlockDetails> for H256 {
pub struct LogGroupKey([u8; 6]);
impl Deref for LogGroupKey {
impl ops::Deref for LogGroupKey {
type Target = [u8];
fn deref(&self) -> &Self::Target {
@@ -160,7 +162,8 @@ pub const EPOCH_KEY_PREFIX: &'static [u8; DB_PREFIX_LEN] = &[
];
pub struct EpochTransitionsKey([u8; EPOCH_KEY_LEN]);
impl Deref for EpochTransitionsKey {
impl ops::Deref for EpochTransitionsKey {
type Target = [u8];
fn deref(&self) -> &[u8] { &self.0[..] }

View File

@@ -36,9 +36,9 @@ impl From<&'static str> for Error {
}
}
impl Into<::evm::Error> for Error {
fn into(self) -> ::evm::Error {
::evm::Error::BuiltIn(self.0)
impl Into<::vm::Error> for Error {
fn into(self) -> ::vm::Error {
::vm::Error::BuiltIn(self.0)
}
}

View File

@@ -42,9 +42,8 @@ use client::{
};
use encoded;
use engines::{Engine, EpochTransition};
use evm::env_info::EnvInfo;
use evm::env_info::LastHashes;
use error::{ImportError, ExecutionError, CallError, BlockError, ImportResult, Error as EthcoreError};
use vm::{EnvInfo, LastHashes};
use evm::{Factory as EvmFactory, Schedule};
use executive::{Executive, Executed, TransactOptions, contract_address};
use factory::Factories;

View File

@@ -23,7 +23,7 @@ use util::kvdb::{self, KeyValueDB};
use {state, state_db, client, executive, trace, db, spec};
use factory::Factories;
use evm::{self, VMType};
use evm::action_params::ActionParams;
use vm::{self, ActionParams};
/// EVM test Error.
#[derive(Debug)]
@@ -31,7 +31,7 @@ pub enum EvmTestError {
/// Trie integrity error.
Trie(util::TrieError),
/// EVM error.
Evm(evm::Error),
Evm(vm::Error),
/// Initialization error.
Initialization(::error::Error),
/// Low-level database error.

View File

@@ -40,7 +40,7 @@ pub use types::pruning_info::PruningInfo;
pub use types::call_analytics::CallAnalytics;
pub use executive::{Executed, Executive, TransactOptions};
pub use evm::env_info::{LastHashes, EnvInfo};
pub use vm::{LastHashes, EnvInfo};
pub use error::{BlockImportError, TransactionImportError, TransactionImportResult};
pub use verification::VerifierType;

View File

@@ -17,6 +17,9 @@
//! Test client.
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
use std::sync::Arc;
use std::collections::{HashMap, BTreeMap};
use std::mem;
use rustc_hex::FromHex;
use util::*;
use rlp::*;
@@ -36,7 +39,8 @@ use log_entry::LocalizedLogEntry;
use receipt::{Receipt, LocalizedReceipt};
use blockchain::extras::BlockReceipts;
use error::{ImportResult, Error as EthcoreError};
use evm::{Factory as EvmFactory, VMType, Schedule};
use evm::{Factory as EvmFactory, VMType};
use vm::Schedule;
use miner::{Miner, MinerService, TransactionImportResult};
use spec::Spec;
use types::basic_account::BasicAccount;

View File

@@ -19,7 +19,7 @@ use std::collections::BTreeMap;
use block::{OpenBlock, SealedBlock, ClosedBlock};
use blockchain::TreeRoute;
use encoded;
use evm::env_info::LastHashes;
use vm::LastHashes;
use error::{ImportResult, CallError, Error as EthcoreError};
use error::{TransactionImportResult, BlockImportError};
use evm::{Factory as EvmFactory, Schedule};

View File

@@ -17,8 +17,10 @@
//! A blockchain engine that supports a non-instant BFT proof-of-authority.
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::time::{UNIX_EPOCH, Duration};
use std::collections::{BTreeMap, HashSet, HashMap};
use std::cmp;
use account_provider::AccountProvider;
use block::*;
@@ -446,9 +448,9 @@ impl Engine for AuthorityRound {
let gas_limit = parent.gas_limit().clone();
let bound_divisor = self.params().gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
cmp::min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
cmp::max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
}
});
}
@@ -515,7 +517,7 @@ impl Engine for AuthorityRound {
fn on_new_block(
&self,
block: &mut ExecutedBlock,
last_hashes: Arc<::evm::env_info::LastHashes>,
last_hashes: Arc<::vm::LastHashes>,
epoch_begin: bool,
) -> Result<(), Error> {
let parent_hash = block.fields().header.parent_hash().clone();
@@ -813,7 +815,7 @@ impl Engine for AuthorityRound {
}
}
fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> result::Result<(), Error> {
fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> Result<(), Error> {
t.check_low_s()?;
if let Some(n) = t.network_id() {
@@ -849,6 +851,7 @@ impl Engine for AuthorityRound {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use util::*;
use header::Header;
@@ -939,10 +942,10 @@ mod tests {
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::new_test_round().engine;
@@ -965,10 +968,10 @@ mod tests {
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::new_test_round().engine;
@@ -991,10 +994,10 @@ mod tests {
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&4usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::new_test_round().engine;
@@ -1028,10 +1031,10 @@ mod tests {
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&1usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_seal(vec![encode(&3usize).into_vec()]);
// Do not report when signer not present.

View File

@@ -16,7 +16,9 @@
//! A blockchain engine that supports a basic, non-BFT proof-of-authority.
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::collections::BTreeMap;
use std::cmp;
use util::*;
use ethkey::{recover, public_to_address, Signature};
use account_provider::AccountProvider;
@@ -116,9 +118,9 @@ impl Engine for BasicAuthority {
let gas_limit = parent.gas_limit().clone();
let bound_divisor = self.params().gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
cmp::min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
cmp::max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
}
});
}
@@ -142,7 +144,7 @@ impl Engine for BasicAuthority {
Seal::None
}
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
// check the seal fields.
// TODO: pull this out into common code.
if header.seal().len() != self.seal_fields() {
@@ -153,11 +155,11 @@ impl Engine for BasicAuthority {
Ok(())
}
fn verify_block_unordered(&self, _header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_unordered(&self, _header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
Ok(())
}
fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
// Do not calculate difficulty for genesis blocks.
if header.number() == 0 {
return Err(From::from(BlockError::RidiculousNumber(OutOfBounds { min: Some(1), max: None, found: header.number() })));
@@ -249,6 +251,7 @@ impl Engine for BasicAuthority {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use util::*;
use block::*;
use error::{BlockError, Error};

View File

@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::collections::BTreeMap;
use util::{Address, HashMap};
use std::collections::{BTreeMap, HashMap};
use util::Address;
use builtin::Builtin;
use engines::{Engine, Seal};
use spec::CommonParams;
@@ -63,6 +63,7 @@ impl Engine for InstantSeal {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use util::*;
use tests::helpers::*;
use spec::Spec;

View File

@@ -35,7 +35,9 @@ pub use self::instant_seal::InstantSeal;
pub use self::null_engine::NullEngine;
pub use self::tendermint::Tendermint;
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use self::epoch::PendingTransition;
@@ -43,16 +45,14 @@ use account_provider::AccountProvider;
use block::ExecutedBlock;
use builtin::Builtin;
use client::Client;
use evm::env_info::{EnvInfo, LastHashes};
use vm::{EnvInfo, LastHashes, Schedule, CreateContractAddress};
use error::Error;
use evm::Schedule;
use header::{Header, BlockNumber};
use receipt::Receipt;
use trace::FlatTrace;
use snapshot::SnapshotComponents;
use spec::CommonParams;
use transaction::{UnverifiedTransaction, SignedTransaction};
use evm::CreateContractAddress;
use ethkey::Signature;
use util::*;
@@ -401,13 +401,12 @@ pub trait Engine : Sync + Send {
/// Common engine utilities
pub mod common {
use std::sync::Arc;
use block::ExecutedBlock;
use evm::env_info::{EnvInfo, LastHashes};
use error::Error;
use transaction::SYSTEM_ADDRESS;
use executive::Executive;
use evm::CallType;
use evm::action_params::{ActionParams, ActionValue};
use vm::{CallType, ActionParams, ActionValue, EnvInfo, LastHashes};
use trace::{NoopTracer, NoopVMTracer};
use state::Substate;

View File

@@ -16,7 +16,8 @@
//! A signer used by Engines which need to sign messages.
use util::{Arc, H256, Address};
use std::sync::Arc;
use util::{H256, Address};
use ethkey::Signature;
use account_provider::{self, AccountProvider};

View File

@@ -16,6 +16,7 @@
//! Tendermint message handling.
use std::cmp;
use util::*;
use super::{Height, View, BlockHash, Step};
use error::Error;
@@ -110,13 +111,13 @@ impl Default for VoteStep {
}
impl PartialOrd for VoteStep {
fn partial_cmp(&self, m: &VoteStep) -> Option<Ordering> {
fn partial_cmp(&self, m: &VoteStep) -> Option<cmp::Ordering> {
Some(self.cmp(m))
}
}
impl Ord for VoteStep {
fn cmp(&self, m: &VoteStep) -> Ordering {
fn cmp(&self, m: &VoteStep) -> cmp::Ordering {
if self.height != m.height {
self.height.cmp(&m.height)
} else if self.view != m.view {
@@ -198,6 +199,7 @@ pub fn message_hash(vote_step: VoteStep, block_hash: H256) -> H256 {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use util::*;
use rlp::*;
use account_provider::AccountProvider;

View File

@@ -25,8 +25,10 @@
mod message;
mod params;
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use std::collections::{HashSet, BTreeMap, HashMap};
use std::cmp;
use util::*;
use client::{Client, EngineClient};
use error::{Error, BlockError};
@@ -470,9 +472,9 @@ impl Engine for Tendermint {
let gas_limit = parent.gas_limit().clone();
let bound_divisor = self.params().gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
cmp::min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
cmp::max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
}
});
}
@@ -783,6 +785,7 @@ impl Engine for Tendermint {
#[cfg(test)]
mod tests {
use std::str::FromStr;
use rustc_hex::FromHex;
use util::*;
use block::*;

View File

@@ -126,6 +126,7 @@ impl ValidatorSet for ValidatorContract {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use util::*;
use rlp::encode;
@@ -142,11 +143,11 @@ mod tests {
#[test]
fn fetches_validators() {
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_contract, None);
let vc = Arc::new(ValidatorContract::new(Address::from_str("0000000000000000000000000000000000000005").unwrap()));
let vc = Arc::new(ValidatorContract::new("0000000000000000000000000000000000000005".parse::<Address>().unwrap()));
vc.register_contract(Arc::downgrade(&client));
let last_hash = client.best_block_header().hash();
assert!(vc.contains(&last_hash, &Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap()));
assert!(vc.contains(&last_hash, &Address::from_str("82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap()));
assert!(vc.contains(&last_hash, &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e".parse::<Address>().unwrap()));
assert!(vc.contains(&last_hash, &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1".parse::<Address>().unwrap()));
}
#[test]
@@ -155,7 +156,7 @@ mod tests {
let v1 = tap.insert_account("1".sha3().into(), "").unwrap();
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_contract, Some(tap.clone()));
client.engine().register_client(Arc::downgrade(&client));
let validator_contract = Address::from_str("0000000000000000000000000000000000000005").unwrap();
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
// Make sure reporting can be done.
client.miner().set_gas_floor_target(1_000_000.into());

View File

@@ -142,6 +142,8 @@ impl ValidatorSet for Multi {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::collections::BTreeMap;
use account_provider::AccountProvider;
use client::{BlockChainClient, EngineClient};
use engines::EpochChange;

View File

@@ -16,7 +16,7 @@
/// Validator set maintained in a contract, updated using `getValidators` method.
use std::sync::Weak;
use std::sync::{Weak, Arc};
use futures::Future;
use native_contracts::ValidatorSet as Provider;
@@ -299,7 +299,7 @@ impl ValidatorSet for ValidatorSafeContract {
let (old_header, state_items) = decode_first_proof(&rlp)?;
let old_hash = old_header.hash();
let env_info = ::evm::env_info::EnvInfo {
let env_info = ::vm::EnvInfo {
number: old_header.number(),
author: *old_header.author(),
difficulty: *old_header.difficulty(),
@@ -422,6 +422,7 @@ impl ValidatorSet for ValidatorSafeContract {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use util::*;
use types::ids::BlockId;
@@ -438,11 +439,11 @@ mod tests {
#[test]
fn fetches_validators() {
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, None);
let vc = Arc::new(ValidatorSafeContract::new(Address::from_str("0000000000000000000000000000000000000005").unwrap()));
let vc = Arc::new(ValidatorSafeContract::new("0000000000000000000000000000000000000005".parse::<Address>().unwrap()));
vc.register_contract(Arc::downgrade(&client));
let last_hash = client.best_block_header().hash();
assert!(vc.contains(&last_hash, &Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap()));
assert!(vc.contains(&last_hash, &Address::from_str("82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap()));
assert!(vc.contains(&last_hash, &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e".parse::<Address>().unwrap()));
assert!(vc.contains(&last_hash, &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1".parse::<Address>().unwrap()));
}
#[test]
@@ -454,7 +455,7 @@ mod tests {
let network_id = Spec::new_validator_safe_contract().network_id();
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, Some(tap));
client.engine().register_client(Arc::downgrade(&client));
let validator_contract = Address::from_str("0000000000000000000000000000000000000005").unwrap();
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
client.miner().set_engine_signer(v1, "".into()).unwrap();
// Remove "1" validator.
@@ -520,7 +521,7 @@ mod tests {
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, None);
let engine = client.engine().clone();
let validator_contract = Address::from_str("0000000000000000000000000000000000000005").unwrap();
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
let last_hash = client.best_block_header().hash();
let mut new_header = Header::default();

View File

@@ -17,8 +17,9 @@
/// Used for Engine testing.
use std::str::FromStr;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use util::{Arc, Bytes, H256, Address, HeapSizeOf};
use util::{Bytes, H256, Address, HeapSizeOf};
use engines::{Call, Engine};
use header::{Header, BlockNumber};

View File

@@ -17,6 +17,8 @@
//! Collects votes on hashes at each Message::Round.
use std::fmt::Debug;
use std::collections::{BTreeMap, HashSet, HashMap};
use std::hash::Hash;
use util::*;
use rlp::{Encodable, RlpStream};

View File

@@ -16,6 +16,7 @@
//! General error types for use in ethcore.
use std::fmt;
use util::*;
use io::*;
use header::BlockNumber;

View File

@@ -15,11 +15,14 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::path::Path;
use std::cmp;
use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;
use ethash::{quick_get_difficulty, slow_get_seedhash, EthashManager};
use util::*;
use block::*;
use builtin::Builtin;
use evm::env_info::EnvInfo;
use vm::EnvInfo;
use error::{BlockError, Error, TransactionError};
use trace::{Tracer, ExecutiveTracer,RewardType};
use header::{Header, BlockNumber};
@@ -30,7 +33,7 @@ use engines::{self, Engine, CloseOutcome};
use evm::Schedule;
use ethjson;
use rlp::{self, UntrustedRlp};
use evm::env_info::LastHashes;
use vm::LastHashes;
/// Parity tries to round block.gas_limit to multiple of this constant
pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]);
@@ -224,15 +227,15 @@ impl Engine for Arc<Ethash> {
let lower_limit = gas_limit - gas_limit / bound_divisor + 1.into();
let upper_limit = gas_limit + gas_limit / bound_divisor - 1.into();
let gas_limit = if gas_limit < gas_floor_target {
let gas_limit = min(gas_floor_target, upper_limit);
let gas_limit = cmp::min(gas_floor_target, upper_limit);
round_block_gas_limit(gas_limit, lower_limit, upper_limit)
} else if gas_limit > gas_ceil_target {
let gas_limit = max(gas_ceil_target, lower_limit);
let gas_limit = cmp::max(gas_ceil_target, lower_limit);
round_block_gas_limit(gas_limit, lower_limit, upper_limit)
} else {
let total_lower_limit = max(lower_limit, gas_floor_target);
let total_upper_limit = min(upper_limit, gas_ceil_target);
let gas_limit = max(gas_floor_target, min(total_upper_limit,
let total_lower_limit = cmp::max(lower_limit, gas_floor_target);
let total_upper_limit = cmp::min(upper_limit, gas_ceil_target);
let gas_limit = cmp::max(gas_floor_target, cmp::min(total_upper_limit,
lower_limit + (header.gas_used().clone() * 6.into() / 5.into()) / bound_divisor));
round_block_gas_limit(gas_limit, total_lower_limit, total_upper_limit)
};
@@ -329,7 +332,7 @@ impl Engine for Arc<Ethash> {
}
}
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
// check the seal fields.
if header.seal().len() != self.seal_fields() {
return Err(From::from(BlockError::InvalidSealArity(
@@ -367,7 +370,7 @@ impl Engine for Arc<Ethash> {
Ok(())
}
fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
if header.seal().len() != self.seal_fields() {
return Err(From::from(BlockError::InvalidSealArity(
Mismatch { expected: self.seal_fields(), found: header.seal().len() }
@@ -386,7 +389,7 @@ impl Engine for Arc<Ethash> {
Ok(())
}
fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
// we should not calculate difficulty for genesis blocks
if header.number() == 0 {
return Err(From::from(BlockError::RidiculousNumber(OutOfBounds { min: Some(1), max: None, found: header.number() })));
@@ -410,7 +413,7 @@ impl Engine for Arc<Ethash> {
Ok(())
}
fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> result::Result<(), Error> {
fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> Result<(), Error> {
if header.number() >= self.ethash_params.min_gas_price_transition && t.gas_price < self.ethash_params.min_gas_price {
return Err(TransactionError::InsufficientGasPrice { minimal: self.ethash_params.min_gas_price, got: t.gas_price }.into());
}
@@ -503,28 +506,28 @@ impl Ethash {
if diff_inc <= threshold {
*parent.difficulty() + *parent.difficulty() / difficulty_bound_divisor * (threshold - diff_inc).into()
} else {
let multiplier = min(diff_inc - threshold, 99).into();
let multiplier = cmp::min(diff_inc - threshold, 99).into();
parent.difficulty().saturating_sub(
*parent.difficulty() / difficulty_bound_divisor * multiplier
)
}
};
target = max(min_difficulty, target);
target = cmp::max(min_difficulty, target);
if header.number() < self.ethash_params.bomb_defuse_transition {
if header.number() < self.ethash_params.ecip1010_pause_transition {
let period = ((parent.number() + 1) / EXP_DIFF_PERIOD) as usize;
if period > 1 {
target = max(min_difficulty, target + (U256::from(1) << (period - 2)));
target = cmp::max(min_difficulty, target + (U256::from(1) << (period - 2)));
}
}
else if header.number() < self.ethash_params.ecip1010_continue_transition {
let fixed_difficulty = ((self.ethash_params.ecip1010_pause_transition / EXP_DIFF_PERIOD) - 2) as usize;
target = max(min_difficulty, target + (U256::from(1) << fixed_difficulty));
target = cmp::max(min_difficulty, target + (U256::from(1) << fixed_difficulty));
}
else {
let period = ((parent.number() + 1) / EXP_DIFF_PERIOD) as usize;
let delay = ((self.ethash_params.ecip1010_continue_transition - self.ethash_params.ecip1010_pause_transition) / EXP_DIFF_PERIOD) as usize;
target = max(min_difficulty, target + (U256::from(1) << (period - delay - 2)));
target = cmp::max(min_difficulty, target + (U256::from(1) << (period - delay - 2)));
}
}
target
@@ -569,6 +572,9 @@ impl Header {
#[cfg(test)]
mod tests {
use std::str::FromStr;
use std::collections::BTreeMap;
use std::sync::Arc;
use util::*;
use block::*;
use tests::helpers::*;

View File

@@ -134,23 +134,4 @@ mod tests {
let _ = frontier.engine;
}
#[test]
fn all_spec_files_valid() {
let tmp = ::std::env::temp_dir();
new_olympic(&tmp);
new_foundation(&tmp);
new_classic(&tmp);
new_expanse(&tmp);
new_kovan(&tmp);
new_ropsten(&tmp);
new_morden(&tmp);
new_frontier_test();
new_homestead_test();
new_eip150_test();
new_eip161_test();
new_transition_test();
new_mainnet_like();
new_metropolis_test();
}
}

View File

@@ -17,7 +17,7 @@
//! Transaction execution format module.
use util::{Bytes, U256, Address, U512, trie};
use evm;
use vm;
use trace::{VMTrace, FlatTrace};
use log_entry::LogEntry;
use state_diff::StateDiff;
@@ -28,7 +28,7 @@ use std::fmt;
#[derive(Debug, PartialEq, Clone)]
pub struct Executed {
/// True if the outer call/create resulted in an exceptional exit.
pub exception: Option<evm::Error>,
pub exception: Option<vm::Error>,
/// Gas paid up front for execution of transaction.
pub gas: U256,

View File

@@ -15,14 +15,16 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Transaction Execution environment.
use std::cmp;
use std::sync::Arc;
use util::*;
use evm::action_params::{ActionParams, ActionValue};
use state::{Backend as StateBackend, State, Substate, CleanupMode};
use engines::Engine;
use evm::CallType;
use evm::env_info::EnvInfo;
use vm::EnvInfo;
use error::ExecutionError;
use evm::{self, wasm, Factory, Ext, Finalize, CreateContractAddress, FinalizationResult, ReturnData, CleanDustMode};
use evm::{CallType, Factory, Finalize, FinalizationResult};
use vm::{self, Ext, CreateContractAddress, ReturnData, CleanDustMode, ActionParams, ActionValue};
use wasm;
use externalities::*;
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer, VMTrace, VMTracer, ExecutiveVMTracer, NoopVMTracer};
use transaction::{Action, SignedTransaction};
@@ -74,8 +76,8 @@ pub struct TransactOptions {
pub check_nonce: bool,
}
pub fn executor<E>(engine: &E, vm_factory: &Factory, params: &ActionParams)
-> Box<evm::Evm> where E: Engine + ?Sized
pub fn executor<E>(engine: &E, vm_factory: &Factory, params: &ActionParams)
-> Box<vm::Vm> where E: Engine + ?Sized
{
if engine.supports_wasm() && params.code.as_ref().map_or(false, |code| code.len() > 4 && &code[0..4] == WASM_MAGIC_NUMBER) {
Box::new(
@@ -269,7 +271,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
output_policy: OutputPolicy,
tracer: &mut T,
vm_tracer: &mut V
) -> evm::Result<FinalizationResult> where T: Tracer, V: VMTracer {
) -> vm::Result<FinalizationResult> where T: Tracer, V: VMTracer {
let depth_threshold = ::io::LOCAL_STACK_SIZE.with(|sz| sz.get() / STACK_SIZE_PER_DEPTH);
let static_call = params.call_type == CallType::StaticCall;
@@ -299,7 +301,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
/// Calls contract function with given contract params.
/// NOTE. It does not finalize the transaction (doesn't do refunds, nor suicides).
/// Modifies the substate and the output.
/// Returns either gas_left or `evm::Error`.
/// Returns either gas_left or `vm::Error`.
pub fn call<T, V>(
&mut self,
params: ActionParams,
@@ -307,14 +309,14 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
mut output: BytesRef,
tracer: &mut T,
vm_tracer: &mut V
) -> evm::Result<(U256, ReturnData)> where T: Tracer, V: VMTracer {
) -> vm::Result<(U256, ReturnData)> where T: Tracer, V: VMTracer {
trace!("Executive::call(params={:?}) self.env_info={:?}", params, self.info);
if (params.call_type == CallType::StaticCall ||
((params.call_type == CallType::Call || params.call_type == CallType::DelegateCall) &&
self.static_flag))
&& params.value.value() > 0.into() {
return Err(evm::Error::MutableCallInStaticContext);
return Err(vm::Error::MutableCallInStaticContext);
}
// backup used in case of running out of gas
@@ -344,7 +346,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
if cost <= params.gas {
if let Err(e) = builtin.execute(data, &mut output) {
self.state.revert_to_checkpoint();
let evm_err: evm::evm::Error = e.into();
let evm_err: vm::Error = e.into();
tracer.trace_failed_call(trace_info, vec![], evm_err.clone().into());
Err(evm_err)
} else {
@@ -371,9 +373,9 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
// just drain the whole gas
self.state.revert_to_checkpoint();
tracer.trace_failed_call(trace_info, vec![], evm::Error::OutOfGas.into());
tracer.trace_failed_call(trace_info, vec![], vm::Error::OutOfGas.into());
Err(evm::Error::OutOfGas)
Err(vm::Error::OutOfGas)
}
} else {
let trace_info = tracer.prepare_trace_call(&params);
@@ -432,17 +434,17 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
substate: &mut Substate,
tracer: &mut T,
vm_tracer: &mut V,
) -> evm::Result<(U256, ReturnData)> where T: Tracer, V: VMTracer {
) -> vm::Result<(U256, ReturnData)> where T: Tracer, V: VMTracer {
let scheme = self.engine.create_address_scheme(self.info.number);
if scheme != CreateContractAddress::FromSenderAndNonce && self.state.exists_and_has_code(&params.address)? {
return Err(evm::Error::OutOfGas);
return Err(vm::Error::OutOfGas);
}
if params.call_type == CallType::StaticCall || self.static_flag {
let trace_info = tracer.prepare_trace_create(&params);
tracer.trace_failed_create(trace_info, vec![], evm::Error::MutableCallInStaticContext.into());
return Err(evm::Error::MutableCallInStaticContext);
tracer.trace_failed_create(trace_info, vec![], vm::Error::MutableCallInStaticContext.into());
return Err(vm::Error::MutableCallInStaticContext);
}
// backup used in case of running out of gas
@@ -496,7 +498,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
&mut self,
t: &SignedTransaction,
mut substate: Substate,
result: evm::Result<(U256, ReturnData)>,
result: vm::Result<(U256, ReturnData)>,
output: Bytes,
trace: Vec<FlatTrace>,
vm_trace: Option<VMTrace>
@@ -538,7 +540,7 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
self.state.kill_garbage(&substate.touched, schedule.kill_empty, &min_balance, schedule.kill_dust == CleanDustMode::WithCodeAndStorage)?;
match result {
Err(evm::Error::Internal(msg)) => Err(ExecutionError::Internal(msg)),
Err(vm::Error::Internal(msg)) => Err(ExecutionError::Internal(msg)),
Err(exception) => {
Ok(Executed {
exception: Some(exception),
@@ -572,20 +574,20 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
}
}
fn enact_result(&mut self, result: &evm::Result<FinalizationResult>, substate: &mut Substate, un_substate: Substate) {
fn enact_result(&mut self, result: &vm::Result<FinalizationResult>, substate: &mut Substate, un_substate: Substate) {
match *result {
Err(evm::Error::OutOfGas)
| Err(evm::Error::BadJumpDestination {..})
| Err(evm::Error::BadInstruction {.. })
| Err(evm::Error::StackUnderflow {..})
| Err(evm::Error::BuiltIn {..})
| Err(evm::Error::Wasm {..})
| Err(evm::Error::OutOfStack {..})
| Err(evm::Error::MutableCallInStaticContext)
Err(vm::Error::OutOfGas)
| Err(vm::Error::BadJumpDestination {..})
| Err(vm::Error::BadInstruction {.. })
| Err(vm::Error::StackUnderflow {..})
| Err(vm::Error::BuiltIn {..})
| Err(vm::Error::Wasm {..})
| Err(vm::Error::OutOfStack {..})
| Err(vm::Error::MutableCallInStaticContext)
| Ok(FinalizationResult { apply_state: false, .. }) => {
self.state.revert_to_checkpoint();
},
Ok(_) | Err(evm::Error::Internal(_)) => {
Ok(_) | Err(vm::Error::Internal(_)) => {
self.state.discard_checkpoint();
substate.accrue(un_substate);
}
@@ -597,14 +599,14 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> {
#[allow(dead_code)]
mod tests {
use std::sync::Arc;
use std::str::FromStr;
use rustc_hex::FromHex;
use ethkey::{Generator, Random};
use super::*;
use util::{H256, U256, U512, Address, FromStr};
use util::{H256, U256, U512, Address};
use util::bytes::BytesRef;
use evm::action_params::{ActionParams, ActionValue};
use evm::env_info::EnvInfo;
use evm::{Factory, VMType, CreateContractAddress};
use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress};
use evm::{Factory, VMType};
use error::ExecutionError;
use state::{Substate, CleanupMode};
use tests::helpers::*;
@@ -613,8 +615,6 @@ mod tests {
use trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, VMTracer, NoopVMTracer, ExecutiveVMTracer};
use transaction::{Action, Transaction};
use evm::CallType;
#[test]
fn test_contract_address() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();

View File

@@ -15,14 +15,17 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Transaction Execution environment.
use std::cmp;
use std::sync::Arc;
use util::*;
use evm::action_params::{ActionParams, ActionValue};
use state::{Backend as StateBackend, State, Substate, CleanupMode};
use engines::Engine;
use evm::env_info::EnvInfo;
use executive::*;
use evm::{self, Schedule, Ext, ContractCreateResult, MessageCallResult, CreateContractAddress, ReturnData};
use evm::CallType;
use vm::{
self, ActionParams, ActionValue, EnvInfo, CallType, Schedule,
Ext, ContractCreateResult, MessageCallResult, CreateContractAddress,
ReturnData
};
use transaction::UNSIGNED_SENDER;
use trace::{Tracer, VMTracer};
@@ -109,31 +112,31 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Externalities<'a, T, V, B, E>
impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for Externalities<'a, T, V, B, E>
where T: Tracer, V: VMTracer, B: StateBackend, E: Engine + ?Sized
{
fn storage_at(&self, key: &H256) -> evm::Result<H256> {
fn storage_at(&self, key: &H256) -> vm::Result<H256> {
self.state.storage_at(&self.origin_info.address, key).map_err(Into::into)
}
fn set_storage(&mut self, key: H256, value: H256) -> evm::Result<()> {
fn set_storage(&mut self, key: H256, value: H256) -> vm::Result<()> {
if self.static_flag {
Err(evm::Error::MutableCallInStaticContext)
Err(vm::Error::MutableCallInStaticContext)
} else {
self.state.set_storage(&self.origin_info.address, key, value).map_err(Into::into)
}
}
fn exists(&self, address: &Address) -> evm::Result<bool> {
fn exists(&self, address: &Address) -> vm::Result<bool> {
self.state.exists(address).map_err(Into::into)
}
fn exists_and_not_null(&self, address: &Address) -> evm::Result<bool> {
fn exists_and_not_null(&self, address: &Address) -> vm::Result<bool> {
self.state.exists_and_not_null(address).map_err(Into::into)
}
fn origin_balance(&self) -> evm::Result<U256> {
fn origin_balance(&self) -> vm::Result<U256> {
self.balance(&self.origin_info.address).map_err(Into::into)
}
fn balance(&self, address: &Address) -> evm::Result<U256> {
fn balance(&self, address: &Address) -> vm::Result<U256> {
self.state.balance(address).map_err(Into::into)
}
@@ -274,16 +277,16 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for Externalities<'a, T, V, B, E>
}
}
fn extcode(&self, address: &Address) -> evm::Result<Arc<Bytes>> {
fn extcode(&self, address: &Address) -> vm::Result<Arc<Bytes>> {
Ok(self.state.code(address)?.unwrap_or_else(|| Arc::new(vec![])))
}
fn extcodesize(&self, address: &Address) -> evm::Result<usize> {
fn extcodesize(&self, address: &Address) -> vm::Result<usize> {
Ok(self.state.code_size(address)?.unwrap_or(0))
}
#[cfg_attr(feature="dev", allow(match_ref_pats))]
fn ret(mut self, gas: &U256, data: &ReturnData) -> evm::Result<U256>
fn ret(mut self, gas: &U256, data: &ReturnData) -> vm::Result<U256>
where Self: Sized {
let handle_copy = |to: &mut Option<&mut Bytes>| {
to.as_mut().map(|b| **b = data.to_vec());
@@ -307,7 +310,7 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for Externalities<'a, T, V, B, E>
let return_cost = U256::from(data.len()) * U256::from(self.schedule.create_data_gas);
if return_cost > *gas || data.len() > self.schedule.create_data_limit {
return match self.schedule.exceptional_failed_code_deposit {
true => Err(evm::Error::OutOfGas),
true => Err(vm::Error::OutOfGas),
false => Ok(*gas)
}
}
@@ -320,11 +323,11 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for Externalities<'a, T, V, B, E>
}
}
fn log(&mut self, topics: Vec<H256>, data: &[u8]) -> evm::Result<()> {
fn log(&mut self, topics: Vec<H256>, data: &[u8]) -> vm::Result<()> {
use log_entry::LogEntry;
if self.static_flag {
return Err(evm::Error::MutableCallInStaticContext);
return Err(vm::Error::MutableCallInStaticContext);
}
let address = self.origin_info.address.clone();
@@ -337,9 +340,9 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for Externalities<'a, T, V, B, E>
Ok(())
}
fn suicide(&mut self, refund_address: &Address) -> evm::Result<()> {
fn suicide(&mut self, refund_address: &Address) -> vm::Result<()> {
if self.static_flag {
return Err(evm::Error::MutableCallInStaticContext);
return Err(vm::Error::MutableCallInStaticContext);
}
let address = self.origin_info.address.clone();
@@ -396,13 +399,11 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for Externalities<'a, T, V, B, E>
mod tests {
use util::*;
use engines::Engine;
use evm::env_info::EnvInfo;
use evm::Ext;
use evm::{EnvInfo, Ext, CallType};
use state::{State, Substate};
use tests::helpers::*;
use super::*;
use trace::{NoopTracer, NoopVMTracer};
use evm::CallType;
fn get_test_origin() -> OriginInfo {
OriginInfo {
@@ -470,7 +471,7 @@ mod tests {
let mut ext = Externalities::new(state, &setup.env_info, &*setup.engine, 0, get_test_origin(), &mut setup.sub_state, OutputPolicy::InitContract(None), &mut tracer, &mut vm_tracer, false);
let hash = ext.blockhash(&U256::from_str("0000000000000000000000000000000000000000000000000000000000120000").unwrap());
let hash = ext.blockhash(&"0000000000000000000000000000000000000000000000000000000000120000".parse::<U256>().unwrap());
assert_eq!(hash, H256::zero());
}
@@ -494,7 +495,7 @@ mod tests {
let mut ext = Externalities::new(state, &setup.env_info, &*setup.engine, 0, get_test_origin(), &mut setup.sub_state, OutputPolicy::InitContract(None), &mut tracer, &mut vm_tracer, false);
let hash = ext.blockhash(&U256::from_str("0000000000000000000000000000000000000000000000000000000000120000").unwrap());
let hash = ext.blockhash(&"0000000000000000000000000000000000000000000000000000000000120000".parse::<U256>().unwrap());
assert_eq!(test_hash, hash);
}
@@ -513,10 +514,10 @@ mod tests {
// this should panic because we have no balance on any account
ext.call(
&U256::from_str("0000000000000000000000000000000000000000000000000000000000120000").unwrap(),
&"0000000000000000000000000000000000000000000000000000000000120000".parse::<U256>().unwrap(),
&Address::new(),
&Address::new(),
Some(U256::from_str("0000000000000000000000000000000000000000000000000000000000150000").unwrap()),
Some("0000000000000000000000000000000000000000000000000000000000150000".parse::<U256>().unwrap()),
&[],
&Address::new(),
&mut output,

View File

@@ -16,13 +16,13 @@
//! Block header.
use std::cmp;
use std::cell::RefCell;
use util::*;
use basic_types::{LogBloom, ZERO_LOGBLOOM};
use time::get_time;
use rlp::*;
use std::cell::RefCell;
pub use basic_types::Seal;
pub use types::BlockNumber;
@@ -175,7 +175,7 @@ impl Header {
/// Set the timestamp field of the header.
pub fn set_timestamp(&mut self, a: u64) { self.timestamp = a; self.note_dirty(); }
/// Set the timestamp field of the header to the current time.
pub fn set_timestamp_now(&mut self, but_later_than: u64) { self.timestamp = max(get_time().sec as u64, but_later_than + 1); self.note_dirty(); }
pub fn set_timestamp_now(&mut self, but_later_than: u64) { self.timestamp = cmp::max(get_time().sec as u64, but_later_than + 1); self.note_dirty(); }
/// Set the number field of the header.
pub fn set_number(&mut self, a: BlockNumber) { self.number = a; self.note_dirty(); }
/// Set the author field of the header.
@@ -275,7 +275,7 @@ impl Decodable for Header {
number: r.val_at(8)?,
gas_limit: r.val_at(9)?,
gas_used: r.val_at(10)?,
timestamp: min(r.val_at::<U256>(11)?, u64::max_value().into()).as_u64(),
timestamp: cmp::min(r.val_at::<U256>(11)?, u64::max_value().into()).as_u64(),
extra_data: r.val_at(12)?,
seal: vec![],
hash: RefCell::new(Some(r.as_raw().sha3())),

View File

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use super::test_common::*;
use std::sync::Arc;
use client::{BlockChainClient, Client, ClientConfig};
use block::Block;
use ethereum;

View File

@@ -14,16 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::sync::Arc;
use super::test_common::*;
use evm::action_params::ActionParams;
use state::{Backend as StateBackend, State, Substate};
use executive::*;
use engines::Engine;
use evm::env_info::EnvInfo;
use evm;
use evm::{Schedule, Ext, Finalize, VMType, ContractCreateResult, MessageCallResult, CreateContractAddress, ReturnData};
use evm::{VMType, Finalize};
use vm::{
self, ActionParams, CallType, Schedule, Ext,
ContractCreateResult, EnvInfo, MessageCallResult,
CreateContractAddress, ReturnData,
};
use externalities::*;
use evm::CallType;
use tests::helpers::*;
use ethjson;
use trace::{Tracer, NoopTracer};
@@ -88,27 +90,27 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> TestExt<'a, T, V, B, E>
impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for TestExt<'a, T, V, B, E>
where T: Tracer, V: VMTracer, B: StateBackend, E: Engine + ?Sized
{
fn storage_at(&self, key: &H256) -> evm::Result<H256> {
fn storage_at(&self, key: &H256) -> vm::Result<H256> {
self.ext.storage_at(key)
}
fn set_storage(&mut self, key: H256, value: H256) -> evm::Result<()> {
fn set_storage(&mut self, key: H256, value: H256) -> vm::Result<()> {
self.ext.set_storage(key, value)
}
fn exists(&self, address: &Address) -> evm::Result<bool> {
fn exists(&self, address: &Address) -> vm::Result<bool> {
self.ext.exists(address)
}
fn exists_and_not_null(&self, address: &Address) -> evm::Result<bool> {
fn exists_and_not_null(&self, address: &Address) -> vm::Result<bool> {
self.ext.exists_and_not_null(address)
}
fn balance(&self, address: &Address) -> evm::Result<U256> {
fn balance(&self, address: &Address) -> vm::Result<U256> {
self.ext.balance(address)
}
fn origin_balance(&self) -> evm::Result<U256> {
fn origin_balance(&self) -> vm::Result<U256> {
self.ext.origin_balance()
}
@@ -146,23 +148,23 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for TestExt<'a, T, V, B, E>
MessageCallResult::Success(*gas, ReturnData::empty())
}
fn extcode(&self, address: &Address) -> evm::Result<Arc<Bytes>> {
fn extcode(&self, address: &Address) -> vm::Result<Arc<Bytes>> {
self.ext.extcode(address)
}
fn extcodesize(&self, address: &Address) -> evm::Result<usize> {
fn extcodesize(&self, address: &Address) -> vm::Result<usize> {
self.ext.extcodesize(address)
}
fn log(&mut self, topics: Vec<H256>, data: &[u8]) -> evm::Result<()> {
fn log(&mut self, topics: Vec<H256>, data: &[u8]) -> vm::Result<()> {
self.ext.log(topics, data)
}
fn ret(self, gas: &U256, data: &ReturnData) -> Result<U256, evm::Error> {
fn ret(self, gas: &U256, data: &ReturnData) -> Result<U256, vm::Error> {
self.ext.ret(gas, data)
}
fn suicide(&mut self, refund_address: &Address) -> evm::Result<()> {
fn suicide(&mut self, refund_address: &Address) -> vm::Result<()> {
self.ext.suicide(refund_address)
}

View File

@@ -22,7 +22,7 @@ use spec::Spec;
use ethjson;
use ethjson::state::test::ForkSpec;
use transaction::SignedTransaction;
use evm::env_info::EnvInfo;
use vm::EnvInfo;
lazy_static! {
pub static ref FRONTIER: Spec = ethereum::new_frontier_test();

View File

@@ -15,6 +15,8 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
pub use util::*;
use std::collections::HashSet;
use std::io::Read;
use std::fs::{File, read_dir};
use std::path::Path;
use std::ffi::OsString;

View File

@@ -106,6 +106,11 @@ extern crate semver;
extern crate stats;
extern crate time;
extern crate transient_hashmap;
extern crate using_queue;
extern crate table;
extern crate bloomable;
extern crate vm;
extern crate wasm;
#[macro_use]
extern crate log;

View File

@@ -15,9 +15,11 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::time::{Instant, Duration};
use std::collections::{BTreeMap, HashSet};
use std::sync::Arc;
use util::*;
use util::using_queue::{UsingQueue, GetAction};
use using_queue::{UsingQueue, GetAction};
use account_provider::{AccountProvider, SignError as AccountError};
use state::{State, CleanupMode};
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockId, CallAnalytics, TransactionId};

View File

@@ -106,7 +106,7 @@ use std::cmp;
use std::collections::{HashSet, HashMap, BTreeSet, BTreeMap};
use linked_hash_map::LinkedHashMap;
use util::{Address, H256, U256, HeapSizeOf};
use util::table::Table;
use table::Table;
use transaction::*;
use error::{Error, TransactionError};
use client::TransactionImportResult;
@@ -1447,7 +1447,7 @@ fn check_if_removed(sender: &Address, nonce: &U256, dropped: Option<HashMap<Addr
#[cfg(test)]
pub mod test {
use rustc_hex::FromHex;
use util::table::*;
use table::Table;
use util::*;
use ethkey::{Random, Generator};
use error::{Error, TransactionError};

View File

@@ -16,6 +16,7 @@
extern crate hyper;
use std::io::Write;
use hyper::header::ContentType;
use hyper::method::Method;
use hyper::client::{Request, Response, Client};

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::fmt;
use std::collections::BTreeMap;
use util::*;
use state::Account;
use ethjson;
@@ -166,7 +168,7 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<A
#[cfg(test)]
mod test {
use util::*;
use std::collections::BTreeMap;
use types::account_diff::*;
use super::{PodAccount, diff_pod};

View File

@@ -16,6 +16,8 @@
//! State of all accounts in the system expressed in Plain Old Data.
use std::fmt;
use std::collections::BTreeMap;
use util::*;
use pod_account::{self, PodAccount};
use types::state_diff::StateDiff;
@@ -77,7 +79,7 @@ pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
#[cfg(test)]
mod test {
use util::*;
use std::collections::BTreeMap;
use types::state_diff::*;
use types::account_diff::*;
use pod_account::PodAccount;

View File

@@ -16,6 +16,8 @@
//! Creates and registers client and network services.
use std::sync::Arc;
use std::path::Path;
use util::*;
use io::*;
use spec::Spec;

View File

@@ -16,14 +16,17 @@
//! Parameters for a block chain.
use std::io::Read;
use std::collections::BTreeMap;
use std::path::Path;
use std::sync::Arc;
use rustc_hex::FromHex;
use super::genesis::Genesis;
use super::seal::Generic as GenericSeal;
use evm::action_params::{ActionValue, ActionParams};
use builtin::Builtin;
use engines::{Engine, NullEngine, InstantSeal, BasicAuthority, AuthorityRound, Tendermint, DEFAULT_BLOCKHASH_CONTRACT};
use evm::env_info::EnvInfo;
use vm::{EnvInfo, CallType, ActionValue, ActionParams};
use error::Error;
use ethereum;
use ethjson;
@@ -36,7 +39,6 @@ use state_db::StateDB;
use state::{Backend, State, Substate};
use state::backend::Basic as BasicBackend;
use trace::{NoopTracer, NoopVMTracer};
use evm::CallType;
use util::*;
/// Parameters common to ethereum-like blockchains.
@@ -102,14 +104,14 @@ pub struct CommonParams {
impl CommonParams {
/// Schedule for an EVM in the post-EIP-150-era of the Ethereum main net.
pub fn schedule(&self, block_number: u64) -> ::evm::Schedule {
let mut schedule = ::evm::Schedule::new_post_eip150(usize::max_value(), true, true, true);
pub fn schedule(&self, block_number: u64) -> ::vm::Schedule {
let mut schedule = ::vm::Schedule::new_post_eip150(usize::max_value(), true, true, true);
self.update_schedule(block_number, &mut schedule);
schedule
}
/// Apply common spec config parameters to the schedule.
pub fn update_schedule(&self, block_number: u64, schedule: &mut ::evm::Schedule) {
pub fn update_schedule(&self, block_number: u64, schedule: &mut ::vm::Schedule) {
schedule.have_create2 = block_number >= self.eip86_transition;
schedule.have_revert = block_number >= self.eip140_transition;
schedule.have_static_call = block_number >= self.eip214_transition;
@@ -119,8 +121,8 @@ impl CommonParams {
}
if block_number >= self.dust_protection_transition {
schedule.kill_dust = match self.remove_dust_contracts {
true => ::evm::CleanDustMode::WithCodeAndStorage,
false => ::evm::CleanDustMode::BasicOnly,
true => ::vm::CleanDustMode::WithCodeAndStorage,
false => ::vm::CleanDustMode::BasicOnly,
};
}
}
@@ -517,6 +519,7 @@ impl Spec {
#[cfg(test)]
mod tests {
use std::str::FromStr;
use util::*;
use views::*;
use tests::helpers::get_temp_state_db;
@@ -529,19 +532,6 @@ mod tests {
assert!(Spec::load(::std::env::temp_dir(), &[] as &[u8]).is_err());
}
#[test]
fn all_spec_files_valid() {
Spec::new_test();
Spec::new_null();
Spec::new_test_constructor();
Spec::new_instant();
Spec::new_test_round();
Spec::new_test_tendermint();
Spec::new_validator_safe_contract();
Spec::new_validator_contract();
Spec::new_validator_multi();
}
#[test]
fn test_chain() {
let test_spec = Spec::new_test();

View File

@@ -16,6 +16,9 @@
//! Single account in the system.
use std::fmt;
use std::sync::Arc;
use std::collections::HashMap;
use util::*;
use pod_account::*;
use rlp::*;

View File

@@ -21,10 +21,13 @@
use std::cell::{RefCell, RefMut};
use std::collections::hash_map::Entry;
use std::collections::{HashMap, BTreeMap, HashSet};
use std::fmt;
use std::sync::Arc;
use receipt::Receipt;
use engines::Engine;
use evm::env_info::EnvInfo;
use vm::EnvInfo;
use error::Error;
use executive::{Executive, TransactOptions};
use factory::Factories;
@@ -982,7 +985,7 @@ mod tests {
use ethkey::Secret;
use util::{U256, H256, Address, Hashable};
use tests::helpers::*;
use evm::env_info::EnvInfo;
use vm::EnvInfo;
use spec::*;
use transaction::*;
use ethcore_logger::init_log;

View File

@@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::collections::{VecDeque, HashSet};
use std::sync::Arc;
use lru_cache::LruCache;
use util::cache::MemoryLruCache;
use util::journaldb::JournalDB;
@@ -23,7 +24,7 @@ use util::hash::{H256};
use util::hashdb::HashDB;
use state::{self, Account};
use header::BlockNumber;
use util::{Arc, Address, DBTransaction, UtilError, Mutex, Hashable};
use util::{Address, DBTransaction, UtilError, Mutex, Hashable};
use bloom_journal::{Bloom, BloomJournal};
use db::COL_ACCOUNT_BLOOM;
use byteorder::{LittleEndian, ByteOrder};

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::str::FromStr;
use std::sync::Arc;
use io::IoChannel;
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId};
use state::{self, State, CleanupMode};

View File

@@ -1,9 +1,8 @@
//! Tests of EVM integration with transaction execution.
use evm::action_params::{ActionParams, ActionValue};
use evm::env_info::EnvInfo;
use std::sync::Arc;
use vm::{EnvInfo, ActionParams, ActionValue, CallType};
use evm::{Factory, VMType};
use evm::call_type::CallType;
use executive::Executive;
use state::Substate;
use tests::helpers::*;

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::collections::BTreeMap;
use std::sync::Arc;
use ethkey::KeyPair;
use io::*;
use client::{BlockChainClient, Client, ClientConfig};
@@ -347,7 +349,7 @@ pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_h
for i in start_number .. start_number + count + 1 {
let mut block_header = Header::new();
block_header.set_gas_limit(test_engine.params().min_gas_limit);
block_header.set_difficulty(U256::from(i).mul(U256([0, 1, 0, 0])));
block_header.set_difficulty(U256::from(i) * U256([0, 1, 0, 0]));
block_header.set_timestamp(rolling_timestamp);
block_header.set_number(i as u64);
block_header.set_parent_hash(parent);

View File

@@ -17,7 +17,7 @@
//! Simple executive tracer.
use util::{Bytes, Address, U256};
use evm::action_params::ActionParams;
use vm::ActionParams;
use trace::trace::{Call, Create, Action, Res, CreateResult, CallResult, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, Suicide, Reward, RewardType};
use trace::{Tracer, VMTracer, FlatTrace, TraceError};

View File

@@ -39,7 +39,7 @@ pub use self::types::filter::{Filter, AddressesFilter};
use util::{Bytes, Address, U256, H256, DBTransaction};
use self::trace::{Call, Create};
use evm::action_params::ActionParams;
use vm::ActionParams;
use header::BlockNumber;
/// This trait is used by executive to build traces.

View File

@@ -17,7 +17,7 @@
//! Nonoperative tracer.
use util::{Bytes, Address, U256};
use evm::action_params::ActionParams;
use vm::ActionParams;
use trace::{Tracer, VMTracer, FlatTrace, TraceError};
use trace::trace::{Call, Create, VMTrace, RewardType};

View File

@@ -18,7 +18,7 @@
use std::fmt;
use rlp::{Encodable, RlpStream, Decodable, DecoderError, UntrustedRlp};
use evm::Error as EvmError;
use vm::Error as VmError;
/// Trace evm errors.
#[derive(Debug, PartialEq, Clone)]
@@ -45,24 +45,24 @@ pub enum Error {
Wasm,
}
impl<'a> From<&'a EvmError> for Error {
fn from(e: &'a EvmError) -> Self {
impl<'a> From<&'a VmError> for Error {
fn from(e: &'a VmError) -> Self {
match *e {
EvmError::OutOfGas => Error::OutOfGas,
EvmError::BadJumpDestination { .. } => Error::BadJumpDestination,
EvmError::BadInstruction { .. } => Error::BadInstruction,
EvmError::StackUnderflow { .. } => Error::StackUnderflow,
EvmError::OutOfStack { .. } => Error::OutOfStack,
EvmError::BuiltIn { .. } => Error::BuiltIn,
EvmError::Wasm { .. } => Error::Wasm,
EvmError::Internal(_) => Error::Internal,
EvmError::MutableCallInStaticContext => Error::MutableCallInStaticContext,
VmError::OutOfGas => Error::OutOfGas,
VmError::BadJumpDestination { .. } => Error::BadJumpDestination,
VmError::BadInstruction { .. } => Error::BadInstruction,
VmError::StackUnderflow { .. } => Error::StackUnderflow,
VmError::OutOfStack { .. } => Error::OutOfStack,
VmError::BuiltIn { .. } => Error::BuiltIn,
VmError::Wasm { .. } => Error::Wasm,
VmError::Internal(_) => Error::Internal,
VmError::MutableCallInStaticContext => Error::MutableCallInStaticContext,
}
}
}
impl From<EvmError> for Error {
fn from(e: EvmError) -> Self {
impl From<VmError> for Error {
fn from(e: VmError) -> Self {
Error::from(&e)
}
}

View File

@@ -20,7 +20,7 @@ use std::ops::Range;
use bloomchain::{Filter as BloomFilter, Bloom, Number};
use util::Address;
use util::sha3::Hashable;
use util::bloom::Bloomable;
use bloomable::Bloomable;
use basic_types::LogBloom;
use trace::flat::FlatTrace;
use super::trace::{Action, Res};
@@ -141,7 +141,7 @@ impl Filter {
mod tests {
use util::Address;
use util::sha3::Hashable;
use util::bloom::Bloomable;
use bloomable::Bloomable;
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward};
use trace::flat::FlatTrace;
use trace::{Filter, AddressesFilter, TraceError, RewardType};

View File

@@ -18,10 +18,10 @@
use util::{U256, Bytes, Address};
use util::sha3::Hashable;
use util::bloom::Bloomable;
use bloomable::Bloomable;
use rlp::*;
use evm::action_params::ActionParams;
use vm::ActionParams;
use basic_types::LogBloom;
use evm::CallType;
use super::error::Error;

View File

@@ -19,7 +19,9 @@
use std::thread::{self, JoinHandle};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering};
use std::sync::{Condvar as SCondvar, Mutex as SMutex};
use std::sync::{Condvar as SCondvar, Mutex as SMutex, Arc};
use std::cmp;
use std::collections::{VecDeque, HashSet, HashMap};
use util::*;
use io::*;
use error::*;
@@ -234,8 +236,8 @@ impl<K: Kind> VerificationQueue<K> {
let scale_verifiers = config.verifier_settings.scale_verifiers;
let num_cpus = ::num_cpus::get();
let max_verifiers = min(num_cpus, MAX_VERIFIERS);
let default_amount = max(1, min(max_verifiers, config.verifier_settings.num_verifiers));
let max_verifiers = cmp::min(num_cpus, MAX_VERIFIERS);
let default_amount = cmp::max(1, cmp::min(max_verifiers, config.verifier_settings.num_verifiers));
let state = Arc::new((Mutex::new(State::Work(default_amount)), Condvar::new()));
let mut verifier_handles = Vec::with_capacity(max_verifiers);
@@ -278,8 +280,8 @@ impl<K: Kind> VerificationQueue<K> {
processing: RwLock::new(HashMap::new()),
empty: empty,
ticks_since_adjustment: AtomicUsize::new(0),
max_queue_size: max(config.max_queue_size, MIN_QUEUE_LIMIT),
max_mem_use: max(config.max_mem_use, MIN_MEM_LIMIT),
max_queue_size: cmp::max(config.max_queue_size, MIN_QUEUE_LIMIT),
max_mem_use: cmp::max(config.max_mem_use, MIN_MEM_LIMIT),
scale_verifiers: scale_verifiers,
verifier_handles: verifier_handles,
state: state,
@@ -567,7 +569,7 @@ impl<K: Kind> VerificationQueue<K> {
/// Removes up to `max` verified items from the queue
pub fn drain(&self, max: usize) -> Vec<K::Verified> {
let mut verified = self.verification.verified.lock();
let count = min(max, verified.len());
let count = cmp::min(max, verified.len());
let result = verified.drain(..count).collect::<Vec<_>>();
let drained_size = result.iter().map(HeapSizeOf::heap_size_of_children).fold(0, |a, c| a + c);
@@ -687,8 +689,8 @@ impl<K: Kind> VerificationQueue<K> {
// or below 1.
fn scale_verifiers(&self, target: usize) {
let current = self.num_verifiers();
let target = min(self.verifier_handles.len(), target);
let target = max(1, target);
let target = cmp::min(self.verifier_handles.len(), target);
let target = cmp::max(1, target);
debug!(target: "verification", "Scaling from {} to {} verifiers", current, target);
@@ -725,7 +727,6 @@ impl<K: Kind> Drop for VerificationQueue<K> {
#[cfg(test)]
mod tests {
use util::*;
use io::*;
use spec::*;
use super::{BlockQueue, Config, State};

View File

@@ -21,6 +21,7 @@
//! 2. Signatures verification done in the queue.
//! 3. Final verification against the blockchain done before enactment.
use std::collections::HashSet;
use util::*;
use engines::Engine;
use error::{BlockError, Error};
@@ -264,6 +265,7 @@ fn verify_block_integrity(block: &[u8], transactions_root: &H256, uncles_hash: &
#[cfg(test)]
mod tests {
use std::collections::{BTreeMap, HashMap};
use util::*;
use ethkey::{Random, Generator};
use header::*;