Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

removed redundant VMType enum with one variant #11266

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 8 additions & 14 deletions ethcore/evm/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,28 @@ use vm::{Exec, Schedule};
use ethereum_types::U256;
use super::vm::ActionParams;
use super::interpreter::SharedCache;
use super::vmtype::VMType;

/// Evm factory. Creates appropriate Evm.
#[derive(Clone)]
pub struct Factory {
evm: VMType,
evm_cache: Arc<SharedCache>,
}

impl Factory {
/// Create fresh instance of VM
/// Might choose implementation depending on supplied gas.
pub fn create(&self, params: ActionParams, schedule: &Schedule, depth: usize) -> Box<dyn Exec> {
match self.evm {
VMType::Interpreter => if Self::can_fit_in_usize(&params.gas) {
Box::new(super::interpreter::Interpreter::<usize>::new(params, self.evm_cache.clone(), schedule, depth))
} else {
Box::new(super::interpreter::Interpreter::<U256>::new(params, self.evm_cache.clone(), schedule, depth))
}
if Self::can_fit_in_usize(&params.gas) {
Box::new(super::interpreter::Interpreter::<usize>::new(params, self.evm_cache.clone(), schedule, depth))
} else {
Box::new(super::interpreter::Interpreter::<U256>::new(params, self.evm_cache.clone(), schedule, depth))
}
}

/// Create new instance of specific `VMType` factory, with a size in bytes
/// Create new instance of a factory, with a size in bytes
/// for caching jump destinations.
pub fn new(evm: VMType, cache_size: usize) -> Self {
pub fn new(cache_size: usize) -> Self {
Factory {
evm,
evm_cache: Arc::new(SharedCache::new(cache_size)),
}
}
Expand All @@ -61,7 +56,6 @@ impl Default for Factory {
/// Returns native rust evm factory
fn default() -> Factory {
Factory {
evm: VMType::Interpreter,
evm_cache: Arc::new(SharedCache::default()),
}
}
Expand All @@ -85,7 +79,7 @@ macro_rules! evm_test(
($name_test: ident: $name_int: ident) => {
#[test]
fn $name_int() {
$name_test(Factory::new(VMType::Interpreter, 1024 * 32));
$name_test(Factory::new(1024 * 32));
}
}
);
Expand All @@ -98,7 +92,7 @@ macro_rules! evm_test_ignore(
#[ignore]
#[cfg(feature = "ignored-tests")]
fn $name_int() {
$name_test(Factory::new(VMType::Interpreter, 1024 * 32));
$name_test(Factory::new(1024 * 32));
}
}
);
3 changes: 1 addition & 2 deletions ethcore/evm/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,14 +1213,13 @@ fn address_to_u256(value: Address) -> U256 {
mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use vmtype::VMType;
use factory::Factory;
use vm::{self, Exec, ActionParams, ActionValue};
use vm::tests::{FakeExt, test_finalize};
use ethereum_types::Address;

fn interpreter(params: ActionParams, ext: &dyn vm::Ext) -> Box<dyn Exec> {
Factory::new(VMType::Interpreter, 1).create(params, ext.schedule(), ext.depth())
Factory::new(1).create(params, ext.schedule(), ext.depth())
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions ethcore/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub mod interpreter;

#[macro_use]
pub mod factory;
mod vmtype;
mod instructions;

#[cfg(test)]
Expand All @@ -54,5 +53,4 @@ pub use vm::{
};
pub use self::evm::{Finalize, FinalizationResult, CostType};
pub use self::instructions::{InstructionInfo, Instruction};
pub use self::vmtype::VMType;
pub use self::factory::Factory;
3 changes: 1 addition & 2 deletions ethcore/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use ethereum_types::{U256, H256, Address};
use vm::{self, ActionParams, ActionValue, Ext};
use vm::tests::{FakeExt, FakeCall, FakeCallType, test_finalize};
use factory::Factory;
use vmtype::VMType;
use hex_literal::hex;

evm_test!{test_add: test_add_int}
Expand Down Expand Up @@ -705,7 +704,7 @@ fn test_signextend(factory: super::Factory) {

#[test] // JIT just returns out of gas
fn test_badinstruction_int() {
let factory = super::Factory::new(VMType::Interpreter, 1024 * 32);
let factory = super::Factory::new(1024 * 32);
let code = hex!("af").to_vec();

let mut params = ActionParams::default();
Expand Down
45 changes: 0 additions & 45 deletions ethcore/evm/src/vmtype.rs

This file was deleted.

2 changes: 1 addition & 1 deletion ethcore/machine/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ mod tests {
transaction::{Action, Transaction},
};
use parity_crypto::publickey::{Generator, Random};
use evm::{Factory, VMType, evm_test, evm_test_ignore};
use evm::{Factory, evm_test, evm_test_ignore};
use macros::vec_into;
use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress};
use ::trace::{
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ impl Client {

let trie_factory = TrieFactory::new(trie_spec, Layout);
let factories = Factories {
vm: VmFactory::new(config.vm_type.clone(), config.jump_table_size),
vm: VmFactory::new(config.jump_table_size),
trie: trie_factory,
accountdb: Default::default(),
};
Expand Down
5 changes: 0 additions & 5 deletions ethcore/src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use trace::Config as TraceConfig;
use types::client_types::Mode;
use verification::{VerifierType, QueueConfig};

pub use evm::VMType;

/// Client state db compaction profile
#[derive(Debug, PartialEq, Clone)]
pub enum DatabaseCompactionProfile {
Expand Down Expand Up @@ -64,8 +62,6 @@ pub struct ClientConfig {
pub blockchain: BlockChainConfig,
/// Trace configuration.
pub tracing: TraceConfig,
/// VM type.
pub vm_type: VMType,
/// Fat DB enabled?
pub fat_db: bool,
/// The JournalDB ("pruning") algorithm to use.
Expand Down Expand Up @@ -107,7 +103,6 @@ impl Default for ClientConfig {
queue: Default::default(),
blockchain: Default::default(),
tracing: Default::default(),
vm_type: Default::default(),
fat_db: false,
pruning: journaldb::Algorithm::OverlayRecent,
name: "default".into(),
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod config;
mod traits;

pub use self::client::Client;
pub use self::config::{ClientConfig, DatabaseCompactionProfile, VMType};
pub use self::config::{ClientConfig, DatabaseCompactionProfile};
pub use self::traits::{
ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock,
Call, EngineInfo, BlockProducer, SealedBlockImporter,
Expand Down
19 changes: 5 additions & 14 deletions ethcore/src/json_tests/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::path::Path;
use std::sync::Arc;
use super::test_common::*;
use account_state::{Backend as StateBackend, State};
use evm::{VMType, Finalize};
use evm::Finalize;
use vm::{
self, ActionParams, CallType, Schedule, Ext,
ContractCreateResult, EnvInfo, MessageCallResult,
Expand Down Expand Up @@ -235,17 +235,8 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B>
}
}

fn do_json_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8], h: &mut H) -> Vec<String> {
let vms = VMType::all();
vms
.iter()
.flat_map(|vm| do_json_test_for(path, vm, json_data, h))
.collect()
}

fn do_json_test_for<H: FnMut(&str, HookType)>(
fn do_json_test<H: FnMut(&str, HookType)>(
path: &Path,
vm_type: &VMType,
json_data: &[u8],
start_stop_hook: &mut H
) -> Vec<String> {
Expand All @@ -254,13 +245,13 @@ fn do_json_test_for<H: FnMut(&str, HookType)>(
let mut failed = Vec::new();

for (name, vm) in tests.into_iter() {
start_stop_hook(&format!("{}-{}", name, vm_type), HookType::OnStart);
start_stop_hook(&format!("{}", name), HookType::OnStart);

info!(target: "jsontests", "name: {:?}", name);
let mut fail = false;

let mut fail_unless = |cond: bool, s: &str | if !cond && !fail {
failed.push(format!("[{}] {}: {}", vm_type, name, s));
failed.push(format!("{}: {}", name, s));
fail = true
};

Expand Down Expand Up @@ -363,7 +354,7 @@ fn do_json_test_for<H: FnMut(&str, HookType)>(
}
};

start_stop_hook(&format!("{}-{}", name, vm_type), HookType::OnStop);
start_stop_hook(&format!("{}", name), HookType::OnStop);
}

for f in &failed {
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/test_helpers/evm_test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use types::{
};
use ethjson::spec::ForkSpec;
use trie_vm_factories::Factories;
use evm::{VMType, FinalizationResult};
use evm::FinalizationResult;
use vm::{self, ActionParams, CreateContractAddress};
use ethtrie;
use account_state::{CleanupMode, State};
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<'a> EvmTestClient<'a> {

fn factories(trie_spec: trie::TrieSpec) -> Factories {
Factories {
vm: trie_vm_factories::VmFactory::new(VMType::Interpreter, 5 * 1024),
vm: trie_vm_factories::VmFactory::new(5 * 1024),
trie: trie::TrieFactory::new(trie_spec, ethtrie::Layout),
accountdb: Default::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/tests/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use std::sync::Arc;
use hash::keccak;
use vm::{EnvInfo, ActionParams, ActionValue, CallType, ParamsType};
use evm::{Factory, VMType};
use evm::Factory;
use machine::{
executive::Executive,
substate::Substate,
Expand Down
8 changes: 4 additions & 4 deletions ethcore/trie-vm-factories/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use trie_db::TrieFactory;
use ethtrie::Layout;
use account_db::Factory as AccountFactory;
use evm::{Factory as EvmFactory, VMType};
use evm::{Factory as EvmFactory};
use vm::{Exec, ActionParams, VersionedSchedule, Schedule};
use wasm::WasmInterpreter;

Expand Down Expand Up @@ -49,14 +49,14 @@ impl VmFactory {
}
}

pub fn new(evm: VMType, cache_size: usize) -> Self {
VmFactory { evm: EvmFactory::new(evm, cache_size) }
pub fn new(cache_size: usize) -> Self {
VmFactory { evm: EvmFactory::new(cache_size) }
}
}

impl From<EvmFactory> for VmFactory {
fn from(evm: EvmFactory) -> Self {
VmFactory { evm: evm }
VmFactory { evm }
}
}

Expand Down
5 changes: 1 addition & 4 deletions parity/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use bytes::ToPretty;
use rlp::PayloadInfo;
use client_traits::{BlockChainReset, Nonce, Balance, BlockChainClient, ImportExportBlocks};
use ethcore::{
client::{DatabaseCompactionProfile, VMType},
client::{DatabaseCompactionProfile},
miner::Miner,
};
use ethcore_service::ClientService;
Expand Down Expand Up @@ -92,7 +92,6 @@ pub struct ImportBlockchain {
pub compaction: DatabaseCompactionProfile,
pub tracing: Switch,
pub fat_db: Switch,
pub vm_type: VMType,
pub check_seal: bool,
pub with_color: bool,
pub verifier_settings: VerifierSettings,
Expand Down Expand Up @@ -351,7 +350,6 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
tracing,
fat_db,
cmd.compaction,
cmd.vm_type,
"".into(),
algorithm,
cmd.pruning_history,
Expand Down Expand Up @@ -488,7 +486,6 @@ fn start_client(
tracing,
fat_db,
compaction,
VMType::default(),
"".into(),
algorithm,
pruning_history,
Expand Down
Loading