From 5180919e52d9d06b9772935d22504ba601088bd9 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Mon, 24 Jul 2017 17:45:15 +0300 Subject: [PATCH 01/20] wasm mvp continued --- Cargo.lock | 1 + ethcore/evm/Cargo.toml | 2 + ethcore/evm/src/lib.rs | 1 + ethcore/evm/src/wasm/env.rs | 55 ++++------- ethcore/evm/src/wasm/mod.rs | 3 +- ethcore/evm/src/wasm/runtime.rs | 158 +++++++++++++++++++++++++++++++- ethcore/evm/src/wasm/tests.rs | 108 ++++++++++++++++++++-- ethcore/res/wasm-tests | 2 +- 8 files changed, 281 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7046b759..16d378150 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -878,6 +878,7 @@ dependencies = [ "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "common-types 0.1.0", + "ethcore-logger 1.8.0", "ethcore-util 1.8.0", "ethjson 0.1.0", "evmjit 1.8.0", diff --git a/ethcore/evm/Cargo.toml b/ethcore/evm/Cargo.toml index b48dd2346..bd95e0587 100644 --- a/ethcore/evm/Cargo.toml +++ b/ethcore/evm/Cargo.toml @@ -14,8 +14,10 @@ lazy_static = "0.2" log = "0.3" rlp = { path = "../../util/rlp" } parity-wasm = "0.12" +ethcore-logger = { path = "../../logger" } wasm-utils = { git = "https://github.com/paritytech/wasm-utils" } + [dev-dependencies] rustc-hex = "1.0" diff --git a/ethcore/evm/src/lib.rs b/ethcore/evm/src/lib.rs index fa4d12315..55f7c5090 100644 --- a/ethcore/evm/src/lib.rs +++ b/ethcore/evm/src/lib.rs @@ -24,6 +24,7 @@ extern crate ethjson; extern crate rlp; extern crate parity_wasm; extern crate wasm_utils; +extern crate ethcore_logger; #[macro_use] extern crate lazy_static; diff --git a/ethcore/evm/src/wasm/env.rs b/ethcore/evm/src/wasm/env.rs index cabd38bd9..e68e50432 100644 --- a/ethcore/evm/src/wasm/env.rs +++ b/ethcore/evm/src/wasm/env.rs @@ -61,6 +61,21 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[ &[I32; 4], Some(I32), ), + Static( + "_ccall", + &[I32; 6], + Some(I32), + ), + Static( + "_dcall", + &[I32; 5], + Some(I32), + ), + Static( + "_scall", + &[I32; 5], + Some(I32), + ), Static( "abort", &[I32], @@ -71,49 +86,19 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[ &[], None, ), - Static( - "invoke_vii", - &[I32; 3], - None, - ), - Static( - "invoke_vi", - &[I32; 2], - None, - ), - Static( - "invoke_v", - &[I32], - None, - ), - Static( - "invoke_iii", - &[I32; 3], - Some(I32), - ), - Static( - "___resumeException", - &[I32], - None, - ), Static( "_rust_begin_unwind", &[I32; 4], None, ), - Static( - "___cxa_find_matching_catch_2", - &[], - Some(I32), - ), - Static( - "___gxx_personality_v0", - &[I32; 6], - Some(I32), - ), Static( "_emscripten_memcpy_big", &[I32; 3], Some(I32), + ), + Static( + "___syscall6", + &[I32; 2], + Some(I32), ) ]; diff --git a/ethcore/evm/src/wasm/mod.rs b/ethcore/evm/src/wasm/mod.rs index a7186add5..acad9e5cb 100644 --- a/ethcore/evm/src/wasm/mod.rs +++ b/ethcore/evm/src/wasm/mod.rs @@ -34,7 +34,7 @@ use wasm_utils; use evm::{self, GasLeft, ReturnData}; use action_params::ActionParams; -use self::runtime::Runtime; +use self::runtime::{Runtime, RuntimeContext}; pub use self::runtime::Error as RuntimeError; @@ -82,6 +82,7 @@ impl evm::Evm for WasmInterpreter { env_memory, DEFAULT_STACK_SPACE, params.gas.low_u64(), + RuntimeContext::new(params.address, params.sender), ); let mut cursor = ::std::io::Cursor::new(&*code); diff --git a/ethcore/evm/src/wasm/runtime.rs b/ethcore/evm/src/wasm/runtime.rs index 7beb4c599..adcb14de1 100644 --- a/ethcore/evm/src/wasm/runtime.rs +++ b/ethcore/evm/src/wasm/runtime.rs @@ -25,6 +25,7 @@ use ext; use parity_wasm::interpreter; use util::{Address, H256, U256}; +use call_type::CallType; use super::ptr::{WasmPtr, Error as PtrError}; use super::call_args::CallArgs; @@ -57,6 +58,20 @@ impl From for Error { } } +pub struct RuntimeContext { + address: Address, + sender: Address, +} + +impl RuntimeContext { + pub fn new(address: Address, sender: Address) -> Self { + RuntimeContext { + address: address, + sender: sender, + } + } +} + /// Runtime enviroment data for wasm contract execution pub struct Runtime<'a> { gas_counter: u64, @@ -64,6 +79,7 @@ pub struct Runtime<'a> { dynamic_top: u32, ext: &'a mut ext::Ext, memory: Arc, + context: RuntimeContext, } impl<'a> Runtime<'a> { @@ -73,6 +89,7 @@ impl<'a> Runtime<'a> { memory: Arc, stack_space: u32, gas_limit: u64, + context: RuntimeContext, ) -> Runtime<'b> { Runtime { gas_counter: 0, @@ -80,6 +97,7 @@ impl<'a> Runtime<'a> { dynamic_top: stack_space, memory: memory, ext: ext, + context: context, } } @@ -139,13 +157,13 @@ impl<'a> Runtime<'a> { trace!(target: "wasm", "runtime: create contract"); let mut context = context; let result_ptr = context.value_stack.pop_as::()? as u32; - trace!(target: "wasm", " result_ptr: {:?}", result_ptr); + trace!(target: "wasm", "result_ptr: {:?}", result_ptr); let code_len = context.value_stack.pop_as::()? as u32; - trace!(target: "wasm", " code_len: {:?}", code_len); + trace!(target: "wasm", " code_len: {:?}", code_len); let code_ptr = context.value_stack.pop_as::()? as u32; - trace!(target: "wasm", " code_ptr: {:?}", code_ptr); + trace!(target: "wasm", " code_ptr: {:?}", code_ptr); let endowment = self.pop_u256(&mut context)?; - trace!(target: "wasm", " val: {:?}", endowment); + trace!(target: "wasm", " val: {:?}", endowment); let code = self.memory.get(code_ptr, code_len as usize)?; @@ -167,6 +185,127 @@ impl<'a> Runtime<'a> { } } + pub fn call(&mut self, context: interpreter::CallerContext) + -> Result, interpreter::Error> + { + // + // method signature: + // fn ( + // address: *const u8, + // val_ptr: *const u8, + // input_ptr: *const u8, + // input_len: u32, + // result_ptr: *mut u8, + // result_len: u32, + // ) -> i32 + + self.do_call(true, CallType::Call, context) + } + + + fn call_code(&mut self, context: interpreter::CallerContext) + -> Result, interpreter::Error> + { + // + // signature (same as static call): + // fn ( + // address: *const u8, + // input_ptr: *const u8, + // input_len: u32, + // result_ptr: *mut u8, + // result_len: u32, + // ) -> i32 + + self.do_call(false, CallType::CallCode, context) + } + + fn do_call( + &mut self, + use_val: bool, + call_type: CallType, + context: interpreter::CallerContext, + ) + -> Result, interpreter::Error> + { + + trace!(target: "wasm", "runtime: call code"); + let mut context = context; + let result_alloc_len = context.value_stack.pop_as::()? as u32; + trace!(target: "wasm", " result_len: {:?}", result_alloc_len); + + let result_ptr = context.value_stack.pop_as::()? as u32; + trace!(target: "wasm", " result_ptr: {:?}", result_ptr); + + let input_len = context.value_stack.pop_as::()? as u32; + trace!(target: "wasm", " input_len: {:?}", input_len); + + let input_ptr = context.value_stack.pop_as::()? as u32; + trace!(target: "wasm", " input_ptr: {:?}", input_ptr); + + let val = if use_val { Some(self.pop_u256(&mut context)?) } + else { None }; + trace!(target: "wasm", " val: {:?}", val); + + let address = self.pop_address(&mut context)?; + trace!(target: "wasm", " address: {:?}", address); + + if let Some(ref val) = val { + let address_balance = self.ext.balance(&self.context.address) + .map_err(|_| interpreter::Error::Trap("Gas state error".to_owned()))?; + + if &address_balance < val { + trace!(target: "wasm", "runtime: call failed due to balance check"); + return Ok(Some((-1i32).into())); + } + } + + let mut result = Vec::with_capacity(result_alloc_len as usize); + result.resize(result_alloc_len as usize, 0); + let gas = self.gas_left() + .map_err(|_| interpreter::Error::Trap("Gas state error".to_owned()))? + .into(); + // todo: optimize to use memory views once it's in + let payload = self.memory.get(input_ptr, input_len as usize)?; + + let call_result = self.ext.call( + &gas, + &self.context.sender, + &self.context.address, + val, + &payload, + &address, + &mut result[..], + call_type, + ); + + match call_result { + ext::MessageCallResult::Success(gas_left, _) => { + self.gas_counter = self.gas_limit - gas_left.low_u64(); + self.memory.set(result_ptr, &result)?; + Ok(Some(0i32.into())) + }, + ext::MessageCallResult::Failed => { + Ok(Some((-1i32).into())) + } + } + } + + pub fn static_call(&mut self, context: interpreter::CallerContext) + -> Result, interpreter::Error> + { + // signature (same as code call): + // fn ( + // address: *const u8, + // input_ptr: *const u8, + // input_len: u32, + // result_ptr: *mut u8, + // result_len: u32, + // ) -> i32 + + self.do_call(false, CallType::StaticCall, context) + } + + /// Allocate memory using the wasm stack params pub fn malloc(&mut self, context: interpreter::CallerContext) -> Result, interpreter::Error> @@ -338,6 +477,15 @@ impl<'a> interpreter::UserFunctionExecutor for Runtime<'a> { "_create" => { self.create(context) }, + "_ccall" => { + self.call(context) + }, + "_dcall" => { + self.call_code(context) + }, + "_scall" => { + self.static_call(context) + }, "_debug" => { self.debug_log(context) }, @@ -348,7 +496,7 @@ impl<'a> interpreter::UserFunctionExecutor for Runtime<'a> { self.mem_copy(context) }, _ => { - trace!("Unknown env func: '{}'", name); + trace!(target: "wasm", "Trapped due to unhandled function: '{}'", name); self.user_trap(context) } } diff --git a/ethcore/evm/src/wasm/tests.rs b/ethcore/evm/src/wasm/tests.rs index 8ae13daae..c9d02a4ad 100644 --- a/ethcore/evm/src/wasm/tests.rs +++ b/ethcore/evm/src/wasm/tests.rs @@ -21,6 +21,7 @@ use super::WasmInterpreter; use evm::{self, Evm, GasLeft}; use action_params::{ActionParams, ActionValue}; use util::{U256, H256, Address}; +use byteorder::{LittleEndian, ByteOrder}; macro_rules! load_sample { ($name: expr) => { @@ -85,7 +86,7 @@ fn logger() { }; println!("ext.store: {:?}", ext.store); - assert_eq!(gas_left, U256::from(99581)); + assert_eq!(gas_left, U256::from(99590)); let address_val: H256 = address.into(); assert_eq!( ext.store.get(&"0100000000000000000000000000000000000000000000000000000000000000".parse().unwrap()).expect("storage key to exist"), @@ -136,7 +137,7 @@ fn identity() { } }; - assert_eq!(gas_left, U256::from(99_689)); + assert_eq!(gas_left, U256::from(99_687)); assert_eq!( Address::from_slice(&result), @@ -170,7 +171,7 @@ fn dispersion() { } }; - assert_eq!(gas_left, U256::from(99_402)); + assert_eq!(gas_left, U256::from(99_423)); assert_eq!( result, @@ -199,7 +200,7 @@ fn suicide_not() { } }; - assert_eq!(gas_left, U256::from(99_703)); + assert_eq!(gas_left, U256::from(99_656)); assert_eq!( result, @@ -233,12 +234,14 @@ fn suicide() { } }; - assert_eq!(gas_left, U256::from(99_747)); + assert_eq!(gas_left, U256::from(99_740)); assert!(ext.suicides.contains(&refund)); } #[test] fn create() { + ::ethcore_logger::init_log(); + let mut params = ActionParams::default(); params.gas = U256::from(100_000); params.code = Some(Arc::new(load_sample!("creator.wasm"))); @@ -262,7 +265,7 @@ fn create() { assert!(ext.calls.contains( &FakeCall { call_type: FakeCallType::Create, - gas: U256::from(99_778), + gas: U256::from(99_767), sender_address: None, receive_address: None, value: Some(1_000_000_000.into()), @@ -270,5 +273,96 @@ fn create() { code_address: None, } )); - assert_eq!(gas_left, U256::from(99_768)); + assert_eq!(gas_left, U256::from(99_759)); } + + +#[test] +fn call_code() { + ::ethcore_logger::init_log(); + + let sender: Address = "01030507090b0d0f11131517191b1d1f21232527".parse().unwrap(); + let receiver: Address = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6".parse().unwrap(); + + let mut params = ActionParams::default(); + params.sender = sender.clone(); + params.address = receiver.clone(); + params.gas = U256::from(100_000); + params.code = Some(Arc::new(load_sample!("call_code.wasm"))); + params.data = Some(Vec::new()); + params.value = ActionValue::transfer(1_000_000_000); + + let mut ext = FakeExt::new(); + + let (gas_left, result) = { + let mut interpreter = wasm_interpreter(); + let result = interpreter.exec(params, &mut ext).expect("Interpreter to execute without any errors"); + match result { + GasLeft::Known(_) => { panic!("Call test should return payload"); }, + GasLeft::NeedsReturn { gas_left: gas, data: result, apply_state: _apply } => (gas, result.to_vec()), + } + }; + + trace!(target: "wasm", "fake_calls: {:?}", &ext.calls); + assert!(ext.calls.contains( + &FakeCall { + call_type: FakeCallType::Call, + gas: U256::from(99_061), + sender_address: Some(sender), + receive_address: Some(receiver), + value: None, + data: vec![1u8, 2, 3, 5, 7, 11], + code_address: Some("0d13710000000000000000000000000000000000".parse().unwrap()), + } + )); + assert_eq!(gas_left, U256::from(94196)); + + // siphash result + let res = LittleEndian::read_u32(&result[..]); + assert_eq!(res, 4198595614); +} + +#[test] +fn call_static() { + ::ethcore_logger::init_log(); + + let sender: Address = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6".parse().unwrap(); + let receiver: Address = "01030507090b0d0f11131517191b1d1f21232527".parse().unwrap(); + + let mut params = ActionParams::default(); + params.sender = sender.clone(); + params.address = receiver.clone(); + params.gas = U256::from(100_000); + params.code = Some(Arc::new(load_sample!("call_static.wasm"))); + params.data = Some(Vec::new()); + params.value = ActionValue::transfer(1_000_000_000); + + let mut ext = FakeExt::new(); + + let (gas_left, result) = { + let mut interpreter = wasm_interpreter(); + let result = interpreter.exec(params, &mut ext).expect("Interpreter to execute without any errors"); + match result { + GasLeft::Known(_) => { panic!("Static call test should return payload"); }, + GasLeft::NeedsReturn { gas_left: gas, data: result, apply_state: _apply } => (gas, result.to_vec()), + } + }; + + trace!(target: "wasm", "fake_calls: {:?}", &ext.calls); + assert!(ext.calls.contains( + &FakeCall { + call_type: FakeCallType::Call, + gas: U256::from(99_061), + sender_address: Some(sender), + receive_address: Some(receiver), + value: None, + data: vec![1u8, 2, 3, 5, 7, 11], + code_address: Some("13077bfb00000000000000000000000000000000".parse().unwrap()), + } + )); + assert_eq!(gas_left, U256::from(94196)); + + // siphash result + let res = LittleEndian::read_u32(&result[..]); + assert_eq!(res, 317632590); +} \ No newline at end of file diff --git a/ethcore/res/wasm-tests b/ethcore/res/wasm-tests index 9ed630431..8361f18c7 160000 --- a/ethcore/res/wasm-tests +++ b/ethcore/res/wasm-tests @@ -1 +1 @@ -Subproject commit 9ed6304313fa949ed92aa0570fb2bc759fb6dc58 +Subproject commit 8361f18c7ea133d9b85edf7dea02f05b9feb1938 From 8238fb37f3bb651b3b519928439defe24ff4893b Mon Sep 17 00:00:00 2001 From: fro Date: Thu, 27 Jul 2017 15:36:55 +0300 Subject: [PATCH 02/20] new env exports added ___syscall140 ___syscall146 ___syscall54 _llvm_trap --- ethcore/evm/src/wasm/env.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ethcore/evm/src/wasm/env.rs b/ethcore/evm/src/wasm/env.rs index e68e50432..19cffad7e 100644 --- a/ethcore/evm/src/wasm/env.rs +++ b/ethcore/evm/src/wasm/env.rs @@ -100,5 +100,25 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[ "___syscall6", &[I32; 2], Some(I32), - ) + ), + Static( + "___syscall140", + &[I32; 2], + Some(I32) + ), + Static( + "___syscall146", + &[I32; 2], + Some(I32) + ), + Static( + "___syscall54", + &[I32; 2], + Some(I32) + ), + Static( + "_llvm_trap", + &[I32; 0], + None + ), ]; From e234b7fdbf2c9ab30044073579fd1bd8488f51b6 Mon Sep 17 00:00:00 2001 From: fro Date: Fri, 28 Jul 2017 16:38:03 +0300 Subject: [PATCH 03/20] realloc test added --- ethcore/evm/src/wasm/env.rs | 37 ++++++++++++++++++++++++++++++++++- ethcore/evm/src/wasm/tests.rs | 24 +++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/ethcore/evm/src/wasm/env.rs b/ethcore/evm/src/wasm/env.rs index cabd38bd9..00770bb4a 100644 --- a/ethcore/evm/src/wasm/env.rs +++ b/ethcore/evm/src/wasm/env.rs @@ -115,5 +115,40 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[ "_emscripten_memcpy_big", &[I32; 3], Some(I32), - ) + ), + Static( + "___syscall140", + &[I32; 2], + Some(I32) + ), + Static( + "___syscall146", + &[I32; 2], + Some(I32) + ), + Static( + "___syscall54", + &[I32; 2], + Some(I32) + ), + Static( + "___syscall6", + &[I32; 2], + Some(I32) + ), + Static( + "_llvm_trap", + &[I32; 0], + None + ), + Static( + "abortOnCannotGrowMemory", + &[I32; 0], + Some(I32) + ), + Static( + "___setErrNo", + &[I32; 1], + None + ), ]; diff --git a/ethcore/evm/src/wasm/tests.rs b/ethcore/evm/src/wasm/tests.rs index 8ae13daae..8c2ec0b3f 100644 --- a/ethcore/evm/src/wasm/tests.rs +++ b/ethcore/evm/src/wasm/tests.rs @@ -272,3 +272,27 @@ fn create() { )); assert_eq!(gas_left, U256::from(99_768)); } + +// Realloc test +#[test] +fn realloc() { + let code = load_sample!("realloc.wasm"); + + let mut params = ActionParams::default(); + params.gas = U256::from(100_000); + params.code = Some(Arc::new(code)); + params.data = Some(vec![0u8]); + let mut ext = FakeExt::new(); + + let (gas_left, result) = { + let mut interpreter = wasm_interpreter(); + let result = interpreter.exec(params, &mut ext).expect("Interpreter to execute without any errors"); + match result { + GasLeft::Known(_) => { panic!("Realloc should return payload"); }, + GasLeft::NeedsReturn { gas_left: gas, data: result, apply_state: _apply } => (gas, result.to_vec()), + } + }; + assert_eq!(gas_left, U256::from(98326)); + assert_eq!(result, vec![0u8; 2]); + +} From eecd823d32b3f4d88f64a6c41acec9c2b0b78994 Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 29 Jul 2017 17:12:07 +0200 Subject: [PATCH 04/20] util reexports less std --- Cargo.lock | 14 ++++++-- ethcore/Cargo.toml | 3 ++ ethcore/evm/src/interpreter/gasometer.rs | 3 +- ethcore/evm/src/interpreter/mod.rs | 3 +- ethcore/evm/src/tests.rs | 2 ++ ethcore/src/account_db.rs | 1 + ethcore/src/blockchain/blockchain.rs | 2 ++ ethcore/src/blockchain/extras.rs | 9 ++++-- ethcore/src/client/test_client.rs | 2 ++ ethcore/src/engines/authority_round/mod.rs | 9 ++++-- ethcore/src/engines/basic_authority.rs | 12 ++++--- ethcore/src/engines/instant_seal.rs | 4 +-- ethcore/src/engines/mod.rs | 2 ++ ethcore/src/engines/tendermint/message.rs | 5 +-- ethcore/src/engines/tendermint/mod.rs | 7 ++-- ethcore/src/engines/validator_set/contract.rs | 8 ++--- ethcore/src/engines/validator_set/multi.rs | 1 + .../engines/validator_set/safe_contract.rs | 10 +++--- ethcore/src/engines/vote_collector.rs | 1 + ethcore/src/error.rs | 1 + ethcore/src/ethereum/ethash.rs | 32 +++++++++++-------- ethcore/src/executive.rs | 6 ++-- ethcore/src/externalities.rs | 9 +++--- ethcore/src/header.rs | 8 ++--- ethcore/src/lib.rs | 3 ++ ethcore/src/miner/miner.rs | 3 +- ethcore/src/miner/transaction_queue.rs | 4 +-- ethcore/src/miner/work_notify.rs | 1 + ethcore/src/pod_account.rs | 4 ++- ethcore/src/pod_state.rs | 4 ++- ethcore/src/spec/spec.rs | 3 ++ ethcore/src/state/account.rs | 2 ++ ethcore/src/state/mod.rs | 2 ++ ethcore/src/tests/client.rs | 1 + ethcore/src/tests/helpers.rs | 3 +- ethcore/src/trace/types/filter.rs | 4 +-- ethcore/src/trace/types/trace.rs | 2 +- ethcore/src/verification/queue/mod.rs | 17 +++++----- ethcore/src/verification/verification.rs | 2 ++ ethcore/types/Cargo.toml | 1 + ethcore/types/src/filter.rs | 2 +- ethcore/types/src/lib.rs | 1 + ethcore/types/src/log_entry.rs | 6 ++-- ethkey/cli/src/main.rs | 16 +++++----- ethkey/src/secret.rs | 7 ++++ hash-fetch/src/client.rs | 3 +- ipc/hypervisor/src/lib.rs | 2 +- ipfs/src/lib.rs | 4 +-- ipfs/src/route.rs | 3 +- js/src/lib.rs.in | 2 +- rpc/src/v1/tests/helpers/miner_service.rs | 1 + stratum/src/lib.rs | 8 ++--- sync/src/block_sync.rs | 4 ++- sync/src/blocks.rs | 1 + sync/src/chain.rs | 28 ++++++++-------- sync/src/tests/helpers.rs | 1 + sync/src/tests/snapshot.rs | 1 + util/Cargo.toml | 2 -- util/bloomable/Cargo.toml | 10 ++++++ util/{src/bloom.rs => bloomable/src/lib.rs} | 32 ++----------------- util/bloomable/tests/test.rs | 31 ++++++++++++++++++ util/src/common.rs | 5 +-- util/src/journaldb/archivedb.rs | 1 + util/src/journaldb/earlymergedb.rs | 2 ++ util/src/journaldb/mod.rs | 3 +- util/src/journaldb/overlayrecentdb.rs | 1 + util/src/journaldb/refcounteddb.rs | 1 + util/src/kvdb.rs | 2 ++ util/src/lib.rs | 5 --- util/src/migration/tests.rs | 1 + util/src/misc.rs | 6 ++-- util/src/nibblevec.rs | 2 +- util/src/standard.rs | 18 ----------- util/src/trie/triedb.rs | 1 + 74 files changed, 255 insertions(+), 168 deletions(-) create mode 100644 util/bloomable/Cargo.toml rename util/{src/bloom.rs => bloomable/src/lib.rs} (70%) create mode 100644 util/bloomable/tests/test.rs diff --git a/Cargo.lock b/Cargo.lock index 359b2d2f9..2f9cb3f6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,6 +181,14 @@ name = "blastfig" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bloomable" +version = "0.1.0" +dependencies = [ + "ethcore-bigint 0.1.3", + "tiny-keccak 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bloomchain" version = "0.1.0" @@ -271,6 +279,7 @@ dependencies = [ name = "common-types" version = "0.1.0" dependencies = [ + "bloomable 0.1.0", "ethcore-util 1.8.0", "ethjson 0.1.0", "rlp 0.2.0", @@ -462,6 +471,7 @@ name = "ethcore" version = "1.8.0" dependencies = [ "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bloomable 0.1.0", "bloomchain 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bn 0.4.4 (git+https://github.com/paritytech/bn)", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -502,8 +512,10 @@ dependencies = [ "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "stats 0.1.0", + "table 0.1.0", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "transient-hashmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "using_queue 0.1.0", ] [[package]] @@ -751,11 +763,9 @@ dependencies = [ "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "sha3 0.1.0", - "table 0.1.0", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "using_queue 0.1.0", "vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 71e329201..7ac147cd0 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -53,6 +53,9 @@ semver = "0.6" stats = { path = "../util/stats" } time = "0.1" transient-hashmap = "0.4" +using_queue = { path = "../util/using_queue" } +table = { path = "../util/table" } +bloomable = { path = "../util/bloomable" } [dev-dependencies] native-contracts = { path = "native_contracts", features = ["test_contracts"] } diff --git a/ethcore/evm/src/interpreter/gasometer.rs b/ethcore/evm/src/interpreter/gasometer.rs index c2dcf5412..5f4ef80a1 100644 --- a/ethcore/evm/src/interpreter/gasometer.rs +++ b/ethcore/evm/src/interpreter/gasometer.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::cmp; use util::*; use super::u256_to_address; @@ -82,7 +83,7 @@ impl Gasometer { }; if let Some(Ok(r)) = requested { - Ok(min(r, max_gas_provided)) + Ok(cmp::min(r, max_gas_provided)) } else { Ok(max_gas_provided) } diff --git a/ethcore/evm/src/interpreter/mod.rs b/ethcore/evm/src/interpreter/mod.rs index 30b431912..621febffd 100644 --- a/ethcore/evm/src/interpreter/mod.rs +++ b/ethcore/evm/src/interpreter/mod.rs @@ -23,12 +23,13 @@ mod stack; mod memory; mod shared_cache; +use std::marker::PhantomData; +use std::{cmp, mem}; use self::gasometer::Gasometer; use self::stack::{Stack, VecStack}; use self::memory::Memory; pub use self::shared_cache::SharedCache; -use std::marker::PhantomData; use action_params::{ActionParams, ActionValue}; use call_type::CallType; use instructions::{self, Instruction, InstructionInfo}; diff --git a/ethcore/evm/src/tests.rs b/ethcore/evm/src/tests.rs index d0502f79a..c19a575f3 100644 --- a/ethcore/evm/src/tests.rs +++ b/ethcore/evm/src/tests.rs @@ -15,6 +15,8 @@ // along with Parity. If not, see . use std::fmt::Debug; +use std::str::FromStr; +use std::collections::{HashMap, HashSet}; use rustc_hex::FromHex; use util::*; use action_params::{ActionParams, ActionValue}; diff --git a/ethcore/src/account_db.rs b/ethcore/src/account_db.rs index 10e63dba3..5ce555aef 100644 --- a/ethcore/src/account_db.rs +++ b/ethcore/src/account_db.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . //! DB backend wrapper for Account trie +use std::collections::HashMap; use util::*; use rlp::NULL_RLP; diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 4412df567..59b4fb7c3 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -16,6 +16,8 @@ //! Blockchain database. +use std::collections::{HashMap, HashSet}; +use std::mem; use bloomchain as bc; use util::*; use rlp::*; diff --git a/ethcore/src/blockchain/extras.rs b/ethcore/src/blockchain/extras.rs index 04c12d53a..ed3a5009b 100644 --- a/ethcore/src/blockchain/extras.rs +++ b/ethcore/src/blockchain/extras.rs @@ -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 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[..] } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 5dfdf5c25..e33888e72 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -17,6 +17,8 @@ //! Test client. use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder}; +use std::collections::{HashMap, BTreeMap}; +use std::mem; use rustc_hex::FromHex; use util::*; use rlp::*; diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 3210368db..a72091e5e 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -19,6 +19,8 @@ use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering}; use std::sync::Weak; use std::time::{UNIX_EPOCH, Duration}; +use std::collections::{BTreeMap, HashSet, HashMap}; +use std::cmp; use account_provider::AccountProvider; use block::*; @@ -463,9 +465,9 @@ impl Engine for AuthorityRound { let gas_limit = parent.gas_limit().clone(); let bound_divisor = self.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()) } }); } @@ -815,7 +817,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() { @@ -852,6 +854,7 @@ impl Engine for AuthorityRound { #[cfg(test)] mod tests { use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; + use std::str::FromStr; use util::*; use header::Header; use error::{Error, BlockError}; diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 68759131d..a3f4b9114 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -17,6 +17,8 @@ //! A blockchain engine that supports a basic, non-BFT proof-of-authority. use std::sync::Weak; +use std::collections::BTreeMap; +use std::cmp; use util::*; use ethkey::{recover, public_to_address, Signature}; use account_provider::AccountProvider; @@ -121,9 +123,9 @@ impl Engine for BasicAuthority { let gas_limit = parent.gas_limit().clone(); let bound_divisor = self.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()) } }); } @@ -147,7 +149,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() { @@ -158,11 +160,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() }))); diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 38834622c..4d297dc3f 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -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; diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index c5fa4818e..77b89e59c 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -36,6 +36,8 @@ pub use self::null_engine::NullEngine; pub use self::tendermint::Tendermint; use std::sync::Weak; +use std::collections::{BTreeMap, HashMap}; +use std::fmt; use self::epoch::PendingTransition; diff --git a/ethcore/src/engines/tendermint/message.rs b/ethcore/src/engines/tendermint/message.rs index b9465f429..623284839 100644 --- a/ethcore/src/engines/tendermint/message.rs +++ b/ethcore/src/engines/tendermint/message.rs @@ -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 { + fn partial_cmp(&self, m: &VoteStep) -> Option { 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 { diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index 453e8f9fb..5d334a610 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -27,6 +27,8 @@ mod params; use std::sync::Weak; 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}; @@ -473,9 +475,9 @@ impl Engine for Tendermint { let gas_limit = parent.gas_limit().clone(); let bound_divisor = self.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()) } }); } @@ -771,6 +773,7 @@ impl Engine for Tendermint { #[cfg(test)] mod tests { + use std::str::FromStr; use rustc_hex::FromHex; use util::*; use block::*; diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index 46f5c8512..e93d06a27 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -142,11 +142,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::
().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::
().unwrap())); + assert!(vc.contains(&last_hash, &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1".parse::
().unwrap())); } #[test] @@ -155,7 +155,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::
().unwrap(); // Make sure reporting can be done. client.miner().set_gas_floor_target(1_000_000.into()); diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 5835dbcdb..79a5a7d26 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -142,6 +142,7 @@ impl ValidatorSet for Multi { #[cfg(test)] mod tests { + use std::collections::BTreeMap; use account_provider::AccountProvider; use client::{BlockChainClient, EngineClient}; use engines::EpochChange; diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 2c42323be..172ec53b7 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -438,11 +438,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::
().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::
().unwrap())); + assert!(vc.contains(&last_hash, &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1".parse::
().unwrap())); } #[test] @@ -454,7 +454,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::
().unwrap(); client.miner().set_engine_signer(v1, "".into()).unwrap(); // Remove "1" validator. @@ -520,7 +520,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::
().unwrap(); let last_hash = client.best_block_header().hash(); let mut new_header = Header::default(); diff --git a/ethcore/src/engines/vote_collector.rs b/ethcore/src/engines/vote_collector.rs index d01d07f15..de9188e74 100644 --- a/ethcore/src/engines/vote_collector.rs +++ b/ethcore/src/engines/vote_collector.rs @@ -17,6 +17,7 @@ //! Collects votes on hashes at each Message::Round. use std::fmt::Debug; +use std::collections::{BTreeMap, HashSet, HashMap}; use util::*; use rlp::{Encodable, RlpStream}; diff --git a/ethcore/src/error.rs b/ethcore/src/error.rs index 2d908cdb6..194cbcb38 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -16,6 +16,7 @@ //! General error types for use in ethcore. +use std::fmt; use util::*; use io::*; use header::BlockNumber; diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 1fbd711c9..06a4ad0d8 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -15,6 +15,8 @@ // along with Parity. If not, see . use std::path::Path; +use std::cmp; +use std::collections::{BTreeMap, HashMap}; use ethash::{quick_get_difficulty, slow_get_seedhash, EthashManager}; use util::*; use block::*; @@ -235,15 +237,15 @@ impl Engine for Arc { 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) }; @@ -319,7 +321,7 @@ impl Engine for Arc { Ok(()) } - 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( @@ -357,7 +359,7 @@ impl Engine for Arc { 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() } @@ -376,7 +378,7 @@ impl Engine for Arc { 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() }))); @@ -400,7 +402,7 @@ impl Engine for Arc { 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()); } @@ -493,28 +495,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 @@ -559,6 +561,8 @@ impl Header { #[cfg(test)] mod tests { + use std::str::FromStr; + use std::collections::BTreeMap; use util::*; use block::*; use tests::helpers::*; diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 9e25b6671..9845d4575 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . //! Transaction Execution environment. +use std::cmp; use util::*; use evm::action_params::{ActionParams, ActionValue}; use state::{Backend as StateBackend, State, Substate, CleanupMode}; @@ -74,7 +75,7 @@ pub struct TransactOptions { pub check_nonce: bool, } -pub fn executor(engine: &E, vm_factory: &Factory, params: &ActionParams) +pub fn executor(engine: &E, vm_factory: &Factory, params: &ActionParams) -> Box 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) { @@ -597,10 +598,11 @@ 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; diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 39c8673a9..d718fd256 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . //! Transaction Execution environment. +use std::cmp; use util::*; use evm::action_params::{ActionParams, ActionValue}; use state::{Backend as StateBackend, State, Substate, CleanupMode}; @@ -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::().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::().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::().unwrap(), &Address::new(), &Address::new(), - Some(U256::from_str("0000000000000000000000000000000000000000000000000000000000150000").unwrap()), + Some("0000000000000000000000000000000000000000000000000000000000150000".parse::().unwrap()), &[], &Address::new(), &mut output, diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs index 83c69e97d..a9a4f948d 100644 --- a/ethcore/src/header.rs +++ b/ethcore/src/header.rs @@ -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::(11)?, u64::max_value().into()).as_u64(), + timestamp: cmp::min(r.val_at::(11)?, u64::max_value().into()).as_u64(), extra_data: r.val_at(12)?, seal: vec![], hash: RefCell::new(Some(r.as_raw().sha3())), diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 89f9d2e57..0805fc7a0 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -106,6 +106,9 @@ extern crate semver; extern crate stats; extern crate time; extern crate transient_hashmap; +extern crate using_queue; +extern crate table; +extern crate bloomable; #[macro_use] extern crate log; diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 80971355b..cc5c8b6f3 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -15,9 +15,10 @@ // along with Parity. If not, see . use std::time::{Instant, Duration}; +use std::collections::{BTreeMap, HashSet}; 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}; diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index 542b42b93..263143ee8 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -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. +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 StateDiff { #[cfg(test)] mod test { - use util::*; + use std::collections::BTreeMap; use types::state_diff::*; use types::account_diff::*; use pod_account::PodAccount; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 7d3900f2c..c4afc93d7 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -16,6 +16,8 @@ //! Parameters for a block chain. +use std::io::Read; +use std::collections::BTreeMap; use rustc_hex::FromHex; use super::genesis::Genesis; use super::seal::Generic as GenericSeal; @@ -484,6 +486,7 @@ impl Spec { #[cfg(test)] mod tests { + use std::str::FromStr; use util::*; use views::*; use tests::helpers::get_temp_state_db; diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index 9e58f2ec0..8f528b9d8 100644 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -16,6 +16,8 @@ //! Single account in the system. +use std::fmt; +use std::collections::HashMap; use util::*; use pod_account::*; use rlp::*; diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index 354da2cc3..25c019dc0 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -21,6 +21,8 @@ use std::cell::{RefCell, RefMut}; use std::collections::hash_map::Entry; +use std::collections::{HashMap, BTreeMap, HashSet}; +use std::fmt; use receipt::Receipt; use engines::Engine; diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 3b32f9094..54256b285 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::str::FromStr; use io::IoChannel; use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId}; use state::{self, State, CleanupMode}; diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index f8e412073..2c50f0fc2 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::collections::BTreeMap; use ethkey::KeyPair; use io::*; use client::{BlockChainClient, Client, ClientConfig}; @@ -347,7 +348,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); diff --git a/ethcore/src/trace/types/filter.rs b/ethcore/src/trace/types/filter.rs index 2dc810442..1b2e2077a 100644 --- a/ethcore/src/trace/types/filter.rs +++ b/ethcore/src/trace/types/filter.rs @@ -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}; @@ -137,7 +137,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}; use trace::flat::FlatTrace; use trace::{Filter, AddressesFilter, TraceError}; diff --git a/ethcore/src/trace/types/trace.rs b/ethcore/src/trace/types/trace.rs index 24250935f..9a22f31a9 100644 --- a/ethcore/src/trace/types/trace.rs +++ b/ethcore/src/trace/types/trace.rs @@ -18,7 +18,7 @@ use util::{U256, Bytes, Address}; use util::sha3::Hashable; -use util::bloom::Bloomable; +use bloomable::Bloomable; use rlp::*; use evm::action_params::ActionParams; diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 7e9a70f7c..192a0dc77 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -20,6 +20,8 @@ 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::cmp; +use std::collections::{VecDeque, HashSet, HashMap}; use util::*; use io::*; use error::*; @@ -234,8 +236,8 @@ impl VerificationQueue { 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 VerificationQueue { 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 VerificationQueue { /// Removes up to `max` verified items from the queue pub fn drain(&self, max: usize) -> Vec { 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::>(); let drained_size = result.iter().map(HeapSizeOf::heap_size_of_children).fold(0, |a, c| a + c); @@ -687,8 +689,8 @@ impl VerificationQueue { // 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 Drop for VerificationQueue { #[cfg(test)] mod tests { - use util::*; use io::*; use spec::*; use super::{BlockQueue, Config, State}; diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 823d2ef70..00976dca7 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -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::*; diff --git a/ethcore/types/Cargo.toml b/ethcore/types/Cargo.toml index 2a3ac6a80..77f392bf6 100644 --- a/ethcore/types/Cargo.toml +++ b/ethcore/types/Cargo.toml @@ -8,6 +8,7 @@ authors = ["Parity Technologies "] rlp = { path = "../../util/rlp" } ethcore-util = { path = "../../util" } ethjson = { path = "../../json" } +bloomable = { path = "../../util/bloomable" } [dev-dependencies] rustc-hex= "1.0" diff --git a/ethcore/types/src/filter.rs b/ethcore/types/src/filter.rs index 6ab53b536..6e344b4ef 100644 --- a/ethcore/types/src/filter.rs +++ b/ethcore/types/src/filter.rs @@ -17,7 +17,7 @@ //! Blockchain filter use util::{Address, H256, Hashable, H2048}; -use util::bloom::Bloomable; +use bloomable::Bloomable; use ids::BlockId; use log_entry::LogEntry; diff --git a/ethcore/types/src/lib.rs b/ethcore/types/src/lib.rs index 589034066..7650cf651 100644 --- a/ethcore/types/src/lib.rs +++ b/ethcore/types/src/lib.rs @@ -19,6 +19,7 @@ extern crate ethcore_util as util; extern crate ethjson; extern crate rlp; +extern crate bloomable; #[cfg(test)] extern crate rustc_hex; diff --git a/ethcore/types/src/log_entry.rs b/ethcore/types/src/log_entry.rs index 724e6a7dc..f917a4dab 100644 --- a/ethcore/types/src/log_entry.rs +++ b/ethcore/types/src/log_entry.rs @@ -18,7 +18,7 @@ use std::ops::Deref; use util::{H256, Address, Bytes, HeapSizeOf, Hashable}; -use util::bloom::Bloomable; +use bloomable::Bloomable; use rlp::*; use {BlockNumber}; @@ -114,8 +114,8 @@ mod tests { #[test] fn test_empty_log_bloom() { - let bloom = H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); + let bloom = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".parse::().unwrap(); + let address = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6".parse::
().unwrap(); let log = LogEntry { address: address, topics: vec![], diff --git a/ethkey/cli/src/main.rs b/ethkey/cli/src/main.rs index 7ad07e295..e60b4583a 100644 --- a/ethkey/cli/src/main.rs +++ b/ethkey/cli/src/main.rs @@ -25,7 +25,7 @@ extern crate panic_hook; use std::{env, fmt, process}; use std::num::ParseIntError; use docopt::Docopt; -use rustc_hex::{FromHex, FromHexError}; +use rustc_hex::{ToHex, FromHex, FromHexError}; use ethkey::{KeyPair, Random, Brain, Prefix, Error as EthkeyError, Generator, sign, verify_public, verify_address}; use std::io; @@ -170,7 +170,7 @@ fn main() { fn display(keypair: KeyPair, mode: DisplayMode) -> String { match mode { DisplayMode::KeyPair => format!("{}", keypair), - DisplayMode::Secret => format!("{:?}", keypair.secret()), + DisplayMode::Secret => format!("{}", keypair.secret().to_hex()), DisplayMode::Public => format!("{:?}", keypair.public()), DisplayMode::Address => format!("{:?}", keypair.address()), } @@ -248,9 +248,9 @@ address: 26d1ec50b4e62c1d1a40d16e7cacc6a6580757d5".to_owned(); .collect::>(); let expected = -"secret: 17d08f5fe8c77af811caa0c9a187e668ce3b74a99acc3f6d976f075fa8e0be55 -public: 689268c0ff57a20cd299fa60d3fb374862aff565b20b5f1767906a99e6e09f3ff04ca2b2a5cd22f62941db103c0356df1a8ed20ce322cab2483db67685afd124 -address: 26d1ec50b4e62c1d1a40d16e7cacc6a6580757d5".to_owned(); +"secret: aa22b54c0cb43ee30a014afe5ef3664b1cde299feabca46cd3167a85a57c39f2 +public: c4c5398da6843632c123f543d714d2d2277716c11ff612b2a2f23c6bda4d6f0327c31cd58c55a9572c3cc141dade0c32747a13b7ef34c241b26c84adbb28fcf4 +address: 006e27b6a72e1f34c626762f3c4761547aff1421".to_owned(); assert_eq!(execute(command).unwrap(), expected); } @@ -261,7 +261,7 @@ address: 26d1ec50b4e62c1d1a40d16e7cacc6a6580757d5".to_owned(); .map(Into::into) .collect::>(); - let expected = "17d08f5fe8c77af811caa0c9a187e668ce3b74a99acc3f6d976f075fa8e0be55".to_owned(); + let expected = "aa22b54c0cb43ee30a014afe5ef3664b1cde299feabca46cd3167a85a57c39f2".to_owned(); assert_eq!(execute(command).unwrap(), expected); } @@ -272,7 +272,7 @@ address: 26d1ec50b4e62c1d1a40d16e7cacc6a6580757d5".to_owned(); .map(Into::into) .collect::>(); - let expected = "689268c0ff57a20cd299fa60d3fb374862aff565b20b5f1767906a99e6e09f3ff04ca2b2a5cd22f62941db103c0356df1a8ed20ce322cab2483db67685afd124".to_owned(); + let expected = "c4c5398da6843632c123f543d714d2d2277716c11ff612b2a2f23c6bda4d6f0327c31cd58c55a9572c3cc141dade0c32747a13b7ef34c241b26c84adbb28fcf4".to_owned(); assert_eq!(execute(command).unwrap(), expected); } @@ -283,7 +283,7 @@ address: 26d1ec50b4e62c1d1a40d16e7cacc6a6580757d5".to_owned(); .map(Into::into) .collect::>(); - let expected = "26d1ec50b4e62c1d1a40d16e7cacc6a6580757d5".to_owned(); + let expected = "006e27b6a72e1f34c626762f3c4761547aff1421".to_owned(); assert_eq!(execute(command).unwrap(), expected); } diff --git a/ethkey/src/secret.rs b/ethkey/src/secret.rs index 982962684..433d8c68e 100644 --- a/ethkey/src/secret.rs +++ b/ethkey/src/secret.rs @@ -17,6 +17,7 @@ use std::fmt; use std::ops::Deref; use std::str::FromStr; +use rustc_hex::ToHex; use secp256k1::key; use bigint::hash::H256; use {Error, SECP256K1}; @@ -26,6 +27,12 @@ pub struct Secret { inner: H256, } +impl ToHex for Secret { + fn to_hex(&self) -> String { + self.inner.to_hex() + } +} + impl fmt::Debug for Secret { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write!(fmt, "Secret: 0x{:x}{:x}..{:x}{:x}", self.inner[0], self.inner[1], self.inner[30], self.inner[31]) diff --git a/hash-fetch/src/client.rs b/hash-fetch/src/client.rs index d52bda7d9..bd773e9b3 100644 --- a/hash-fetch/src/client.rs +++ b/hash-fetch/src/client.rs @@ -188,8 +188,9 @@ fn random_temp_path() -> PathBuf { #[cfg(test)] mod tests { + use rustc_hex::FromHex; use std::sync::{Arc, mpsc}; - use util::{Mutex, FromHex}; + use util::Mutex; use futures::future; use fetch::{self, Fetch}; use parity_reactor::Remote; diff --git a/ipc/hypervisor/src/lib.rs b/ipc/hypervisor/src/lib.rs index 1031905d4..b522122b5 100644 --- a/ipc/hypervisor/src/lib.rs +++ b/ipc/hypervisor/src/lib.rs @@ -260,7 +260,7 @@ mod tests { let client = nanoipc::fast_client::>(url).unwrap(); client.handshake().unwrap(); - client.module_ready(test_module_id); + client.module_ready(test_module_id, url.to_owned()); }); let hypervisor = Hypervisor::with_url(url).local_module(test_module_id); diff --git a/ipfs/src/lib.rs b/ipfs/src/lib.rs index 4821ef59d..104c7db19 100644 --- a/ipfs/src/lib.rs +++ b/ipfs/src/lib.rs @@ -233,7 +233,7 @@ mod tests { let _ = write_chunk(&mut transport, &mut progress, b"foobar"); - assert_eq!(b"foobar".into_vec(), transport); + assert_eq!(b"foobar".to_vec(), transport); assert_eq!(6, progress); } @@ -244,7 +244,7 @@ mod tests { let _ = write_chunk(&mut transport, &mut progress, b"foobar"); - assert_eq!(b"bar".into_vec(), transport); + assert_eq!(b"bar".to_vec(), transport); assert_eq!(6, progress); } diff --git a/ipfs/src/route.rs b/ipfs/src/route.rs index b034c2d4c..40edc8de0 100644 --- a/ipfs/src/route.rs +++ b/ipfs/src/route.rs @@ -119,7 +119,8 @@ mod tests { use ethcore::client::TestBlockChainClient; fn get_mocked_handler() -> IpfsHandler { - IpfsHandler::new(None, None, Arc::new(TestBlockChainClient::new())) + //IpfsHandler::new(None, None, Arc::new(TestBlockChainClient::new())) + unimplemented!(); } #[test] diff --git a/js/src/lib.rs.in b/js/src/lib.rs.in index 220811656..b811c1066 100644 --- a/js/src/lib.rs.in +++ b/js/src/lib.rs.in @@ -51,5 +51,5 @@ impl WebApp for App { #[test] fn test_js() { - parity_dapps_glue::js::build(env!("CARGO_MANIFEST_DIR")); + parity_dapps_glue::js::build(env!("CARGO_MANIFEST_DIR"), "build"); } diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index c5bc0a259..ecc453622 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -16,6 +16,7 @@ //! Test implementation of miner service. +use std::collections::{BTreeMap, HashMap}; use std::collections::hash_map::Entry; use util::{Address, H256, Bytes, U256}; use util::standard::*; diff --git a/stratum/src/lib.rs b/stratum/src/lib.rs index d87bf59a8..0042ab1e9 100644 --- a/stratum/src/lib.rs +++ b/stratum/src/lib.rs @@ -342,7 +342,7 @@ mod tests { let mut core = Core::new().expect("Tokio Core should be created with no errors"); let mut buffer = vec![0u8; 2048]; - let mut data_vec = data.as_bytes().into_vec(); + let mut data_vec = data.as_bytes().to_vec(); data_vec.extend(b"\n"); let stream = TcpStream::connect(addr, &core.handle()) @@ -353,7 +353,7 @@ mod tests { io::read(stream, &mut buffer) }) .and_then(|(_, read_buf, len)| { - future::ok(read_buf[0..len].into_vec()) + future::ok(read_buf[0..len].to_vec()) }); let result = core.run(stream).expect("Core should run with no errors"); @@ -454,7 +454,7 @@ mod tests { let mut auth_request = r#"{"jsonrpc": "2.0", "method": "mining.authorize", "params": ["miner1", ""], "id": 1}"# .as_bytes() - .into_vec(); + .to_vec(); auth_request.extend(b"\n"); let mut core = Core::new().expect("Tokio Core should be created with no errors"); @@ -487,7 +487,7 @@ mod tests { }) .and_then(|(_, read_buf, len)| { trace!(target: "stratum", "Received work from server"); - future::ok(read_buf[0..len].into_vec()) + future::ok(read_buf[0..len].to_vec()) }); let response = String::from_utf8( core.run(stream).expect("Core should run with no errors") diff --git a/sync/src/block_sync.rs b/sync/src/block_sync.rs index e7192d525..8215b775b 100644 --- a/sync/src/block_sync.rs +++ b/sync/src/block_sync.rs @@ -18,6 +18,8 @@ /// Blockchain downloader /// +use std::collections::{HashSet, VecDeque}; +use std::cmp; use util::*; use rlp::*; use ethcore::views::{BlockView}; @@ -386,7 +388,7 @@ impl BlockDownloader { debug!(target: "sync", "Could not revert to previous ancient block, last: {} ({})", start, start_hash); self.reset(); } else { - let n = start - min(self.retract_step, start); + let n = start - cmp::min(self.retract_step, start); self.retract_step *= 2; match io.chain().block_hash(BlockId::Number(n)) { Some(h) => { diff --git a/sync/src/blocks.rs b/sync/src/blocks.rs index 3dcc912a7..dbd797007 100644 --- a/sync/src/blocks.rs +++ b/sync/src/blocks.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::collections::{HashSet, HashMap}; use std::collections::hash_map::Entry; use smallvec::SmallVec; use util::*; diff --git a/sync/src/chain.rs b/sync/src/chain.rs index b3ca25328..38872b24f 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -89,6 +89,8 @@ /// All other messages are ignored. /// +use std::collections::{HashSet, HashMap}; +use std::cmp; use util::*; use rlp::*; use network::*; @@ -421,7 +423,7 @@ impl ChainSync { start_block_number: self.starting_block, last_imported_block_number: Some(last_imported_number), last_imported_old_block_number: self.old_blocks.as_ref().map(|d| d.last_imported_block_number()), - highest_block_number: self.highest_block.map(|n| max(n, last_imported_number)), + highest_block_number: self.highest_block.map(|n| cmp::max(n, last_imported_number)), blocks_received: if last_imported_number > self.starting_block { last_imported_number - self.starting_block } else { 0 }, blocks_total: match self.highest_block { Some(x) if x > self.starting_block => x - self.starting_block, _ => 0 }, num_peers: self.peers.values().filter(|p| p.is_allowed()).count(), @@ -961,7 +963,7 @@ impl ChainSync { } if self.state != SyncState::Idle { trace!(target: "sync", "Ignoring new hashes since we're already downloading."); - let max = r.iter().take(MAX_NEW_HASHES).map(|item| item.val_at::(1).unwrap_or(0)).fold(0u64, max); + let max = r.iter().take(MAX_NEW_HASHES).map(|item| item.val_at::(1).unwrap_or(0)).fold(0u64, cmp::max); if max > self.highest_block.unwrap_or(0) { self.highest_block = Some(max); } @@ -1473,7 +1475,7 @@ impl ChainSync { let mut item_count = r.item_count()?; trace!(target: "sync", "{:02} -> Transactions ({} entries)", peer_id, item_count); - item_count = min(item_count, MAX_TX_TO_IMPORT); + item_count = cmp::min(item_count, MAX_TX_TO_IMPORT); let mut transactions = Vec::with_capacity(item_count); for i in 0 .. item_count { let rlp = r.at(i)?; @@ -1549,11 +1551,11 @@ impl ChainSync { }; let mut number = if reverse { - min(last, number) + cmp::min(last, number) } else { - max(0, number) + cmp::max(0, number) }; - let max_count = min(MAX_HEADERS_TO_SEND, max_headers); + let max_count = cmp::min(MAX_HEADERS_TO_SEND, max_headers); let mut count = 0; let mut data = Bytes::new(); let inc = (skip + 1) as BlockNumber; @@ -1594,7 +1596,7 @@ impl ChainSync { debug!(target: "sync", "Empty GetBlockBodies request, ignoring."); return Ok(None); } - count = min(count, MAX_BODIES_TO_SEND); + count = cmp::min(count, MAX_BODIES_TO_SEND); let mut added = 0usize; let mut data = Bytes::new(); for i in 0..count { @@ -1617,7 +1619,7 @@ impl ChainSync { debug!(target: "sync", "Empty GetNodeData request, ignoring."); return Ok(None); } - count = min(count, MAX_NODE_DATA_TO_SEND); + count = cmp::min(count, MAX_NODE_DATA_TO_SEND); let mut added = 0usize; let mut data = Vec::new(); for i in 0..count { @@ -1641,7 +1643,7 @@ impl ChainSync { debug!(target: "sync", "Empty GetReceipts request, ignoring."); return Ok(None); } - count = min(count, MAX_RECEIPTS_HEADERS_TO_SEND); + count = cmp::min(count, MAX_RECEIPTS_HEADERS_TO_SEND); let mut added_headers = 0usize; let mut added_receipts = 0usize; let mut data = Bytes::new(); @@ -1915,8 +1917,8 @@ impl ChainSync { // take sqrt(x) peers let mut peers = peers.to_vec(); let mut count = (peers.len() as f64).powf(0.5).round() as usize; - count = min(count, MAX_PEERS_PROPAGATION); - count = max(count, MIN_PEERS_PROPAGATION); + count = cmp::min(count, MAX_PEERS_PROPAGATION); + count = cmp::max(count, MIN_PEERS_PROPAGATION); random::new().shuffle(&mut peers); peers.truncate(count); peers @@ -2006,7 +2008,7 @@ impl ChainSync { fn select_peers_for_transactions(&self, filter: F) -> Vec where F: Fn(&PeerId) -> bool { // sqrt(x)/x scaled to max u32 - let fraction = (self.peers.len() as f64).powf(-0.5).mul(u32::max_value() as f64).round() as u32; + let fraction = ((self.peers.len() as f64).powf(-0.5) * (u32::max_value() as f64).round()) as u32; let small = self.peers.len() < MIN_PEERS_PROPAGATION; let mut random = random::new(); @@ -2112,7 +2114,7 @@ impl ChainSync { peers.insert(peer_id); self.send_packet(io, peer_id, TRANSACTIONS_PACKET, rlp); trace!(target: "sync", "{:02} <- Transactions ({} entries)", peer_id, sent); - max_sent = max(max_sent, sent); + max_sent = cmp::max(max_sent, sent); } debug!(target: "sync", "Sent up to {} transactions to {} peers.", max_sent, lucky_peers_len); } diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index 9d32d1951..fa3039b63 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::collections::{VecDeque, HashSet, HashMap}; use util::*; use network::*; use tests::snapshot::*; diff --git a/sync/src/tests/snapshot.rs b/sync/src/tests/snapshot.rs index f52cdb39a..0a3b31fb0 100644 --- a/sync/src/tests/snapshot.rs +++ b/sync/src/tests/snapshot.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::collections::HashMap; use util::*; use ethcore::snapshot::{SnapshotService, ManifestData, RestorationStatus}; use ethcore::header::BlockNumber; diff --git a/util/Cargo.toml b/util/Cargo.toml index aa846898f..5306e3c57 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -28,8 +28,6 @@ vergen = "0.1" target_info = "0.1" ethcore-bigint = { path = "bigint", features = ["heapsizeof"] } parking_lot = "0.4" -using_queue = { path = "using_queue" } -table = { path = "table" } ansi_term = "0.9" tiny-keccak= "1.0" ethcore-bloom-journal = { path = "bloom" } diff --git a/util/bloomable/Cargo.toml b/util/bloomable/Cargo.toml new file mode 100644 index 000000000..46009d381 --- /dev/null +++ b/util/bloomable/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "bloomable" +version = "0.1.0" +authors = ["debris "] + +[dependencies] +ethcore-bigint = { path = "../bigint" } + +[dev-dependencies] +tiny-keccak = "1.2.1" diff --git a/util/src/bloom.rs b/util/bloomable/src/lib.rs similarity index 70% rename from util/src/bloom.rs rename to util/bloomable/src/lib.rs index c39921f5d..29a9abde5 100644 --- a/util/src/bloom.rs +++ b/util/bloomable/src/lib.rs @@ -16,9 +16,11 @@ //! Bloom operations. +extern crate ethcore_bigint; + use std::mem; use std::ops::DerefMut; -use {H64, H160, H256, H512, H520, H2048}; +use ethcore_bigint::hash::{H64, H160, H256, H512, H520, H2048}; /// Returns log2. pub fn log2(x: usize) -> u32 { @@ -115,31 +117,3 @@ impl_bloomable_for_hash!(H256, 32); impl_bloomable_for_hash!(H512, 64); impl_bloomable_for_hash!(H520, 65); impl_bloomable_for_hash!(H2048, 256); - -#[cfg(test)] -mod tests { - use {H160, H256, H2048}; - use sha3::Hashable; - use super::Bloomable; - - #[test] - fn shift_bloomed() { - let bloom: H2048 = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); - let address: H160 = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into(); - let topic: H256 = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".into(); - - let mut my_bloom = H2048::default(); - assert!(!my_bloom.contains_bloomed(&address.sha3())); - assert!(!my_bloom.contains_bloomed(&topic.sha3())); - - my_bloom.shift_bloomed(&address.sha3()); - assert!(my_bloom.contains_bloomed(&address.sha3())); - assert!(!my_bloom.contains_bloomed(&topic.sha3())); - - my_bloom.shift_bloomed(&topic.sha3()); - assert_eq!(my_bloom, bloom); - assert!(my_bloom.contains_bloomed(&address.sha3())); - assert!(my_bloom.contains_bloomed(&topic.sha3())); - } -} - diff --git a/util/bloomable/tests/test.rs b/util/bloomable/tests/test.rs new file mode 100644 index 000000000..85ced83e6 --- /dev/null +++ b/util/bloomable/tests/test.rs @@ -0,0 +1,31 @@ +extern crate tiny_keccak; +extern crate ethcore_bigint; +extern crate bloomable; + +use ethcore_bigint::hash::{H160, H256, H2048}; +use bloomable::Bloomable; +use tiny_keccak::keccak256; + +fn sha3(input: &[u8]) -> H256 { + keccak256(input).into() +} + +#[test] +fn shift_bloomed() { + let bloom: H2048 = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); + let address: H160 = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into(); + let topic: H256 = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".into(); + + let mut my_bloom = H2048::default(); + assert!(!my_bloom.contains_bloomed(&sha3(&address))); + assert!(!my_bloom.contains_bloomed(&sha3(&topic))); + + my_bloom.shift_bloomed(&sha3(&address)); + assert!(my_bloom.contains_bloomed(&sha3(&address))); + assert!(!my_bloom.contains_bloomed(&sha3(&topic))); + + my_bloom.shift_bloomed(&sha3(&topic)); + assert_eq!(my_bloom, bloom); + assert!(my_bloom.contains_bloomed(&sha3(&address))); + assert!(my_bloom.contains_bloomed(&sha3(&topic))); +} diff --git a/util/src/common.rs b/util/src/common.rs index eff697bc2..89ce9d95f 100644 --- a/util/src/common.rs +++ b/util/src/common.rs @@ -16,6 +16,7 @@ //! Utils common types and macros global reexport. +use std::io; pub use standard::*; pub use error::*; pub use bytes::*; @@ -100,8 +101,8 @@ macro_rules! flushln { #[doc(hidden)] pub fn flush(s: String) { - let _ = ::std::io::stdout().write(s.as_bytes()); - let _ = ::std::io::stdout().flush(); + let _ = io::Write::write(&mut io::stdout(), s.as_bytes()); + let _ = io::Write::flush(&mut io::stdout()); } #[test] diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index cf21fbd9f..e882f3f18 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -16,6 +16,7 @@ //! Disk-backed `HashDB` implementation. +use std::collections::HashMap; use common::*; use rlp::*; use hashdb::*; diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index 7eb3f3259..de0e19d6e 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -16,6 +16,8 @@ //! Disk-backed `HashDB` implementation. +use std::fmt; +use std::collections::HashMap; use common::*; use rlp::*; use hashdb::*; diff --git a/util/src/journaldb/mod.rs b/util/src/journaldb/mod.rs index 84a71339a..80ddbf7a1 100644 --- a/util/src/journaldb/mod.rs +++ b/util/src/journaldb/mod.rs @@ -16,6 +16,7 @@ //! `JournalDB` interface and implementation. +use std::{fmt, str}; use common::*; /// Export the journaldb module. @@ -59,7 +60,7 @@ impl Default for Algorithm { fn default() -> Algorithm { Algorithm::OverlayRecent } } -impl FromStr for Algorithm { +impl str::FromStr for Algorithm { type Err = String; fn from_str(s: &str) -> Result { diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index 915e64d05..73a63bd4b 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -16,6 +16,7 @@ //! `JournalDB` over in-memory overlay +use std::collections::HashMap; use common::*; use rlp::*; use hashdb::*; diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index 4f8600bde..772281abd 100644 --- a/util/src/journaldb/refcounteddb.rs +++ b/util/src/journaldb/refcounteddb.rs @@ -16,6 +16,7 @@ //! Disk-backed, ref-counted `JournalDB` implementation. +use std::collections::HashMap; use common::*; use rlp::*; use hashdb::*; diff --git a/util/src/kvdb.rs b/util/src/kvdb.rs index d1cf67218..6692064ed 100644 --- a/util/src/kvdb.rs +++ b/util/src/kvdb.rs @@ -16,6 +16,8 @@ //! Key-Value store abstraction with `RocksDB` backend. +use std::{mem, fs}; +use std::collections::{HashMap, BTreeMap}; use std::io::ErrorKind; use std::marker::PhantomData; use std::path::PathBuf; diff --git a/util/src/lib.rs b/util/src/lib.rs index c6a50f58b..c2d9c59d3 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -112,10 +112,6 @@ extern crate ethcore_logger; #[macro_use] extern crate log as rlog; -pub extern crate using_queue; -pub extern crate table; - -pub mod bloom; pub mod standard; #[macro_use] pub mod common; @@ -147,7 +143,6 @@ pub use overlaydb::*; pub use journaldb::JournalDB; pub use triehash::*; pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrieDB, SecTrieDBMut}; -pub use nibbleslice::*; pub use semantic_version::*; pub use kvdb::*; pub use timer::*; diff --git a/util/src/migration/tests.rs b/util/src/migration/tests.rs index 585bb5f36..7cd19009a 100644 --- a/util/src/migration/tests.rs +++ b/util/src/migration/tests.rs @@ -18,6 +18,7 @@ //! A random temp directory is created. A database is created within it, and migrations //! are performed in temp sub-directories. +use std::collections::BTreeMap; use common::*; use migration::{Batch, Config, Error, SimpleMigration, Migration, Manager}; use kvdb::Database; diff --git a/util/src/misc.rs b/util/src/misc.rs index 6dc2fba12..120805f0c 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -60,9 +60,9 @@ pub fn version() -> String { pub fn version_data() -> Bytes { let mut s = RlpStream::new_list(4); let v = - (u32::from_str(env!("CARGO_PKG_VERSION_MAJOR")).expect("Environment variables are known to be valid; qed") << 16) + - (u32::from_str(env!("CARGO_PKG_VERSION_MINOR")).expect("Environment variables are known to be valid; qed") << 8) + - u32::from_str(env!("CARGO_PKG_VERSION_PATCH")).expect("Environment variables are known to be valid; qed"); + (env!("CARGO_PKG_VERSION_MAJOR").parse::().expect("Environment variables are known to be valid; qed") << 16) + + (env!("CARGO_PKG_VERSION_MINOR").parse::().expect("Environment variables are known to be valid; qed") << 8) + + env!("CARGO_PKG_VERSION_PATCH").parse::().expect("Environment variables are known to be valid; qed"); s.append(&v); s.append(&"Parity"); s.append(&rustc_version()); diff --git a/util/src/nibblevec.rs b/util/src/nibblevec.rs index 718ff8e9e..b38198593 100644 --- a/util/src/nibblevec.rs +++ b/util/src/nibblevec.rs @@ -17,7 +17,7 @@ //! An owning, nibble-oriented byte vector. -use ::NibbleSlice; +use nibbleslice::NibbleSlice; use elastic_array::ElasticArray36; /// Owning, nibble-oriented byte vector. Counterpart to `NibbleSlice`. diff --git a/util/src/standard.rs b/util/src/standard.rs index 19521a5d5..cc67b0de5 100644 --- a/util/src/standard.rs +++ b/util/src/standard.rs @@ -16,28 +16,10 @@ //! Std lib global reexports. -pub use std::io; -pub use std::fs; -pub use std::str; -pub use std::fmt; -pub use std::cmp; -pub use std::ptr; -pub use std::mem; -pub use std::ops; -pub use std::slice; -pub use std::result; -pub use std::option; - pub use std::path::Path; -pub use std::str::{FromStr}; -pub use std::io::{Read,Write}; pub use std::hash::{Hash, Hasher}; -pub use std::error::Error as StdError; -pub use std::ops::*; -pub use std::cmp::*; pub use std::sync::Arc; -pub use std::collections::*; pub use heapsize::HeapSizeOf; pub use itertools::Itertools; diff --git a/util/src/trie/triedb.rs b/util/src/trie/triedb.rs index 5da304167..a8600914c 100644 --- a/util/src/trie/triedb.rs +++ b/util/src/trie/triedb.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::fmt; use common::*; use hashdb::*; use nibbleslice::*; From c4989ddc442df2d8a09a7a28057a640f8898894b Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 29 Jul 2017 21:56:42 +0200 Subject: [PATCH 05/20] removed util::common --- dapps/src/api/time.rs | 5 ++-- ethcore/evm/src/ext.rs | 1 + ethcore/evm/src/interpreter/mod.rs | 1 + ethcore/evm/src/tests.rs | 2 ++ ethcore/src/blockchain/blockchain.rs | 1 + ethcore/src/client/test_client.rs | 1 + ethcore/src/engines/authority_round/mod.rs | 22 +++++++-------- ethcore/src/engines/basic_authority.rs | 3 ++- ethcore/src/engines/instant_seal.rs | 1 + ethcore/src/engines/mod.rs | 3 ++- ethcore/src/engines/signer.rs | 3 ++- ethcore/src/engines/tendermint/message.rs | 1 + ethcore/src/engines/tendermint/mod.rs | 2 +- ethcore/src/engines/validator_set/contract.rs | 1 + ethcore/src/engines/validator_set/multi.rs | 1 + .../engines/validator_set/safe_contract.rs | 3 ++- ethcore/src/engines/validator_set/test.rs | 3 ++- ethcore/src/engines/vote_collector.rs | 1 + ethcore/src/ethereum/ethash.rs | 2 ++ ethcore/src/executive.rs | 1 + ethcore/src/externalities.rs | 1 + ethcore/src/miner/miner.rs | 1 + ethcore/src/service.rs | 2 ++ ethcore/src/spec/spec.rs | 2 ++ ethcore/src/state/account.rs | 1 + ethcore/src/state/mod.rs | 1 + ethcore/src/state_db.rs | 3 ++- ethcore/src/tests/client.rs | 1 + ethcore/src/tests/evm.rs | 1 + ethcore/src/tests/helpers.rs | 1 + ethcore/src/verification/queue/mod.rs | 2 +- json/src/spec/authority_round.rs | 5 ++-- rpc/src/v1/tests/helpers/miner_service.rs | 3 +-- sync/src/tests/chain.rs | 2 +- sync/src/tests/consensus.rs | 1 + sync/src/tests/helpers.rs | 1 + sync/src/tests/snapshot.rs | 1 + util/network/src/tests.rs | 3 ++- util/src/common.rs | 11 ++------ util/src/error.rs | 2 +- util/src/journaldb/archivedb.rs | 6 +++-- util/src/journaldb/earlymergedb.rs | 9 +++++-- util/src/journaldb/mod.rs | 2 +- util/src/journaldb/overlayrecentdb.rs | 8 ++++-- util/src/journaldb/refcounteddb.rs | 6 +++-- util/src/journaldb/traits.rs | 3 ++- util/src/kvdb.rs | 7 +++-- util/src/lib.rs | 12 +++++++-- util/src/migration/tests.rs | 5 ++-- util/src/misc.rs | 2 +- util/src/standard.rs | 27 ------------------- util/src/trie/triedb.rs | 3 ++- 52 files changed, 109 insertions(+), 84 deletions(-) delete mode 100644 util/src/standard.rs diff --git a/dapps/src/api/time.rs b/dapps/src/api/time.rs index b81b4a844..3117f4cc9 100644 --- a/dapps/src/api/time.rs +++ b/dapps/src/api/time.rs @@ -33,13 +33,14 @@ use std::io; use std::{fmt, mem, time}; - +use std::sync::Arc; use std::collections::VecDeque; + use futures::{self, Future, BoxFuture}; use futures_cpupool::CpuPool; use ntp; use time::{Duration, Timespec}; -use util::{Arc, RwLock}; +use util::RwLock; /// Time checker error. #[derive(Debug, Clone, PartialEq)] diff --git a/ethcore/evm/src/ext.rs b/ethcore/evm/src/ext.rs index 1c3ddb317..2861b1ca5 100644 --- a/ethcore/evm/src/ext.rs +++ b/ethcore/evm/src/ext.rs @@ -16,6 +16,7 @@ //! Interface for Evm externalities. +use std::sync::Arc; use util::*; use call_type::CallType; use env_info::EnvInfo; diff --git a/ethcore/evm/src/interpreter/mod.rs b/ethcore/evm/src/interpreter/mod.rs index 621febffd..36e652ab2 100644 --- a/ethcore/evm/src/interpreter/mod.rs +++ b/ethcore/evm/src/interpreter/mod.rs @@ -25,6 +25,7 @@ mod shared_cache; use std::marker::PhantomData; use std::{cmp, mem}; +use std::sync::Arc; use self::gasometer::Gasometer; use self::stack::{Stack, VecStack}; use self::memory::Memory; diff --git a/ethcore/evm/src/tests.rs b/ethcore/evm/src/tests.rs index c19a575f3..7679ab980 100644 --- a/ethcore/evm/src/tests.rs +++ b/ethcore/evm/src/tests.rs @@ -16,6 +16,8 @@ use std::fmt::Debug; use std::str::FromStr; +use std::hash::Hash; +use std::sync::Arc; use std::collections::{HashMap, HashSet}; use rustc_hex::FromHex; use util::*; diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 59b4fb7c3..bd0defa47 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -17,6 +17,7 @@ //! Blockchain database. use std::collections::{HashMap, HashSet}; +use std::sync::Arc; use std::mem; use bloomchain as bc; use util::*; diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index e33888e72..aa49e6abc 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -17,6 +17,7 @@ //! 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; diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index a72091e5e..d260c9ac8 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -17,7 +17,7 @@ //! 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; @@ -853,8 +853,8 @@ impl Engine for AuthorityRound { #[cfg(test)] mod tests { + use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; - use std::str::FromStr; use util::*; use header::Header; use error::{Error, BlockError}; @@ -944,10 +944,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::().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::().unwrap()); header.set_author(addr); let engine = Spec::new_test_round().engine; @@ -970,10 +970,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::().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::().unwrap()); header.set_author(addr); let engine = Spec::new_test_round().engine; @@ -996,10 +996,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::().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::().unwrap()); header.set_author(addr); let engine = Spec::new_test_round().engine; @@ -1017,7 +1017,7 @@ mod tests { fn reports_skipped() { let last_benign = Arc::new(AtomicUsize::new(0)); let params = AuthorityRoundParams { - gas_limit_bound_divisor: U256::from_str("400").unwrap(), + gas_limit_bound_divisor: "400".parse::().unwrap(), step_duration: Default::default(), block_reward: Default::default(), registrar: Default::default(), @@ -1032,10 +1032,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::().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::().unwrap()); header.set_seal(vec![encode(&3usize).into_vec()]); // Do not report when signer not present. diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index a3f4b9114..38db41c53 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -16,7 +16,7 @@ //! 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::*; @@ -256,6 +256,7 @@ impl Engine for BasicAuthority { #[cfg(test)] mod tests { + use std::sync::Arc; use util::*; use block::*; use error::{BlockError, Error}; diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 4d297dc3f..94e3184ef 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -65,6 +65,7 @@ impl Engine for InstantSeal { #[cfg(test)] mod tests { + use std::sync::Arc; use util::*; use tests::helpers::*; use spec::Spec; diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 77b89e59c..b5a0d934f 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -35,7 +35,7 @@ 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; @@ -395,6 +395,7 @@ 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; diff --git a/ethcore/src/engines/signer.rs b/ethcore/src/engines/signer.rs index 4ec4318c9..4069488ab 100644 --- a/ethcore/src/engines/signer.rs +++ b/ethcore/src/engines/signer.rs @@ -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}; diff --git a/ethcore/src/engines/tendermint/message.rs b/ethcore/src/engines/tendermint/message.rs index 623284839..68bdcb0f7 100644 --- a/ethcore/src/engines/tendermint/message.rs +++ b/ethcore/src/engines/tendermint/message.rs @@ -199,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; diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index 5d334a610..a340db5d4 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -25,7 +25,7 @@ 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; diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index e93d06a27..7c1890379 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -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; diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 79a5a7d26..9acf6050b 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -142,6 +142,7 @@ impl ValidatorSet for Multi { #[cfg(test)] mod tests { + use std::sync::Arc; use std::collections::BTreeMap; use account_provider::AccountProvider; use client::{BlockChainClient, EngineClient}; diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 172ec53b7..8148846e7 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -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; @@ -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; diff --git a/ethcore/src/engines/validator_set/test.rs b/ethcore/src/engines/validator_set/test.rs index 4960ee7be..25eeff66e 100644 --- a/ethcore/src/engines/validator_set/test.rs +++ b/ethcore/src/engines/validator_set/test.rs @@ -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}; diff --git a/ethcore/src/engines/vote_collector.rs b/ethcore/src/engines/vote_collector.rs index de9188e74..b934fdb2e 100644 --- a/ethcore/src/engines/vote_collector.rs +++ b/ethcore/src/engines/vote_collector.rs @@ -18,6 +18,7 @@ use std::fmt::Debug; use std::collections::{BTreeMap, HashSet, HashMap}; +use std::hash::Hash; use util::*; use rlp::{Encodable, RlpStream}; diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 06a4ad0d8..0f984517c 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -17,6 +17,7 @@ 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::*; @@ -563,6 +564,7 @@ impl Header { mod tests { use std::str::FromStr; use std::collections::BTreeMap; + use std::sync::Arc; use util::*; use block::*; use tests::helpers::*; diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 9845d4575..a63605a81 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -16,6 +16,7 @@ //! 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}; diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index d718fd256..5baca496d 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -16,6 +16,7 @@ //! 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}; diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index cc5c8b6f3..241d90c32 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -16,6 +16,7 @@ use std::time::{Instant, Duration}; use std::collections::{BTreeMap, HashSet}; +use std::sync::Arc; use util::*; use using_queue::{UsingQueue, GetAction}; diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index e4c3d7519..5e65a4de8 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -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; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index c4afc93d7..a5426faa8 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -18,6 +18,8 @@ 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; diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index 8f528b9d8..1235fd289 100644 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -17,6 +17,7 @@ //! Single account in the system. use std::fmt; +use std::sync::Arc; use std::collections::HashMap; use util::*; use pod_account::*; diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index 25c019dc0..1dd6204c3 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -23,6 +23,7 @@ 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; diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index de5a3f75b..e2f6fdaf0 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . 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}; diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 54256b285..639fce3ab 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . use std::str::FromStr; +use std::sync::Arc; use io::IoChannel; use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId}; use state::{self, State, CleanupMode}; diff --git a/ethcore/src/tests/evm.rs b/ethcore/src/tests/evm.rs index c97fd4ac0..50cf4deb7 100644 --- a/ethcore/src/tests/evm.rs +++ b/ethcore/src/tests/evm.rs @@ -1,5 +1,6 @@ //! Tests of EVM integration with transaction execution. +use std::sync::Arc; use evm::action_params::{ActionParams, ActionValue}; use evm::env_info::EnvInfo; use evm::{Factory, VMType}; diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 2c50f0fc2..2d48e470b 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . use std::collections::BTreeMap; +use std::sync::Arc; use ethkey::KeyPair; use io::*; use client::{BlockChainClient, Client, ClientConfig}; diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 192a0dc77..ce0cb4179 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -19,7 +19,7 @@ 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::*; diff --git a/json/src/spec/authority_round.rs b/json/src/spec/authority_round.rs index 0fdbfbfb3..91a5fd828 100644 --- a/json/src/spec/authority_round.rs +++ b/json/src/spec/authority_round.rs @@ -63,11 +63,10 @@ pub struct AuthorityRound { #[cfg(test)] mod tests { + use util::{H160, U256}; use uint::Uint; - use util::U256; - use util::H160; - use serde_json; use hash::Address; + use serde_json; use spec::validator_set::ValidatorSet; use spec::authority_round::AuthorityRound; diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index ecc453622..ef9b5724b 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -18,8 +18,7 @@ use std::collections::{BTreeMap, HashMap}; use std::collections::hash_map::Entry; -use util::{Address, H256, Bytes, U256}; -use util::standard::*; +use util::{Address, H256, Bytes, U256, RwLock, Mutex}; use ethcore::error::{Error, CallError}; use ethcore::client::{MiningBlockChainClient, Executed, CallAnalytics}; use ethcore::block::{ClosedBlock, IsBlock}; diff --git a/sync/src/tests/chain.rs b/sync/src/tests/chain.rs index 23ed4b7ea..f9ce17b5b 100644 --- a/sync/src/tests/chain.rs +++ b/sync/src/tests/chain.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::*; +use std::sync::Arc; use ethcore::client::{TestBlockChainClient, BlockChainClient, BlockId, EachBlockWith}; use chain::{SyncState}; use super::helpers::*; diff --git a/sync/src/tests/consensus.rs b/sync/src/tests/consensus.rs index 6b91b11c6..499b7de17 100644 --- a/sync/src/tests/consensus.rs +++ b/sync/src/tests/consensus.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::sync::Arc; use util::*; use io::{IoHandler, IoContext, IoChannel}; use ethcore::client::{BlockChainClient, Client}; diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index fa3039b63..3ac68b0fb 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . use std::collections::{VecDeque, HashSet, HashMap}; +use std::sync::Arc; use util::*; use network::*; use tests::snapshot::*; diff --git a/sync/src/tests/snapshot.rs b/sync/src/tests/snapshot.rs index 0a3b31fb0..9303aa9f7 100644 --- a/sync/src/tests/snapshot.rs +++ b/sync/src/tests/snapshot.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . use std::collections::HashMap; +use std::sync::Arc; use util::*; use ethcore::snapshot::{SnapshotService, ManifestData, RestorationStatus}; use ethcore::header::BlockNumber; diff --git a/util/network/src/tests.rs b/util/network/src/tests.rs index 52184061c..81325f57b 100644 --- a/util/network/src/tests.rs +++ b/util/network/src/tests.rs @@ -16,9 +16,10 @@ use super::*; use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}; +use std::sync::Arc; use std::thread; use std::time::*; -use util::common::*; +use util::{Bytes, Mutex}; use io::TimerToken; use ethkey::{Random, Generator}; diff --git a/util/src/common.rs b/util/src/common.rs index 89ce9d95f..4bf3a06ed 100644 --- a/util/src/common.rs +++ b/util/src/common.rs @@ -17,13 +17,6 @@ //! Utils common types and macros global reexport. use std::io; -pub use standard::*; -pub use error::*; -pub use bytes::*; -pub use vector::*; -pub use sha3::*; -pub use bigint::prelude::*; -pub use bigint::hash; #[macro_export] macro_rules! vec_into { @@ -89,8 +82,8 @@ macro_rules! map_into { #[macro_export] macro_rules! flush { - ($arg:expr) => ($crate::flush($arg.into())); - ($($arg:tt)*) => ($crate::flush(format!("{}", format_args!($($arg)*)))); + ($arg:expr) => ($crate::common::flush($arg.into())); + ($($arg:tt)*) => ($crate::common::flush(format!("{}", format_args!($($arg)*)))); } #[macro_export] diff --git a/util/src/error.rs b/util/src/error.rs index 4ed2fc9bd..b0e887434 100644 --- a/util/src/error.rs +++ b/util/src/error.rs @@ -19,7 +19,7 @@ use rustc_hex::FromHexError; use rlp::DecoderError; use std::fmt; -use hash::H256; +use bigint::hash::H256; #[derive(Debug)] /// Error in database subsystem. diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index e882f3f18..fc893654a 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -17,13 +17,14 @@ //! Disk-backed `HashDB` implementation. use std::collections::HashMap; -use common::*; +use std::sync::Arc; use rlp::*; use hashdb::*; use memorydb::*; use super::{DB_PREFIX_LEN, LATEST_ERA_KEY}; use super::traits::JournalDB; use kvdb::{KeyValueDB, DBTransaction}; +use {Bytes, H256, BaseDataError, UtilError}; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay /// and latent-removal semantics. @@ -197,11 +198,12 @@ mod tests { #![cfg_attr(feature="dev", allow(blacklisted_name))] #![cfg_attr(feature="dev", allow(similar_names))] - use common::*; + use std::path::Path; use hashdb::{HashDB, DBValue}; use super::*; use journaldb::traits::JournalDB; use kvdb::Database; + use {Hashable, H32}; #[test] fn insert_same_in_fork() { diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index de0e19d6e..5f409d327 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -18,13 +18,17 @@ use std::fmt; use std::collections::HashMap; -use common::*; +use std::sync::Arc; +use parking_lot::RwLock; +use heapsize::HeapSizeOf; +use itertools::Itertools; use rlp::*; use hashdb::*; use memorydb::*; use super::{DB_PREFIX_LEN, LATEST_ERA_KEY}; use super::traits::JournalDB; use kvdb::{KeyValueDB, DBTransaction}; +use {H256, BaseDataError, UtilError, Bytes}; #[derive(Clone, PartialEq, Eq)] struct RefInfo { @@ -551,12 +555,13 @@ mod tests { #![cfg_attr(feature="dev", allow(blacklisted_name))] #![cfg_attr(feature="dev", allow(similar_names))] - use common::*; + use std::path::Path; use hashdb::{HashDB, DBValue}; use super::*; use super::super::traits::JournalDB; use ethcore_logger::init_log; use kvdb::{DatabaseConfig}; + use {Hashable, H32}; #[test] fn insert_same_in_fork() { diff --git a/util/src/journaldb/mod.rs b/util/src/journaldb/mod.rs index 80ddbf7a1..4f0f2fb1b 100644 --- a/util/src/journaldb/mod.rs +++ b/util/src/journaldb/mod.rs @@ -17,7 +17,7 @@ //! `JournalDB` interface and implementation. use std::{fmt, str}; -use common::*; +use std::sync::Arc; /// Export the journaldb module. pub mod traits; diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index 73a63bd4b..e96430e06 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -17,13 +17,16 @@ //! `JournalDB` over in-memory overlay use std::collections::HashMap; -use common::*; +use std::sync::Arc; +use parking_lot::RwLock; +use heapsize::HeapSizeOf; use rlp::*; use hashdb::*; use memorydb::*; use super::{DB_PREFIX_LEN, LATEST_ERA_KEY}; use kvdb::{KeyValueDB, DBTransaction}; use super::JournalDB; +use {H256, BaseDataError, UtilError, Bytes, H256FastMap}; /// Implementation of the `JournalDB` trait for a disk-backed database with a memory overlay /// and, possibly, latent-removal semantics. @@ -451,12 +454,13 @@ mod tests { #![cfg_attr(feature="dev", allow(blacklisted_name))] #![cfg_attr(feature="dev", allow(similar_names))] - use common::*; + use std::path::Path; use super::*; use hashdb::{HashDB, DBValue}; use ethcore_logger::init_log; use journaldb::JournalDB; use kvdb::Database; + use {H32, Hashable}; fn new_db(path: &Path) -> OverlayRecentDB { let backing = Arc::new(Database::open_default(path.to_str().unwrap()).unwrap()); diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index 772281abd..e38994700 100644 --- a/util/src/journaldb/refcounteddb.rs +++ b/util/src/journaldb/refcounteddb.rs @@ -17,7 +17,8 @@ //! Disk-backed, ref-counted `JournalDB` implementation. use std::collections::HashMap; -use common::*; +use std::sync::Arc; +use heapsize::HeapSizeOf; use rlp::*; use hashdb::*; use overlaydb::OverlayDB; @@ -25,6 +26,7 @@ use memorydb::MemoryDB; use super::{DB_PREFIX_LEN, LATEST_ERA_KEY}; use super::traits::JournalDB; use kvdb::{KeyValueDB, DBTransaction}; +use {UtilError, H256, Bytes}; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay /// and latent-removal semantics. @@ -211,10 +213,10 @@ mod tests { #![cfg_attr(feature="dev", allow(blacklisted_name))] #![cfg_attr(feature="dev", allow(similar_names))] - use common::*; use hashdb::{HashDB, DBValue}; use super::*; use super::super::traits::JournalDB; + use {Hashable}; #[test] fn long_history() { diff --git a/util/src/journaldb/traits.rs b/util/src/journaldb/traits.rs index 8a89f1368..1f14e9765 100644 --- a/util/src/journaldb/traits.rs +++ b/util/src/journaldb/traits.rs @@ -16,9 +16,10 @@ //! Disk-backed `HashDB` implementation. -use common::*; +use std::sync::Arc; use hashdb::*; use kvdb::{self, DBTransaction}; +use {Bytes, H256, UtilError}; /// A `HashDB` which can manage a short-term journal potentially containing many forks of mutually /// exclusive actions. diff --git a/util/src/kvdb.rs b/util/src/kvdb.rs index 6692064ed..c231e682d 100644 --- a/util/src/kvdb.rs +++ b/util/src/kvdb.rs @@ -20,14 +20,17 @@ use std::{mem, fs}; use std::collections::{HashMap, BTreeMap}; use std::io::ErrorKind; use std::marker::PhantomData; -use std::path::PathBuf; +use std::path::{PathBuf, Path}; +use parking_lot::{Mutex, MutexGuard, RwLock}; -use common::*; use elastic_array::*; use hashdb::DBValue; use rlp::{UntrustedRlp, RlpType, Compressible}; use rocksdb::{DB, Writable, WriteBatch, WriteOptions, IteratorMode, DBIterator, Options, DBCompactionStyle, BlockBasedOptions, Direction, Cache, Column, ReadOptions}; +use {UtilError, Bytes}; + + #[cfg(target_os = "linux")] use regex::Regex; #[cfg(target_os = "linux")] diff --git a/util/src/lib.rs b/util/src/lib.rs index c2d9c59d3..544f60d39 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -112,7 +112,6 @@ extern crate ethcore_logger; #[macro_use] extern crate log as rlog; -pub mod standard; #[macro_use] pub mod common; pub mod error; @@ -135,7 +134,6 @@ pub mod snappy; pub mod cache; mod timer; -pub use common::*; pub use misc::*; pub use hashdb::*; pub use memorydb::MemoryDB; @@ -146,7 +144,17 @@ pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrie pub use semantic_version::*; pub use kvdb::*; pub use timer::*; +pub use error::*; +pub use bytes::*; +pub use vector::*; +pub use sha3::*; +pub use bigint::prelude::*; +pub use bigint::hash; + pub use ansi_term::{Colour, Style}; +pub use heapsize::HeapSizeOf; +pub use itertools::Itertools; +pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; /// 160-bit integer representing account address pub type Address = H160; diff --git a/util/src/migration/tests.rs b/util/src/migration/tests.rs index 7cd19009a..64f2d976a 100644 --- a/util/src/migration/tests.rs +++ b/util/src/migration/tests.rs @@ -19,12 +19,11 @@ //! are performed in temp sub-directories. use std::collections::BTreeMap; -use common::*; +use std::sync::Arc; +use std::path::{Path, PathBuf}; use migration::{Batch, Config, Error, SimpleMigration, Migration, Manager}; use kvdb::Database; - use devtools::RandomTempPath; -use std::path::PathBuf; fn db_path(path: &Path) -> PathBuf { let mut p = path.to_owned(); diff --git a/util/src/misc.rs b/util/src/misc.rs index 120805f0c..e33b5e857 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -16,9 +16,9 @@ //! Diff misc. -use common::*; use rlp::RlpStream; use target_info::Target; +use Bytes; include!(concat!(env!("OUT_DIR"), "/version.rs")); include!(concat!(env!("OUT_DIR"), "/rustc_version.rs")); diff --git a/util/src/standard.rs b/util/src/standard.rs deleted file mode 100644 index cc67b0de5..000000000 --- a/util/src/standard.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2015-2017 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . - -//! Std lib global reexports. - -pub use std::path::Path; -pub use std::hash::{Hash, Hasher}; - -pub use std::sync::Arc; - -pub use heapsize::HeapSizeOf; -pub use itertools::Itertools; - -pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; diff --git a/util/src/trie/triedb.rs b/util/src/trie/triedb.rs index a8600914c..262a874ea 100644 --- a/util/src/trie/triedb.rs +++ b/util/src/trie/triedb.rs @@ -15,13 +15,14 @@ // along with Parity. If not, see . use std::fmt; -use common::*; +use itertools::Itertools; use hashdb::*; use nibbleslice::*; use rlp::*; use super::node::{Node, OwnedNode}; use super::lookup::Lookup; use super::{Trie, TrieItem, TrieError, TrieIterator, Query}; +use {ToPretty, Bytes, H256}; /// A `Trie` implementation using a generic `HashDB` backing database. /// From 2b02651bbfef634c157d06534d3de80d3c93c9c4 Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 29 Jul 2017 22:53:52 +0200 Subject: [PATCH 06/20] alway test --all (temporary exclude ipfs and evmjit) --- scripts/cov.sh | 3 +-- scripts/doc.sh | 4 +--- scripts/hook.sh | 4 +--- scripts/targets.sh | 22 ---------------------- test.sh | 3 +-- 5 files changed, 4 insertions(+), 32 deletions(-) delete mode 100755 scripts/targets.sh diff --git a/scripts/cov.sh b/scripts/cov.sh index eae6a4f72..8d618e2c3 100755 --- a/scripts/cov.sh +++ b/scripts/cov.sh @@ -20,8 +20,7 @@ if ! type $KCOV > /dev/null; then exit 1 fi -. ./scripts/targets.sh -RUSTFLAGS="-C link-dead-code" cargo test $TARGETS --no-run || exit $? +RUSTFLAGS="-C link-dead-code" cargo test --all --exclude ipfs --exclude evmjit --no-run || exit $? KCOV_TARGET="target/cov" diff --git a/scripts/doc.sh b/scripts/doc.sh index 657f47567..8174ed5d6 100755 --- a/scripts/doc.sh +++ b/scripts/doc.sh @@ -1,7 +1,5 @@ #!/bin/sh # generate documentation only for partiy and ethcore libraries -. ./scripts/targets.sh - -cargo doc --no-deps --verbose $TARGETS && +cargo doc --no-deps --verbose --all --exclude ipfs --exclude evmjit && echo '' > target/doc/index.html diff --git a/scripts/hook.sh b/scripts/hook.sh index 9b5512ac0..c8977aacf 100755 --- a/scripts/hook.sh +++ b/scripts/hook.sh @@ -1,6 +1,5 @@ #!/bin/sh FILE=./.git/hooks/pre-push -. ./scripts/targets.sh echo "#!/bin/sh\n" > $FILE # Exit on any error @@ -8,7 +7,6 @@ echo "set -e" >> $FILE # Run release build echo "cargo build --features dev" >> $FILE # Build tests -echo "cargo test --no-run --features dev \\" >> $FILE -echo $TARGETS >> $FILE +echo "cargo test --no-run --features dev --all --exclude ipfs --exclude evmjit" >> $FILE echo "" >> $FILE chmod +x $FILE diff --git a/scripts/targets.sh b/scripts/targets.sh deleted file mode 100755 index fb10c43f2..000000000 --- a/scripts/targets.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -export TARGETS=" - -p rlp\ - -p ethash \ - -p ethcore \ - -p ethcore-bigint\ - -p parity-dapps \ - -p parity-rpc \ - -p parity-rpc-client \ - -p rpc-cli \ - -p ethcore-util \ - -p ethcore-network \ - -p ethcore-io \ - -p ethkey \ - -p ethstore \ - -p ethsync \ - -p ethcore-ipc \ - -p ethcore-ipc-tests \ - -p ethcore-ipc-nano \ - -p ethcore-light \ - -p parity" diff --git a/test.sh b/test.sh index 2d0cc2e5f..6eb447970 100755 --- a/test.sh +++ b/test.sh @@ -22,5 +22,4 @@ case $1 in ;; esac -. ./scripts/targets.sh -cargo test -j 8 $OPTIONS --features "$FEATURES" $TARGETS $1 \ +cargo test -j 8 $OPTIONS --features "$FEATURES" --all --exclude ipfs --exclude evmjit $1 \ From 48f28fe29c180a8fe634bd0695650f0b9dc90fe9 Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 29 Jul 2017 23:19:33 +0200 Subject: [PATCH 07/20] fixed json_tests --- ethcore/src/json_tests/chain.rs | 2 +- ethcore/src/json_tests/executive.rs | 1 + ethcore/src/json_tests/test_common.rs | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ethcore/src/json_tests/chain.rs b/ethcore/src/json_tests/chain.rs index ccdd7d499..7047c9882 100644 --- a/ethcore/src/json_tests/chain.rs +++ b/ethcore/src/json_tests/chain.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use super::test_common::*; +use std::sync::Arc; use client::{BlockChainClient, Client, ClientConfig}; use block::Block; use ethereum; diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index 0c5a6a90d..495ff3cdb 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::sync::Arc; use super::test_common::*; use evm::action_params::ActionParams; use state::{Backend as StateBackend, State, Substate}; diff --git a/ethcore/src/json_tests/test_common.rs b/ethcore/src/json_tests/test_common.rs index f9716d221..fa1078776 100644 --- a/ethcore/src/json_tests/test_common.rs +++ b/ethcore/src/json_tests/test_common.rs @@ -15,6 +15,8 @@ // along with Parity. If not, see . 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; From fe6bdc870c150a708253a2338d29e8605c1514be Mon Sep 17 00:00:00 2001 From: fro Date: Mon, 31 Jul 2017 16:54:26 +0300 Subject: [PATCH 08/20] realloc test contract submodule update --- ethcore/res/wasm-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/res/wasm-tests b/ethcore/res/wasm-tests index 9ed630431..04c9d84c5 160000 --- a/ethcore/res/wasm-tests +++ b/ethcore/res/wasm-tests @@ -1 +1 @@ -Subproject commit 9ed6304313fa949ed92aa0570fb2bc759fb6dc58 +Subproject commit 04c9d84c5fe5c3ad707be58664c7e72b97cc9996 From 2ca4adb62cf605830f35ee89c0b42205bd98a3b5 Mon Sep 17 00:00:00 2001 From: maciejhirsz Date: Mon, 31 Jul 2017 17:51:23 +0200 Subject: [PATCH 09/20] Re-enable wallets, fixed forgetting accounts --- js/src/api/local/accounts/account.js | 4 ++++ js/src/api/local/accounts/accounts.js | 6 ++++++ js/src/api/local/localAccountsMiddleware.js | 4 ++++ js/src/views/Accounts/accounts.js | 4 ---- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/js/src/api/local/accounts/account.js b/js/src/api/local/accounts/account.js index 0bb069c8b..224a05cd9 100644 --- a/js/src/api/local/accounts/account.js +++ b/js/src/api/local/accounts/account.js @@ -31,6 +31,10 @@ export default class Account { } isValidPassword (password) { + if (!this._keyObject) { + return false; + } + return decryptPrivateKey(this._keyObject, password) .then((privateKey) => { if (!privateKey) { diff --git a/js/src/api/local/accounts/accounts.js b/js/src/api/local/accounts/accounts.js index 823ab3624..d11ea2bad 100644 --- a/js/src/api/local/accounts/accounts.js +++ b/js/src/api/local/accounts/accounts.js @@ -168,6 +168,12 @@ export default class Accounts { return false; } + if (!account.uuid) { + this.removeUnsafe(address); + + return true; + } + return account .isValidPassword(password) .then((isValid) => { diff --git a/js/src/api/local/localAccountsMiddleware.js b/js/src/api/local/localAccountsMiddleware.js index c8e767f89..c452f541a 100644 --- a/js/src/api/local/localAccountsMiddleware.js +++ b/js/src/api/local/localAccountsMiddleware.js @@ -206,6 +206,10 @@ export default class LocalAccountsMiddleware extends Middleware { return accounts.remove(address, password); }); + register('parity_removeAddress', ([address]) => { + return accounts.remove(address, null); + }); + register('parity_testPassword', ([address, password]) => { const account = accounts.get(address); diff --git a/js/src/views/Accounts/accounts.js b/js/src/views/Accounts/accounts.js index 2d37b7a4b..c8828cff6 100644 --- a/js/src/views/Accounts/accounts.js +++ b/js/src/views/Accounts/accounts.js @@ -373,10 +373,6 @@ class Accounts extends Component { } renderNewWalletButton () { - if (this.props.availability !== 'personal') { - return null; - } - return (