From e551122ab9a485e3a1baf3002023df5a8c600126 Mon Sep 17 00:00:00 2001 From: joshua-mir Date: Tue, 13 Aug 2019 13:37:43 +0200 Subject: [PATCH 01/10] Disable unsyncable expanse chain (#10926) * Only remove expanse from cli * remove whitespace * remove whitespace (restart CI) * (restart CI) --- parity/cli/mod.rs | 2 +- parity/params.rs | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 2b86f709087..96e68056d34 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -300,7 +300,7 @@ usage! { ARG arg_chain: (String) = "foundation", or |c: &Config| c.parity.as_ref()?.chain.clone(), "--chain=[CHAIN]", - "Specify the blockchain type. CHAIN may be either a JSON chain specification file or ethereum, classic, poacore, volta, ewc, expanse, musicoin, ellaism, mix, callisto, morden, ropsten, kovan, rinkeby, goerli, kotti, poasokol, testnet, or dev.", + "Specify the blockchain type. CHAIN may be either a JSON chain specification file or ethereum, classic, poacore, volta, ewc, musicoin, ellaism, mix, callisto, morden, ropsten, kovan, rinkeby, goerli, kotti, poasokol, testnet, or dev.", ARG arg_keys_path: (String) = "$BASE/keys", or |c: &Config| c.parity.as_ref()?.keys_path.clone(), "--keys-path=[PATH]", diff --git a/parity/params.rs b/parity/params.rs index f7fd9a37cbe..65b8d77ee7a 100644 --- a/parity/params.rs +++ b/parity/params.rs @@ -36,7 +36,6 @@ pub enum SpecType { Poanet, Volta, Ewc, - Expanse, Musicoin, Ellaism, Mix, @@ -68,7 +67,6 @@ impl str::FromStr for SpecType { "poanet" | "poacore" => SpecType::Poanet, "volta" => SpecType::Volta, "ewc" | "energyweb" => SpecType::Ewc, - "expanse" => SpecType::Expanse, "musicoin" => SpecType::Musicoin, "ellaism" => SpecType::Ellaism, "mix" => SpecType::Mix, @@ -95,7 +93,6 @@ impl fmt::Display for SpecType { SpecType::Poanet => "poanet", SpecType::Volta => "volta", SpecType::Ewc => "energyweb", - SpecType::Expanse => "expanse", SpecType::Musicoin => "musicoin", SpecType::Ellaism => "ellaism", SpecType::Mix => "mix", @@ -122,7 +119,6 @@ impl SpecType { SpecType::Poanet => Ok(spec::new_poanet(params)), SpecType::Volta => Ok(spec::new_volta(params)), SpecType::Ewc => Ok(spec::new_ewc(params)), - SpecType::Expanse => Ok(spec::new_expanse(params)), SpecType::Musicoin => Ok(spec::new_musicoin(params)), SpecType::Ellaism => Ok(spec::new_ellaism(params)), SpecType::Mix => Ok(spec::new_mix(params)), @@ -145,7 +141,6 @@ impl SpecType { pub fn legacy_fork_name(&self) -> Option { match *self { SpecType::Classic => Some("classic".to_owned()), - SpecType::Expanse => Some("expanse".to_owned()), SpecType::Musicoin => Some("musicoin".to_owned()), _ => None, } @@ -379,7 +374,6 @@ mod tests { assert_eq!(SpecType::Volta, "volta".parse().unwrap()); assert_eq!(SpecType::Ewc, "ewc".parse().unwrap()); assert_eq!(SpecType::Ewc, "energyweb".parse().unwrap()); - assert_eq!(SpecType::Expanse, "expanse".parse().unwrap()); assert_eq!(SpecType::Musicoin, "musicoin".parse().unwrap()); assert_eq!(SpecType::Ellaism, "ellaism".parse().unwrap()); assert_eq!(SpecType::Mix, "mix".parse().unwrap()); @@ -409,7 +403,6 @@ mod tests { assert_eq!(format!("{}", SpecType::Poanet), "poanet"); assert_eq!(format!("{}", SpecType::Volta), "volta"); assert_eq!(format!("{}", SpecType::Ewc), "energyweb"); - assert_eq!(format!("{}", SpecType::Expanse), "expanse"); assert_eq!(format!("{}", SpecType::Musicoin), "musicoin"); assert_eq!(format!("{}", SpecType::Ellaism), "ellaism"); assert_eq!(format!("{}", SpecType::Mix), "mix"); From bd2e4f9c131f544a8fde62df2370bd93bc3d2944 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 13 Aug 2019 14:20:59 +0100 Subject: [PATCH 02/10] tx-pool: accept local tx with higher gas price when pool full (#10901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tx-pool: accept local tx with higher gas price when pool full * Revert "tx-pool: accept local tx with higher gas price when pool full" This reverts commit 9d4adc5a * tx-pool: new tx with same nonce as existing is ready * tx-pool: explicit check for replacement tx (same sender & nonce) * Update comment Co-Authored-By: Tomasz Drwięga * Replace `ReplaceOld` with `InsertNew` for replacement txs --- miner/src/pool/replace.rs | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/miner/src/pool/replace.rs b/miner/src/pool/replace.rs index b1112dcae1f..0655af59990 100644 --- a/miner/src/pool/replace.rs +++ b/miner/src/pool/replace.rs @@ -71,6 +71,20 @@ where let old_score = (old.priority(), old.gas_price()); let new_score = (new.priority(), new.gas_price()); if new_score > old_score { + // Check if this is a replacement transaction. + // + // With replacement transactions we can safely return `InsertNew` here, because + // we don't need to remove `old` (worst transaction in the pool) since `new` will replace + // some other transaction in the pool so we will never go above limit anyway. + if let Some(txs) = new.pooled_by_sender { + if let Ok(index) = txs.binary_search_by(|old| self.scoring.compare(old, new)) { + return match self.scoring.choose(&txs[index], new) { + Choice::ReplaceOld => Choice::InsertNew, + choice => choice, + } + } + } + let state = &self.client; // calculate readiness based on state nonce + pooled txs from same sender let is_ready = |replace: &ReplaceTransaction| { @@ -412,4 +426,88 @@ mod tests { assert_eq!(replace.should_replace(&old, &new), ReplaceOld); } + + #[test] + fn should_accept_local_tx_with_same_sender_and_nonce_with_better_gas_price() { + let scoring = NonceAndGasPrice(PrioritizationStrategy::GasPriceOnly); + let client = TestClient::new().with_nonce(1); + let replace = ReplaceByScoreAndReadiness::new(scoring, client); + + // current transaction is ready + let old_tx = { + let tx = Tx { + nonce: 1, + gas_price: 1, + ..Default::default() + }; + tx.signed().verified() + }; + + let new_sender = Random.generate().unwrap(); + let tx_new_ready_1 = local_tx_verified(Tx { + nonce: 1, + gas_price: 1, + ..Default::default() + }, &new_sender); + + let tx_new_ready_2 = local_tx_verified(Tx { + nonce: 1, + gas_price: 2, // same nonce, higher gas price + ..Default::default() + }, &new_sender); + + let old_tx = txpool::Transaction { insertion_id: 0, transaction: Arc::new(old_tx) }; + + let new_tx = txpool::Transaction { insertion_id: 0, transaction: Arc::new(tx_new_ready_2) }; + let pooled_txs = [ + txpool::Transaction { insertion_id: 0, transaction: Arc::new(tx_new_ready_1) }, + ]; + + let old = ReplaceTransaction::new(&old_tx, None); + let new = ReplaceTransaction::new(&new_tx, Some(&pooled_txs)); + + assert_eq!(replace.should_replace(&old, &new), InsertNew); + } + + #[test] + fn should_reject_local_tx_with_same_sender_and_nonce_with_worse_gas_price() { + let scoring = NonceAndGasPrice(PrioritizationStrategy::GasPriceOnly); + let client = TestClient::new().with_nonce(1); + let replace = ReplaceByScoreAndReadiness::new(scoring, client); + + // current transaction is ready + let old_tx = { + let tx = Tx { + nonce: 1, + gas_price: 1, + ..Default::default() + }; + tx.signed().verified() + }; + + let new_sender = Random.generate().unwrap(); + let tx_new_ready_1 = local_tx_verified(Tx { + nonce: 1, + gas_price: 2, + ..Default::default() + }, &new_sender); + + let tx_new_ready_2 = local_tx_verified(Tx { + nonce: 1, + gas_price: 1, // same nonce, lower gas price + ..Default::default() + }, &new_sender); + + let old_tx = txpool::Transaction { insertion_id: 0, transaction: Arc::new(old_tx) }; + + let new_tx = txpool::Transaction { insertion_id: 0, transaction: Arc::new(tx_new_ready_2) }; + let pooled_txs = [ + txpool::Transaction { insertion_id: 0, transaction: Arc::new(tx_new_ready_1) }, + ]; + + let old = ReplaceTransaction::new(&old_tx, None); + let new = ReplaceTransaction::new(&new_tx, Some(&pooled_txs)); + + assert_eq!(replace.should_replace(&old, &new), RejectNew); + } } From a23f5b8fd9c68ddd238986e580e5d310ed775a4b Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Tue, 13 Aug 2019 15:27:28 +0200 Subject: [PATCH 03/10] Fix ethcore/benches build. (#10964) --- ethcore/benches/builtin.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ethcore/benches/builtin.rs b/ethcore/benches/builtin.rs index 93158cb21a6..973332932f7 100644 --- a/ethcore/benches/builtin.rs +++ b/ethcore/benches/builtin.rs @@ -20,17 +20,19 @@ extern crate criterion; #[macro_use] extern crate lazy_static; +extern crate machine; extern crate ethcore; +extern crate ethcore_builtin; extern crate ethereum_types; extern crate parity_bytes as bytes; extern crate rustc_hex; use criterion::{Criterion, Bencher}; use bytes::BytesRef; -use ethcore::builtin::Builtin; -use ethcore::machine::Machine; +use ethcore_builtin::Builtin; use ethereum_types::H160; -use ethcore::ethereum::new_byzantium_test_machine; +use machine::Machine; +use machine::test_helpers::new_byzantium_test_machine; use rustc_hex::FromHex; lazy_static! { From e50eafe6e161301188c51d2d305b8e44e580c134 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 15 Aug 2019 15:36:07 +0200 Subject: [PATCH 04/10] [blooms-db] Fix benchmarks (#10974) * [blooms-db] Fix benchmarks * Use Bloom::zero() --- util/blooms-db/benches/blooms.rs | 16 ++++++++-------- util/blooms-db/src/db.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/util/blooms-db/benches/blooms.rs b/util/blooms-db/benches/blooms.rs index 1cb3bad543e..4a0c54fbdbc 100644 --- a/util/blooms-db/benches/blooms.rs +++ b/util/blooms-db/benches/blooms.rs @@ -31,8 +31,8 @@ use ethbloom::Bloom; fn blooms_filter_1_million_ok(b: &mut Bencher) { let tempdir = TempDir::new("").unwrap(); let database = Database::open(tempdir.path()).unwrap(); - database.insert_blooms(999_999, iter::once(&Bloom::from(0))).unwrap(); - let bloom = Bloom::from(0x001); + database.insert_blooms(999_999, iter::once(&Bloom::zero())).unwrap(); + let bloom = Bloom::from_low_u64_be(0x001); database.insert_blooms(200_000, iter::once(&bloom)).unwrap(); database.insert_blooms(400_000, iter::once(&bloom)).unwrap(); database.insert_blooms(600_000, iter::once(&bloom)).unwrap(); @@ -48,9 +48,9 @@ fn blooms_filter_1_million_ok(b: &mut Bencher) { fn blooms_filter_1_million_miss(b: &mut Bencher) { let tempdir = TempDir::new("").unwrap(); let database = Database::open(tempdir.path()).unwrap(); - database.insert_blooms(999_999, iter::once(&Bloom::from(0))).unwrap(); - let bloom = Bloom::from(0x001); - let bad_bloom = Bloom::from(0x0001); + database.insert_blooms(999_999, iter::once(&Bloom::zero())).unwrap(); + let bloom = Bloom::from_low_u64_be(0x001); + let bad_bloom = Bloom::from_low_u64_be(0x0001); database.insert_blooms(200_000, iter::once(&bloom)).unwrap(); database.insert_blooms(400_000, iter::once(&bloom)).unwrap(); database.insert_blooms(600_000, iter::once(&bloom)).unwrap(); @@ -66,9 +66,9 @@ fn blooms_filter_1_million_miss(b: &mut Bencher) { fn blooms_filter_1_million_miss_and_ok(b: &mut Bencher) { let tempdir = TempDir::new("").unwrap(); let database = Database::open(tempdir.path()).unwrap(); - database.insert_blooms(999_999, iter::once(&Bloom::from(0))).unwrap(); - let bloom = Bloom::from(0x001); - let bad_bloom = Bloom::from(0x0001); + database.insert_blooms(999_999, iter::once(&Bloom::zero())).unwrap(); + let bloom = Bloom::from_low_u64_be(0x001); + let bad_bloom = Bloom::from_low_u64_be(0x0001); database.insert_blooms(200_000, iter::once(&bloom)).unwrap(); database.insert_blooms(400_000, iter::once(&bloom)).unwrap(); database.insert_blooms(600_000, iter::once(&bloom)).unwrap(); diff --git a/util/blooms-db/src/db.rs b/util/blooms-db/src/db.rs index f3cf837cd50..b91d4823724 100644 --- a/util/blooms-db/src/db.rs +++ b/util/blooms-db/src/db.rs @@ -19,7 +19,7 @@ use std::path::{Path, PathBuf}; use ethbloom; use crate::file::{File, FileIterator}; -fn other_io_err(e: E) -> io::Error where E: Into> { +fn other_io_err(e: E) -> io::Error where E: Into> { io::Error::new(io::ErrorKind::Other, e) } From 5807402a0b29d1462fad8ae9b69cbb287f5db8f8 Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 15 Aug 2019 15:36:48 +0200 Subject: [PATCH 05/10] Update to latest trie version. (#10972) * Switch to 'trie' crates, there is an unpublished deps to staging parity-common triehash still. * Use crates.io dependency. * indentation * Update util/journaldb/src/traits.rs indentation Co-Authored-By: cheme * Rem import braces * switch deps to simple-codec branch (code broken) * painfull update of trie and memdb, plus rework codec to be compatible with simple_codec changes * Removed useless implementation from trait. * Remove some malloc size until update and patch triehash, seems ok otherwhise. * Update parity-util-mem. * Switch to published triehash 0.8. * Avoid redundancy in encode_partial functions. Use better namings. * Update util/patricia-trie-ethereum/src/rlp_node_codec.rs Co-Authored-By: Andronik Ordian * Update util/patricia-trie-ethereum/src/rlp_node_codec.rs Co-Authored-By: Andronik Ordian * Restore previous child rlp header length check. Better comments and formatting. * Update util/patricia-trie-ethereum/src/rlp_node_codec.rs Co-Authored-By: David * Update util/patricia-trie-ethereum/src/rlp_node_codec.rs Co-Authored-By: David --- Cargo.lock | 132 ++++++++---------- Cargo.toml | 2 +- ethcore/Cargo.toml | 8 +- ethcore/account-db/Cargo.toml | 2 +- ethcore/account-state/Cargo.toml | 8 +- ethcore/blockchain/Cargo.toml | 2 +- ethcore/db/Cargo.toml | 2 +- ethcore/evm/Cargo.toml | 2 +- ethcore/light/Cargo.toml | 8 +- ethcore/pod/Cargo.toml | 4 +- ethcore/pod/src/account.rs | 4 +- ethcore/private-tx/Cargo.toml | 4 +- ethcore/src/client/client.rs | 4 +- ethcore/src/client/evm_test_client.rs | 2 +- ethcore/src/executive_state.rs | 3 +- ethcore/src/json_tests/trie.rs | 3 +- ethcore/state-db/Cargo.toml | 2 +- ethcore/sync/Cargo.toml | 4 +- ethcore/trace/Cargo.toml | 2 +- ethcore/trie-vm-factories/Cargo.toml | 2 +- ethcore/trie-vm-factories/src/lib.rs | 5 +- ethcore/types/Cargo.toml | 2 +- miner/Cargo.toml | 2 +- util/journaldb/Cargo.toml | 6 +- util/journaldb/src/earlymergedb.rs | 2 +- util/keccak-hasher/Cargo.toml | 2 +- util/memory-cache/Cargo.toml | 2 +- util/patricia-trie-ethereum/Cargo.toml | 6 +- util/patricia-trie-ethereum/src/lib.rs | 26 +++- .../src/rlp_node_codec.rs | 132 ++++++++++++++---- util/triehash-ethereum/Cargo.toml | 2 +- 31 files changed, 229 insertions(+), 158 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e4981535a0..0b8f8cfc310 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,7 @@ name = "account-db" version = "0.1.0" dependencies = [ "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -20,16 +20,16 @@ dependencies = [ "common-types 0.1.0", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "pod 0.1.0", @@ -37,7 +37,7 @@ dependencies = [ "rlp_compress 0.1.0", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "trace 0.1.0", - "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-vm-factories 0.1.0", ] @@ -403,14 +403,6 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "clear_on_drop" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cli-signer" version = "1.4.0" @@ -471,7 +463,7 @@ dependencies = [ "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", @@ -889,7 +881,7 @@ dependencies = [ "evm 0.1.0", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -908,7 +900,7 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "pod 0.1.0", @@ -928,8 +920,8 @@ dependencies = [ "time-utils 0.1.0", "trace 0.1.0", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-standardmap 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-standardmap 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-vm-factories 0.1.0", "triehash-ethereum 0.2.0", "unexpected 0.1.0", @@ -969,7 +961,7 @@ dependencies = [ "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1020,7 +1012,7 @@ dependencies = [ "common-types 0.1.0", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", @@ -1062,7 +1054,7 @@ dependencies = [ "failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1072,9 +1064,9 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "machine 0.1.0", "memory-cache 0.1.0", - "memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1085,7 +1077,7 @@ dependencies = [ "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "stats 0.1.0", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "triehash-ethereum 0.2.0", "vm 0.1.0", ] @@ -1127,7 +1119,7 @@ dependencies = [ "linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "price-info 1.12.0", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1221,7 +1213,7 @@ dependencies = [ "machine 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1236,7 +1228,7 @@ dependencies = [ "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "trace 0.1.0", "transaction-pool 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "vm 0.1.0", ] @@ -1335,7 +1327,7 @@ dependencies = [ "ethstore 0.2.1", "fastmap 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1345,7 +1337,7 @@ dependencies = [ "macros 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1468,7 +1460,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "memory-cache 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "vm 0.1.0", @@ -1728,12 +1720,12 @@ dependencies = [ [[package]] name = "hash-db" -version = "0.12.4" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hash256-std-hasher" -version = "0.12.4" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2008,15 +2000,15 @@ dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2137,18 +2129,18 @@ name = "keccak-hasher" version = "0.1.1" dependencies = [ "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "keccak-hasher" -version = "0.12.4" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", - "hash256-std-hasher 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hash256-std-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2375,17 +2367,17 @@ name = "memory-cache" version = "0.1.0" dependencies = [ "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "memory-db" -version = "0.12.4" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2774,7 +2766,7 @@ dependencies = [ "parity-rpc 1.12.0", "parity-runtime 0.1.0", "parity-updater 1.12.0", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-version 2.7.0", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3031,11 +3023,10 @@ dependencies = [ [[package]] name = "parity-util-mem" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3128,14 +3119,14 @@ version = "0.1.0" dependencies = [ "elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", - "memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3231,7 +3222,7 @@ dependencies = [ "common-types 0.1.0", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", @@ -3243,7 +3234,7 @@ dependencies = [ "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "triehash-ethereum 0.2.0", ] @@ -3956,7 +3947,7 @@ dependencies = [ "ethcore-bloom-journal 0.1.0", "ethcore-db 0.1.0", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", @@ -4409,7 +4400,7 @@ dependencies = [ "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", @@ -4441,11 +4432,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "trie-db" -version = "0.12.4" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4453,11 +4444,11 @@ dependencies = [ [[package]] name = "trie-standardmap" -version = "0.12.4" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hasher 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4468,17 +4459,17 @@ dependencies = [ "evm 0.1.0", "keccak-hasher 0.1.1", "patricia-trie-ethereum 0.1.0", - "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "vm 0.1.0", "wasm 0.1.0", ] [[package]] name = "triehash" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4488,7 +4479,7 @@ version = "0.2.0" dependencies = [ "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", - "triehash 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4886,7 +4877,6 @@ dependencies = [ "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0e37fba0087d9f3f4e269827a55dc511abf3e440cc097a0c154ff4e6584f988" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" -"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a" "checksum combine 3.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fc1d011beeed29187b8db2ac3925c8dd4d3e87db463dc9d2d2833985388fc5bc" @@ -4949,8 +4939,8 @@ dependencies = [ "checksum h2 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "a27e7ed946e8335bdf9a191bc1b9b14a03ba822d013d2f58437f4fabcbd7fc2c" "checksum hamming 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65043da274378d68241eb9a8f8f8aa54e349136f7b8e12f63e3ef44043cc30e1" "checksum handlebars 0.32.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d89ec99d1594f285d4590fc32bac5f75cdab383f1123d504d27862c644a807dd" -"checksum hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3c95a428c86ed4633d83e07ef9e0a147a906da01e931f07e74a85bedce5a43" -"checksum hash256-std-hasher 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "663ce20dae36902c16d12c6aaae400ca40d922407a8cf2b4caf8cae9b39b4f03" +"checksum hash-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32c87fec93c4a2d264483ef843ac1930ae7c7999d97d73721305a5188b4c23a4" +"checksum hash256-std-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16293646125e09e5bc216d9f73fa81ab31c4f97007d56c036bbf15a58e970540" "checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" @@ -4990,7 +4980,7 @@ dependencies = [ "checksum jsonrpc-tcp-server 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ede8a327b567123038ca3dac22311923dc03602487de19c70b45d82760d31205" "checksum jsonrpc-ws-server 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "977ea40f077c027553e4112d750114b9e5cc7bcf5642512838abc2a9b322bd23" "checksum keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69e8ee697b9aa6dcc34d7657565fa5052763a1627a5b59e4c3c0ae3ed0d70a65" -"checksum keccak-hasher 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6c936c737d79690593c34275faf583151a0e8c0abf34eaecad10399eed0beb7d" +"checksum keccak-hasher 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bf18164fd7ce989041f8fc4a1ae72a8bd1bec3575f2aeaf1d4968fc053aabef" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72ae89206cea31c32014b39d5a454b96135894221610dbfd19cf4d2d044fa546" "checksum kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45bcdf5eb083602cff61a6f8438dce2a7900d714e893fc48781c39fb119d37aa" @@ -5012,7 +5002,7 @@ dependencies = [ "checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b" "checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" "checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" -"checksum memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1eeeeab44c01c7da4409e68ec5b5db74c92305386efab3615e495b1dacaec196" +"checksum memory-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a688133a81c915553c1dd9c3e859949f43a854cb8f8773e690e849b53b1f89f0" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" "checksum memzero 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "93c0d11ac30a033511ae414355d80f70d9f29a44a49140face477117a1ee90db" "checksum mime 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0a907b83e7b9e987032439a387e187119cddafc92d5c2aaeb1d92580a793f630" @@ -5051,7 +5041,7 @@ dependencies = [ "checksum parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2c5f9d149b13134b8b354d93a92830efcbee6fe5b73a2e6e540fe70d4dd8a63" "checksum parity-snappy-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1a413d51e5e1927320c9de992998e4a279dffb8c8a7363570198bd8383e66f1b" "checksum parity-tokio-ipc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb002c2d3539ccd3b82bd915ec060028d4ab350ad203dbffa20028c1e483af5b" -"checksum parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89e80f22052161e0cb55cb5a8a75890420c525031f95c9d262dbb0434aa85dc1" +"checksum parity-util-mem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2005637ccf93dbb60c85081ccaaf3f945f573da48dcc79f27f9646caa3ec1dc" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" "checksum parity-wordlist 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "573d08f0d3bc8a6ffcdac1de2725b5daeed8db26345a9c12d91648e2d6457f3e" "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" @@ -5194,9 +5184,9 @@ dependencies = [ "checksum trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe82f2f0bf1991e163e757baf044282823155dd326e70f44ce2186c3c320cc9" "checksum transaction-pool 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8d8bd3123931aa6e49dd03bc8a2400490e14701d779458d1f1fff1f04c6f666" "checksum transient-hashmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aeb4b191d033a35edfce392a38cdcf9790b6cebcb30fa690c312c29da4dc433e" -"checksum trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ae063390324bfcf36c7e8e4fb1f85f6f0fb5dd04e1cd282581eb7b8b34b32de7" -"checksum trie-standardmap 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "40787fb1a63a97ed56d12bc303937ea274e09d1afa2e20e4f074eff2074b24d3" -"checksum triehash 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b645ad3fc9871596897fb64a57c9c29adc9f5ece87c2d78766e3fc5a5da56b56" +"checksum trie-db 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b65d609ae631d808c6c1cc23a622733d5a0b66a7d67e9f5cd5171562a1f4cb5" +"checksum trie-standardmap 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "64fda153c00484d640bc91334624be22ead0e5baca917d9fd53ff29bdebcf9b2" +"checksum triehash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "61d0a66fa2412c7eb7816640e8ea14cf6bd63b6c824e72315b6ca76d33851134" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" diff --git a/Cargo.toml b/Cargo.toml index ea85995a556..4c5d4898e17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ ethcore-secretstore = { path = "secret-store", optional = true } registrar = { path = "util/registrar" } -parity-util-mem = { version = "0.1", features = ["jemalloc-global"] } +parity-util-mem = { version = "0.2.0", features = ["jemalloc-global"] } [build-dependencies] rustc_version = "0.2" diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index b61932b0ceb..107413d91ea 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -32,8 +32,8 @@ ethkey = { path = "../accounts/ethkey" } evm = { path = "evm" } trie-vm-factories = { path = "trie-vm-factories" } futures = "0.1" -hash-db = "0.12.4" -parity-util-mem = "0.1" +hash-db = "0.15.0" +parity-util-mem = "0.2.0" itertools = "0.5" journaldb = { path = "../util/journaldb" } keccak-hash = "0.2.0" @@ -53,7 +53,7 @@ parity-bytes = "0.1" parity-snappy = "0.1" parking_lot = "0.8" pod = { path = "pod" } -trie-db = "0.12.4" +trie-db = "0.15.0" patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } rand = "0.6" rayon = "1.1" @@ -86,7 +86,7 @@ parity-runtime = { path = "../util/runtime" } rlp_compress = { path = "../util/rlp-compress" } serde_json = "1.0" tempdir = "0.3" -trie-standardmap = "0.12.4" +trie-standardmap = "0.15.0" machine = { path = "./machine", features = ["test-helpers"] } [features] diff --git a/ethcore/account-db/Cargo.toml b/ethcore/account-db/Cargo.toml index 850b55905fb..e60621fbdf6 100644 --- a/ethcore/account-db/Cargo.toml +++ b/ethcore/account-db/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] ethereum-types = "0.6" -hash-db = "0.12.4" +hash-db = "0.15.0" keccak-hash = "0.2.0" keccak-hasher = { path = "../../util/keccak-hasher" } kvdb = "0.1" diff --git a/ethcore/account-state/Cargo.toml b/ethcore/account-state/Cargo.toml index e7ff784e425..9a39cd811e8 100644 --- a/ethcore/account-state/Cargo.toml +++ b/ethcore/account-state/Cargo.toml @@ -12,22 +12,22 @@ derive_more = "0.15.0" ethereum-types = "0.6.0" ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" } trie-vm-factories = { path = "../trie-vm-factories" } -hash-db = "0.12.4" +hash-db = "0.15.0" journaldb = { path = "../../util/journaldb" } keccak-hash = "0.2.0" keccak-hasher = { path = "../../util/keccak-hasher" } kvdb = "0.1.0" log = "0.4" lru-cache = "0.1.2" -memory-db = "0.12.4" +memory-db = "0.15.0" parity-bytes = "0.1.0" -parity-util-mem = "0.1.0" +parity-util-mem = "0.2.0" parking_lot = "0.8.0" pod = { path = "../pod" } rlp = "0.4.0" serde = { version = "1.0", features = ["derive"] } trace = { path = "../trace" } -trie-db = "0.12.4" +trie-db = "0.15.0" [dev-dependencies] account-db = { path = "../account-db" } diff --git a/ethcore/blockchain/Cargo.toml b/ethcore/blockchain/Cargo.toml index 32afed855f8..6015634a3c1 100644 --- a/ethcore/blockchain/Cargo.toml +++ b/ethcore/blockchain/Cargo.toml @@ -14,7 +14,7 @@ common-types = { path = "../types" } ethcore-db = { path = "../db" } ethereum-types = "0.6.0" keccak-hash = "0.2.0" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" itertools = "0.5" kvdb = "0.1" log = "0.4" diff --git a/ethcore/db/Cargo.toml b/ethcore/db/Cargo.toml index 2999c7b1983..c7e75a9a6ac 100644 --- a/ethcore/db/Cargo.toml +++ b/ethcore/db/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" common-types = { path = "../types" } ethereum-types = "0.6.0" kvdb = "0.1" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" parking_lot = "0.8" rlp = "0.4.0" rlp_derive = { path = "../../util/rlp-derive" } diff --git a/ethcore/evm/Cargo.toml b/ethcore/evm/Cargo.toml index 9f83e70e276..094d22f84d1 100644 --- a/ethcore/evm/Cargo.toml +++ b/ethcore/evm/Cargo.toml @@ -8,7 +8,7 @@ authors = ["Parity Technologies "] bit-set = "0.4" parity-bytes = "0.1" ethereum-types = "0.6.0" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" lazy_static = "1.0" log = "0.4" vm = { path = "../vm" } diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 998d82b6229..83494b37ac7 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -17,14 +17,14 @@ ethcore-db = { path = "../db" } ethcore-blockchain = { path = "../blockchain" } ethereum-types = "0.6.0" machine = { path = "../machine" } -memory-db = "0.12.4" -trie-db = "0.12.4" +memory-db = "0.15.0" +trie-db = "0.15.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } ethcore-network = { path = "../../util/network" } ethcore-miner = { path = "../../miner" } ethcore-io = { path = "../../util/io" } -hash-db = "0.12.4" -parity-util-mem = "0.1" +hash-db = "0.15.0" +parity-util-mem = "0.2.0" vm = { path = "../vm" } fastmap = { path = "../../util/fastmap" } failsafe = { version = "0.3.0", default-features = false, features = ["parking_lot_mutex"] } diff --git a/ethcore/pod/Cargo.toml b/ethcore/pod/Cargo.toml index f9bc2b3ad5e..c695b2533cc 100644 --- a/ethcore/pod/Cargo.toml +++ b/ethcore/pod/Cargo.toml @@ -11,7 +11,7 @@ common-types = { path = "../types" } ethereum-types = "0.6" ethjson = { path = "../../json" } ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" } -hash-db = "0.12" +hash-db = "0.15.0" itertools = "0.8" keccak-hash = "0.2.0" keccak-hasher = { path = "../../util/keccak-hasher" } @@ -21,7 +21,7 @@ parity-bytes = "0.1.0" rlp = "0.4" rustc-hex = "1" serde = { version = "1.0", features = ["derive"] } -trie-db = "0.12.4" +trie-db = "0.15.0" triehash = { package = "triehash-ethereum", version = "0.2", path = "../../util/triehash-ethereum" } [dev-dependencies] diff --git a/ethcore/pod/src/account.rs b/ethcore/pod/src/account.rs index 4d5b0143f51..42f5abf7416 100644 --- a/ethcore/pod/src/account.rs +++ b/ethcore/pod/src/account.rs @@ -26,7 +26,7 @@ use keccak_hasher::KeccakHasher; use triehash::sec_trie_root; use parity_bytes::Bytes; use trie_db::TrieFactory; -use ethtrie::RlpCodec; +use ethtrie::Layout; use ethjson; use common_types::account_diff::*; use rlp::{self, RlpStream}; @@ -70,7 +70,7 @@ impl PodAccount { } /// Place additional data into given hash DB. - pub fn insert_additional(&self, db: &mut dyn HashDB, factory: &TrieFactory) { + pub fn insert_additional(&self, db: &mut dyn HashDB, factory: &TrieFactory) { match self.code { Some(ref c) if !c.is_empty() => { db.insert(hash_db::EMPTY_PREFIX, c); } _ => {} diff --git a/ethcore/private-tx/Cargo.toml b/ethcore/private-tx/Cargo.toml index b7a27bfb711..c0050bbb22c 100644 --- a/ethcore/private-tx/Cargo.toml +++ b/ethcore/private-tx/Cargo.toml @@ -22,14 +22,14 @@ ethjson = { path = "../../json" } ethkey = { path = "../../accounts/ethkey" } fetch = { path = "../../util/fetch" } futures = "0.1" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" keccak-hash = "0.2.0" log = "0.4" machine = { path = "../machine" } parity-bytes = "0.1" parity-crypto = "0.4.0" parking_lot = "0.8" -trie-db = "0.12.4" +trie-db = "0.15.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } rand = "0.3" rlp = "0.4.0" diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 207a92da03b..67003839954 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -91,7 +91,7 @@ use verification::queue::kind::blocks::Unverified; use verification::{Verifier, BlockQueue}; use verification; use ansi_term::Colour; - +use ethtrie::Layout; // re-export pub use blockchain::CacheSize as BlockChainCacheSize; use db::{Writable, Readable, keys::BlockDetails}; @@ -726,7 +726,7 @@ impl Client { false => TrieSpec::Secure, }; - let trie_factory = TrieFactory::new(trie_spec); + let trie_factory = TrieFactory::new(trie_spec, Layout); let factories = Factories { vm: VmFactory::new(config.vm_type.clone(), config.jump_table_size), trie: trie_factory, diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index 00ae5748271..f11a9336314 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -158,7 +158,7 @@ impl<'a> EvmTestClient<'a> { fn factories(trie_spec: trie::TrieSpec) -> Factories { Factories { vm: trie_vm_factories::VmFactory::new(VMType::Interpreter, 5 * 1024), - trie: trie::TrieFactory::new(trie_spec), + trie: trie::TrieFactory::new(trie_spec, ethtrie::Layout), accountdb: Default::default(), } } diff --git a/ethcore/src/executive_state.rs b/ethcore/src/executive_state.rs index 02f6ffa8cd0..d045102ceef 100644 --- a/ethcore/src/executive_state.rs +++ b/ethcore/src/executive_state.rs @@ -1658,13 +1658,14 @@ mod tests { #[test] fn should_get_full_pod_storage_values() { use trie::{TrieFactory, TrieSpec}; + use ethtrie; let a = Address::from_low_u64_be(10); let db = get_temp_state_db(); let factories = Factories { vm: Default::default(), - trie: TrieFactory::new(TrieSpec::Fat), + trie: TrieFactory::new(TrieSpec::Fat, ethtrie::Layout), accountdb: Default::default(), }; diff --git a/ethcore/src/json_tests/trie.rs b/ethcore/src/json_tests/trie.rs index 31ca6135e9d..232cc15fc5b 100644 --- a/ethcore/src/json_tests/trie.rs +++ b/ethcore/src/json_tests/trie.rs @@ -16,7 +16,6 @@ use ethjson; use trie::{TrieFactory, TrieSpec}; -use ethtrie::RlpCodec; use ethereum_types::H256; use super::HookType; @@ -28,7 +27,7 @@ pub use self::secure::run_test_file as run_secure_test_file; fn test_trie(json: &[u8], trie: TrieSpec, start_stop_hook: &mut H) -> Vec { let tests = ethjson::trie::Test::load(json).unwrap(); - let factory = TrieFactory::<_, RlpCodec>::new(trie); + let factory = TrieFactory::new(trie, ethtrie::Layout); let mut result = vec![]; for (name, test) in tests.into_iter() { diff --git a/ethcore/state-db/Cargo.toml b/ethcore/state-db/Cargo.toml index 547c398dbc2..31ac3c1d467 100644 --- a/ethcore/state-db/Cargo.toml +++ b/ethcore/state-db/Cargo.toml @@ -12,7 +12,7 @@ bloom_journal = { package = "ethcore-bloom-journal", path = "../../util/bloom" } common-types = { path = "../types"} ethcore-db = { path = "../db" } ethereum-types = "0.6.0" -hash-db = "0.12.4" +hash-db = "0.15.0" keccak-hash = "0.2.0" keccak-hasher = { path = "../../util/keccak-hasher" } journaldb = { path = "../../util/journaldb" } diff --git a/ethcore/sync/Cargo.toml b/ethcore/sync/Cargo.toml index 3f60b0b0df9..5e2cf1cadaa 100644 --- a/ethcore/sync/Cargo.toml +++ b/ethcore/sync/Cargo.toml @@ -20,7 +20,7 @@ ethereum-types = "0.6.0" ethkey = { path = "../../accounts/ethkey" } ethstore = { path = "../../accounts/ethstore" } fastmap = { path = "../../util/fastmap" } -hash-db = "0.12.4" +hash-db = "0.15.0" keccak-hash = "0.2.0" keccak-hasher = { path = "../../util/keccak-hasher" } kvdb = "0.1" @@ -29,7 +29,7 @@ machine = { path = "../machine" } macros = { path = "../../util/macros" } parity-bytes = "0.1" parking_lot = "0.8" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" rand = "0.6" rlp = "0.4.0" trace-time = "0.1" diff --git a/ethcore/trace/Cargo.toml b/ethcore/trace/Cargo.toml index af0f9f21ae6..4c5e65a6e24 100644 --- a/ethcore/trace/Cargo.toml +++ b/ethcore/trace/Cargo.toml @@ -14,7 +14,7 @@ evm = { path = "../evm" } kvdb = "0.1.0" log = "0.4" parity-bytes = "0.1.0" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" parking_lot = "0.8.0" rlp = "0.4.0" rlp_derive = { path = "../../util/rlp-derive" } diff --git a/ethcore/trie-vm-factories/Cargo.toml b/ethcore/trie-vm-factories/Cargo.toml index e0ca6b7061b..c552d147540 100644 --- a/ethcore/trie-vm-factories/Cargo.toml +++ b/ethcore/trie-vm-factories/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -trie-db = "0.12.4" +trie-db = "0.15.0" ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" } account-db = { path = "../account-db" } evm = { path = "../evm" } diff --git a/ethcore/trie-vm-factories/src/lib.rs b/ethcore/trie-vm-factories/src/lib.rs index e1c9ed152af..887fc2cc692 100644 --- a/ethcore/trie-vm-factories/src/lib.rs +++ b/ethcore/trie-vm-factories/src/lib.rs @@ -15,12 +15,11 @@ // along with Parity Ethereum. If not, see . use trie_db::TrieFactory; -use ethtrie::RlpCodec; +use ethtrie::Layout; use account_db::Factory as AccountFactory; use evm::{Factory as EvmFactory, VMType}; use vm::{Exec, ActionParams, VersionedSchedule, Schedule}; use wasm::WasmInterpreter; -use keccak_hasher::KeccakHasher; const WASM_MAGIC_NUMBER: &'static [u8; 4] = b"\0asm"; @@ -67,7 +66,7 @@ pub struct Factories { /// factory for evm. pub vm: VmFactory, /// factory for tries. - pub trie: TrieFactory, + pub trie: TrieFactory, /// factory for account databases. pub accountdb: AccountFactory, } diff --git a/ethcore/types/Cargo.toml b/ethcore/types/Cargo.toml index f1ef9794654..a77a88206a5 100644 --- a/ethcore/types/Cargo.toml +++ b/ethcore/types/Cargo.toml @@ -13,7 +13,7 @@ ethjson = { path = "../../json" } ethkey = { path = "../../accounts/ethkey" } keccak-hash = "0.2.0" parity-bytes = "0.1" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" parity-snappy = "0.1" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } rlp = "0.4.0" diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 84c213a01c1..46507d008ce 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -23,7 +23,7 @@ ethabi-contract = "8.0" ethcore-call-contract = { path = "../ethcore/call-contract" } ethereum-types = "0.6.0" futures = "0.1" -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" keccak-hash = "0.2.0" linked-hash-map = "0.5" log = "0.4" diff --git a/util/journaldb/Cargo.toml b/util/journaldb/Cargo.toml index 051a519aeb8..bbe6df2fef8 100644 --- a/util/journaldb/Cargo.toml +++ b/util/journaldb/Cargo.toml @@ -9,12 +9,12 @@ edition = "2018" [dependencies] parity-bytes = "0.1" ethereum-types = "0.6.0" -hash-db = "0.12.4" -malloc_size_of = { version = "0.1", package = "parity-util-mem" } +hash-db = "0.15.0" +malloc_size_of = { version = "0.2", package = "parity-util-mem" } keccak-hasher = { path = "../keccak-hasher" } kvdb = "0.1" log = "0.4" -memory-db = "0.12.4" +memory-db = "0.15.0" parking_lot = "0.8" fastmap = { path = "../../util/fastmap" } rlp = "0.4.0" diff --git a/util/journaldb/src/earlymergedb.rs b/util/journaldb/src/earlymergedb.rs index 9589212b9ef..54b8beb7552 100644 --- a/util/journaldb/src/earlymergedb.rs +++ b/util/journaldb/src/earlymergedb.rs @@ -343,7 +343,7 @@ impl JournalDB for EarlyMergeDB { Some(ref c) => c.read().size_of(&mut ops), None => 0 } - } + } fn state(&self, id: &H256) -> Option { self.backing.get_by_prefix(self.column, &id[0..DB_PREFIX_LEN]).map(|b| b.into_vec()) diff --git a/util/keccak-hasher/Cargo.toml b/util/keccak-hasher/Cargo.toml index b15a2872482..a807eaabbcf 100644 --- a/util/keccak-hasher/Cargo.toml +++ b/util/keccak-hasher/Cargo.toml @@ -8,5 +8,5 @@ license = "GPL-3.0" [dependencies] ethereum-types = "0.6.0" tiny-keccak = "1.4.2" -hash-db = "0.12.4" +hash-db = "0.15.0" plain_hasher = "0.2" diff --git a/util/memory-cache/Cargo.toml b/util/memory-cache/Cargo.toml index ceb49c4dc44..5d51b616ff0 100644 --- a/util/memory-cache/Cargo.toml +++ b/util/memory-cache/Cargo.toml @@ -6,5 +6,5 @@ description = "An LRU-cache which operates on memory used" license = "GPL3" [dependencies] -parity-util-mem = "0.1" +parity-util-mem = "0.2.0" lru-cache = "0.1" diff --git a/util/patricia-trie-ethereum/Cargo.toml b/util/patricia-trie-ethereum/Cargo.toml index 52f6d7dc716..329fb9da5b1 100644 --- a/util/patricia-trie-ethereum/Cargo.toml +++ b/util/patricia-trie-ethereum/Cargo.toml @@ -6,15 +6,15 @@ description = "Merkle-Patricia Trie (Ethereum Style)" license = "GPL-3.0" [dependencies] -trie-db = "0.12.4" +trie-db = "0.15.0" keccak-hasher = { version = "0.1.1", path = "../keccak-hasher" } -hash-db = "0.12.4" +hash-db = "0.15.0" rlp = "0.4.0" parity-bytes = "0.1" ethereum-types = "0.6.0" elastic-array = "0.10" [dev-dependencies] -memory-db = "0.12.4" +memory-db = "0.15.0" keccak-hash = "0.2.0" journaldb = { path = "../journaldb" } diff --git a/util/patricia-trie-ethereum/src/lib.rs b/util/patricia-trie-ethereum/src/lib.rs index ac8479fe333..b2fb6ff8f7a 100644 --- a/util/patricia-trie-ethereum/src/lib.rs +++ b/util/patricia-trie-ethereum/src/lib.rs @@ -35,6 +35,17 @@ use rlp::DecoderError; /// Convenience type alias to instantiate a Keccak-flavoured `RlpNodeCodec` pub type RlpCodec = RlpNodeCodec; +#[derive(Clone, Default)] +/// Defines the working of a particular flavour of trie: +/// how keys are hashed, how values are encoded, does it use extension nodes or not. +pub struct Layout; + +impl trie_db::TrieLayout for Layout { + const USE_EXTENSION: bool = true; + type Hash = keccak_hasher::KeccakHasher; + type Codec = RlpNodeCodec; +} + /// Convenience type alias to instantiate a Keccak/Rlp-flavoured `TrieDB` /// /// Use it as a `Trie` trait object. You can use `db()` to get the backing database object. @@ -70,13 +81,13 @@ pub type RlpCodec = RlpNodeCodec; /// assert_eq!(t.get(b"foo").unwrap().unwrap(), DBValue::from_slice(b"bar")); /// } /// ``` -pub type TrieDB<'db> = trie::TrieDB<'db, KeccakHasher, RlpCodec>; +pub type TrieDB<'db> = trie::TrieDB<'db, Layout>; /// Convenience type alias to instantiate a Keccak/Rlp-flavoured `SecTrieDB` -pub type SecTrieDB<'db> = trie::SecTrieDB<'db, KeccakHasher, RlpCodec>; +pub type SecTrieDB<'db> = trie::SecTrieDB<'db, Layout>; /// Convenience type alias to instantiate a Keccak/Rlp-flavoured `FatDB` -pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>; +pub type FatDB<'db> = trie::FatDB<'db, Layout>; /// Convenience type alias to instantiate a Keccak/Rlp-flavoured `TrieDBMut` /// @@ -102,6 +113,7 @@ pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>; /// use memory_db::*; /// use ethereum_types::H256; /// use elastic_array::ElasticArray128; +/// use trie::Trie; /// /// type DBValue = ElasticArray128; /// @@ -118,16 +130,16 @@ pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>; /// assert!(!t.contains(b"foo").unwrap()); /// } /// ``` -pub type TrieDBMut<'db> = trie::TrieDBMut<'db, KeccakHasher, RlpCodec>; +pub type TrieDBMut<'db> = trie::TrieDBMut<'db, Layout>; /// Convenience type alias to instantiate a Keccak/Rlp-flavoured `SecTrieDBMut` -pub type SecTrieDBMut<'db> = trie::SecTrieDBMut<'db, KeccakHasher, RlpCodec>; +pub type SecTrieDBMut<'db> = trie::SecTrieDBMut<'db, Layout>; /// Convenience type alias to instantiate a Keccak/Rlp-flavoured `FatDBMut` -pub type FatDBMut<'db> = trie::FatDBMut<'db, KeccakHasher, RlpCodec>; +pub type FatDBMut<'db> = trie::FatDBMut<'db, Layout>; /// Convenience type alias to instantiate a Keccak/Rlp-flavoured `TrieFactory` -pub type TrieFactory = trie::TrieFactory; +pub type TrieFactory = trie::TrieFactory; /// Convenience type alias for Keccak/Rlp flavoured trie errors pub type TrieError = trie::TrieError; diff --git a/util/patricia-trie-ethereum/src/rlp_node_codec.rs b/util/patricia-trie-ethereum/src/rlp_node_codec.rs index ea8aea8a771..bc8f975bda7 100644 --- a/util/patricia-trie-ethereum/src/rlp_node_codec.rs +++ b/util/patricia-trie-ethereum/src/rlp_node_codec.rs @@ -16,13 +16,15 @@ //! `NodeCodec` implementation for Rlp -use elastic_array::ElasticArray128; use ethereum_types::H256; use hash_db::Hasher; use keccak_hasher::KeccakHasher; use rlp::{DecoderError, RlpStream, Rlp, Prototype}; use std::marker::PhantomData; -use trie::{NibbleSlice, NodeCodec, node::Node, ChildReference}; +use std::borrow::Borrow; +use trie::{NibbleSlice, NodeCodec, node::Node, ChildReference, Partial}; + + /// Concrete implementation of a `NodeCodec` with Rlp encoding, generic over the `Hasher` #[derive(Default, Clone)] @@ -30,15 +32,50 @@ pub struct RlpNodeCodec {mark: PhantomData} const HASHED_NULL_NODE_BYTES : [u8;32] = [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21]; const HASHED_NULL_NODE : H256 = H256( HASHED_NULL_NODE_BYTES ); + +/// Encode a partial value with a partial tuple as input. +fn encode_partial_iter<'a>(partial: Partial<'a>, is_leaf: bool) -> impl Iterator + 'a { + encode_partial_inner_iter((partial.0).1, partial.1.iter().map(|v| *v), (partial.0).0 > 0, is_leaf) +} + +/// Encode a partial value with an iterator as input. +fn encode_partial_from_iterator_iter<'a>( + mut partial: impl Iterator + 'a, + odd: bool, + is_leaf: bool, +) -> impl Iterator + 'a { + let first = if odd { partial.next().unwrap_or(0) } else { 0 }; + encode_partial_inner_iter(first, partial, odd, is_leaf) +} + +/// Encode a partial value with an iterator as input. +fn encode_partial_inner_iter<'a>( + first_byte: u8, + partial_remaining: impl Iterator + 'a, + odd: bool, + is_leaf: bool, +) -> impl Iterator + 'a { + let encoded_type = if is_leaf {0x20} else {0}; + let first = if odd { + 0x10 + encoded_type + first_byte + } else { + encoded_type + }; + std::iter::once(first).chain(partial_remaining) +} + // NOTE: what we'd really like here is: // `impl NodeCodec for RlpNodeCodec where H::Out: Decodable` // but due to the current limitations of Rust const evaluation we can't // do `const HASHED_NULL_NODE: H::Out = H::Out( … … )`. Perhaps one day soon? impl NodeCodec for RlpNodeCodec { + type Error = DecoderError; + fn hashed_null_node() -> ::Out { HASHED_NULL_NODE } + fn decode(data: &[u8]) -> ::std::result::Result { let r = Rlp::new(data); match r.prototype()? { @@ -47,19 +84,36 @@ impl NodeCodec for RlpNodeCodec { // if leaf, second item is a value (is_data()) // if extension, second item is a node (either SHA3 to be looked up and // fed back into this function or inline RLP which can be fed back into this function). - Prototype::List(2) => match NibbleSlice::from_encoded(r.at(0)?.data()?) { - (slice, true) => Ok(Node::Leaf(slice, r.at(1)?.data()?)), - (slice, false) => Ok(Node::Extension(slice, r.at(1)?.as_raw())), + Prototype::List(2) => { + let enc_nibble = r.at(0)?.data()?; + let from_encoded = if enc_nibble.is_empty() { + (NibbleSlice::new(&[]), false) + } else { + // check leaf bit from header. + let is_leaf = enc_nibble[0] & 32 == 32; + // Check the header bit to see if we're dealing with an odd partial (only a nibble of header info) + // or an even partial (skip a full byte). + let (start, byte_offset) = if enc_nibble[0] & 16 == 16 { (0, 1) } else { (1, 0) }; + (NibbleSlice::new_offset(&enc_nibble[start..], byte_offset), is_leaf) + }; + match from_encoded { + (slice, true) => Ok(Node::Leaf(slice, r.at(1)?.data()?)), + (slice, false) => Ok(Node::Extension(slice, r.at(1)?.data()?)), + } }, // branch - first 16 are nodes, 17th is a value (or empty). Prototype::List(17) => { let mut nodes = [None as Option<&[u8]>; 16]; for i in 0..16 { - let v = r.at(i)?; - if v.is_empty() { + let value = r.at(i)?; + if value.is_empty() { nodes[i] = None; } else { - nodes[i] = Some(v.as_raw()); + if value.is_data() && value.size() == KeccakHasher::LENGTH { + nodes[i] = Some(value.data()?); + } else { + return Err(DecoderError::Custom("Rlp is not valid.")); + } } } Ok(Node::Branch(nodes, if r.at(16)?.is_empty() { None } else { Some(r.at(16)?.data()?) })) @@ -70,65 +124,81 @@ impl NodeCodec for RlpNodeCodec { _ => Err(DecoderError::Custom("Rlp is not valid.")) } } + fn try_decode_hash(data: &[u8]) -> Option<::Out> { - let r = Rlp::new(data); - if r.is_data() && r.size() == KeccakHasher::LENGTH { - Some(r.as_val().expect("Hash is the correct size; qed")) + + if data.len() == KeccakHasher::LENGTH { + let mut r = ::Out::default(); + r.as_mut().copy_from_slice(data); + Some(r) } else { None } } + fn is_empty_node(data: &[u8]) -> bool { Rlp::new(data).is_empty() } - fn empty_node() -> Vec { - let mut stream = RlpStream::new(); - stream.append_empty_data(); - stream.drain() + + fn empty_node() -> &'static[u8] { + &[0x80] } - fn leaf_node(partial: &[u8], value: &[u8]) -> Vec { + fn leaf_node(partial: Partial, value: &[u8]) -> Vec { let mut stream = RlpStream::new_list(2); - stream.append(&partial); + stream.append_iter(encode_partial_iter(partial, true)); stream.append(&value); stream.drain() } - fn ext_node(partial: &[u8], child_ref: ChildReference<::Out>) -> Vec { + fn extension_node( + partial: impl Iterator, + number_nibble: usize, + child_ref: ChildReference<::Out>, + ) -> Vec { let mut stream = RlpStream::new_list(2); - stream.append(&partial); + stream.append_iter(encode_partial_from_iterator_iter(partial, number_nibble % 2 > 0, false)); match child_ref { - ChildReference::Hash(h) => stream.append(&h), - ChildReference::Inline(inline_data, len) => { - let bytes = &AsRef::<[u8]>::as_ref(&inline_data)[..len]; + ChildReference::Hash(hash) => stream.append(&hash), + ChildReference::Inline(inline_data, length) => { + let bytes = &AsRef::<[u8]>::as_ref(&inline_data)[..length]; stream.append_raw(bytes, 1) }, }; stream.drain() } - // fn branch_node(children: I, value: Option>) -> Vec - fn branch_node(children: I, value: Option>) -> Vec - where I: IntoIterator::Out>>> - { + fn branch_node( + children: impl Iterator::Out>>>>, + maybe_value: Option<&[u8]>, + ) -> Vec { let mut stream = RlpStream::new_list(17); for child_ref in children { - match child_ref { + match child_ref.borrow() { Some(c) => match c { - ChildReference::Hash(h) => stream.append(&h), - ChildReference::Inline(inline_data, len) => { - let bytes = &AsRef::<[u8]>::as_ref(&inline_data)[..len]; + ChildReference::Hash(h) => stream.append(h), + ChildReference::Inline(inline_data, length) => { + let bytes = &AsRef::<[u8]>::as_ref(inline_data)[..*length]; stream.append_raw(bytes, 1) }, }, None => stream.append_empty_data() }; } - if let Some(value) = value { + if let Some(value) = maybe_value { stream.append(&&*value); } else { stream.append_empty_data(); } stream.drain() } + + fn branch_node_nibbled( + _partial: impl Iterator, + _number_nibble: usize, + _children: impl Iterator::Out>>>>, + _maybe_value: Option<&[u8]>) -> Vec { + unreachable!("This codec is only used with a trie Layout that uses extension node.") + } + } diff --git a/util/triehash-ethereum/Cargo.toml b/util/triehash-ethereum/Cargo.toml index 07f720be189..2f9f0c24a9c 100644 --- a/util/triehash-ethereum/Cargo.toml +++ b/util/triehash-ethereum/Cargo.toml @@ -6,6 +6,6 @@ description = "Trie-root helpers, ethereum style" license = "GPL-3.0" [dependencies] -triehash = "0.6.0" +triehash = "0.8.0" ethereum-types = "0.6.0" keccak-hasher = { path = "../keccak-hasher" } From ef47426a93a722f03b0217187c8235f4a4b72021 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 15 Aug 2019 16:06:43 +0200 Subject: [PATCH 06/10] [evmbin] fix compilation (#10976) * Fix compilation error Include the test-helpers from `machine` (used by json-tests, although I'm not sure why evmbin needs ethcore/json-tests) * Update to edition --- Cargo.lock | 2 -- ethcore/Cargo.toml | 2 +- evmbin/Cargo.toml | 5 ++-- evmbin/README.md | 1 - evmbin/src/display/json.rs | 15 ++++++++---- evmbin/src/display/simple.rs | 8 +++--- evmbin/src/display/std_json.rs | 14 +++++++---- evmbin/src/info.rs | 14 +++++++---- evmbin/src/main.rs | 45 +++++++++------------------------- 9 files changed, 48 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b8f8cfc310..467c385e0de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1481,10 +1481,8 @@ dependencies = [ "panic_hook 0.1.0", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pod 0.1.0", - "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "trace 0.1.0", diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 107413d91ea..44118bbea79 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -111,7 +111,7 @@ evm-debug-tests = ["evm-debug", "evm/evm-debug-tests"] # EVM debug traces are printed. slow-blocks = [] # Run JSON consensus tests. -json-tests = ["env_logger", "test-helpers"] +json-tests = ["env_logger", "test-helpers", "machine/test-helpers"] # Skip JSON consensus tests with pending issues. ci-skip-tests = [] # Run memory/cpu heavy tests. diff --git a/evmbin/Cargo.toml b/evmbin/Cargo.toml index c3706b60e64..0a9a481e40f 100644 --- a/evmbin/Cargo.toml +++ b/evmbin/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity EVM Implementation" name = "evmbin" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2018" [[bin]] name = "parity-evm" @@ -21,14 +22,12 @@ panic_hook = { path = "../util/panic-hook" } parity-bytes = "0.1" pod = { path = "../ethcore/pod" } rustc-hex = "1.0" -serde = "1.0" -serde_derive = "1.0" +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" trace = { path = "../ethcore/trace" } vm = { path = "../ethcore/vm" } [dev-dependencies] -pretty_assertions = "0.1" tempdir = "0.3" [features] diff --git a/evmbin/README.md b/evmbin/README.md index 1a4396ec071..4e06525c5e3 100644 --- a/evmbin/README.md +++ b/evmbin/README.md @@ -52,4 +52,3 @@ _This project is a part of the Parity Ethereum toolchain._ - [ethabi](https://github.com/paritytech/ethabi) - Parity Ethereum function calls encoding. - [ethstore](https://github.com/paritytech/parity-ethereum/blob/master/accounts/ethstore) - Parity Ethereum key management. - [ethkey](https://github.com/paritytech/parity-ethereum/blob/master/accounts/ethkey) - Parity Ethereum keys generator. -- [whisper](https://github.com/paritytech/whisper) - Implementation of Whisper-v2 PoC. diff --git a/evmbin/src/display/json.rs b/evmbin/src/display/json.rs index b25d2bbb26a..d4cacc8bbf2 100644 --- a/evmbin/src/display/json.rs +++ b/evmbin/src/display/json.rs @@ -20,11 +20,14 @@ use std::collections::HashMap; use std::mem; use ethereum_types::{U256, H256, BigEndianHash}; -use bytes::ToPretty; +use parity_bytes::ToPretty; +use serde::Serialize; use trace; -use display; -use info as vm; +use crate::{ + display, + info as vm, +}; /// JSON formatting informant. #[derive(Default)] @@ -273,10 +276,12 @@ impl trace::VMTracer for Informant { #[cfg(test)] mod tests { - use super::*; - use info::tests::run_test; + use serde::{Deserialize, Serialize}; use serde_json; + use super::*; + use crate::info::tests::run_test; + #[derive(Serialize, Deserialize, Debug, PartialEq)] #[serde(rename_all = "camelCase")] struct TestTrace { diff --git a/evmbin/src/display/simple.rs b/evmbin/src/display/simple.rs index 7bc3a0e7c95..dad498fb853 100644 --- a/evmbin/src/display/simple.rs +++ b/evmbin/src/display/simple.rs @@ -17,10 +17,12 @@ //! Log EVM instruction output data traces from a simple formatting informant. use trace; -use bytes::ToPretty; +use parity_bytes::ToPretty; -use display; -use info as vm; +use crate::{ + display, + info as vm, +}; /// Simple formatting informant. #[derive(Default)] diff --git a/evmbin/src/display/std_json.rs b/evmbin/src/display/std_json.rs index a5974bc915d..8104d6a7894 100644 --- a/evmbin/src/display/std_json.rs +++ b/evmbin/src/display/std_json.rs @@ -20,11 +20,15 @@ use std::collections::HashMap; use std::io; use ethereum_types::{H256, U256, BigEndianHash}; -use bytes::ToPretty; -use trace; +use parity_bytes::ToPretty; use pod::PodState; -use display; -use info as vm; +use serde::Serialize; +use trace; + +use crate::{ + display, + info as vm, +}; pub trait Writer: io::Write + Send + Sized { fn clone(&self) -> Self; @@ -312,7 +316,7 @@ impl trace::VMTracer for Informant { pub mod tests { use std::sync::{Arc, Mutex}; use super::*; - use info::tests::run_test; + use crate::info::tests::run_test; #[derive(Debug, Clone, Default)] pub struct TestWriter(pub Arc>>); diff --git a/evmbin/src/info.rs b/evmbin/src/info.rs index cd58161815f..c42454a0193 100644 --- a/evmbin/src/info.rs +++ b/evmbin/src/info.rs @@ -17,13 +17,17 @@ //! EVM runner. use std::time::{Instant, Duration}; -use ethcore::client::{self, EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; -use ethcore::{spec, TrieSpec}; + +use common_types::transaction; +use ethcore::{ + client::{self, EvmTestClient, EvmTestError, TransactErr, TransactSuccess}, + spec, + TrieSpec, +}; use ethereum_types::{H256, U256}; use ethjson; use pod::PodState; use trace; -use types::transaction; use vm::ActionParams; /// EVM execution informant. @@ -37,7 +41,7 @@ pub trait Informant: trace::VMTracer { /// Clone sink. fn clone_sink(&self) -> Self::Sink; /// Display final result. - fn finish(result: RunResult, &mut Self::Sink); + fn finish(result: RunResult, _: &mut Self::Sink); } /// Execution finished correctly. @@ -272,7 +276,7 @@ pub mod tests { #[test] fn should_call_account_from_spec() { - use display::std_json::tests::informant; + use crate::display::std_json::tests::informant; let (inf, res, _) = informant(); let mut params = ActionParams::default(); diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index 7491d3c1824..40d394180be 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -34,46 +34,22 @@ #![warn(missing_docs)] -extern crate account_state; -extern crate common_types as types; -extern crate docopt; -extern crate env_logger; -extern crate ethcore; -extern crate ethereum_types; -extern crate ethjson; -extern crate evm; -extern crate panic_hook; -extern crate parity_bytes as bytes; -extern crate pod; -extern crate rustc_hex; -extern crate serde; -#[macro_use] -extern crate serde_derive; -extern crate serde_json; -extern crate trace; -extern crate vm; - -#[cfg(test)] -#[macro_use] -extern crate pretty_assertions; - -#[cfg(test)] -extern crate tempdir; - use std::sync::Arc; use std::{fmt, fs}; use std::path::PathBuf; + +use parity_bytes::Bytes; use docopt::Docopt; use rustc_hex::FromHex; use ethereum_types::{U256, Address}; -use bytes::Bytes; use ethcore::{spec, json_tests, TrieSpec}; +use serde::Deserialize; use vm::{ActionParams, CallType}; mod info; mod display; -use info::{Informant, TxInput}; +use crate::info::{Informant, TxInput}; const USAGE: &'static str = r#" EVM implementation for Parity. @@ -289,7 +265,7 @@ fn run_state_test(args: Args) { } fn run_stats_jsontests_vm(args: Args) { - use json_tests::HookType; + use crate::json_tests::HookType; use std::collections::HashMap; use std::time::{Instant, Duration}; @@ -464,14 +440,17 @@ fn die(msg: T) -> ! { #[cfg(test)] mod tests { - use display::std_json::tests::informant; + use common_types::transaction; use docopt::Docopt; use ethcore::{TrieSpec}; use ethjson::state::test::{State}; - use info::{self, TxInput}; - use super::{Args, USAGE, Address, run_call}; - use types::transaction; + use serde::Deserialize; + use super::{Args, USAGE, Address, run_call}; + use crate::{ + display::std_json::tests::informant, + info::{self, TxInput} + }; #[derive(Debug, PartialEq, Deserialize)] pub struct SampleStateTests { From fd754911037de335cb4ab58d5c058803eef560b4 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Thu, 15 Aug 2019 16:10:39 +0200 Subject: [PATCH 07/10] Verify transaction against its block during import (#10954) * Verify transaction against its block during import * Client method for transaction verification added * Verification methods united * Verification sequence for transaction verifier returned --- ethcore/src/miner/miner.rs | 2 +- ethcore/src/miner/pool_client.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index aeb664b57ad..6157e8d284b 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -513,7 +513,7 @@ impl Miner { let sender = transaction.sender(); // Re-verify transaction again vs current state. - let result = client.verify_signed(&transaction) + let result = client.verify_for_pending_block(&transaction, &open_block.header) .map_err(|e| e.into()) .and_then(|_| { open_block.push_transaction(transaction, None) diff --git a/ethcore/src/miner/pool_client.rs b/ethcore/src/miner/pool_client.rs index 669076c1849..4a9852409ff 100644 --- a/ethcore/src/miner/pool_client.rs +++ b/ethcore/src/miner/pool_client.rs @@ -117,11 +117,13 @@ impl<'a, C: 'a> PoolClient<'a, C> where } } - /// Verifies if signed transaction is executable. + /// Verifies transaction against its block (before its import into this block) + /// Also Verifies if signed transaction is executable. /// /// This should perform any verifications that rely on chain status. - pub fn verify_signed(&self, tx: &SignedTransaction) -> Result<(), transaction::Error> { - self.engine.machine().verify_transaction(&tx, &self.best_block_header, self.chain) + pub fn verify_for_pending_block(&self, tx: &SignedTransaction, header: &Header) -> Result<(), transaction::Error> { + self.engine.machine().verify_transaction_basic(tx, header)?; + self.engine.machine().verify_transaction(tx, &self.best_block_header, self.chain) } } @@ -142,8 +144,7 @@ impl<'a, C: 'a> pool::client::Client for PoolClient<'a, C> where self.engine.verify_transaction_basic(&tx, &self.best_block_header)?; let tx = tx.verify_unordered()?; - self.verify_signed(&tx)?; - + self.engine.machine().verify_transaction(&tx, &self.best_block_header, self.chain)?; Ok(tx) } From abb2a8c5a29bae46bd98977dc83749fe8f0686c7 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Thu, 15 Aug 2019 16:28:25 +0200 Subject: [PATCH 08/10] [.gitlab.yml] cargo check ethcore benches (#10965) --- .gitlab-ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f03d79625cd..ada44333120 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,7 +46,7 @@ variables: sccache --start-server - sccache -s after_script: - # sccache debug info + # sccache debug info - if test -e sccache_debug.log; then echo "_____All crate-types:_____"; @@ -100,6 +100,13 @@ cargo-check 2 3: - time cargo check --target $CARGO_TARGET --locked --manifest-path util/io/Cargo.toml --features "mio" --verbose --color=always - sccache -s +cargo-check-ethcore-benches: + stage: test + <<: *docker-cache-status + script: + - time cargo check -p ethcore --benches --target $CARGO_TARGET --locked --verbose --color=always + - sccache -s + cargo-audit: stage: test <<: *docker-cache-status @@ -223,7 +230,7 @@ publish-docker: DOCKER_DRIVER: overlay2 GIT_STRATEGY: none # DOCKERFILE: tools/Dockerfile - # CONTAINER_IMAGE: parity/parity + # CONTAINER_IMAGE: parity/parity script: # we stopped pushing nightlies to dockerhub, will push to own registry prb. - ./tools/publish-docker.sh From 1ba4df08f9c5dbadbbd287688fe6c709b1c4a7a0 Mon Sep 17 00:00:00 2001 From: Seun LanLege Date: Thu, 15 Aug 2019 15:48:41 +0100 Subject: [PATCH 09/10] Better error message for rpc gas price errors (#10931) * Better error message for rpc gas price errors * correct tests * dedupe error variants * fixed tests, removed spacing --- ethcore/types/src/transaction/error.rs | 16 ++++++++++++---- miner/src/pool/queue.rs | 2 +- miner/src/pool/tests/mod.rs | 16 ++++++++-------- miner/src/pool/verifier.rs | 6 +++--- rpc/src/v1/helpers/errors.rs | 7 +++++-- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ethcore/types/src/transaction/error.rs b/ethcore/types/src/transaction/error.rs index a563347ce3f..1ad9d535803 100644 --- a/ethcore/types/src/transaction/error.rs +++ b/ethcore/types/src/transaction/error.rs @@ -30,9 +30,6 @@ pub enum Error { AlreadyImported, /// Transaction is not valid anymore (state already has higher nonce) Old, - /// Transaction has too low fee - /// (there is already a transaction with the same sender-nonce but higher gas price) - TooCheapToReplace, /// Transaction was not imported to the queue because limit has been reached. LimitReached, /// Transaction's gas price is below threshold. @@ -42,6 +39,14 @@ pub enum Error { /// Transaction gas price got: U256, }, + /// Transaction has too low fee + /// (there is already a transaction with the same sender-nonce but higher gas price) + TooCheapToReplace { + /// previous transaction's gas price + prev: Option, + /// new transaction's gas price + new: Option, + }, /// Transaction's gas is below currently set minimal gas requirement. InsufficientGas { /// Minimal expected gas @@ -101,7 +106,10 @@ impl fmt::Display for Error { let msg = match *self { AlreadyImported => "Already imported".into(), Old => "No longer valid".into(), - TooCheapToReplace => "Gas price too low to replace".into(), + TooCheapToReplace { prev, new } => + format!("Gas price too low to replace, previous tx gas: {:?}, new tx gas: {:?}", + prev, new + ), LimitReached => "Transaction limit reached".into(), InsufficientGasPrice { minimal, got } => format!("Insufficient gas price. Min={}, Given={}", minimal, got), diff --git a/miner/src/pool/queue.rs b/miner/src/pool/queue.rs index bc79d34246d..a6dbe3450a8 100644 --- a/miner/src/pool/queue.rs +++ b/miner/src/pool/queue.rs @@ -594,7 +594,7 @@ fn convert_error(err: txpool::Error) -> transa match err { Error::AlreadyImported(..) => transaction::Error::AlreadyImported, Error::TooCheapToEnter(..) => transaction::Error::LimitReached, - Error::TooCheapToReplace(..) => transaction::Error::TooCheapToReplace + Error::TooCheapToReplace(..) => transaction::Error::TooCheapToReplace { prev: None, new: None } } } diff --git a/miner/src/pool/tests/mod.rs b/miner/src/pool/tests/mod.rs index 0eb223dba00..1df1be4ce7f 100644 --- a/miner/src/pool/tests/mod.rs +++ b/miner/src/pool/tests/mod.rs @@ -91,10 +91,10 @@ fn should_return_correct_nonces_when_dropped_because_of_limit() { // then assert_eq!(res, vec![Ok(()), Ok(())]); assert_eq!(res2, vec![ - // The error here indicates reaching the limit - // and minimal effective gas price taken into account. - Err(transaction::Error::InsufficientGasPrice { minimal: 2.into(), got: 1.into() }), - Ok(()) + // The error here indicates reaching the limit + // and minimal effective gas price taken into account. + Err(transaction::Error::TooCheapToReplace { prev: Some(2.into()), new: Some(1.into()) }), + Ok(()) ]); assert_eq!(txq.status().status.transaction_count, 3); // tx2 transaction got dropped because of limit @@ -585,7 +585,7 @@ fn should_not_replace_same_transaction_if_the_fee_is_less_than_minimal_bump() { let res = txq.import(client.clone(), vec![tx2, tx4].local()); // then - assert_eq!(res, vec![Err(transaction::Error::TooCheapToReplace), Ok(())]); + assert_eq!(res, vec![Err(transaction::Error::TooCheapToReplace { prev: None, new: None }), Ok(())]); assert_eq!(txq.status().status.transaction_count, 2); assert_eq!(txq.pending(client.clone(), PendingSettings::all_prioritized(0, 0))[0].signed().gas_price, U256::from(20)); assert_eq!(txq.pending(client.clone(), PendingSettings::all_prioritized(0, 0))[1].signed().gas_price, U256::from(2)); @@ -1027,9 +1027,9 @@ fn should_reject_early_in_case_gas_price_is_less_than_min_effective() { let client = TestClient::new(); let tx1 = Tx::default().signed().unverified(); let res = txq.import(client.clone(), vec![tx1]); - assert_eq!(res, vec![Err(transaction::Error::InsufficientGasPrice { - minimal: 2.into(), - got: 1.into(), + assert_eq!(res, vec![Err(transaction::Error::TooCheapToReplace { + prev: Some(2.into()), + new: Some(1.into()), })]); assert!(!client.was_verification_triggered()); diff --git a/miner/src/pool/verifier.rs b/miner/src/pool/verifier.rs index 5c8273dd577..79d50d7138f 100644 --- a/miner/src/pool/verifier.rs +++ b/miner/src/pool/verifier.rs @@ -231,9 +231,9 @@ impl txpool::Verifier for Verifier String { match *error { AlreadyImported => "Transaction with the same hash was already imported.".into(), Old => "Transaction nonce is too low. Try incrementing the nonce.".into(), - TooCheapToReplace => { - "Transaction gas price is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce.".into() + TooCheapToReplace { prev, new } => { + format!("Transaction gas price {} is too low. There is another transaction with same nonce in the queue{}. Try increasing the gas price or incrementing the nonce.", + new.map(|gas| format!("{}wei", gas)).unwrap_or("supplied".into()), + prev.map(|gas| format!(" with gas price: {}wei", gas)).unwrap_or("".into()) + ) } LimitReached => { "There are too many transactions in the queue. Your transaction was dropped due to limit. Try increasing the fee.".into() From 6a9de9b11e787aab17ac796b83f33e3ab1300fc0 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 15 Aug 2019 17:59:22 +0200 Subject: [PATCH 10/10] Extract the Engine trait (#10958) * Add client-traits crate Move the BlockInfo trait to new crate * New crate `machine` Contains code extracted from ethcore that defines `Machine`, `Externalities` and other execution related code. * Use new machine and client-traits crates in ethcore * Use new crates machine and client-traits instead of ethcore where appropriate * Fix tests * Don't re-export so many types from ethcore::client * Fixing more fallout from removing re-export * fix test * More fallout from not re-exporting types * Add some docs * cleanup * import the macro edition style * Tweak docs * Add missing import * remove unused ethabi_derive imports * Use latest ethabi-contract * Move many traits from ethcore/client/traits to client-traits crate Initial version of extracted Engine trait * Move snapshot related traits to the engine crate (eew) * Move a few snapshot related types to common_types Cleanup Executed as exported from machine crate * fix warning * Gradually introduce new engine crate: snapshot * ethcore typechecks with new engine crate * Sort out types outside ethcore * Add an EpochVerifier to ethash and use that in Engine.epoch_verifier() Cleanup * Document pub members * Sort out tests Sort out default impls for EpochVerifier * Add test-helpers feature and move EngineSigner impl to the right place * Sort out tests * Sort out tests and refactor verification types * Fix missing traits * More missing traits Fix Histogram * Fix tests and cleanup * cleanup * Put back needed logger import * Don't rexport common_types from ethcore/src/client Don't export ethcore::client::* * Remove files no longer used Use types from the engine crate Explicit exports from engine::engine * Get rid of itertools * Move a few more traits from ethcore to client-traits: BlockChainReset, ScheduleInfo, StateClient * Move ProvingBlockChainClient to client-traits * Don't re-export ForkChoice and Transition from ethcore * Address grumbles: sort imports, remove commented out code * Fix merge resolution error * merge failure --- Cargo.lock | 36 ++ Cargo.toml | 1 + ethash/src/lib.rs | 2 +- ethcore/Cargo.toml | 14 +- ethcore/client-traits/Cargo.toml | 13 +- ethcore/client-traits/src/lib.rs | 412 ++++++++++++++++- ethcore/engine/Cargo.toml | 29 ++ ethcore/engine/src/engine.rs | 418 ++++++++++++++++++ ethcore/engine/src/lib.rs | 37 ++ ethcore/{src/engines => engine/src}/signer.rs | 33 -- ethcore/engine/src/snapshot.rs | 90 ++++ ethcore/engine/src/test_helpers.rs | 49 ++ ethcore/light/Cargo.toml | 1 + ethcore/light/src/client/fetch.rs | 10 +- ethcore/light/src/client/header_chain.rs | 5 +- ethcore/light/src/client/mod.rs | 13 +- ethcore/light/src/lib.rs | 1 + ethcore/light/src/on_demand/request.rs | 6 +- ethcore/light/src/provider.rs | 8 +- ethcore/machine/src/executed.rs | 50 +-- ethcore/machine/src/executive.rs | 4 +- ethcore/machine/src/test_helpers.rs | 1 - ethcore/machine/src/tx_filter.rs | 3 +- ethcore/node-filter/Cargo.toml | 1 + ethcore/node-filter/src/lib.rs | 12 +- ethcore/private-tx/src/encryptor.rs | 4 +- ethcore/private-tx/src/lib.rs | 11 +- ethcore/private-tx/tests/private_contract.rs | 3 +- ethcore/src/block.rs | 12 +- ethcore/src/client/ancient_import.rs | 2 +- ethcore/src/client/bad_blocks.rs | 2 +- ethcore/src/client/client.rs | 55 +-- ethcore/src/client/config.rs | 28 +- ethcore/src/client/mod.rs | 14 +- ethcore/src/client/test_client.rs | 26 +- ethcore/src/client/traits.rs | 379 +--------------- ethcore/src/engines/authority_round/mod.rs | 32 +- ethcore/src/engines/basic_authority.rs | 35 +- ethcore/src/engines/block_reward.rs | 4 +- ethcore/src/engines/clique/mod.rs | 15 +- ethcore/src/engines/clique/tests.rs | 2 +- ethcore/src/engines/ethash.rs | 99 +++-- ethcore/src/engines/instant_seal.rs | 9 +- ethcore/src/engines/mod.rs | 415 ----------------- ethcore/src/engines/null_engine.rs | 5 +- ethcore/src/engines/validator_set/contract.rs | 16 +- ethcore/src/engines/validator_set/mod.rs | 8 +- ethcore/src/engines/validator_set/multi.rs | 25 +- .../engines/validator_set/safe_contract.rs | 49 +- .../src/engines/validator_set/simple_list.rs | 4 +- ethcore/src/engines/validator_set/test.rs | 4 +- ethcore/src/executive_state.rs | 3 +- ethcore/src/json_tests/chain.rs | 5 +- ethcore/src/json_tests/executive.rs | 1 - ethcore/src/lib.rs | 2 +- ethcore/src/miner/miner.rs | 21 +- ethcore/src/miner/mod.rs | 7 +- ethcore/src/miner/pool_client.rs | 5 +- ethcore/src/snapshot/account.rs | 7 +- ethcore/src/snapshot/consensus/authority.rs | 14 +- ethcore/src/snapshot/consensus/mod.rs | 73 --- ethcore/src/snapshot/consensus/work.rs | 17 +- ethcore/src/snapshot/mod.rs | 46 +- ethcore/src/snapshot/service.rs | 14 +- ethcore/src/snapshot/tests/helpers.rs | 5 +- .../src/snapshot/tests/proof_of_authority.rs | 3 +- ethcore/src/snapshot/tests/proof_of_work.rs | 7 +- ethcore/src/snapshot/tests/service.rs | 13 +- ethcore/src/spec/spec.rs | 3 +- ethcore/src/test_helpers.rs | 22 +- ethcore/src/tests/client.rs | 10 +- ethcore/src/tests/trace.rs | 6 +- ethcore/src/verification/canon_verifier.rs | 2 +- ethcore/src/verification/noop_verifier.rs | 2 +- ethcore/src/verification/queue/kind.rs | 45 +- ethcore/src/verification/queue/mod.rs | 8 +- ethcore/src/verification/verification.rs | 6 +- ethcore/src/verification/verifier.rs | 2 +- ethcore/sync/Cargo.toml | 1 + ethcore/sync/src/api.rs | 3 +- ethcore/sync/src/blocks.rs | 15 +- ethcore/sync/src/chain/handler.rs | 7 +- ethcore/sync/src/chain/mod.rs | 11 +- ethcore/sync/src/chain/propagator.rs | 4 +- ethcore/sync/src/chain/supplier.rs | 3 +- ethcore/sync/src/lib.rs | 3 +- ethcore/sync/src/sync_io.rs | 2 +- ethcore/sync/src/tests/chain.rs | 3 +- ethcore/sync/src/tests/consensus.rs | 9 +- ethcore/sync/src/tests/helpers.rs | 3 +- ethcore/sync/src/tests/private.rs | 9 +- ethcore/types/src/client_types.rs | 49 ++ ethcore/types/src/engines/machine.rs | 53 ++- ethcore/types/src/engines/mod.rs | 10 + ethcore/types/src/lib.rs | 5 +- .../src/{snapshot_manifest.rs => snapshot.rs} | 60 ++- ...fication_queue_info.rs => verification.rs} | 44 +- ipfs/Cargo.toml | 1 + ipfs/src/lib.rs | 3 +- miner/src/pool/local_transactions.rs | 2 +- parity/account_utils.rs | 2 +- parity/blockchain.rs | 15 +- parity/helpers.rs | 13 +- parity/informant.rs | 7 +- parity/ipfs.rs | 2 +- parity/lib.rs | 1 + parity/light_helpers/epoch_fetch.rs | 10 +- parity/modules.rs | 2 +- parity/params.rs | 2 +- parity/rpc_apis.rs | 2 +- parity/run.rs | 9 +- parity/snapshot.rs | 10 +- parity/user_defaults.rs | 2 +- rpc/Cargo.toml | 2 + rpc/src/lib.rs | 4 +- rpc/src/v1/helpers/block_import.rs | 2 +- rpc/src/v1/helpers/dispatch/full.rs | 2 +- rpc/src/v1/helpers/dispatch/mod.rs | 2 +- rpc/src/v1/helpers/engine_signer.rs | 2 +- rpc/src/v1/helpers/errors.rs | 2 +- rpc/src/v1/helpers/light_fetch.rs | 2 +- rpc/src/v1/impls/debug.rs | 2 +- rpc/src/v1/impls/eth.rs | 3 +- rpc/src/v1/impls/eth_filter.rs | 2 +- rpc/src/v1/impls/eth_pubsub.rs | 3 +- rpc/src/v1/impls/parity.rs | 9 +- rpc/src/v1/impls/parity_set.rs | 5 +- rpc/src/v1/impls/traces.rs | 3 +- rpc/src/v1/tests/eth.rs | 16 +- rpc/src/v1/tests/helpers/miner_service.rs | 7 +- rpc/src/v1/tests/mocked/eth.rs | 3 +- rpc/src/v1/types/histogram.rs | 7 +- rpc/src/v1/types/trace_filter.rs | 1 - secret-store/Cargo.toml | 1 + secret-store/src/helpers.rs | 3 +- secret-store/src/key_server_set.rs | 3 +- secret-store/src/lib.rs | 1 + secret-store/src/listener/service_contract.rs | 3 +- secret-store/src/trusted_client.rs | 7 +- updater/Cargo.toml | 1 + updater/src/lib.rs | 1 + updater/src/updater.rs | 3 +- 142 files changed, 1852 insertions(+), 1483 deletions(-) create mode 100644 ethcore/engine/Cargo.toml create mode 100644 ethcore/engine/src/engine.rs create mode 100644 ethcore/engine/src/lib.rs rename ethcore/{src/engines => engine/src}/signer.rs (62%) create mode 100644 ethcore/engine/src/snapshot.rs create mode 100644 ethcore/engine/src/test_helpers.rs create mode 100644 ethcore/types/src/client_types.rs rename ethcore/types/src/{snapshot_manifest.rs => snapshot.rs} (57%) rename ethcore/types/src/{verification_queue_info.rs => verification.rs} (67%) diff --git a/Cargo.lock b/Cargo.lock index 467c385e0de..be413453a7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,8 +418,18 @@ dependencies = [ name = "client-traits" version = "0.1.0" dependencies = [ + "account-state 0.1.0", "common-types 0.1.0", + "ethcore-blockchain 0.1.0", + "ethcore-call-contract 0.1.0", + "ethcore-db 0.1.0", + "ethcore-miner 1.12.0", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "stats 0.1.0", + "trace 0.1.0", + "vm 0.1.0", ] [[package]] @@ -748,6 +758,23 @@ dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "engine" +version = "0.1.0" +dependencies = [ + "client-traits 0.1.0", + "common-types 0.1.0", + "ethcore-accounts 0.1.0", + "ethcore-blockchain 0.1.0", + "ethcore-builtin 0.1.0", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethkey 0.3.0", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "machine 0.1.0", + "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vm 0.1.0", +] + [[package]] name = "enum_primitive" version = "0.1.1" @@ -861,6 +888,7 @@ dependencies = [ "common-types 0.1.0", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "engine 0.1.0", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1043,6 +1071,7 @@ dependencies = [ "client-traits 0.1.0", "common-types 0.1.0", "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "engine 0.1.0", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-blockchain 0.1.0", @@ -1238,6 +1267,7 @@ name = "ethcore-secretstore" version = "1.0.0" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "client-traits 0.1.0", "common-types 0.1.0", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1314,6 +1344,7 @@ version = "1.12.0" dependencies = [ "client-traits 0.1.0", "common-types 0.1.0", + "engine 0.1.0", "enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", @@ -2524,6 +2555,7 @@ dependencies = [ name = "node-filter" version = "1.12.0" dependencies = [ + "client-traits 0.1.0", "common-types 0.1.0", "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2723,6 +2755,7 @@ dependencies = [ "ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)", "dir 0.1.2", "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "engine 0.1.0", "ethcore 1.12.0", "ethcore-accounts 0.1.0", "ethcore-blockchain 0.1.0", @@ -2813,6 +2846,7 @@ name = "parity-ipfs-api" version = "1.12.0" dependencies = [ "cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "client-traits 0.1.0", "common-types 0.1.0", "ethcore 1.12.0", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2876,6 +2910,7 @@ dependencies = [ "client-traits 0.1.0", "common-types 0.1.0", "eip-712 0.1.0", + "engine 0.1.0", "ethash 1.12.0", "ethcore 1.12.0", "ethcore-accounts 0.1.0", @@ -2997,6 +3032,7 @@ dependencies = [ name = "parity-updater" version = "1.12.0" dependencies = [ + "client-traits 0.1.0", "common-types 0.1.0", "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 4c5d4898e17..69fe1f02a81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ jsonrpc-core = "12.0.0" parity-bytes = "0.1" client-traits = { path = "ethcore/client-traits" } common-types = { path = "ethcore/types" } +engine = { path = "ethcore/engine" } ethcore = { path = "ethcore", features = ["parity"] } ethcore-accounts = { path = "accounts", optional = true } ethcore-blockchain = { path = "ethcore/blockchain" } diff --git a/ethash/src/lib.rs b/ethash/src/lib.rs index 47dd0688d54..3225ceb9f58 100644 --- a/ethash/src/lib.rs +++ b/ethash/src/lib.rs @@ -85,7 +85,7 @@ impl EthashManager { EthashManager { cache_dir: cache_dir.to_path_buf(), nodecache_builder: NodeCacheBuilder::new(optimize_for.into().unwrap_or_default(), progpow_transition), - progpow_transition: progpow_transition, + progpow_transition, cache: Mutex::new(LightCache { recent_epoch: None, recent: None, diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 44118bbea79..f896042aa88 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -8,11 +8,13 @@ authors = ["Parity Technologies "] [dependencies] account-db = { path = "account-db" } +account-state = { path = "account-state" } ansi_term = "0.11" blooms-db = { path = "../util/blooms-db", optional = true } client-traits = { path = "./client-traits" } common-types = { path = "types" } crossbeam-utils = "0.6" +engine = { path = "./engine" } env_logger = { version = "0.5", optional = true } ethabi = "8.0" ethabi-contract = "8.0" @@ -30,7 +32,6 @@ ethereum-types = "0.6.0" ethjson = { path = "../json" } ethkey = { path = "../accounts/ethkey" } evm = { path = "evm" } -trie-vm-factories = { path = "trie-vm-factories" } futures = "0.1" hash-db = "0.15.0" parity-util-mem = "0.2.0" @@ -52,42 +53,43 @@ num_cpus = "1.2" parity-bytes = "0.1" parity-snappy = "0.1" parking_lot = "0.8" -pod = { path = "pod" } trie-db = "0.15.0" patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } +pod = { path = "pod" } rand = "0.6" +rand_xorshift = "0.1.1" rayon = "1.1" rlp = "0.4.0" rlp_derive = { path = "../util/rlp-derive" } rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" -account-state = { path = "account-state" } -stats = { path = "../util/stats" } state-db = { path = "state-db" } +stats = { path = "../util/stats" } tempdir = { version = "0.3", optional = true } time-utils = { path = "../util/time-utils" } trace = { path = "trace" } trace-time = "0.1" +trie-vm-factories = { path = "trie-vm-factories" } triehash-ethereum = { version = "0.2", path = "../util/triehash-ethereum" } unexpected = { path = "../util/unexpected" } using_queue = { path = "../miner/using-queue" } vm = { path = "vm" } -rand_xorshift = "0.1.1" [dev-dependencies] blooms-db = { path = "../util/blooms-db" } criterion = "0.2" +engine = { path = "./engine", features = ["test-helpers"] } env_logger = "0.5" ethcore-accounts = { path = "../accounts" } fetch = { path = "../util/fetch" } kvdb-rocksdb = "0.1.3" +machine = { path = "./machine", features = ["test-helpers"] } parity-runtime = { path = "../util/runtime" } rlp_compress = { path = "../util/rlp-compress" } serde_json = "1.0" tempdir = "0.3" trie-standardmap = "0.15.0" -machine = { path = "./machine", features = ["test-helpers"] } [features] parity = ["work-notify", "price-info", "stratum"] diff --git a/ethcore/client-traits/Cargo.toml b/ethcore/client-traits/Cargo.toml index cbc5b1934f1..bc8b06f0fe2 100644 --- a/ethcore/client-traits/Cargo.toml +++ b/ethcore/client-traits/Cargo.toml @@ -7,6 +7,15 @@ edition = "2018" license = "GPL-3.0" [dependencies] -ethereum-types = "0.6.0" +account-state = { path = "../account-state" } +blockchain = { package = "ethcore-blockchain", path = "../blockchain" } +bytes = { package = "parity-bytes", version = "0.1.0" } +call-contract = { package = "ethcore-call-contract", path = "../call-contract" } common-types = { path = "../types" } - +ethcore-db = { path = "../db" } +ethcore-miner = { path = "../../miner" } +ethereum-types = "0.6.0" +kvdb = "0.1.0" +stats = { path = "../../util/stats" } +trace = { path = "../trace" } +vm = { path = "../vm" } diff --git a/ethcore/client-traits/src/lib.rs b/ethcore/client-traits/src/lib.rs index 84b418e3bda..af68b9b3f6c 100644 --- a/ethcore/client-traits/src/lib.rs +++ b/ethcore/client-traits/src/lib.rs @@ -14,24 +14,412 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethereum_types::{Address, H256}; +use std::{ + collections::BTreeMap, + sync::Arc, +}; + +use account_state::state::StateInfo; +use blockchain::BlockProvider; +use bytes::Bytes; +use call_contract::{CallContract, RegistryInfo}; use common_types::{ - header::Header, - encoded, - ids::BlockId, + basic_account::BasicAccount, + block_status::BlockStatus, + blockchain_info::BlockChainInfo, + BlockNumber, + call_analytics::CallAnalytics, + client_types::Mode, + encoded, + engines::{epoch::Transition as EpochTransition, machine::Executed}, + errors::EthcoreResult, + filter::Filter, + header::Header, + ids::{BlockId, TransactionId, TraceId, UncleId}, + log_entry::LocalizedLogEntry, + pruning_info::PruningInfo, + receipt::LocalizedReceipt, + trace_filter::Filter as TraceFilter, + transaction::{self, LocalizedTransaction, CallError, SignedTransaction}, + tree_route::TreeRoute, + verification::{VerificationQueueInfo, Unverified}, }; +use ethereum_types::{Address, H256, U256}; +use ethcore_db::keys::BlockReceipts; +use ethcore_miner::pool::VerifiedTransaction; +use kvdb::DBValue; +use stats; +use trace::{ + FlatTrace, + localized::LocalizedTrace, + VMTrace, +}; +use vm::{LastHashes, Schedule}; + +/// State information to be used during client query +pub enum StateOrBlock { + /// State to be used, may be pending + State(Box), + + /// Id of an existing block from a chain to get state from + Block(BlockId) +} + +impl From> for StateOrBlock { + fn from(info: Box) -> StateOrBlock { + StateOrBlock::State(info) + } +} + +impl From for StateOrBlock { + fn from(id: BlockId) -> StateOrBlock { + StateOrBlock::Block(id) + } +} + +/// Provides `nonce` and `latest_nonce` methods +pub trait Nonce { + /// Attempt to get address nonce at given block. + /// May not fail on BlockId::Latest. + fn nonce(&self, address: &Address, id: BlockId) -> Option; + + /// Get address nonce at the latest block's state. + fn latest_nonce(&self, address: &Address) -> U256 { + self.nonce(address, BlockId::Latest) + .expect("nonce will return Some when given BlockId::Latest. nonce was given BlockId::Latest. \ + Therefore nonce has returned Some; qed") + } +} + +/// Provides `balance` and `latest_balance` methods +pub trait Balance { + /// Get address balance at the given block's state. + /// + /// May not return None if given BlockId::Latest. + /// Returns None if and only if the block's root hash has been pruned from the DB. + fn balance(&self, address: &Address, state: StateOrBlock) -> Option; + + /// Get address balance at the latest block's state. + fn latest_balance(&self, address: &Address) -> U256 { + self.balance(address, BlockId::Latest.into()) + .expect("balance will return Some if given BlockId::Latest. balance was given BlockId::Latest \ + Therefore balance has returned Some; qed") + } +} + +/// Provides methods to access account info +pub trait AccountData: Nonce + Balance {} + +/// Provides `chain_info` method +pub trait ChainInfo { + /// Get blockchain information. + fn chain_info(&self) -> BlockChainInfo; +} /// Provides various information on a block by it's ID pub trait BlockInfo { - /// Get raw block header data by block id. - fn block_header(&self, id: BlockId) -> Option; + /// Get raw block header data by block id. + fn block_header(&self, id: BlockId) -> Option; + + /// Get the best block header. + fn best_block_header(&self) -> Header; + + /// Get raw block data by block header hash. + fn block(&self, id: BlockId) -> Option; + + /// Get address code hash at given block's state. + fn code_hash(&self, address: &Address, id: BlockId) -> Option; +} + +/// Provides various information on a transaction by it's ID +pub trait TransactionInfo { + /// Get the hash of block that contains the transaction, if any. + fn transaction_block(&self, id: TransactionId) -> Option; +} + +/// Provides various blockchain information, like block header, chain state etc. +pub trait BlockChain: ChainInfo + BlockInfo + TransactionInfo {} + +/// Client facilities used by internally sealing Engines. +pub trait EngineClient: Sync + Send + ChainInfo { + /// Make a new block and seal it. + fn update_sealing(&self); + + /// Submit a seal for a block in the mining queue. + fn submit_seal(&self, block_hash: H256, seal: Vec); + + /// Broadcast a consensus message to the network. + fn broadcast_consensus_message(&self, message: Bytes); + + /// Get the transition to the epoch the given parent hash is part of + /// or transitions to. + /// This will give the epoch that any children of this parent belong to. + /// + /// The block corresponding the the parent hash must be stored already. + fn epoch_transition_for(&self, parent_hash: H256) -> Option; + + /// Attempt to cast the engine client to a full client. + fn as_full_client(&self) -> Option<&dyn BlockChainClient>; + + /// Get a block number by ID. + fn block_number(&self, id: BlockId) -> Option; + + /// Get raw block header data by block id. + fn block_header(&self, id: BlockId) -> Option; +} + +// FIXME Why these methods belong to BlockChainClient and not MiningBlockChainClient? +/// Provides methods to import block into blockchain +pub trait ImportBlock { + /// Import a block into the blockchain. + fn import_block(&self, block: Unverified) -> EthcoreResult; +} + +/// IO operations that should off-load heavy work to another thread. +pub trait IoClient: Sync + Send { + /// Queue transactions for importing. + fn queue_transactions(&self, transactions: Vec, peer_id: usize); + + /// Queue block import with transaction receipts. Does no sealing and transaction validation. + fn queue_ancient_block(&self, block_bytes: Unverified, receipts_bytes: Bytes) -> EthcoreResult; + + /// Queue consensus engine message. + fn queue_consensus_message(&self, message: Bytes); +} + +/// Provides recently seen bad blocks. +pub trait BadBlocks { + /// Returns a list of blocks that were recently not imported because they were invalid. + fn bad_blocks(&self) -> Vec<(Unverified, String)>; +} + + +/// Blockchain database client. Owns and manages a blockchain and a block queue. +pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContract + RegistryInfo + ImportBlock ++ IoClient + BadBlocks { + /// Look up the block number for the given block ID. + fn block_number(&self, id: BlockId) -> Option; + + /// Get raw block body data by block id. + /// Block body is an RLP list of two items: uncles and transactions. + fn block_body(&self, id: BlockId) -> Option; + + /// Get block status by block header hash. + fn block_status(&self, id: BlockId) -> BlockStatus; + + /// Get block total difficulty. + fn block_total_difficulty(&self, id: BlockId) -> Option; + + /// Attempt to get address storage root at given block. + /// May not fail on BlockId::Latest. + fn storage_root(&self, address: &Address, id: BlockId) -> Option; + + /// Get block hash. + fn block_hash(&self, id: BlockId) -> Option; + + /// Get address code at given block's state. + fn code(&self, address: &Address, state: StateOrBlock) -> Option>; + + /// Get address code at the latest block's state. + fn latest_code(&self, address: &Address) -> Option { + self.code(address, BlockId::Latest.into()) + .expect("code will return Some if given BlockId::Latest; qed") + } + + /// Get a reference to the `BlockProvider`. + fn chain(&self) -> Arc; + + /// Get block queue information. + fn queue_info(&self) -> VerificationQueueInfo; + + /// Get address code hash at given block's state. + + /// Get value of the storage at given position at the given block's state. + /// + /// May not return None if given BlockId::Latest. + /// Returns None if and only if the block's root hash has been pruned from the DB. + fn storage_at(&self, address: &Address, position: &H256, state: StateOrBlock) -> Option; + + /// Get value of the storage at given position at the latest block's state. + fn latest_storage_at(&self, address: &Address, position: &H256) -> H256 { + self.storage_at(address, position, BlockId::Latest.into()) + .expect("storage_at will return Some if given BlockId::Latest. storage_at was given BlockId::Latest. \ + Therefore storage_at has returned Some; qed") + } + + /// Get a list of all accounts in the block `id`, if fat DB is in operation, otherwise `None`. + /// If `after` is set the list starts with the following item. + fn list_accounts(&self, id: BlockId, after: Option<&Address>, count: u64) -> Option>; + + /// Get a list of all storage keys in the block `id`, if fat DB is in operation, otherwise `None`. + /// If `after` is set the list starts with the following item. + fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: u64) -> Option>; + + /// Get transaction with given hash. + fn transaction(&self, id: TransactionId) -> Option; + + /// Get uncle with given id. + fn uncle(&self, id: UncleId) -> Option; + + /// Get transaction receipt with given hash. + fn transaction_receipt(&self, id: TransactionId) -> Option; + + /// Get localized receipts for all transaction in given block. + fn localized_block_receipts(&self, id: BlockId) -> Option>; + + /// Get a tree route between `from` and `to`. + /// See `BlockChain::tree_route`. + fn tree_route(&self, from: &H256, to: &H256) -> Option; + + /// Get all possible uncle hashes for a block. + fn find_uncles(&self, hash: &H256) -> Option>; + + /// Get latest state node + fn state_data(&self, hash: &H256) -> Option; + + /// Get block receipts data by block header hash. + fn block_receipts(&self, hash: &H256) -> Option; + + /// Returns true if block queue is empty. + fn is_queue_empty(&self) -> bool { + self.queue_info().is_empty() + } + + /// Clear block queue and abort all import activity. + fn clear_queue(&self); + + /// Returns logs matching given filter. If one of the filtering block cannot be found, returns the block id that caused the error. + fn logs(&self, filter: Filter) -> Result, BlockId>; + + /// Replays a given transaction for inspection. + fn replay(&self, t: TransactionId, analytics: CallAnalytics) -> Result, CallError>; + + /// Replays all the transactions in a given block for inspection. + fn replay_block_transactions(&self, block: BlockId, analytics: CallAnalytics) -> Result)>>, CallError>; + + /// Returns traces matching given filter. + fn filter_traces(&self, filter: TraceFilter) -> Option>; + + /// Returns trace with given id. + fn trace(&self, trace: TraceId) -> Option; + + /// Returns traces created by transaction. + fn transaction_traces(&self, trace: TransactionId) -> Option>; + + /// Returns traces created by transaction from block. + fn block_traces(&self, trace: BlockId) -> Option>; + + /// Get last hashes starting from best block. + fn last_hashes(&self) -> LastHashes; + + /// List all ready transactions that should be propagated to other peers. + fn transactions_to_propagate(&self) -> Vec>; + + /// Sorted list of transaction gas prices from at least last sample_size blocks. + fn gas_price_corpus(&self, sample_size: usize) -> stats::Corpus { + let mut h = self.chain_info().best_block_hash; + let mut corpus = Vec::new(); + while corpus.is_empty() { + for _ in 0..sample_size { + let block = match self.block(BlockId::Hash(h)) { + Some(block) => block, + None => return corpus.into(), + }; + + if block.number() == 0 { + return corpus.into(); + } + for t in block.transaction_views().iter() { + corpus.push( t.gas_price() ) + } + h = block.parent_hash().clone(); + } + } + corpus.into() + } + + /// Get the preferred chain ID to sign on + fn signing_chain_id(&self) -> Option; + + /// Get the mode. + fn mode(&self) -> Mode; + + /// Set the mode. + fn set_mode(&self, mode: Mode); + + /// Get the chain spec name. + fn spec_name(&self) -> String; + + /// Set the chain via a spec name. + fn set_spec_name(&self, spec_name: String) -> Result<(), ()>; + + /// Disable the client from importing blocks. This cannot be undone in this session and indicates + /// that a subsystem has reason to believe this executable incapable of syncing the chain. + fn disable(&self); + + /// Returns engine-related extra info for `BlockId`. + fn block_extra_info(&self, id: BlockId) -> Option>; + + /// Returns engine-related extra info for `UncleId`. + fn uncle_extra_info(&self, id: UncleId) -> Option>; + + /// Returns information about pruning/data availability. + fn pruning_info(&self) -> PruningInfo; + + /// Schedule state-altering transaction to be executed on the next pending block. + fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error>; + + /// Get the address of the registry itself. + fn registrar_address(&self) -> Option
; +} + +/// resets the blockchain +pub trait BlockChainReset { + /// reset to best_block - n + fn reset(&self, num: u32) -> Result<(), String>; +} + + +/// Provides `latest_schedule` method +pub trait ScheduleInfo { + /// Returns latest schedule. + fn latest_schedule(&self) -> Schedule; +} + +/// Provides methods to access chain state +pub trait StateClient { + /// Type representing chain state + type State: StateInfo; + + /// Get a copy of the best block's state. + fn latest_state(&self) -> Self::State; + + /// Attempt to get a copy of a specific block's final state. + /// + /// This will not fail if given BlockId::Latest. + /// Otherwise, this can fail (but may not) if the DB prunes state or the block + /// is unknown. + fn state_at(&self, id: BlockId) -> Option; +} + +/// Extended client interface for providing proofs of the state. +pub trait ProvingBlockChainClient: BlockChainClient { + /// Prove account storage at a specific block id. + /// + /// Both provided keys assume a secure trie. + /// Returns a vector of raw trie nodes (in order from the root) proving the storage query. + fn prove_storage(&self, key1: H256, key2: H256, id: BlockId) -> Option<(Vec, H256)>; - /// Get the best block header. - fn best_block_header(&self) -> Header; + /// Prove account existence at a specific block id. + /// The key is the keccak hash of the account's address. + /// Returns a vector of raw trie nodes (in order from the root) proving the query. + fn prove_account(&self, key1: H256, id: BlockId) -> Option<(Vec, BasicAccount)>; - /// Get raw block data by block header hash. - fn block(&self, id: BlockId) -> Option; + /// Prove execution of a transaction at the given block. + /// Returns the output of the call and a vector of database items necessary + /// to reproduce it. + fn prove_transaction(&self, transaction: SignedTransaction, id: BlockId) -> Option<(Bytes, Vec)>; - /// Get address code hash at given block's state. - fn code_hash(&self, address: &Address, id: BlockId) -> Option; + /// Get an epoch change signal by block hash. + fn epoch_signal(&self, hash: H256) -> Option>; } diff --git a/ethcore/engine/Cargo.toml b/ethcore/engine/Cargo.toml new file mode 100644 index 00000000000..28b2e5527fd --- /dev/null +++ b/ethcore/engine/Cargo.toml @@ -0,0 +1,29 @@ +[package] +description = "Ethereum engine trait definition" +name = "engine" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0" + +[dependencies] +blockchain = { package = "ethcore-blockchain", path = "../blockchain" } +builtin = { path = "../builtin", package = "ethcore-builtin" } +bytes = { package = "parity-bytes", version = "0.1.0" } +client-traits = { path = "../client-traits" } +common-types = { path = "../types" } +ethereum-types = "0.6.0" +ethkey = { path = "../../accounts/ethkey" } +machine = { path = "../machine" } +vm = { path = "../vm" } + +# used from test-helpers +accounts = { package = "ethcore-accounts", path = "../../accounts", optional = true } +log = { version = "0.4.8", optional = true } + +[dev-dependencies] +accounts = { package = "ethcore-accounts", path = "../../accounts" } +log = "0.4.8" + +[features] +test-helpers = ["accounts", "log"] diff --git a/ethcore/engine/src/engine.rs b/ethcore/engine/src/engine.rs new file mode 100644 index 00000000000..33c25335792 --- /dev/null +++ b/ethcore/engine/src/engine.rs @@ -0,0 +1,418 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . + +//! Consensus engine specification and basic implementations. + +use std::sync::{Weak, Arc}; +use std::collections::BTreeMap; + +use builtin::Builtin; +use common_types::{ + BlockNumber, + ancestry_action::AncestryAction, + header::{Header, ExtendedHeader}, + engines::{ + Seal, SealingState, Headers, PendingTransitionStore, + params::CommonParams, + machine as machine_types, + machine::{AuxiliaryData, AuxiliaryRequest}, + }, + errors::{EthcoreError as Error, EngineError}, + transaction::{self, UnverifiedTransaction}, +}; +use client_traits::EngineClient; + +use ethereum_types::{H256, U256, Address}; +use ethkey::Signature; +use machine::{ + Machine, + executed_block::ExecutedBlock, +}; +use vm::{EnvInfo, Schedule, CallType, ActionValue}; + +use crate::{ + signer::EngineSigner, + snapshot::SnapshotComponents, +}; + +/// A system-calling closure. Enacts calls on a block's state from the system address. +pub type SystemCall<'a> = dyn FnMut(Address, Vec) -> Result, String> + 'a; + +/// A system-calling closure. Enacts calls on a block's state with code either from an on-chain contract, or hard-coded EVM or WASM (if enabled on-chain) codes. +pub type SystemOrCodeCall<'a> = dyn FnMut(SystemOrCodeCallKind, Vec) -> Result, String> + 'a; + +/// Kind of SystemOrCodeCall, this is either an on-chain address, or code. +#[derive(PartialEq, Debug, Clone)] +pub enum SystemOrCodeCallKind { + /// On-chain address. + Address(Address), + /// Hard-coded code. + Code(Arc>, H256), +} + +/// Default SystemOrCodeCall implementation. +pub fn default_system_or_code_call<'a>(machine: &'a Machine, block: &'a mut ExecutedBlock) -> impl FnMut(SystemOrCodeCallKind, Vec) -> Result, String> + 'a { + move |to, data| { + let result = match to { + SystemOrCodeCallKind::Address(address) => { + machine.execute_as_system( + block, + address, + U256::max_value(), + Some(data), + ) + }, + SystemOrCodeCallKind::Code(code, code_hash) => { + machine.execute_code_as_system( + block, + None, + Some(code), + Some(code_hash), + Some(ActionValue::Apparent(U256::zero())), + U256::max_value(), + Some(data), + Some(CallType::StaticCall), + ) + }, + }; + + result.map_err(|e| format!("{}", e)) + } +} + +/// Proof dependent on state. +pub trait StateDependentProof: Send + Sync { + /// Generate a proof, given the state. + fn generate_proof<'a>(&self, state: &machine_types::Call) -> Result, String>; + /// Check a proof generated elsewhere (potentially by a peer). + // `engine` needed to check state proofs, while really this should + // just be state machine params. + fn check_proof(&self, machine: &Machine, proof: &[u8]) -> Result<(), String>; +} + +/// Proof generated on epoch change. +pub enum Proof { + /// Known proof (extracted from signal) + Known(Vec), + /// State dependent proof. + WithState(Arc), +} + +/// Generated epoch verifier. +pub enum ConstructedVerifier<'a> { + /// Fully trusted verifier. + Trusted(Box), + /// Verifier unconfirmed. Check whether given finality proof finalizes given hash + /// under previous epoch. + Unconfirmed(Box, &'a [u8], H256), + /// Error constructing verifier. + Err(Error), +} + +impl<'a> ConstructedVerifier<'a> { + /// Convert to a result, indicating that any necessary confirmation has been done + /// already. + pub fn known_confirmed(self) -> Result, Error> { + match self { + ConstructedVerifier::Trusted(v) | ConstructedVerifier::Unconfirmed(v, _, _) => Ok(v), + ConstructedVerifier::Err(e) => Err(e), + } + } +} + +/// Results of a query of whether an epoch change occurred at the given block. +pub enum EpochChange { + /// Cannot determine until more data is passed. + Unsure(AuxiliaryRequest), + /// No epoch change. + No, + /// The epoch will change, with proof. + Yes(Proof), +} + +/// A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based. +/// Provides hooks into each of the major parts of block import. +pub trait Engine: Sync + Send { + /// The name of this engine. + fn name(&self) -> &str; + + /// Get access to the underlying state machine. + // TODO: decouple. + fn machine(&self) -> &Machine; + + /// The number of additional header fields required for this engine. + fn seal_fields(&self, _header: &Header) -> usize { 0 } + + /// Additional engine-specific information for the user/developer concerning `header`. + fn extra_info(&self, _header: &Header) -> BTreeMap { BTreeMap::new() } + + /// Maximum number of uncles a block is allowed to declare. + fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { 0 } + + /// Optional maximum gas limit. + fn maximum_gas_limit(&self) -> Option { None } + + /// Block transformation functions, before the transactions. + /// `epoch_begin` set to true if this block kicks off an epoch. + fn on_new_block( + &self, + _block: &mut ExecutedBlock, + _epoch_begin: bool, + ) -> Result<(), Error> { + Ok(()) + } + + /// Block transformation functions, after the transactions. + fn on_close_block( + &self, + _block: &mut ExecutedBlock, + _parent_header: &Header, + ) -> Result<(), Error> { + Ok(()) + } + + /// Allow mutating the header during seal generation. Currently only used by Clique. + fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { Ok(()) } + + /// Returns the engine's current sealing state. + fn sealing_state(&self) -> SealingState { SealingState::External } + + /// Attempt to seal the block internally. + /// + /// If `Some` is returned, then you get a valid seal. + /// + /// This operation is synchronous and may (quite reasonably) not be available, in which None will + /// be returned. + /// + /// It is fine to require access to state or a full client for this function, since + /// light clients do not generate seals. + fn generate_seal(&self, _block: &ExecutedBlock, _parent: &Header) -> Seal { Seal::None } + + /// Verify a locally-generated seal of a header. + /// + /// If this engine seals internally, + /// no checks have to be done here, since all internally generated seals + /// should be valid. + /// + /// Externally-generated seals (e.g. PoW) will need to be checked for validity. + /// + /// It is fine to require access to state or a full client for this function, since + /// light clients do not generate seals. + fn verify_local_seal(&self, header: &Header) -> Result<(), Error>; + + /// Phase 1 quick block verification. Only does checks that are cheap. Returns either a null `Ok` or a general error detailing the problem with import. + /// The verification module can optionally avoid checking the seal (`check_seal`), if seal verification is disabled this method won't be called. + fn verify_block_basic(&self, _header: &Header) -> Result<(), Error> { Ok(()) } + + /// Phase 2 verification. Perform costly checks such as transaction signatures. Returns either a null `Ok` or a general error detailing the problem with import. + /// The verification module can optionally avoid checking the seal (`check_seal`), if seal verification is disabled this method won't be called. + fn verify_block_unordered(&self, _header: &Header) -> Result<(), Error> { Ok(()) } + + /// Phase 3 verification. Check block information against parent. Returns either a null `Ok` or a general error detailing the problem with import. + fn verify_block_family(&self, _header: &Header, _parent: &Header) -> Result<(), Error> { Ok(()) } + + /// Phase 4 verification. Verify block header against potentially external data. + /// Should only be called when `register_client` has been called previously. + fn verify_block_external(&self, _header: &Header) -> Result<(), Error> { Ok(()) } + + /// Genesis epoch data. + fn genesis_epoch_data<'a>(&self, _header: &Header, _state: &machine_types::Call) -> Result, String> { Ok(Vec::new()) } + + /// Whether an epoch change is signalled at the given header but will require finality. + /// If a change can be enacted immediately then return `No` from this function but + /// `Yes` from `is_epoch_end`. + /// + /// If auxiliary data of the block is required, return an auxiliary request and the function will be + /// called again with them. + /// Return `Yes` or `No` when the answer is definitively known. + /// + /// Should not interact with state. + fn signals_epoch_end<'a>(&self, _header: &Header, _aux: AuxiliaryData<'a>) -> EpochChange { + EpochChange::No + } + + /// Whether a block is the end of an epoch. + /// + /// This either means that an immediate transition occurs or a block signalling transition + /// has reached finality. The `Headers` given are not guaranteed to return any blocks + /// from any epoch other than the current. The client must keep track of finality and provide + /// the latest finalized headers to check against the transition store. + /// + /// Return optional transition proof. + fn is_epoch_end( + &self, + _chain_head: &Header, + _finalized: &[H256], + _chain: &Headers
, + _transition_store: &PendingTransitionStore, + ) -> Option> { + None + } + + /// Whether a block is the end of an epoch. + /// + /// This either means that an immediate transition occurs or a block signalling transition + /// has reached finality. The `Headers` given are not guaranteed to return any blocks + /// from any epoch other than the current. This is a specialized method to use for light + /// clients since the light client doesn't track finality of all blocks, and therefore finality + /// for blocks in the current epoch is built inside this method by the engine. + /// + /// Return optional transition proof. + fn is_epoch_end_light( + &self, + _chain_head: &Header, + _chain: &Headers
, + _transition_store: &PendingTransitionStore, + ) -> Option> { + None + } + + /// Create an epoch verifier from validation proof and a flag indicating + /// whether finality is required. + fn epoch_verifier<'a>(&self, _header: &Header, _proof: &'a [u8]) -> ConstructedVerifier<'a> { + ConstructedVerifier::Trusted(Box::new(NoOp)) + } + + /// Populate a header's fields based on its parent's header. + /// Usually implements the chain scoring rule based on weight. + fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) { } + + /// Handle any potential consensus messages; + /// updating consensus state and potentially issuing a new one. + fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError> { Err(EngineError::UnexpectedMessage) } + + /// Register a component which signs consensus messages. + fn set_signer(&self, _signer: Box) {} + + /// Sign using the EngineSigner, to be used for consensus tx signing. + fn sign(&self, _hash: H256) -> Result { unimplemented!() } + + /// Add Client which can be used for sealing, potentially querying the state and sending messages. + fn register_client(&self, _client: Weak) {} + + /// Trigger next step of the consensus engine. + fn step(&self) {} + + /// Create a factory for building snapshot chunks and restoring from them. + /// Returning `None` indicates that this engine doesn't support snapshot creation. + fn snapshot_components(&self) -> Option> { + None + } + + /// Whether this engine supports warp sync. + fn supports_warp(&self) -> bool { + self.snapshot_components().is_some() + } + + /// Return a new open block header timestamp based on the parent timestamp. + fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64 { + use std::{time, cmp}; + + let now = time::SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap_or_default(); + cmp::max(now.as_secs() as u64, parent_timestamp + 1) + } + + /// Check whether the parent timestamp is valid. + fn is_timestamp_valid(&self, header_timestamp: u64, parent_timestamp: u64) -> bool { + header_timestamp > parent_timestamp + } + + /// Gather all ancestry actions. Called at the last stage when a block is committed. The Engine must guarantee that + /// the ancestry exists. + fn ancestry_actions(&self, _header: &Header, _ancestry: &mut dyn Iterator) -> Vec { + Vec::new() + } + + /// Returns author should used when executing tx's for this block. + fn executive_author(&self, header: &Header) -> Result { + Ok(*header.author()) + } + + /// Get the general parameters of the chain. + fn params(&self) -> &CommonParams; + + /// Get the EVM schedule for the given block number. + fn schedule(&self, block_number: BlockNumber) -> Schedule { + self.machine().schedule(block_number) + } + + /// Builtin-contracts for the chain.. + fn builtins(&self) -> &BTreeMap { + self.machine().builtins() + } + + /// Attempt to get a handle to a built-in contract. + /// Only returns references to activated built-ins. + fn builtin(&self, a: &Address, block_number: BlockNumber) -> Option<&Builtin> { + self.machine().builtin(a, block_number) + } + + /// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`. + fn maximum_extra_data_size(&self) -> usize { self.params().maximum_extra_data_size } + + /// The nonce with which accounts begin at given block. + fn account_start_nonce(&self, block: BlockNumber) -> U256 { + self.machine().account_start_nonce(block) + } + + /// The network ID that transactions should be signed with. + fn signing_chain_id(&self, env_info: &EnvInfo) -> Option { + self.machine().signing_chain_id(env_info) + } + + /// Perform basic/cheap transaction verification. + /// + /// This should include all cheap checks that can be done before + /// actually checking the signature, like chain-replay protection. + /// + /// NOTE This is done before the signature is recovered so avoid + /// doing any state-touching checks that might be expensive. + /// + /// TODO: Add flags for which bits of the transaction to check. + /// TODO: consider including State in the params. + fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> Result<(), transaction::Error> { + self.machine().verify_transaction_basic(t, header) + } + + /// Performs pre-validation of RLP decoded transaction before other processing + fn decode_transaction(&self, transaction: &[u8]) -> Result { + self.machine().decode_transaction(transaction) + } +} + +/// Verifier for all blocks within an epoch with self-contained state. +pub trait EpochVerifier: Send + Sync { + /// Lightly verify the next block header. + /// This may not be a header belonging to a different epoch. + fn verify_light(&self, _header: &Header) -> Result<(), Error> { Ok(()) } + + /// Perform potentially heavier checks on the next block header. + fn verify_heavy(&self, header: &Header) -> Result<(), Error> { + self.verify_light(header) + } + + /// Check a finality proof against this epoch verifier. + /// Returns `Some(hashes)` if the proof proves finality of these hashes. + /// Returns `None` if the proof doesn't prove anything. + fn check_finality_proof(&self, _proof: &[u8]) -> Option> { + None + } +} + +/// Special "no-op" verifier for stateless, epoch-less engines. +pub struct NoOp; + +impl EpochVerifier for NoOp {} diff --git a/ethcore/engine/src/lib.rs b/ethcore/engine/src/lib.rs new file mode 100644 index 00000000000..5b3c93bf649 --- /dev/null +++ b/ethcore/engine/src/lib.rs @@ -0,0 +1,37 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . + +//! This crate defines the Engine trait and related types. + +mod engine; +pub mod signer; +pub mod snapshot; + +pub use crate::engine::{ + Engine, + EpochVerifier, + StateDependentProof, + ConstructedVerifier, + EpochChange, + Proof, + SystemCall, + SystemOrCodeCall, + SystemOrCodeCallKind, + default_system_or_code_call, +}; + +#[cfg(any(test, feature = "test-helpers"))] +pub mod test_helpers; diff --git a/ethcore/src/engines/signer.rs b/ethcore/engine/src/signer.rs similarity index 62% rename from ethcore/src/engines/signer.rs rename to ethcore/engine/src/signer.rs index 196c535fe76..1e932feefc3 100644 --- a/ethcore/src/engines/signer.rs +++ b/ethcore/engine/src/signer.rs @@ -44,36 +44,3 @@ impl EngineSigner for Signer { self.0.address() } } - -#[cfg(test)] -mod test_signer { - use std::sync::Arc; - - use ethkey::Password; - use accounts::{self, AccountProvider, SignError}; - - use super::*; - - impl EngineSigner for (Arc, Address, Password) { - fn sign(&self, hash: H256) -> Result { - match self.0.sign(self.1, Some(self.2.clone()), hash) { - Err(SignError::NotUnlocked) => unreachable!(), - Err(SignError::NotFound) => Err(ethkey::Error::InvalidAddress), - Err(SignError::SStore(accounts::Error::EthKey(err))) => Err(err), - Err(SignError::SStore(accounts::Error::EthKeyCrypto(err))) => { - warn!("Low level crypto error: {:?}", err); - Err(ethkey::Error::InvalidSecret) - }, - Err(SignError::SStore(err)) => { - warn!("Error signing for engine: {:?}", err); - Err(ethkey::Error::InvalidSignature) - }, - Ok(ok) => Ok(ok), - } - } - - fn address(&self) -> Address { - self.1 - } - } -} diff --git a/ethcore/engine/src/snapshot.rs b/ethcore/engine/src/snapshot.rs new file mode 100644 index 00000000000..8499b97bf2d --- /dev/null +++ b/ethcore/engine/src/snapshot.rs @@ -0,0 +1,90 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . + +//! This module contains traits used while creating/restoring snapshots. They +//! are here because they use and are used by the Engine trait itself. + +use std::sync::{Arc, atomic::AtomicBool}; + +use ethereum_types::H256; + +use blockchain::{BlockChain, BlockChainDB}; +use common_types::{ + errors::{EthcoreError as Error, SnapshotError}, + snapshot::{ManifestData, ChunkSink, Progress}, +}; + +use crate::engine::Engine; + +/// Restore from secondary snapshot chunks. +pub trait Rebuilder: Send { + /// Feed a chunk, potentially out of order. + /// + /// Check `abort_flag` periodically while doing heavy work. If set to `false`, should bail with + /// `Error::RestorationAborted`. + fn feed( + &mut self, + chunk: &[u8], + engine: &dyn Engine, + abort_flag: &AtomicBool, + ) -> Result<(), Error>; + + /// Finalize the restoration. Will be done after all chunks have been + /// fed successfully. + /// + /// This should apply the necessary "glue" between chunks, + /// and verify against the restored state. + fn finalize(&mut self) -> Result<(), Error>; +} + +/// Components necessary for snapshot creation and restoration. +pub trait SnapshotComponents: Send { + /// Create secondary snapshot chunks; these corroborate the state data + /// in the state chunks. + /// + /// Chunks shouldn't exceed the given preferred size, and should be fed + /// uncompressed into the sink. + /// + /// This will vary by consensus engine, so it's exposed as a trait. + fn chunk_all( + &mut self, + chain: &BlockChain, + block_at: H256, + chunk_sink: &mut ChunkSink, + progress: &Progress, + preferred_size: usize, + ) -> Result<(), SnapshotError>; + + /// Create a rebuilder, which will have chunks fed into it in arbitrary + /// order and then be finalized. + /// + /// The manifest, a database, and fresh `BlockChain` are supplied. + /// + /// The engine passed to the `Rebuilder` methods will be the same instance + /// that created the `SnapshotComponents`. + fn rebuilder( + &self, + chain: BlockChain, + db: Arc, + manifest: &ManifestData, + ) -> Result, Error>; + + /// Minimum supported snapshot version number. + fn min_supported_version(&self) -> u64; + + /// Current version number + fn current_version(&self) -> u64; +} diff --git a/ethcore/engine/src/test_helpers.rs b/ethcore/engine/src/test_helpers.rs new file mode 100644 index 00000000000..92ba66ff480 --- /dev/null +++ b/ethcore/engine/src/test_helpers.rs @@ -0,0 +1,49 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . + +//! Test helpers for engine related tests + +use std::sync::Arc; + +use ethereum_types::{Address, H256}; +use ethkey::{Password, Signature}; +use log::warn; +use accounts::{self, AccountProvider, SignError}; + +use crate::signer::EngineSigner; + +impl EngineSigner for (Arc, Address, Password) { + fn sign(&self, hash: H256) -> Result { + match self.0.sign(self.1, Some(self.2.clone()), hash) { + Err(SignError::NotUnlocked) => unreachable!(), + Err(SignError::NotFound) => Err(ethkey::Error::InvalidAddress), + Err(SignError::SStore(accounts::Error::EthKey(err))) => Err(err), + Err(SignError::SStore(accounts::Error::EthKeyCrypto(err))) => { + warn!("Low level crypto error: {:?}", err); + Err(ethkey::Error::InvalidSecret) + }, + Err(SignError::SStore(err)) => { + warn!("Error signing for engine: {:?}", err); + Err(ethkey::Error::InvalidSignature) + }, + Ok(ok) => Ok(ok), + } + } + + fn address(&self) -> Address { + self.1 + } +} diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 83494b37ac7..19911db39c2 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -12,6 +12,7 @@ parity-bytes = "0.1" client-traits = { path = "../client-traits" } common-types = { path = "../types" } derive_more = "0.14.0" +engine = { path = "../engine" } ethcore = { path = ".."} ethcore-db = { path = "../db" } ethcore-blockchain = { path = "../blockchain" } diff --git a/ethcore/light/src/client/fetch.rs b/ethcore/light/src/client/fetch.rs index 602be8fc3a6..cbb5d3e2279 100644 --- a/ethcore/light/src/client/fetch.rs +++ b/ethcore/light/src/client/fetch.rs @@ -18,10 +18,12 @@ use std::sync::Arc; -use common_types::encoded; -use common_types::header::Header; -use common_types::receipt::Receipt; -use ethcore::engines::{Engine, StateDependentProof}; +use common_types::{ + header::Header, + encoded, + receipt::Receipt, +}; +use engine::{Engine, StateDependentProof}; use ethereum_types::H256; use futures::future::IntoFuture; diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index 3b9d2beec4b..92207139a0e 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -33,11 +33,14 @@ use cht; use common_types::{ block_status::BlockStatus, encoded, + engines::epoch::{ + Transition as EpochTransition, + PendingTransition as PendingEpochTransition, + }, errors::{EthcoreError as Error, BlockError, EthcoreResult}, header::Header, ids::BlockId, }; -use ethcore::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; use ethcore::spec::{Spec, SpecHardcodedSync}; use ethereum_types::{H256, H264, U256}; use parity_util_mem::{MallocSizeOf, MallocSizeOfOps}; diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index 6d4dd5a0b09..73e512b10b2 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -18,8 +18,8 @@ use std::sync::{Weak, Arc}; +use engine::{Engine, EpochChange, Proof}; use ethcore::client::{ClientReport, EnvInfo, ClientIoMessage}; -use ethcore::engines::{epoch, Engine, EpochChange, EpochTransition, Proof}; use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::spec::{Spec, SpecHardcodedSync}; use io::IoChannel; @@ -31,11 +31,12 @@ use common_types::{ block_status::BlockStatus, blockchain_info::BlockChainInfo, encoded, + engines::epoch::{Transition as EpochTransition, PendingTransition}, errors::EthcoreError as Error, errors::EthcoreResult, header::Header, ids::BlockId, - verification_queue_info::VerificationQueueInfo as BlockQueueInfo, + verification::VerificationQueueInfo as BlockQueueInfo, }; use kvdb::KeyValueDB; @@ -528,7 +529,7 @@ impl Client { }; let mut batch = self.db.transaction(); - self.chain.insert_pending_transition(&mut batch, header.hash(), &epoch::PendingTransition { + self.chain.insert_pending_transition(&mut batch, header.hash(), &PendingTransition { proof, }); self.db.write_buffered(batch); @@ -616,13 +617,13 @@ impl LightChainClient for Client { } } -impl ::ethcore::client::ChainInfo for Client { +impl client_traits::ChainInfo for Client { fn chain_info(&self) -> BlockChainInfo { Client::chain_info(self) } } -impl ::ethcore::client::EngineClient for Client { +impl client_traits::EngineClient for Client { fn update_sealing(&self) { } fn submit_seal(&self, _block_hash: H256, _seal: Vec>) { } fn broadcast_consensus_message(&self, _message: Vec) { } @@ -635,7 +636,7 @@ impl ::ethcore::client::EngineClient for Client { }) } - fn as_full_client(&self) -> Option<&dyn (::ethcore::client::BlockChainClient)> { + fn as_full_client(&self) -> Option<&dyn (client_traits::BlockChainClient)> { None } diff --git a/ethcore/light/src/lib.rs b/ethcore/light/src/lib.rs index 64b7f7d69dc..9b9c4053315 100644 --- a/ethcore/light/src/lib.rs +++ b/ethcore/light/src/lib.rs @@ -56,6 +56,7 @@ extern crate log; extern crate bincode; extern crate client_traits; extern crate common_types; +extern crate engine; extern crate ethcore_blockchain; extern crate ethcore_db; extern crate ethcore_io as io; diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index f74d2e492e1..cff0b63fc26 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -24,7 +24,7 @@ use common_types::basic_account::BasicAccount; use common_types::encoded; use common_types::receipt::Receipt; use common_types::transaction::SignedTransaction; -use ethcore::engines::{Engine, StateDependentProof}; +use engine::{Engine, StateDependentProof}; use ethcore::executive_state::{ProvedExecution, self}; use ethereum_types::{H256, U256, Address}; use ethtrie::{TrieError, TrieDB}; @@ -1099,8 +1099,8 @@ mod tests { use trie::Recorder; use hash::keccak; - use ethcore::client::{BlockChainClient, TestBlockChainClient, EachBlockWith}; - use client_traits::BlockInfo; + use ethcore::client::{TestBlockChainClient, EachBlockWith}; + use client_traits::{BlockInfo, BlockChainClient}; use common_types::header::Header; use common_types::encoded; use common_types::receipt::{Receipt, TransactionOutcome}; diff --git a/ethcore/light/src/provider.rs b/ethcore/light/src/provider.rs index 5e9533d5bc5..c44bf59b398 100644 --- a/ethcore/light/src/provider.rs +++ b/ethcore/light/src/provider.rs @@ -25,8 +25,12 @@ use common_types::{ ids::BlockId, transaction::PendingTransaction, }; -use ethcore::client::{BlockChainClient, ProvingBlockChainClient, ChainInfo}; -use client_traits::BlockInfo as ClientBlockInfo; +use client_traits::{ + BlockChainClient, + BlockInfo as ClientBlockInfo, + ChainInfo, + ProvingBlockChainClient, +}; use ethereum_types::H256; use parking_lot::RwLock; diff --git a/ethcore/machine/src/executed.rs b/ethcore/machine/src/executed.rs index 42c165bcb96..b34f264ce93 100644 --- a/ethcore/machine/src/executed.rs +++ b/ethcore/machine/src/executed.rs @@ -16,58 +16,14 @@ //! Transaction execution format module. -use ethereum_types::{U256, Address}; -use parity_bytes::Bytes; -use vm; use trace::{VMTrace, FlatTrace}; use common_types::{ - state_diff::StateDiff, - log_entry::LogEntry, + engines::machine, errors::ExecutionError, }; -/// Transaction execution receipt. -#[derive(Debug, PartialEq, Clone)] -pub struct Executed { - /// True if the outer call/create resulted in an exceptional exit. - pub exception: Option, - - /// Gas paid up front for execution of transaction. - pub gas: U256, - - /// Gas used during execution of transaction. - pub gas_used: U256, - - /// Gas refunded after the execution of transaction. - /// To get gas that was required up front, add `refunded` and `gas_used`. - pub refunded: U256, - - /// Cumulative gas used in current block so far. - /// - /// `cumulative_gas_used = gas_used(t0) + gas_used(t1) + ... gas_used(tn)` - /// - /// where `tn` is current transaction. - pub cumulative_gas_used: U256, - - /// Vector of logs generated by transaction. - pub logs: Vec, - - /// Addresses of contracts created during execution of transaction. - /// Ordered from earliest creation. - /// - /// eg. sender creates contract A and A in constructor creates contract B - /// - /// B creation ends first, and it will be the first element of the vector. - pub contracts_created: Vec
, - /// Transaction output. - pub output: Bytes, - /// The trace of this transaction. - pub trace: Vec, - /// The VM trace of this transaction. - pub vm_trace: Option, - /// The state diff, if we traced it. - pub state_diff: Option, -} +/// /// Transaction execution receipt, parametrised with convenient defaults. +pub type Executed = machine::Executed; /// Transaction execution result. pub type ExecutionResult = Result, ExecutionError>; diff --git a/ethcore/machine/src/executive.rs b/ethcore/machine/src/executive.rs index c49562dce3a..81b92599ca9 100644 --- a/ethcore/machine/src/executive.rs +++ b/ethcore/machine/src/executive.rs @@ -36,14 +36,14 @@ use trace::{self, Tracer, VMTracer}; use common_types::{ errors::ExecutionError, transaction::{Action, SignedTransaction}, + engines::machine::Executed, }; use crate::{ Machine, substate::Substate, - externalities::{Externalities, OutputPolicy, OriginInfo}, // todo: make explicit + externalities::{Externalities, OutputPolicy, OriginInfo}, transaction_ext::Transaction, - executed::Executed, }; #[cfg(debug_assertions)] diff --git a/ethcore/machine/src/test_helpers.rs b/ethcore/machine/src/test_helpers.rs index 49394d727bf..2182212b6c8 100644 --- a/ethcore/machine/src/test_helpers.rs +++ b/ethcore/machine/src/test_helpers.rs @@ -20,7 +20,6 @@ use common_types::engines::params::CommonParams; use ethjson; use crate::Machine; - pub fn load_machine(reader: &[u8]) -> Machine { let spec = ethjson::spec::Spec::load(reader).expect("chain spec is invalid"); diff --git a/ethcore/machine/src/tx_filter.rs b/ethcore/machine/src/tx_filter.rs index b688668d408..76a5d571a1b 100644 --- a/ethcore/machine/src/tx_filter.rs +++ b/ethcore/machine/src/tx_filter.rs @@ -153,12 +153,13 @@ mod test { use tempdir::TempDir; use ethereum_types::{U256, Address}; + use client_traits::BlockChainClient; use common_types::{ ids::BlockId, transaction::{Transaction, Action} }; use ethcore::{ - client::{BlockChainClient, Client, ClientConfig}, + client::{Client, ClientConfig}, spec::Spec, miner::Miner, test_helpers, diff --git a/ethcore/node-filter/Cargo.toml b/ethcore/node-filter/Cargo.toml index e174e6189c7..73a8612523d 100644 --- a/ethcore/node-filter/Cargo.toml +++ b/ethcore/node-filter/Cargo.toml @@ -7,6 +7,7 @@ version = "1.12.0" authors = ["Parity Technologies "] [dependencies] +client-traits = { path = "../client-traits" } common-types = { path = "../types" } ethcore = { path = ".."} ethcore-network = { path = "../../util/network" } diff --git a/ethcore/node-filter/src/lib.rs b/ethcore/node-filter/src/lib.rs index 2886a58e3f3..2c4313c37f0 100644 --- a/ethcore/node-filter/src/lib.rs +++ b/ethcore/node-filter/src/lib.rs @@ -16,6 +16,7 @@ //! Smart contract based node filter. +extern crate client_traits; extern crate common_types; extern crate ethabi; extern crate ethcore; @@ -25,8 +26,6 @@ extern crate ethereum_types; extern crate lru_cache; extern crate parking_lot; -#[macro_use] -extern crate ethabi_derive; #[macro_use] extern crate ethabi_contract; #[cfg(test)] @@ -42,7 +41,8 @@ use std::collections::{HashMap, VecDeque}; use std::sync::Weak; use common_types::ids::BlockId; -use ethcore::client::{BlockChainClient, ChainNotify, NewBlocks}; +use ethcore::client::{ChainNotify, NewBlocks}; +use client_traits::BlockChainClient; use ethereum_types::{H256, Address}; use ethabi::FunctionOutputDecoder; use network::{ConnectionFilter, ConnectionDirection}; @@ -54,7 +54,7 @@ use_contract!(peer_set, "res/peer_set.json"); /// Connection filter that uses a contract to manage permissions. pub struct NodeFilter { - client: Weak, + client: Weak, contract_address: Address, cache: RwLock } @@ -128,8 +128,10 @@ impl ChainNotify for NodeFilter { #[cfg(test)] mod test { use std::sync::{Arc, Weak}; + + use client_traits::BlockChainClient; use ethcore::spec::Spec; - use ethcore::client::{BlockChainClient, Client, ClientConfig}; + use ethcore::client::{Client, ClientConfig}; use ethcore::miner::Miner; use ethcore::test_helpers; use network::{ConnectionDirection, ConnectionFilter, NodeId}; diff --git a/ethcore/private-tx/src/encryptor.rs b/ethcore/private-tx/src/encryptor.rs index 323f44a692e..d62ba546b6a 100644 --- a/ethcore/private-tx/src/encryptor.rs +++ b/ethcore/private-tx/src/encryptor.rs @@ -81,7 +81,7 @@ pub struct SecretStoreEncryptor { config: EncryptorConfig, client: FetchClient, sessions: Mutex>, - signer: Arc, + signer: Arc, } impl SecretStoreEncryptor { @@ -89,7 +89,7 @@ impl SecretStoreEncryptor { pub fn new( config: EncryptorConfig, client: FetchClient, - signer: Arc, + signer: Arc, ) -> Result { Ok(SecretStoreEncryptor { config, diff --git a/ethcore/private-tx/src/lib.rs b/ethcore/private-tx/src/lib.rs index ebbfb191875..283df9b7a8e 100644 --- a/ethcore/private-tx/src/lib.rs +++ b/ethcore/private-tx/src/lib.rs @@ -91,11 +91,12 @@ use ethkey::{Signature, recover, public_to_address}; use io::IoChannel; use machine::{ executive::{Executive, TransactOptions, contract_address as ethcore_contract_address}, - executed::Executed, + executed::Executed as FlatExecuted, }; use types::{ ids::BlockId, - transaction::{SignedTransaction, Transaction, Action, UnverifiedTransaction} + transaction::{SignedTransaction, Transaction, Action, UnverifiedTransaction}, + engines::machine::Executed, }; use ethcore::client::{ Client, ChainNotify, NewBlocks, ChainMessageType, ClientIoMessage, Call @@ -307,7 +308,7 @@ impl Provider { nonce_cache, engine, local_accounts, - None, // refuse_service_transactions = true + None, // refuse_service_transactions = true ) } @@ -456,7 +457,7 @@ impl Provider { } } - fn last_required_signature(&self, desc: &PrivateTransactionSigningDesc, sign: Signature) -> Result<(bool, Address), Error> { + fn last_required_signature(&self, desc: &PrivateTransactionSigningDesc, sign: Signature) -> Result<(bool, Address), Error> { let state_hash = self.calculate_state_hash(&desc.state, desc.contract_nonce); match recover(&sign, &state_hash) { Ok(public) => { @@ -702,7 +703,7 @@ impl Provider { } /// Call into private contract. - pub fn private_call(&self, block: BlockId, transaction: &SignedTransaction) -> Result { + pub fn private_call(&self, block: BlockId, transaction: &SignedTransaction) -> Result { let result = self.execute_private(transaction, TransactOptions::with_no_tracing(), block)?; Ok(result.result) } diff --git a/ethcore/private-tx/tests/private_contract.rs b/ethcore/private-tx/tests/private_contract.rs index 5d144e787a4..e4ee445df11 100644 --- a/ethcore/private-tx/tests/private_contract.rs +++ b/ethcore/private-tx/tests/private_contract.rs @@ -16,6 +16,7 @@ //! Contract for private transactions tests. +extern crate client_traits; extern crate common_types as types; extern crate env_logger; extern crate ethcore; @@ -36,11 +37,11 @@ use types::ids::BlockId; use types::transaction::{Transaction, Action}; use ethcore::{ CreateContractAddress, - client::BlockChainClient, test_helpers::{generate_dummy_client, push_block_with_transactions}, miner::Miner, spec, }; +use client_traits::BlockChainClient; use ethkey::{Secret, KeyPair, Signature}; use machine::executive::contract_address; use hash::keccak; diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 2e4d050f632..2ed86bb66bf 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -37,7 +37,7 @@ use std::sync::Arc; use bytes::Bytes; use ethereum_types::{H256, U256, Address, Bloom}; -use engines::Engine; +use engine::Engine; use trie_vm_factories::Factories; use state_db::StateDB; use account_state::State; @@ -485,17 +485,19 @@ pub fn enact_verified( mod tests { use test_helpers::get_temp_state_db; use super::*; - use engines::Engine; + use engine::Engine; use vm::LastHashes; use trie_vm_factories::Factories; use state_db::StateDB; use ethereum_types::Address; use std::sync::Arc; - use verification::queue::kind::blocks::Unverified; - use types::transaction::SignedTransaction; use types::{ - header::Header, view, views::BlockView, errors::EthcoreError as Error, + header::Header, + transaction::SignedTransaction, + view, + views::BlockView, + verification::Unverified, }; use hash_db::EMPTY_PREFIX; use crate::spec; diff --git a/ethcore/src/client/ancient_import.rs b/ethcore/src/client/ancient_import.rs index 22f13ff5388..c25c5a599a4 100644 --- a/ethcore/src/client/ancient_import.rs +++ b/ethcore/src/client/ancient_import.rs @@ -18,7 +18,7 @@ use std::sync::Arc; -use engines::{Engine, EpochVerifier}; +use engine::{Engine, EpochVerifier}; use blockchain::BlockChain; use parking_lot::RwLock; diff --git a/ethcore/src/client/bad_blocks.rs b/ethcore/src/client/bad_blocks.rs index 6af24cc4093..5df225c5b66 100644 --- a/ethcore/src/client/bad_blocks.rs +++ b/ethcore/src/client/bad_blocks.rs @@ -21,7 +21,7 @@ use ethereum_types::H256; use itertools::Itertools; use memory_cache::MemoryLruCache; use parking_lot::RwLock; -use verification::queue::kind::blocks::Unverified; +use types::verification::Unverified; /// Recently seen bad blocks. pub struct BadBlocks { diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 67003839954..f2a03144df9 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -39,20 +39,18 @@ use hash_db::EMPTY_PREFIX; use block::{LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock}; use client::ancient_import::AncientVerifier; use client::{ - Nonce, Balance, ChainInfo, TransactionInfo, - ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock, - BroadcastProposalBlock, ImportBlock, StateOrBlock, StateInfo, StateClient, Call, - AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter, - BlockChainReset + ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock, StateInfo, + Call, BlockProducer, SealedBlockImporter, ChainNotify, EngineInfo, + ClientConfig, NewBlocks, ChainRoute, ChainMessageType, bad_blocks, ClientIoMessage, }; -use client::{ - ClientConfig, BlockChainClient, - TraceFilter, CallAnalytics, Mode, - ChainNotify, NewBlocks, ChainRoute, PruningInfo, ProvingBlockChainClient, EngineInfo, ChainMessageType, - IoClient, BadBlocks, bad_blocks, ClientIoMessage, +use client_traits::{ + BlockInfo, ScheduleInfo, StateClient, BlockChainReset, + Nonce, Balance, ChainInfo, TransactionInfo, ImportBlock, + AccountData, BlockChain as BlockChainTrait, BlockChainClient, + IoClient, BadBlocks, ProvingBlockChainClient, + StateOrBlock }; -use client_traits::BlockInfo; -use engines::{Engine, EpochTransition, ForkChoice}; +use engine::Engine; use machine::{ executed::Executed, executive::{Executive, TransactOptions, contract_address}, @@ -70,11 +68,14 @@ use types::{ ancestry_action::AncestryAction, BlockNumber, block::PreverifiedBlock, + block_status::BlockStatus, + blockchain_info::BlockChainInfo, encoded, engines::{ + ForkChoice, SealingState, MAX_UNCLE_AGE, - epoch::PendingTransition, + epoch::{PendingTransition, Transition as EpochTransition}, machine::{AuxiliaryData, Call as MachineCall}, }, errors::{EngineError, ExecutionError, BlockError, EthcoreError, SnapshotError, ImportError, EthcoreResult}, @@ -84,10 +85,15 @@ use types::{ log_entry::LocalizedLogEntry, receipt::{Receipt, LocalizedReceipt}, header::Header, + snapshot::Progress, + trace_filter::Filter as TraceFilter, + pruning_info::PruningInfo, + call_analytics::CallAnalytics, + client_types::Mode, + verification::{Unverified, VerificationQueueInfo as BlockQueueInfo}, }; use verification::queue::kind::BlockLike; -use verification::queue::kind::blocks::Unverified; use verification::{Verifier, BlockQueue}; use verification; use ansi_term::Colour; @@ -95,9 +101,6 @@ use ethtrie::Layout; // re-export pub use blockchain::CacheSize as BlockChainCacheSize; use db::{Writable, Readable, keys::BlockDetails}; -pub use types::blockchain_info::BlockChainInfo; -pub use types::block_status::BlockStatus; -pub use types::verification_queue_info::VerificationQueueInfo as BlockQueueInfo; use_contract!(registry, "res/contracts/registrar.json"); @@ -604,7 +607,7 @@ impl Importer { state_db: &StateDB, client: &Client, ) -> EthcoreResult> { - use engines::EpochChange; + use engine::EpochChange; let hash = header.hash(); let auxiliary = AuxiliaryData { @@ -614,7 +617,7 @@ impl Importer { match self.engine.signals_epoch_end(header, auxiliary) { EpochChange::Yes(proof) => { - use engines::Proof; + use engine::Proof; let proof = match proof { Proof::Known(proof) => proof, @@ -1163,7 +1166,7 @@ impl Client { &self, writer: W, at: BlockId, - p: &snapshot::Progress, + p: &Progress, ) -> Result<(), EthcoreError> { let db = self.state_db.read().journal_db().boxed_clone(); let best_block_number = self.chain_info().best_block_number; @@ -1275,6 +1278,7 @@ impl Client { t: &SignedTransaction, analytics: CallAnalytics, ) -> Result { + use types::engines::machine::Executed as RawExecuted; fn call( state: &mut State, env_info: &EnvInfo, @@ -1282,7 +1286,7 @@ impl Client { state_diff: bool, transaction: &SignedTransaction, options: TransactOptions, - ) -> Result, CallError> where + ) -> Result, CallError> where T: trace::Tracer, V: trace::VMTracer, { @@ -2507,7 +2511,7 @@ impl SealedBlockImporter for Client {} impl ::miner::TransactionVerifierClient for Client {} impl ::miner::BlockChainClient for Client {} -impl super::traits::EngineClient for Client { +impl client_traits::EngineClient for Client { fn update_sealing(&self) { self.importer.miner.update_sealing(self) } @@ -2523,7 +2527,7 @@ impl super::traits::EngineClient for Client { self.notify(|notify| notify.broadcast(ChainMessageType::Consensus(message.clone()))); } - fn epoch_transition_for(&self, parent_hash: H256) -> Option<::engines::EpochTransition> { + fn epoch_transition_for(&self, parent_hash: H256) -> Option { self.chain.read().epoch_transition_for(parent_hash) } @@ -2657,9 +2661,10 @@ impl IoChannelQueue { #[cfg(test)] mod tests { use ethereum_types::{H256, Address}; - use client::{BlockChainClient, ChainInfo}; + use client_traits::{BlockChainClient, ChainInfo}; use types::{ encoded, + engines::ForkChoice, ids::{BlockId, TransactionId}, log_entry::{LogEntry, LocalizedLogEntry}, receipt::{Receipt, LocalizedReceipt, TransactionOutcome}, @@ -2690,7 +2695,7 @@ mod tests { thread::spawn(move || { let mut batch = DBTransaction::new(); another_client.chain.read().insert_block(&mut batch, encoded::Block::new(new_block), Vec::new(), ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: ForkChoice::New, is_finalized: false, }); go_thread.store(true, Ordering::SeqCst); diff --git a/ethcore/src/client/config.rs b/ethcore/src/client/config.rs index 59fc4f8135e..8397344a214 100644 --- a/ethcore/src/client/config.rs +++ b/ethcore/src/client/config.rs @@ -15,11 +15,11 @@ // along with Parity Ethereum. If not, see . use std::str::FromStr; -use std::fmt::{Display, Formatter, Error as FmtError}; use verification::{VerifierType, QueueConfig}; use journaldb; use snapshot::SnapshotConfiguration; +use types::client_types::Mode; pub use std::time::Duration; pub use blockchain::Config as BlockChainConfig; @@ -56,32 +56,6 @@ impl FromStr for DatabaseCompactionProfile { } } -/// Operating mode for the client. -#[derive(Debug, Eq, PartialEq, Clone)] -pub enum Mode { - /// Always on. - Active, - /// Goes offline after client is inactive for some (given) time, but - /// comes back online after a while of inactivity. - Passive(Duration, Duration), - /// Goes offline after client is inactive for some (given) time and - /// stays inactive. - Dark(Duration), - /// Always off. - Off, -} - -impl Display for Mode { - fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { - match *self { - Mode::Active => write!(f, "active"), - Mode::Passive(..) => write!(f, "passive"), - Mode::Dark(..) => write!(f, "dark"), - Mode::Off => write!(f, "offline"), - } - } -} - /// Client configuration. Includes configs for all sub-systems. #[derive(Debug, PartialEq, Clone)] pub struct ClientConfig { diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 8ac833f0da4..cd5dd473598 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -26,8 +26,8 @@ mod io_message; #[cfg(any(test, feature = "test-helpers"))] mod test_client; -pub use self::client::*; -pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType}; +pub use self::client::{Client, ClientReport}; +pub use self::config::{ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType}; #[cfg(any(test, feature = "test-helpers"))] pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; pub use self::io_message::ClientIoMessage; @@ -35,17 +35,11 @@ pub use self::io_message::ClientIoMessage; pub use self::test_client::{TestBlockChainClient, EachBlockWith, TestState}; pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType}; pub use self::traits::{ - Nonce, Balance, ChainInfo, ReopenBlock, PrepareOpenBlock, TransactionInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, - StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, BadBlocks, - BlockChainReset, BlockChainClient, EngineClient, ProvingBlockChainClient, IoClient + ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock, + Call, EngineInfo, BlockProducer, SealedBlockImporter, }; pub use account_state::state::StateInfo; -use types::{ - trace_filter::Filter as TraceFilter, - pruning_info::PruningInfo, - call_analytics::CallAnalytics, -}; pub use vm::{LastHashes, EnvInfo}; diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 801215cb2e7..42d30bbc22c 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -40,6 +40,7 @@ use rustc_hex::FromHex; use types::{ BlockNumber, encoded, + engines::epoch::Transition as EpochTransition, ids::{BlockId, TransactionId, UncleId, TraceId}, basic_account::BasicAccount, errors::{EthcoreError as Error, EthcoreResult}, @@ -53,20 +54,26 @@ use types::{ receipt::{Receipt, LocalizedReceipt, TransactionOutcome}, view, views::BlockView, + verification::Unverified, + client_types::Mode, + blockchain_info::BlockChainInfo, + block_status::BlockStatus, }; use vm::Schedule; use block::{OpenBlock, SealedBlock, ClosedBlock}; use call_contract::{CallContract, RegistryInfo}; use client::{ - Nonce, Balance, ChainInfo, ReopenBlock, TransactionInfo, - PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, Mode, - LastHashes, ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, - ImportBlock, StateOrBlock, Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer, - SealedBlockImporter, IoClient, BadBlocks + ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock, Call, + EngineInfo, BlockProducer, SealedBlockImporter, + LastHashes, }; -use client_traits::BlockInfo; -use engines::Engine; +use client_traits::{ + BlockInfo, Nonce, Balance, ChainInfo, TransactionInfo, BlockChainClient, ImportBlock, + AccountData, BlockChain, IoClient, BadBlocks, ScheduleInfo, StateClient, ProvingBlockChainClient, + StateOrBlock +}; +use engine::Engine; use machine::executed::Executed; use journaldb; use miner::{self, Miner, MinerService}; @@ -75,7 +82,6 @@ use account_state::state::StateInfo; use state_db::StateDB; use trace::LocalizedTrace; use verification::queue::QueueInfo as BlockQueueInfo; -use verification::queue::kind::blocks::Unverified; /// Test client. pub struct TestBlockChainClient { @@ -945,7 +951,7 @@ impl ProvingBlockChainClient for TestBlockChainClient { } } -impl super::traits::EngineClient for TestBlockChainClient { +impl client_traits::EngineClient for TestBlockChainClient { fn update_sealing(&self) { self.miner.update_sealing(self) } @@ -959,7 +965,7 @@ impl super::traits::EngineClient for TestBlockChainClient { fn broadcast_consensus_message(&self, _message: Bytes) {} - fn epoch_transition_for(&self, _block_hash: H256) -> Option<::engines::EpochTransition> { + fn epoch_transition_for(&self, _block_hash: H256) -> Option { None } diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index ccb7d38a716..36ce4144497 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -14,138 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use std::collections::BTreeMap; -use std::sync::Arc; - -use blockchain::{BlockReceipts, TreeRoute, BlockProvider}; use bytes::Bytes; -use call_contract::{CallContract, RegistryInfo}; -use client_traits::BlockInfo; -use ethcore_miner::pool::VerifiedTransaction; use ethereum_types::{H256, U256, Address}; -use evm::Schedule; -use itertools::Itertools; -use kvdb::DBValue; use types::{ - transaction::{self, LocalizedTransaction, SignedTransaction, CallError}, - BlockNumber, - basic_account::BasicAccount, - block_status::BlockStatus, - blockchain_info::BlockChainInfo, + transaction::{SignedTransaction, CallError}, call_analytics::CallAnalytics, - encoded, errors::EthcoreError as Error, errors::EthcoreResult, - filter::Filter, header::Header, - ids::*, - log_entry::LocalizedLogEntry, - pruning_info::PruningInfo, - receipt::LocalizedReceipt, - trace_filter::Filter as TraceFilter, - verification_queue_info::VerificationQueueInfo as BlockQueueInfo, }; -use vm::LastHashes; use block::{OpenBlock, SealedBlock, ClosedBlock}; -use client::Mode; -use engines::Engine; +use engine::Engine; use machine::executed::Executed; use account_state::state::StateInfo; -use trace::LocalizedTrace; -use verification::queue::kind::blocks::Unverified; // todo this is reexported from common_types - -/// State information to be used during client query -pub enum StateOrBlock { - /// State to be used, may be pending - State(Box), - - /// Id of an existing block from a chain to get state from - Block(BlockId) -} - -impl From> for StateOrBlock { - fn from(info: Box) -> StateOrBlock { - StateOrBlock::State(info) - } -} - -impl From for StateOrBlock { - fn from(id: BlockId) -> StateOrBlock { - StateOrBlock::Block(id) - } -} - -/// Provides `nonce` and `latest_nonce` methods -pub trait Nonce { - /// Attempt to get address nonce at given block. - /// May not fail on BlockId::Latest. - fn nonce(&self, address: &Address, id: BlockId) -> Option; - - /// Get address nonce at the latest block's state. - fn latest_nonce(&self, address: &Address) -> U256 { - self.nonce(address, BlockId::Latest) - .expect("nonce will return Some when given BlockId::Latest. nonce was given BlockId::Latest. \ - Therefore nonce has returned Some; qed") - } -} - -/// Provides `balance` and `latest_balance` methods -pub trait Balance { - /// Get address balance at the given block's state. - /// - /// May not return None if given BlockId::Latest. - /// Returns None if and only if the block's root hash has been pruned from the DB. - fn balance(&self, address: &Address, state: StateOrBlock) -> Option; - - /// Get address balance at the latest block's state. - fn latest_balance(&self, address: &Address) -> U256 { - self.balance(address, BlockId::Latest.into()) - .expect("balance will return Some if given BlockId::Latest. balance was given BlockId::Latest \ - Therefore balance has returned Some; qed") - } -} - -/// Provides methods to access account info -pub trait AccountData: Nonce + Balance {} - -/// Provides `chain_info` method -pub trait ChainInfo { - /// Get blockchain information. - fn chain_info(&self) -> BlockChainInfo; -} - -/// Provides various information on a transaction by it's ID -pub trait TransactionInfo { - /// Get the hash of block that contains the transaction, if any. - fn transaction_block(&self, id: TransactionId) -> Option; -} - -/// Provides methods to access chain state -pub trait StateClient { - /// Type representing chain state - type State: StateInfo; - - /// Get a copy of the best block's state. - fn latest_state(&self) -> Self::State; - - /// Attempt to get a copy of a specific block's final state. - /// - /// This will not fail if given BlockId::Latest. - /// Otherwise, this can fail (but may not) if the DB prunes state or the block - /// is unknown. - fn state_at(&self, id: BlockId) -> Option; -} - -/// Provides various blockchain information, like block header, chain state etc. -pub trait BlockChain: ChainInfo + BlockInfo + TransactionInfo {} - -// FIXME Why these methods belong to BlockChainClient and not MiningBlockChainClient? -/// Provides methods to import block into blockchain -pub trait ImportBlock { - /// Import a block into the blockchain. - fn import_block(&self, block: Unverified) -> EthcoreResult; -} /// Provides `call` and `call_many` methods pub trait Call { @@ -169,201 +51,6 @@ pub trait EngineInfo { fn engine(&self) -> &dyn Engine; } -/// IO operations that should off-load heavy work to another thread. -pub trait IoClient: Sync + Send { - /// Queue transactions for importing. - fn queue_transactions(&self, transactions: Vec, peer_id: usize); - - /// Queue block import with transaction receipts. Does no sealing and transaction validation. - fn queue_ancient_block(&self, block_bytes: Unverified, receipts_bytes: Bytes) -> EthcoreResult; - - /// Queue consensus engine message. - fn queue_consensus_message(&self, message: Bytes); -} - -/// Provides recently seen bad blocks. -pub trait BadBlocks { - /// Returns a list of blocks that were recently not imported because they were invalid. - fn bad_blocks(&self) -> Vec<(Unverified, String)>; -} - -/// Blockchain database client. Owns and manages a blockchain and a block queue. -pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContract + RegistryInfo + ImportBlock -+ IoClient + BadBlocks { - /// Look up the block number for the given block ID. - fn block_number(&self, id: BlockId) -> Option; - - /// Get raw block body data by block id. - /// Block body is an RLP list of two items: uncles and transactions. - fn block_body(&self, id: BlockId) -> Option; - - /// Get block status by block header hash. - fn block_status(&self, id: BlockId) -> BlockStatus; - - /// Get block total difficulty. - fn block_total_difficulty(&self, id: BlockId) -> Option; - - /// Attempt to get address storage root at given block. - /// May not fail on BlockId::Latest. - fn storage_root(&self, address: &Address, id: BlockId) -> Option; - - /// Get block hash. - fn block_hash(&self, id: BlockId) -> Option; - - /// Get address code at given block's state. - fn code(&self, address: &Address, state: StateOrBlock) -> Option>; - - /// Get address code at the latest block's state. - fn latest_code(&self, address: &Address) -> Option { - self.code(address, BlockId::Latest.into()) - .expect("code will return Some if given BlockId::Latest; qed") - } - - /// Get a reference to the `BlockProvider`. - fn chain(&self) -> Arc; - - /// Get block queue information. - fn queue_info(&self) -> BlockQueueInfo; - - /// Get address code hash at given block's state. - - /// Get value of the storage at given position at the given block's state. - /// - /// May not return None if given BlockId::Latest. - /// Returns None if and only if the block's root hash has been pruned from the DB. - fn storage_at(&self, address: &Address, position: &H256, state: StateOrBlock) -> Option; - - /// Get value of the storage at given position at the latest block's state. - fn latest_storage_at(&self, address: &Address, position: &H256) -> H256 { - self.storage_at(address, position, BlockId::Latest.into()) - .expect("storage_at will return Some if given BlockId::Latest. storage_at was given BlockId::Latest. \ - Therefore storage_at has returned Some; qed") - } - - /// Get a list of all accounts in the block `id`, if fat DB is in operation, otherwise `None`. - /// If `after` is set the list starts with the following item. - fn list_accounts(&self, id: BlockId, after: Option<&Address>, count: u64) -> Option>; - - /// Get a list of all storage keys in the block `id`, if fat DB is in operation, otherwise `None`. - /// If `after` is set the list starts with the following item. - fn list_storage(&self, id: BlockId, account: &Address, after: Option<&H256>, count: u64) -> Option>; - - /// Get transaction with given hash. - fn transaction(&self, id: TransactionId) -> Option; - - /// Get uncle with given id. - fn uncle(&self, id: UncleId) -> Option; - - /// Get transaction receipt with given hash. - fn transaction_receipt(&self, id: TransactionId) -> Option; - - /// Get localized receipts for all transaction in given block. - fn localized_block_receipts(&self, id: BlockId) -> Option>; - - /// Get a tree route between `from` and `to`. - /// See `BlockChain::tree_route`. - fn tree_route(&self, from: &H256, to: &H256) -> Option; - - /// Get all possible uncle hashes for a block. - fn find_uncles(&self, hash: &H256) -> Option>; - - /// Get latest state node - fn state_data(&self, hash: &H256) -> Option; - - /// Get block receipts data by block header hash. - fn block_receipts(&self, hash: &H256) -> Option; - - /// Returns true if block queue is empty. - fn is_queue_empty(&self) -> bool { - self.queue_info().is_empty() - } - - /// Clear block queue and abort all import activity. - fn clear_queue(&self); - - /// Returns logs matching given filter. If one of the filtering block cannot be found, returns the block id that caused the error. - fn logs(&self, filter: Filter) -> Result, BlockId>; - - /// Replays a given transaction for inspection. - fn replay(&self, t: TransactionId, analytics: CallAnalytics) -> Result; - - /// Replays all the transactions in a given block for inspection. - fn replay_block_transactions(&self, block: BlockId, analytics: CallAnalytics) -> Result>, CallError>; - - /// Returns traces matching given filter. - fn filter_traces(&self, filter: TraceFilter) -> Option>; - - /// Returns trace with given id. - fn trace(&self, trace: TraceId) -> Option; - - /// Returns traces created by transaction. - fn transaction_traces(&self, trace: TransactionId) -> Option>; - - /// Returns traces created by transaction from block. - fn block_traces(&self, trace: BlockId) -> Option>; - - /// Get last hashes starting from best block. - fn last_hashes(&self) -> LastHashes; - - /// List all ready transactions that should be propagated to other peers. - fn transactions_to_propagate(&self) -> Vec>; - - /// Sorted list of transaction gas prices from at least last sample_size blocks. - fn gas_price_corpus(&self, sample_size: usize) -> ::stats::Corpus { - let mut h = self.chain_info().best_block_hash; - let mut corpus = Vec::new(); - while corpus.is_empty() { - for _ in 0..sample_size { - let block = match self.block(BlockId::Hash(h)) { - Some(block) => block, - None => return corpus.into(), - }; - - if block.number() == 0 { - return corpus.into(); - } - block.transaction_views().iter().foreach(|t| corpus.push(t.gas_price())); - h = block.parent_hash().clone(); - } - } - corpus.into() - } - - /// Get the preferred chain ID to sign on - fn signing_chain_id(&self) -> Option; - - /// Get the mode. - fn mode(&self) -> Mode; - - /// Set the mode. - fn set_mode(&self, mode: Mode); - - /// Get the chain spec name. - fn spec_name(&self) -> String; - - /// Set the chain via a spec name. - fn set_spec_name(&self, spec_name: String) -> Result<(), ()>; - - /// Disable the client from importing blocks. This cannot be undone in this session and indicates - /// that a subsystem has reason to believe this executable incapable of syncing the chain. - fn disable(&self); - - /// Returns engine-related extra info for `BlockId`. - fn block_extra_info(&self, id: BlockId) -> Option>; - - /// Returns engine-related extra info for `UncleId`. - fn uncle_extra_info(&self, id: UncleId) -> Option>; - - /// Returns information about pruning/data availability. - fn pruning_info(&self) -> PruningInfo; - - /// Schedule state-altering transaction to be executed on the next pending block. - fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error>; - - /// Get the address of the registry itself. - fn registrar_address(&self) -> Option
; -} - /// Provides `reopen_block` method pub trait ReopenBlock { /// Reopens an OpenBlock and updates uncles. @@ -383,12 +70,6 @@ pub trait PrepareOpenBlock { /// Provides methods used for sealing new state pub trait BlockProducer: PrepareOpenBlock + ReopenBlock {} -/// Provides `latest_schedule` method -pub trait ScheduleInfo { - /// Returns latest schedule. - fn latest_schedule(&self) -> Schedule; -} - ///Provides `import_sealed_block` method pub trait ImportSealedBlock { /// Import sealed block. Skips all verifications. @@ -403,59 +84,3 @@ pub trait BroadcastProposalBlock { /// Provides methods to import sealed block and broadcast a block proposal pub trait SealedBlockImporter: ImportSealedBlock + BroadcastProposalBlock {} - -/// Client facilities used by internally sealing Engines. -pub trait EngineClient: Sync + Send + ChainInfo { - /// Make a new block and seal it. - fn update_sealing(&self); - - /// Submit a seal for a block in the mining queue. - fn submit_seal(&self, block_hash: H256, seal: Vec); - - /// Broadcast a consensus message to the network. - fn broadcast_consensus_message(&self, message: Bytes); - - /// Get the transition to the epoch the given parent hash is part of - /// or transitions to. - /// This will give the epoch that any children of this parent belong to. - /// - /// The block corresponding the the parent hash must be stored already. - fn epoch_transition_for(&self, parent_hash: H256) -> Option<::engines::EpochTransition>; - - /// Attempt to cast the engine client to a full client. - fn as_full_client(&self) -> Option<&dyn BlockChainClient>; - - /// Get a block number by ID. - fn block_number(&self, id: BlockId) -> Option; - - /// Get raw block header data by block id. - fn block_header(&self, id: BlockId) -> Option; -} - -/// Extended client interface for providing proofs of the state. -pub trait ProvingBlockChainClient: BlockChainClient { - /// Prove account storage at a specific block id. - /// - /// Both provided keys assume a secure trie. - /// Returns a vector of raw trie nodes (in order from the root) proving the storage query. - fn prove_storage(&self, key1: H256, key2: H256, id: BlockId) -> Option<(Vec, H256)>; - - /// Prove account existence at a specific block id. - /// The key is the keccak hash of the account's address. - /// Returns a vector of raw trie nodes (in order from the root) proving the query. - fn prove_account(&self, key1: H256, id: BlockId) -> Option<(Vec, BasicAccount)>; - - /// Prove execution of a transaction at the given block. - /// Returns the output of the call and a vector of database items necessary - /// to reproduce it. - fn prove_transaction(&self, transaction: SignedTransaction, id: BlockId) -> Option<(Bytes, Vec)>; - - /// Get an epoch change signal by block hash. - fn epoch_signal(&self, hash: H256) -> Option>; -} - -/// resets the blockchain -pub trait BlockChainReset { - /// reset to best_block - n - fn reset(&self, num: u32) -> Result<(), String>; -} diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index d4523ffbffe..dae24e9ef55 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -24,17 +24,18 @@ use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering}; use std::sync::{Weak, Arc}; use std::time::{UNIX_EPOCH, Duration}; -use client::EngineClient; -use engines::{Engine, Seal, ConstructedVerifier}; +use client_traits::EngineClient; +use engine::{Engine,ConstructedVerifier}; use engines::block_reward; use engines::block_reward::{BlockRewardContract, RewardKind}; +use engine::snapshot::SnapshotComponents; use ethjson; use machine::{ ExecutedBlock, Machine, }; use hash::keccak; -use super::signer::EngineSigner; +use engine::signer::EngineSigner; use super::validator_set::{ValidatorSet, SimpleList, new_validator_set}; use self::finality::RollingFinality; use ethkey::{self, Signature}; @@ -49,7 +50,10 @@ use types::{ BlockNumber, header::{Header, ExtendedHeader}, engines::{ + Headers, params::CommonParams, + PendingTransitionStore, + Seal, SealingState, machine::{Call, AuxiliaryData}, }, @@ -459,7 +463,7 @@ struct EpochVerifier { empty_steps_transition: u64, } -impl super::EpochVerifier for EpochVerifier { +impl engine::EpochVerifier for EpochVerifier { fn verify_light(&self, header: &Header) -> Result<(), Error> { // Validate the timestamp verify_timestamp(&self.step.inner, header_step(header, self.empty_steps_transition)?)?; @@ -1273,7 +1277,7 @@ impl Engine for AuthorityRound { let rewards: Vec<_> = match self.block_reward_contract { Some(ref c) if block.header.number() >= self.block_reward_contract_transition => { - let mut call = super::default_system_or_code_call(&self.machine, block); + let mut call = engine::default_system_or_code_call(&self.machine, block); let rewards = c.reward(beneficiaries, &mut call)?; rewards.into_iter().map(|(author, amount)| (author, RewardKind::External, amount)).collect() @@ -1429,8 +1433,8 @@ impl Engine for AuthorityRound { .map(|set_proof| combine_proofs(0, &set_proof, &[])) } - fn signals_epoch_end(&self, header: &Header, aux: AuxiliaryData) -> super::EpochChange { - if self.immediate_transitions { return super::EpochChange::No } + fn signals_epoch_end(&self, header: &Header, aux: AuxiliaryData) -> engine::EpochChange { + if self.immediate_transitions { return engine::EpochChange::No } let first = header.number() == 0; self.validators.signals_epoch_end(first, header, aux) @@ -1439,8 +1443,8 @@ impl Engine for AuthorityRound { fn is_epoch_end_light( &self, chain_head: &Header, - chain: &super::Headers
, - transition_store: &super::PendingTransitionStore, + chain: &Headers
, + transition_store: &PendingTransitionStore, ) -> Option> { // epochs only matter if we want to support light clients. if self.immediate_transitions { return None } @@ -1483,8 +1487,8 @@ impl Engine for AuthorityRound { &self, chain_head: &Header, finalized: &[H256], - chain: &super::Headers
, - transition_store: &super::PendingTransitionStore, + chain: &Headers
, + transition_store: &PendingTransitionStore, ) -> Option> { // epochs only matter if we want to support light clients. if self.immediate_transitions { return None } @@ -1591,7 +1595,7 @@ impl Engine for AuthorityRound { ) } - fn snapshot_components(&self) -> Option> { + fn snapshot_components(&self) -> Option> { if self.immediate_transitions { None } else { @@ -1628,7 +1632,7 @@ mod tests { use ethkey::Signature; use types::{ header::Header, - engines::params::CommonParams, + engines::{Seal, params::CommonParams}, errors::{EthcoreError as Error, EngineError}, transaction::{Action, Transaction}, }; @@ -1639,7 +1643,7 @@ mod tests { TestNotify }; use crate::spec::{Spec, self}; - use engines::{Seal, Engine}; + use engine::Engine; use engines::validator_set::{TestSet, SimpleList}; use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score}; use machine::Machine; diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 632e2a0e8c9..55c8ab5e7aa 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -20,10 +20,14 @@ use std::sync::Weak; use ethereum_types::{H256, H520}; use parking_lot::RwLock; use ethkey::{self, Signature}; -use engines::{Engine, Seal, ConstructedVerifier}; -use engines::signer::EngineSigner; +use engine::{ + Engine, + ConstructedVerifier, + snapshot::SnapshotComponents, + signer::EngineSigner, +}; use ethjson; -use client::EngineClient; +use client_traits::EngineClient; use machine::{ Machine, executed_block::ExecutedBlock, @@ -31,7 +35,10 @@ use machine::{ use types::{ header::Header, engines::{ + Headers, + PendingTransitionStore, SealingState, + Seal, params::CommonParams, machine::{AuxiliaryData, Call}, }, @@ -59,7 +66,7 @@ struct EpochVerifier { list: SimpleList, } -impl super::EpochVerifier for EpochVerifier { +impl engine::EpochVerifier for EpochVerifier { fn verify_light(&self, header: &Header) -> Result<(), Error> { verify_external(header, &self.list) } @@ -144,13 +151,13 @@ impl Engine for BasicAuthority { } #[cfg(not(test))] - fn signals_epoch_end(&self, _header: &Header, _auxiliary: AuxiliaryData) -> super::EpochChange { + fn signals_epoch_end(&self, _header: &Header, _auxiliary: AuxiliaryData) -> engine::EpochChange { // don't bother signalling even though a contract might try. - super::EpochChange::No + engine::EpochChange::No } #[cfg(test)] - fn signals_epoch_end(&self, header: &Header, auxiliary: AuxiliaryData) -> super::EpochChange { + fn signals_epoch_end(&self, header: &Header, auxiliary: AuxiliaryData) -> engine::EpochChange { // in test mode, always signal even though they don't be finalized. let first = header.number() == 0; self.validators.signals_epoch_end(first, header, auxiliary) @@ -160,8 +167,8 @@ impl Engine for BasicAuthority { &self, chain_head: &Header, _finalized: &[H256], - _chain: &super::Headers
, - _transition_store: &super::PendingTransitionStore, + _chain: &Headers
, + _transition_store: &PendingTransitionStore, ) -> Option> { let first = chain_head.number() == 0; @@ -172,8 +179,8 @@ impl Engine for BasicAuthority { fn is_epoch_end_light( &self, chain_head: &Header, - chain: &super::Headers
, - transition_store: &super::PendingTransitionStore, + chain: &Headers
, + transition_store: &PendingTransitionStore, ) -> Option> { self.is_epoch_end(chain_head, &[], chain, transition_store) } @@ -183,7 +190,7 @@ impl Engine for BasicAuthority { match self.validators.epoch_set(first, &self.machine, header.number(), proof) { Ok((list, finalize)) => { - let verifier = Box::new(EpochVerifier { list: list }); + let verifier = Box::new(EpochVerifier { list }); // our epoch verifier will ensure no unverified verifier is ever verified. match finalize { @@ -211,7 +218,7 @@ impl Engine for BasicAuthority { ) } - fn snapshot_components(&self) -> Option> { + fn snapshot_components(&self) -> Option> { None } @@ -230,7 +237,7 @@ mod tests { use accounts::AccountProvider; use types::header::Header; use spec::Spec; - use engines::{Seal, SealingState}; + use types::engines::{Seal, SealingState}; use tempdir::TempDir; /// Create a new test chain spec with `BasicAuthority` consensus engine. diff --git a/ethcore/src/engines/block_reward.rs b/ethcore/src/engines/block_reward.rs index 3429a28cef0..c2f66c13e78 100644 --- a/ethcore/src/engines/block_reward.rs +++ b/ethcore/src/engines/block_reward.rs @@ -28,7 +28,7 @@ use types::{ BlockNumber, errors::{EngineError, EthcoreError as Error}, }; -use super::{SystemOrCodeCall, SystemOrCodeCallKind}; +use engine::{SystemOrCodeCall, SystemOrCodeCallKind}; use trace::{Tracer, ExecutiveTracer, Tracing}; use_contract!(block_reward_contract, "res/contracts/block_reward.json"); @@ -166,7 +166,7 @@ mod test { use crate::spec; use test_helpers::generate_dummy_client_with_spec; - use engines::SystemOrCodeCallKind; + use engine::SystemOrCodeCallKind; use super::{BlockRewardContract, RewardKind}; #[test] diff --git a/ethcore/src/engines/clique/mod.rs b/ethcore/src/engines/clique/mod.rs index 8dea9d9979c..3f249f42a5e 100644 --- a/ethcore/src/engines/clique/mod.rs +++ b/ethcore/src/engines/clique/mod.rs @@ -65,9 +65,15 @@ use std::thread; use std::time; use std::time::{Instant, Duration, SystemTime, UNIX_EPOCH}; -use client::EngineClient; -use engines::clique::util::{extract_signers, recover_creator}; -use engines::{Engine, Seal, SealingState, EthashSeal}; +use client_traits::EngineClient; +use engines::{ + clique::util::{extract_signers, recover_creator}, + EthashSeal, +}; +use engine::{ + Engine, + signer::EngineSigner, +}; use ethereum_types::{Address, H64, H160, H256, U256}; use ethkey::Signature; use hash::KECCAK_EMPTY_LIST_RLP; @@ -79,7 +85,6 @@ use machine::{ }; use parking_lot::RwLock; use rand::Rng; -use super::signer::EngineSigner; use unexpected::{Mismatch, OutOfBounds}; use time_utils::CheckedSystemTime; use types::{ @@ -87,6 +92,8 @@ use types::{ ids::BlockId, header::Header, engines::{ + Seal, + SealingState, params::CommonParams, machine::Call, }, diff --git a/ethcore/src/engines/clique/tests.rs b/ethcore/src/engines/clique/tests.rs index 46e9506f1e4..e1954a13faf 100644 --- a/ethcore/src/engines/clique/tests.rs +++ b/ethcore/src/engines/clique/tests.rs @@ -17,7 +17,7 @@ //! Consensus tests for `PoA Clique Engine`, see http://eips.ethereum.org/EIPS/eip-225 for more information use block::*; -use engines::Engine; +use engine::Engine; use ethereum_types::{Address, H256}; use ethkey::{Secret, KeyPair}; use state_db::StateDB; diff --git a/ethcore/src/engines/ethash.rs b/ethcore/src/engines/ethash.rs index 22f81804f67..df75ae816b5 100644 --- a/ethcore/src/engines/ethash.rs +++ b/ethcore/src/engines/ethash.rs @@ -19,6 +19,7 @@ use std::collections::BTreeMap; use std::path::Path; use std::sync::Arc; +use engine::snapshot::SnapshotComponents; use ethereum_types::{H256, H64, U256}; use ethjson; use hash::{KECCAK_EMPTY_LIST_RLP}; @@ -33,7 +34,7 @@ use types::{ use unexpected::{OutOfBounds, Mismatch}; use engines::block_reward::{self, BlockRewardContract, RewardKind}; -use engines::{self, Engine}; +use engine::Engine; use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor}; use machine::{ ExecutedBlock, @@ -179,7 +180,7 @@ impl From for EthashParams { /// mainnet chains in the Olympic, Frontier and Homestead eras. pub struct Ethash { ethash_params: EthashParams, - pow: EthashManager, + pow: Arc, machine: Machine, } @@ -190,17 +191,48 @@ impl Ethash { ethash_params: EthashParams, machine: Machine, optimize_for: T, - ) -> Arc { + ) -> Self { let progpow_transition = ethash_params.progpow_transition; - Arc::new(Ethash { + Ethash { ethash_params, machine, - pow: EthashManager::new(cache_dir.as_ref(), optimize_for.into(), progpow_transition), - }) + pow: Arc::new(EthashManager::new( + cache_dir.as_ref(), + optimize_for.into(), + progpow_transition + )), + } } } +fn verify_block_unordered(pow: &Arc, header: &Header) -> Result<(), Error> { + let seal = Seal::parse_seal(header.seal())?; + + let result = pow.compute_light( + header.number() as u64, + &header.bare_hash().0, + seal.nonce.to_low_u64_be() + ); + let mix = H256(result.mix_hash); + let difficulty = ethash::boundary_to_difficulty(&H256(result.value)); + trace!(target: "miner", "num: {num}, seed: {seed}, h: {h}, non: {non}, mix: {mix}, res: {res}", + num = header.number() as u64, + seed = H256(slow_hash_block_number(header.number() as u64)), + h = header.bare_hash(), + non = seal.nonce.to_low_u64_be(), + mix = H256(result.mix_hash), + res = H256(result.value)); + if mix != seal.mix_hash { + return Err(From::from(BlockError::MismatchedH256SealElement(Mismatch { expected: mix, found: seal.mix_hash }))); + } + if &difficulty < header.difficulty() { + return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty().clone()), max: None, found: difficulty }))); + } + Ok(()) +} + + // TODO [rphmeier] // // for now, this is different than Ethash's own epochs, and signal @@ -209,17 +241,17 @@ impl Ethash { // for any block in the chain. // in the future, we might move the Ethash epoch // caching onto this mechanism as well. -// NOTE[dvdplm]: the reason we impl this for Arc and not plain Ethash is the -// way `epoch_verifier()` works. This means `new()` returns an `Arc` which is -// then re-wrapped in an Arc in `spec::engine()`. -impl engines::EpochVerifier for Arc { - fn verify_light(&self, _header: &Header) -> Result<(), Error> { Ok(()) } +struct EpochVerifier { + pow: Arc +} + +impl engine::EpochVerifier for EpochVerifier { fn verify_heavy(&self, header: &Header) -> Result<(), Error> { - self.verify_block_unordered(header).into() + verify_block_unordered(&self.pow, header) } } -impl Engine for Arc { +impl Engine for Ethash { fn name(&self) -> &str { "Ethash" } fn machine(&self) -> &Machine { &self.machine } @@ -241,11 +273,6 @@ impl Engine for Arc { fn maximum_gas_limit(&self) -> Option { Some(0x7fff_ffff_ffff_ffffu64.into()) } - fn populate_from_parent(&self, header: &mut Header, parent: &Header) { - let difficulty = self.calculate_difficulty(header, parent); - header.set_difficulty(difficulty); - } - /// Apply the block reward on finalisation of the block. /// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current). fn on_close_block(&self, block: &mut ExecutedBlock, _parent_header: &Header) -> Result<(), Error> { @@ -264,7 +291,7 @@ impl Engine for Arc { beneficiaries.push((*uncle_author, RewardKind::uncle(number, u.number()))); } - let mut call = engines::default_system_or_code_call(&self.machine, block); + let mut call = engine::default_system_or_code_call(&self.machine, block); let rewards = c.reward(beneficiaries, &mut call)?; rewards.into_iter().map(|(author, amount)| (author, RewardKind::External, amount)).collect() @@ -346,25 +373,7 @@ impl Engine for Arc { } fn verify_block_unordered(&self, header: &Header) -> Result<(), Error> { - let seal = Seal::parse_seal(header.seal())?; - - let result = self.pow.compute_light(header.number() as u64, &header.bare_hash().0, seal.nonce.to_low_u64_be()); - let mix = H256(result.mix_hash); - let difficulty = ethash::boundary_to_difficulty(&H256(result.value)); - trace!(target: "miner", "num: {num}, seed: {seed}, h: {h}, non: {non}, mix: {mix}, res: {res}", - num = header.number() as u64, - seed = H256(slow_hash_block_number(header.number() as u64)), - h = header.bare_hash(), - non = seal.nonce.to_low_u64_be(), - mix = H256(result.mix_hash), - res = H256(result.value)); - if mix != seal.mix_hash { - return Err(From::from(BlockError::MismatchedH256SealElement(Mismatch { expected: mix, found: seal.mix_hash }))); - } - if &difficulty < header.difficulty() { - return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty().clone()), max: None, found: difficulty }))); - } - Ok(()) + verify_block_unordered(&self.pow, header) } fn verify_block_family(&self, header: &Header, parent: &Header) -> Result<(), Error> { @@ -382,11 +391,17 @@ impl Engine for Arc { Ok(()) } - fn epoch_verifier<'a>(&self, _header: &Header, _proof: &'a [u8]) -> engines::ConstructedVerifier<'a> { - engines::ConstructedVerifier::Trusted(Box::new(self.clone())) + fn epoch_verifier<'a>(&self, _header: &Header, _proof: &'a [u8]) -> engine::ConstructedVerifier<'a> { + let v = EpochVerifier{pow: self.pow.clone()}; + engine::ConstructedVerifier::Trusted(Box::new(v)) + } + + fn populate_from_parent(&self, header: &mut Header, parent: &Header) { + let difficulty = self.calculate_difficulty(header, parent); + header.set_difficulty(difficulty); } - fn snapshot_components(&self) -> Option> { + fn snapshot_components(&self) -> Option> { Some(Box::new(::snapshot::PowSnapshot::new(SNAPSHOT_BLOCKS, MAX_SNAPSHOT_BLOCKS))) } @@ -502,7 +517,7 @@ mod tests { errors::{BlockError, EthcoreError as Error}, }; use spec::Spec; - use engines::Engine; + use engine::Engine; use crate::spec::{new_morden, new_mcip3_test, new_homestead_test_machine}; use super::{Ethash, EthashParams, ecip1017_eras_block_reward}; use rlp; diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 8b2be486575..d786176bdd7 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use engines::{Engine, Seal}; +use engine::Engine; use machine::{ ExecutedBlock, Machine @@ -22,6 +22,7 @@ use machine::{ use types::{ header::Header, engines::{ + Seal, SealingState, params::CommonParams, }, @@ -110,9 +111,11 @@ mod tests { use ethereum_types::{H520, Address}; use test_helpers::get_temp_state_db; use crate::spec; - use types::header::Header; + use types::{ + header::Header, + engines::Seal, + }; use block::*; - use engines::Seal; #[test] fn instant_can_seal() { diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index b5391c0b226..780a6a06328 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -25,425 +25,10 @@ mod null_engine; mod validator_set; pub mod block_reward; -pub mod signer; pub use self::authority_round::AuthorityRound; pub use self::basic_authority::BasicAuthority; pub use self::instant_seal::{InstantSeal, InstantSealParams}; pub use self::null_engine::NullEngine; -pub use self::signer::EngineSigner; pub use self::clique::Clique; pub use self::ethash::{Ethash, Seal as EthashSeal}; - -// TODO [ToDr] Remove re-export (#10130) -pub use types::engines::ForkChoice; -pub use types::engines::epoch::{self, Transition as EpochTransition}; - -use std::sync::{Weak, Arc}; -use std::collections::BTreeMap; - -use builtin::Builtin; -use vm::{EnvInfo, Schedule, CallType, ActionValue}; -use types::{ - BlockNumber, - ancestry_action::AncestryAction, - header::{Header, ExtendedHeader}, - engines::{ - SealingState, Headers, PendingTransitionStore, - params::CommonParams, - machine as machine_types, - machine::{AuxiliaryData, AuxiliaryRequest}, - }, - errors::{EthcoreError as Error, EngineError}, - transaction::{self, UnverifiedTransaction}, -}; -use snapshot::SnapshotComponents; -use client::EngineClient; - -use ethkey::Signature; -use machine::{ - Machine, - executed_block::ExecutedBlock, -}; -use ethereum_types::{H256, U256, Address}; -use bytes::Bytes; - -/// Seal type. -#[derive(Debug, PartialEq, Eq)] -pub enum Seal { - /// Regular block seal; should be part of the blockchain. - Regular(Vec), - /// Engine does not generate seal for this block right now. - None, -} - -/// A system-calling closure. Enacts calls on a block's state from the system address. -pub type SystemCall<'a> = dyn FnMut(Address, Vec) -> Result, String> + 'a; - -/// A system-calling closure. Enacts calls on a block's state with code either from an on-chain contract, or hard-coded EVM or WASM (if enabled on-chain) codes. -pub type SystemOrCodeCall<'a> = dyn FnMut(SystemOrCodeCallKind, Vec) -> Result, String> + 'a; - -/// Kind of SystemOrCodeCall, this is either an on-chain address, or code. -#[derive(PartialEq, Debug, Clone)] -pub enum SystemOrCodeCallKind { - /// On-chain address. - Address(Address), - /// Hard-coded code. - Code(Arc>, H256), -} - -/// Default SystemOrCodeCall implementation. -pub fn default_system_or_code_call<'a>(machine: &'a Machine, block: &'a mut ExecutedBlock) -> impl FnMut(SystemOrCodeCallKind, Vec) -> Result, String> + 'a { - move |to, data| { - let result = match to { - SystemOrCodeCallKind::Address(address) => { - machine.execute_as_system( - block, - address, - U256::max_value(), - Some(data), - ) - }, - SystemOrCodeCallKind::Code(code, code_hash) => { - machine.execute_code_as_system( - block, - None, - Some(code), - Some(code_hash), - Some(ActionValue::Apparent(U256::zero())), - U256::max_value(), - Some(data), - Some(CallType::StaticCall), - ) - }, - }; - - result.map_err(|e| format!("{}", e)) - } -} - -/// Proof dependent on state. -pub trait StateDependentProof: Send + Sync { - /// Generate a proof, given the state. - fn generate_proof<'a>(&self, state: &machine_types::Call) -> Result, String>; - /// Check a proof generated elsewhere (potentially by a peer). - // `engine` needed to check state proofs, while really this should - // just be state machine params. - fn check_proof(&self, machine: &Machine, proof: &[u8]) -> Result<(), String>; -} - -/// Proof generated on epoch change. -pub enum Proof { - /// Known proof (extracted from signal) - Known(Vec), - /// State dependent proof. - WithState(Arc), -} - -/// Generated epoch verifier. -pub enum ConstructedVerifier<'a> { - /// Fully trusted verifier. - Trusted(Box), - /// Verifier unconfirmed. Check whether given finality proof finalizes given hash - /// under previous epoch. - Unconfirmed(Box, &'a [u8], H256), - /// Error constructing verifier. - Err(Error), -} - -impl<'a> ConstructedVerifier<'a> { - /// Convert to a result, indicating that any necessary confirmation has been done - /// already. - pub fn known_confirmed(self) -> Result, Error> { - match self { - ConstructedVerifier::Trusted(v) | ConstructedVerifier::Unconfirmed(v, _, _) => Ok(v), - ConstructedVerifier::Err(e) => Err(e), - } - } -} - -/// Results of a query of whether an epoch change occurred at the given block. -pub enum EpochChange { - /// Cannot determine until more data is passed. - Unsure(AuxiliaryRequest), - /// No epoch change. - No, - /// The epoch will change, with proof. - Yes(Proof), -} - -/// A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based. -/// Provides hooks into each of the major parts of block import. -pub trait Engine: Sync + Send { - /// The name of this engine. - fn name(&self) -> &str; - - /// Get access to the underlying state machine. - // TODO: decouple. - fn machine(&self) -> &Machine; - - /// The number of additional header fields required for this engine. - fn seal_fields(&self, _header: &Header) -> usize { 0 } - - /// Additional engine-specific information for the user/developer concerning `header`. - fn extra_info(&self, _header: &Header) -> BTreeMap { BTreeMap::new() } - - /// Maximum number of uncles a block is allowed to declare. - fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { 0 } - - /// Optional maximum gas limit. - fn maximum_gas_limit(&self) -> Option { None } - - /// Block transformation functions, before the transactions. - /// `epoch_begin` set to true if this block kicks off an epoch. - fn on_new_block( - &self, - _block: &mut ExecutedBlock, - _epoch_begin: bool, - ) -> Result<(), Error> { - Ok(()) - } - - /// Block transformation functions, after the transactions. - fn on_close_block( - &self, - _block: &mut ExecutedBlock, - _parent_header: &Header, - ) -> Result<(), Error> { - Ok(()) - } - - /// Allow mutating the header during seal generation. Currently only used by Clique. - fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { Ok(()) } - - /// Returns the engine's current sealing state. - fn sealing_state(&self) -> SealingState { SealingState::External } - - /// Attempt to seal the block internally. - /// - /// If `Some` is returned, then you get a valid seal. - /// - /// This operation is synchronous and may (quite reasonably) not be available, in which None will - /// be returned. - /// - /// It is fine to require access to state or a full client for this function, since - /// light clients do not generate seals. - fn generate_seal(&self, _block: &ExecutedBlock, _parent: &Header) -> Seal { Seal::None } - - /// Verify a locally-generated seal of a header. - /// - /// If this engine seals internally, - /// no checks have to be done here, since all internally generated seals - /// should be valid. - /// - /// Externally-generated seals (e.g. PoW) will need to be checked for validity. - /// - /// It is fine to require access to state or a full client for this function, since - /// light clients do not generate seals. - fn verify_local_seal(&self, header: &Header) -> Result<(), Error>; - - /// Phase 1 quick block verification. Only does checks that are cheap. Returns either a null `Ok` or a general error detailing the problem with import. - /// The verification module can optionally avoid checking the seal (`check_seal`), if seal verification is disabled this method won't be called. - fn verify_block_basic(&self, _header: &Header) -> Result<(), Error> { Ok(()) } - - /// Phase 2 verification. Perform costly checks such as transaction signatures. Returns either a null `Ok` or a general error detailing the problem with import. - /// The verification module can optionally avoid checking the seal (`check_seal`), if seal verification is disabled this method won't be called. - fn verify_block_unordered(&self, _header: &Header) -> Result<(), Error> { Ok(()) } - - /// Phase 3 verification. Check block information against parent. Returns either a null `Ok` or a general error detailing the problem with import. - fn verify_block_family(&self, _header: &Header, _parent: &Header) -> Result<(), Error> { Ok(()) } - - /// Phase 4 verification. Verify block header against potentially external data. - /// Should only be called when `register_client` has been called previously. - fn verify_block_external(&self, _header: &Header) -> Result<(), Error> { Ok(()) } - - /// Genesis epoch data. - fn genesis_epoch_data<'a>(&self, _header: &Header, _state: &machine_types::Call) -> Result, String> { Ok(Vec::new()) } - - /// Whether an epoch change is signalled at the given header but will require finality. - /// If a change can be enacted immediately then return `No` from this function but - /// `Yes` from `is_epoch_end`. - /// - /// If auxiliary data of the block is required, return an auxiliary request and the function will be - /// called again with them. - /// Return `Yes` or `No` when the answer is definitively known. - /// - /// Should not interact with state. - fn signals_epoch_end<'a>(&self, _header: &Header, _aux: AuxiliaryData<'a>) -> EpochChange { - EpochChange::No - } - - /// Whether a block is the end of an epoch. - /// - /// This either means that an immediate transition occurs or a block signalling transition - /// has reached finality. The `Headers` given are not guaranteed to return any blocks - /// from any epoch other than the current. The client must keep track of finality and provide - /// the latest finalized headers to check against the transition store. - /// - /// Return optional transition proof. - fn is_epoch_end( - &self, - _chain_head: &Header, - _finalized: &[H256], - _chain: &Headers
, - _transition_store: &PendingTransitionStore, - ) -> Option> { - None - } - - /// Whether a block is the end of an epoch. - /// - /// This either means that an immediate transition occurs or a block signalling transition - /// has reached finality. The `Headers` given are not guaranteed to return any blocks - /// from any epoch other than the current. This is a specialized method to use for light - /// clients since the light client doesn't track finality of all blocks, and therefore finality - /// for blocks in the current epoch is built inside this method by the engine. - /// - /// Return optional transition proof. - fn is_epoch_end_light( - &self, - _chain_head: &Header, - _chain: &Headers
, - _transition_store: &PendingTransitionStore, - ) -> Option> { - None - } - - /// Create an epoch verifier from validation proof and a flag indicating - /// whether finality is required. - fn epoch_verifier<'a>(&self, _header: &Header, _proof: &'a [u8]) -> ConstructedVerifier<'a> { - ConstructedVerifier::Trusted(Box::new(NoOp)) - } - - /// Populate a header's fields based on its parent's header. - /// Usually implements the chain scoring rule based on weight. - fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) { } - - /// Handle any potential consensus messages; - /// updating consensus state and potentially issuing a new one. - fn handle_message(&self, _message: &[u8]) -> Result<(), EngineError> { Err(EngineError::UnexpectedMessage) } - - /// Register a component which signs consensus messages. - fn set_signer(&self, _signer: Box) {} - - /// Sign using the EngineSigner, to be used for consensus tx signing. - fn sign(&self, _hash: H256) -> Result { unimplemented!() } - - /// Add Client which can be used for sealing, potentially querying the state and sending messages. - fn register_client(&self, _client: Weak) {} - - /// Trigger next step of the consensus engine. - fn step(&self) {} - - /// Create a factory for building snapshot chunks and restoring from them. - /// Returning `None` indicates that this engine doesn't support snapshot creation. - fn snapshot_components(&self) -> Option> { - None - } - - /// Whether this engine supports warp sync. - fn supports_warp(&self) -> bool { - self.snapshot_components().is_some() - } - - /// Return a new open block header timestamp based on the parent timestamp. - fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64 { - use std::{time, cmp}; - - let now = time::SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap_or_default(); - cmp::max(now.as_secs() as u64, parent_timestamp + 1) - } - - /// Check whether the parent timestamp is valid. - fn is_timestamp_valid(&self, header_timestamp: u64, parent_timestamp: u64) -> bool { - header_timestamp > parent_timestamp - } - - /// Gather all ancestry actions. Called at the last stage when a block is committed. The Engine must guarantee that - /// the ancestry exists. - fn ancestry_actions(&self, _header: &Header, _ancestry: &mut dyn Iterator) -> Vec { - Vec::new() - } - - /// Returns author should used when executing tx's for this block. - fn executive_author(&self, header: &Header) -> Result { - Ok(*header.author()) - } - - /// Get the general parameters of the chain. - fn params(&self) -> &CommonParams; - - /// Get the EVM schedule for the given block number. - fn schedule(&self, block_number: BlockNumber) -> Schedule { - self.machine().schedule(block_number) - } - - /// Builtin-contracts for the chain.. - fn builtins(&self) -> &BTreeMap { - self.machine().builtins() - } - - /// Attempt to get a handle to a built-in contract. - /// Only returns references to activated built-ins. - fn builtin(&self, a: &Address, block_number: BlockNumber) -> Option<&Builtin> { - self.machine().builtin(a, block_number) - } - - /// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`. - fn maximum_extra_data_size(&self) -> usize { self.params().maximum_extra_data_size } - - /// The nonce with which accounts begin at given block. - fn account_start_nonce(&self, block: BlockNumber) -> U256 { - self.machine().account_start_nonce(block) - } - - /// The network ID that transactions should be signed with. - fn signing_chain_id(&self, env_info: &EnvInfo) -> Option { - self.machine().signing_chain_id(env_info) - } - - /// Perform basic/cheap transaction verification. - /// - /// This should include all cheap checks that can be done before - /// actually checking the signature, like chain-replay protection. - /// - /// NOTE This is done before the signature is recovered so avoid - /// doing any state-touching checks that might be expensive. - /// - /// TODO: Add flags for which bits of the transaction to check. - /// TODO: consider including State in the params. - fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> Result<(), transaction::Error> { - self.machine().verify_transaction_basic(t, header) - } - - /// Performs pre-validation of RLP decoded transaction before other processing - fn decode_transaction(&self, transaction: &[u8]) -> Result { - self.machine().decode_transaction(transaction) - } -} - -/// Verifier for all blocks within an epoch with self-contained state. -pub trait EpochVerifier: Send + Sync { - /// Lightly verify the next block header. - /// This may not be a header belonging to a different epoch. - fn verify_light(&self, header: &Header) -> Result<(), Error>; - - /// Perform potentially heavier checks on the next block header. - fn verify_heavy(&self, header: &Header) -> Result<(), Error> { - self.verify_light(header) - } - - /// Check a finality proof against this epoch verifier. - /// Returns `Some(hashes)` if the proof proves finality of these hashes. - /// Returns `None` if the proof doesn't prove anything. - fn check_finality_proof(&self, _proof: &[u8]) -> Option> { - None - } -} - -/// Special "no-op" verifier for stateless, epoch-less engines. -pub struct NoOp; - -impl EpochVerifier for NoOp { - fn verify_light(&self, _header: &Header) -> Result<(), Error> { Ok(()) } -} diff --git a/ethcore/src/engines/null_engine.rs b/ethcore/src/engines/null_engine.rs index 549bf22e053..37e4e2ce608 100644 --- a/ethcore/src/engines/null_engine.rs +++ b/ethcore/src/engines/null_engine.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use engines::Engine; +use engine::snapshot::SnapshotComponents; +use engine::Engine; use engines::block_reward::{self, RewardKind}; use ethereum_types::U256; use machine::{ @@ -103,7 +104,7 @@ impl Engine for NullEngine { Ok(()) } - fn snapshot_components(&self) -> Option> { + fn snapshot_components(&self) -> Option> { Some(Box::new(::snapshot::PowSnapshot::new(10000, 10000))) } diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index b680bdeeba8..bf97695563d 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -30,9 +30,10 @@ use types::{ engines::machine::{Call, AuxiliaryData}, }; -use client::EngineClient; +use client_traits::EngineClient; +use engine::SystemCall; -use super::{ValidatorSet, SimpleList, SystemCall}; +use super::{ValidatorSet, SimpleList}; use super::safe_contract::ValidatorSafeContract; use_contract!(validator_report, "res/contracts/validator_report.json"); @@ -93,7 +94,7 @@ impl ValidatorSet for ValidatorContract { first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange { + ) -> engine::EpochChange { self.validators.signals_epoch_end(first, header, aux) } @@ -145,14 +146,15 @@ mod tests { use bytes::ToPretty; use rlp::encode; use crate::spec; - use types::header::Header; + use types::{ + header::Header, + ids::BlockId, + }; use accounts::AccountProvider; use miner::{self, MinerService}; - use types::ids::BlockId; use test_helpers::generate_dummy_client_with_spec; use call_contract::CallContract; - use client::{BlockChainClient, ChainInfo}; - use client_traits::BlockInfo; + use client_traits::{BlockChainClient, ChainInfo, BlockInfo}; use super::super::ValidatorSet; use super::ValidatorContract; diff --git a/ethcore/src/engines/validator_set/mod.rs b/ethcore/src/engines/validator_set/mod.rs index 3a72554271a..27f11f4e2cb 100644 --- a/ethcore/src/engines/validator_set/mod.rs +++ b/ethcore/src/engines/validator_set/mod.rs @@ -26,6 +26,8 @@ mod multi; use std::sync::Weak; use bytes::Bytes; +use client_traits::EngineClient; +use engine::SystemCall; use ethereum_types::{H256, Address}; use ethjson::spec::ValidatorSet as ValidatorSpec; use machine::Machine; @@ -37,15 +39,13 @@ use types::{ engines::machine::{Call, AuxiliaryData}, }; -use client::EngineClient; - #[cfg(test)] pub use self::test::TestSet; pub use self::simple_list::SimpleList; + use self::contract::ValidatorContract; use self::safe_contract::ValidatorSafeContract; use self::multi::Multi; -use super::SystemCall; /// Creates a validator set from spec. pub fn new_validator_set(spec: ValidatorSpec) -> Box { @@ -117,7 +117,7 @@ pub trait ValidatorSet: Send + Sync + 'static { first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange; + ) -> engine::EpochChange; /// Recover the validator set from the given proof, the block number, and /// whether this header is first in its set. diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 48b00b9cf7a..9e44430f4a1 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -30,7 +30,7 @@ use types::{ engines::machine::{Call, AuxiliaryData}, }; -use client::EngineClient; +use client_traits::EngineClient; use machine::Machine; use super::{SystemCall, ValidatorSet}; @@ -100,7 +100,7 @@ impl ValidatorSet for Multi { } fn signals_epoch_end(&self, _first: bool, header: &Header, aux: AuxiliaryData) - -> ::engines::EpochChange + -> engine::EpochChange { let (set_block, set) = self.correct_set_by_number(header.number()); let first = set_block == header.number(); @@ -155,18 +155,19 @@ mod tests { use std::collections::BTreeMap; use hash::keccak; use accounts::AccountProvider; - use client::{BlockChainClient, ChainInfo, ImportBlock}; - use client_traits::BlockInfo; - use engines::EpochChange; + use client_traits::{BlockChainClient, BlockInfo, ChainInfo, ImportBlock, EngineClient}; + use engine::EpochChange; use engines::validator_set::ValidatorSet; use ethkey::Secret; use types::header::Header; use miner::{self, MinerService}; use crate::spec; use test_helpers::{generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data}; - use types::ids::BlockId; + use types::{ + ids::BlockId, + verification::Unverified, + }; use ethereum_types::Address; - use verification::queue::kind::blocks::Unverified; use super::Multi; @@ -186,24 +187,24 @@ mod tests { let signer = Box::new((tap.clone(), v1, "".into())); client.miner().set_author(miner::Author::Sealer(signer)); client.transact_contract(Default::default(), Default::default()).unwrap(); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); assert_eq!(client.chain_info().best_block_number, 0); // Right signer for the first block. let signer = Box::new((tap.clone(), v0, "".into())); client.miner().set_author(miner::Author::Sealer(signer)); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); assert_eq!(client.chain_info().best_block_number, 1); // This time v0 is wrong. client.transact_contract(Default::default(), Default::default()).unwrap(); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); assert_eq!(client.chain_info().best_block_number, 1); let signer = Box::new((tap.clone(), v1, "".into())); client.miner().set_author(miner::Author::Sealer(signer)); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); assert_eq!(client.chain_info().best_block_number, 2); // v1 is still good. client.transact_contract(Default::default(), Default::default()).unwrap(); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); assert_eq!(client.chain_info().best_block_number, 3); // Check syncing. diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 68c9575c6ee..08f03c7a4f8 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -36,7 +36,7 @@ use types::{ }; use unexpected::Mismatch; -use client::EngineClient; +use client_traits::EngineClient; use machine::Machine; use super::{SystemCall, ValidatorSet}; use super::simple_list::SimpleList; @@ -59,7 +59,7 @@ struct StateProof { header: Header, } -impl ::engines::StateDependentProof for StateProof { +impl engine::StateDependentProof for StateProof { fn generate_proof(&self, caller: &Call) -> Result, String> { prove_initial(self.contract_address, &self.header, caller) } @@ -314,7 +314,7 @@ impl ValidatorSet for ValidatorSafeContract { } fn signals_epoch_end(&self, first: bool, header: &Header, aux: AuxiliaryData) - -> ::engines::EpochChange + -> engine::EpochChange { let receipts = aux.receipts; @@ -325,27 +325,27 @@ impl ValidatorSet for ValidatorSafeContract { contract_address: self.contract_address, header: header.clone(), }); - return ::engines::EpochChange::Yes(::engines::Proof::WithState(state_proof as Arc<_>)); + return engine::EpochChange::Yes(engine::Proof::WithState(state_proof as Arc<_>)); } // otherwise, we're checking for logs. let bloom = self.expected_bloom(header); let header_bloom = header.log_bloom(); - if &bloom & header_bloom != bloom { return ::engines::EpochChange::No } + if &bloom & header_bloom != bloom { return engine::EpochChange::No } trace!(target: "engine", "detected epoch change event bloom"); match receipts { - None => ::engines::EpochChange::Unsure(AuxiliaryRequest::Receipts), + None => engine::EpochChange::Unsure(AuxiliaryRequest::Receipts), Some(receipts) => match self.extract_from_event(bloom, header, receipts) { - None => ::engines::EpochChange::No, + None => engine::EpochChange::No, Some(list) => { info!(target: "engine", "Signal for transition within contract. New validator list: {:?}", &*list); let proof = encode_proof(&header, receipts); - ::engines::EpochChange::Yes(::engines::Proof::Known(proof)) + engine::EpochChange::Yes(engine::Proof::Known(proof)) } }, } @@ -452,19 +452,24 @@ mod tests { use std::sync::Arc; use rustc_hex::FromHex; use hash::keccak; + use engine::{EpochChange, Proof}; use ethereum_types::Address; - use types::ids::BlockId; use crate::spec; use accounts::AccountProvider; - use types::transaction::{Transaction, Action}; - use client::{ChainInfo, ImportBlock}; - use client_traits::BlockInfo; + use types::{ + ids::BlockId, + engines::machine::AuxiliaryRequest, + header::Header, + log_entry::LogEntry, + transaction::{Transaction, Action}, + verification::Unverified, + }; + use client_traits::{BlockInfo, ChainInfo, ImportBlock, EngineClient}; use ethkey::Secret; use miner::{self, MinerService}; use test_helpers::{generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data}; use super::super::ValidatorSet; use super::{ValidatorSafeContract, EVENT_NAME_HASH}; - use verification::queue::kind::blocks::Unverified; #[test] fn fetches_validators() { @@ -500,7 +505,7 @@ mod tests { data: "bfc708a000000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1".from_hex().unwrap(), }.sign(&s0, Some(chain_id)); client.miner().import_own_transaction(client.as_ref(), tx.into()).unwrap(); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); assert_eq!(client.chain_info().best_block_number, 1); // Add "1" validator back in. let tx = Transaction { @@ -512,14 +517,14 @@ mod tests { data: "4d238c8e00000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1".from_hex().unwrap(), }.sign(&s0, Some(chain_id)); client.miner().import_own_transaction(client.as_ref(), tx.into()).unwrap(); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); // The transaction is not yet included so still unable to seal. assert_eq!(client.chain_info().best_block_number, 1); // Switch to the validator that is still there. let signer = Box::new((tap.clone(), v0, "".into())); client.miner().set_author(miner::Author::Sealer(signer)); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); assert_eq!(client.chain_info().best_block_number, 2); // Switch back to the added validator, since the state is updated. let signer = Box::new((tap.clone(), v1, "".into())); @@ -533,7 +538,7 @@ mod tests { data: Vec::new(), }.sign(&s0, Some(chain_id)); client.miner().import_own_transaction(client.as_ref(), tx.into()).unwrap(); - ::client::EngineClient::update_sealing(&*client); + EngineClient::update_sealing(&*client); // Able to seal again. assert_eq!(client.chain_info().best_block_number, 3); @@ -549,13 +554,6 @@ mod tests { #[test] fn detects_bloom() { - use engines::EpochChange; - use types::{ - header::Header, - log_entry::LogEntry, - engines::machine::AuxiliaryRequest, - }; - let client = generate_dummy_client_with_spec(spec::new_validator_safe_contract); let engine = client.engine().clone(); let validator_contract = "0000000000000000000000000000000000000005".parse::
().unwrap(); @@ -590,9 +588,6 @@ mod tests { #[test] fn initial_contract_is_signal() { - use types::header::Header; - use engines::{EpochChange, Proof}; - let client = generate_dummy_client_with_spec(spec::new_validator_safe_contract); let engine = client.engine().clone(); diff --git a/ethcore/src/engines/validator_set/simple_list.rs b/ethcore/src/engines/validator_set/simple_list.rs index 5ec08b28684..d3d14f009f6 100644 --- a/ethcore/src/engines/validator_set/simple_list.rs +++ b/ethcore/src/engines/validator_set/simple_list.rs @@ -77,9 +77,9 @@ impl ValidatorSet for SimpleList { } fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) - -> ::engines::EpochChange + -> engine::EpochChange { - ::engines::EpochChange::No + engine::EpochChange::No } fn epoch_set(&self, _first: bool, _: &Machine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option), EthcoreError> { diff --git a/ethcore/src/engines/validator_set/test.rs b/ethcore/src/engines/validator_set/test.rs index 7abb294bc23..c4572a75cd4 100644 --- a/ethcore/src/engines/validator_set/test.rs +++ b/ethcore/src/engines/validator_set/test.rs @@ -71,9 +71,9 @@ impl ValidatorSet for TestSet { fn is_epoch_end(&self, _first: bool, _chain_head: &Header) -> Option> { None } fn signals_epoch_end(&self, _: bool, _: &Header, _: AuxiliaryData) - -> ::engines::EpochChange + -> engine::EpochChange { - ::engines::EpochChange::No + engine::EpochChange::No } fn epoch_set(&self, _: bool, _: &Machine, _: BlockNumber, _: &[u8]) -> Result<(SimpleList, Option), EthcoreError> { diff --git a/ethcore/src/executive_state.rs b/ethcore/src/executive_state.rs index d045102ceef..7d440e26a5f 100644 --- a/ethcore/src/executive_state.rs +++ b/ethcore/src/executive_state.rs @@ -25,6 +25,7 @@ use machine::{ }; use vm::EnvInfo; use types::{ + engines::machine::Executed as RawExecuted, errors::{ExecutionError, EthcoreError as Error}, transaction::SignedTransaction, receipt::{TransactionOutcome, Receipt}, @@ -242,7 +243,7 @@ fn execute( t: &SignedTransaction, options: TransactOptions, virt: bool -) -> Result, ExecutionError> +) -> Result, ExecutionError> where B: Backend, T: trace::Tracer, diff --git a/ethcore/src/json_tests/chain.rs b/ethcore/src/json_tests/chain.rs index 1e9861f61e5..4bfe3c7c962 100644 --- a/ethcore/src/json_tests/chain.rs +++ b/ethcore/src/json_tests/chain.rs @@ -16,13 +16,14 @@ use std::path::Path; use std::sync::Arc; -use client::{EvmTestClient, Client, ClientConfig, ChainInfo, ImportBlock}; +use client::{EvmTestClient, Client, ClientConfig}; +use client_traits::{ImportBlock, ChainInfo}; use spec::Genesis; use ethjson; use miner::Miner; use io::IoChannel; use test_helpers; -use verification::queue::kind::blocks::Unverified; +use types::verification::Unverified; use verification::VerifierType; use super::SKIP_TEST_STATE; use super::HookType; diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index aaac509c488..234cd557d54 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -29,7 +29,6 @@ use machine::{ externalities::{OutputPolicy, OriginInfo, Externalities}, substate::Substate, executive::contract_address, - test_helpers::new_frontier_test_machine, }; use test_helpers::get_temp_state; diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 7802dc4dad5..d1936aa9d1a 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -59,6 +59,7 @@ extern crate ansi_term; extern crate client_traits; extern crate common_types as types; extern crate crossbeam_utils; +extern crate engine; extern crate ethabi; extern crate ethash; extern crate ethcore_blockchain as blockchain; @@ -102,7 +103,6 @@ extern crate parity_util_mem as malloc_size_of; extern crate rustc_hex; extern crate serde; extern crate state_db; -extern crate stats; extern crate time_utils; extern crate trace; extern crate triehash_ethereum as triehash; diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 6157e8d284b..e7e066d452d 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -49,7 +49,7 @@ use types::{ block::Block, header::Header, ids::BlockId, - engines::{SealingState}, + engines::{Seal, SealingState}, errors::{EthcoreError as Error, ExecutionError}, receipt::RichReceipt, }; @@ -57,9 +57,15 @@ use using_queue::{UsingQueue, GetAction}; use block::{ClosedBlock, SealedBlock}; use client::{ - BlockChain, ChainInfo, BlockProducer, SealedBlockImporter, Nonce, TransactionInfo, ClientIoMessage, + BlockProducer, SealedBlockImporter, ClientIoMessage, +}; +use client_traits::{ + BlockChain, ChainInfo, Nonce, TransactionInfo, +}; +use engine::{ + Engine, + signer::EngineSigner }; -use engines::{Engine, Seal, EngineSigner}; use machine::executive::contract_address; use spec::Spec; use account_state::State; @@ -1483,12 +1489,15 @@ mod tests { use ethkey::{Generator, Random}; use hash::keccak; use rustc_hex::FromHex; - use types::BlockNumber; - use client::{TestBlockChainClient, EachBlockWith, ChainInfo, ImportSealedBlock}; + use client::{TestBlockChainClient, EachBlockWith, ImportSealedBlock}; + use client_traits::ChainInfo; use miner::{MinerService, PendingOrdering}; use test_helpers::{generate_dummy_client, generate_dummy_client_with_spec}; - use types::transaction::{Transaction}; + use types::{ + BlockNumber, + transaction::Transaction + }; use crate::spec; #[test] diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index c9f4c0d1f04..0de9390259d 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -47,11 +47,8 @@ use types::{ use block::SealedBlock; use call_contract::{CallContract, RegistryInfo}; -use client::{ - ScheduleInfo, - BlockChain, BlockProducer, SealedBlockImporter, ChainInfo, - AccountData, Nonce, -}; +use client::{BlockProducer, SealedBlockImporter}; +use client_traits::{BlockChain, ChainInfo, AccountData, Nonce, ScheduleInfo}; use account_state::state::StateInfo; /// Provides methods to verify incoming external transactions diff --git a/ethcore/src/miner/pool_client.rs b/ethcore/src/miner/pool_client.rs index 4a9852409ff..97a4d004d84 100644 --- a/ethcore/src/miner/pool_client.rs +++ b/ethcore/src/miner/pool_client.rs @@ -39,9 +39,8 @@ use types::{ use parking_lot::RwLock; use call_contract::CallContract; -use client::Nonce; -use client_traits::BlockInfo; -use engines::Engine; +use client_traits::{BlockInfo, Nonce}; +use engine::Engine; use machine::transaction_ext::Transaction; use miner; diff --git a/ethcore/src/snapshot/account.rs b/ethcore/src/snapshot/account.rs index 7bf2f4829c4..62d9ac71d0d 100644 --- a/ethcore/src/snapshot/account.rs +++ b/ethcore/src/snapshot/account.rs @@ -17,14 +17,17 @@ //! Account state encoding and decoding use account_db::{AccountDB, AccountDBMut}; -use types::basic_account::BasicAccount; +use types::{ + basic_account::BasicAccount, + snapshot::Progress, + errors::SnapshotError as Error, +}; use bytes::Bytes; use ethereum_types::{H256, U256}; use ethtrie::{TrieDB, TrieDBMut}; use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP}; use hash_db::HashDB; use rlp::{RlpStream, Rlp}; -use snapshot::{Error, Progress}; use std::collections::HashSet; use trie::{Trie, TrieMut}; use std::sync::atomic::Ordering; diff --git a/ethcore/src/snapshot/consensus/authority.rs b/ethcore/src/snapshot/consensus/authority.rs index 341c70d34c5..19f46bb144c 100644 --- a/ethcore/src/snapshot/consensus/authority.rs +++ b/ethcore/src/snapshot/consensus/authority.rs @@ -19,14 +19,14 @@ //! //! The chunks here contain state proofs of transitions, along with validator proofs. -use super::{SnapshotComponents, Rebuilder, ChunkSink}; - use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use engines::{Engine, EpochVerifier, EpochTransition}; -use snapshot::{ManifestData, Progress}; - +use engine::{ + Engine, + EpochVerifier, + snapshot::{SnapshotComponents, Rebuilder} +}; use blockchain::{BlockChain, BlockChainDB, BlockProvider}; use bytes::Bytes; use ethereum_types::{H256, U256}; @@ -35,10 +35,12 @@ use kvdb::KeyValueDB; use rlp::{RlpStream, Rlp}; use types::{ encoded, + engines::epoch::Transition as EpochTransition, header::Header, ids::BlockId, errors::{SnapshotError, EthcoreError}, receipt::Receipt, + snapshot::{ChunkSink, Progress, ManifestData} }; /// Snapshot creation and restoration for PoA chains. @@ -189,7 +191,7 @@ impl ChunkRebuilder { transition_rlp: Rlp, engine: &dyn Engine, ) -> Result { - use engines::ConstructedVerifier; + use engine::ConstructedVerifier; // decode. let header: Header = transition_rlp.val_at(0)?; diff --git a/ethcore/src/snapshot/consensus/mod.rs b/ethcore/src/snapshot/consensus/mod.rs index 102acdeca2a..3623d008d30 100644 --- a/ethcore/src/snapshot/consensus/mod.rs +++ b/ethcore/src/snapshot/consensus/mod.rs @@ -17,81 +17,8 @@ //! Secondary chunk creation and restoration, implementations for different consensus //! engines. -use std::sync::atomic::AtomicBool; -use std::sync::Arc; - -use blockchain::{BlockChain, BlockChainDB}; -use engines::Engine; -use snapshot::{ManifestData, Progress}; -use types::errors::{SnapshotError, EthcoreError}; - -use ethereum_types::H256; - mod authority; mod work; pub use self::authority::*; pub use self::work::*; - -/// A sink for produced chunks. -pub type ChunkSink<'a> = dyn FnMut(&[u8]) -> ::std::io::Result<()> + 'a; - -/// Components necessary for snapshot creation and restoration. -pub trait SnapshotComponents: Send { - /// Create secondary snapshot chunks; these corroborate the state data - /// in the state chunks. - /// - /// Chunks shouldn't exceed the given preferred size, and should be fed - /// uncompressed into the sink. - /// - /// This will vary by consensus engine, so it's exposed as a trait. - fn chunk_all( - &mut self, - chain: &BlockChain, - block_at: H256, - chunk_sink: &mut ChunkSink, - progress: &Progress, - preferred_size: usize, - ) -> Result<(), SnapshotError>; - - /// Create a rebuilder, which will have chunks fed into it in aribtrary - /// order and then be finalized. - /// - /// The manifest, a database, and fresh `BlockChain` are supplied. - /// - /// The engine passed to the `Rebuilder` methods will be the same instance - /// that created the `SnapshotComponents`. - fn rebuilder( - &self, - chain: BlockChain, - db: Arc, - manifest: &ManifestData, - ) -> Result, EthcoreError>; - - /// Minimum supported snapshot version number. - fn min_supported_version(&self) -> u64; - - /// Current version number - fn current_version(&self) -> u64; -} - -/// Restore from secondary snapshot chunks. -pub trait Rebuilder: Send { - /// Feed a chunk, potentially out of order. - /// - /// Check `abort_flag` periodically while doing heavy work. If set to `false`, should bail with - /// `Error::RestorationAborted`. - fn feed( - &mut self, - chunk: &[u8], - engine: &dyn Engine, - abort_flag: &AtomicBool, - ) -> Result<(), EthcoreError>; - - /// Finalize the restoration. Will be done after all chunks have been - /// fed successfully. - /// - /// This should apply the necessary "glue" between chunks, - /// and verify against the restored state. - fn finalize(&mut self) -> Result<(), EthcoreError>; -} diff --git a/ethcore/src/snapshot/consensus/work.rs b/ethcore/src/snapshot/consensus/work.rs index f286006a921..f9c4faec343 100644 --- a/ethcore/src/snapshot/consensus/work.rs +++ b/ethcore/src/snapshot/consensus/work.rs @@ -20,15 +20,13 @@ //! The secondary chunks in this instance are 30,000 "abridged blocks" from the head //! of the chain, which serve as an indication of valid chain. -use super::{SnapshotComponents, Rebuilder, ChunkSink}; - use std::collections::VecDeque; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use blockchain::{BlockChain, BlockChainDB, BlockProvider}; -use engines::Engine; -use snapshot::{ManifestData, Progress}; +use engine::Engine; +use engine::snapshot::{SnapshotComponents, Rebuilder}; use snapshot::block::AbridgedBlock; use ethereum_types::H256; use kvdb::KeyValueDB; @@ -37,7 +35,9 @@ use rlp::{RlpStream, Rlp}; use rand::rngs::OsRng; use types::{ encoded, + engines::epoch::Transition as EpochTransition, errors::{SnapshotError, EthcoreError}, + snapshot::{ChunkSink, ManifestData, Progress}, }; /// Snapshot creation and restoration for PoW chains. @@ -84,7 +84,12 @@ impl SnapshotComponents for PowSnapshot { db: Arc, manifest: &ManifestData, ) -> Result, EthcoreError> { - PowRebuilder::new(chain, db.key_value().clone(), manifest, self.max_restore_blocks).map(|r| Box::new(r) as Box<_>) + PowRebuilder::new( + chain, + db.key_value().clone(), + manifest, + self.max_restore_blocks + ).map(|r| Box::new(r) as Box<_>) } fn min_supported_version(&self) -> u64 { ::snapshot::MIN_SUPPORTED_STATE_CHUNK_VERSION } @@ -314,7 +319,7 @@ impl Rebuilder for PowRebuilder { } let genesis_hash = self.chain.genesis_hash(); - self.chain.insert_epoch_transition(&mut batch, 0, ::engines::EpochTransition { + self.chain.insert_epoch_transition(&mut batch, 0, EpochTransition { block_number: 0, block_hash: genesis_hash, proof: vec![], diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 256db1d94ec..3dab15d4f13 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -22,16 +22,16 @@ use std::collections::{HashMap, HashSet}; use std::cmp; use std::sync::Arc; -use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, Ordering}; use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY}; use account_db::{AccountDB, AccountDBMut}; use blockchain::{BlockChain, BlockProvider}; -use engines::Engine; use types::{ ids::BlockId, header::Header, errors::{SnapshotError as Error, EthcoreError}, + snapshot::Progress, }; use ethereum_types::{H256, U256}; use hash_db::HashDB; @@ -51,6 +51,10 @@ use self::io::SnapshotWriter; use super::state_db::StateDB; use account_state::Account as StateAccount; +use engine::{ + Engine, + snapshot::SnapshotComponents +}; use crossbeam_utils::thread; use rand::{Rng, rngs::OsRng}; @@ -59,7 +63,7 @@ pub use self::consensus::*; pub use self::service::{SnapshotClient, Service, DatabaseRestore}; pub use self::traits::SnapshotService; pub use self::watcher::Watcher; -pub use types::snapshot_manifest::ManifestData; +pub use types::snapshot::ManifestData; pub use types::restoration_status::RestorationStatus; pub use types::basic_account::BasicAccount; @@ -111,42 +115,6 @@ impl Default for SnapshotConfiguration { } } -/// A progress indicator for snapshots. -#[derive(Debug, Default)] -pub struct Progress { - accounts: AtomicUsize, - blocks: AtomicUsize, - size: AtomicU64, - done: AtomicBool, - abort: AtomicBool, -} - -impl Progress { - /// Reset the progress. - pub fn reset(&self) { - self.accounts.store(0, Ordering::Release); - self.blocks.store(0, Ordering::Release); - self.size.store(0, Ordering::Release); - self.abort.store(false, Ordering::Release); - - // atomic fence here to ensure the others are written first? - // logs might very rarely get polluted if not. - self.done.store(false, Ordering::Release); - } - - /// Get the number of accounts snapshotted thus far. - pub fn accounts(&self) -> usize { self.accounts.load(Ordering::Acquire) } - - /// Get the number of blocks snapshotted thus far. - pub fn blocks(&self) -> usize { self.blocks.load(Ordering::Acquire) } - - /// Get the written size of the snapshot in bytes. - pub fn size(&self) -> u64 { self.size.load(Ordering::Acquire) } - - /// Whether the snapshot is complete. - pub fn done(&self) -> bool { self.done.load(Ordering::Acquire) } - -} /// Take a snapshot using the given blockchain, starting block hash, and database, writing into the given writer. pub fn take_snapshot( chunker: Box, diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index 79bdb902cd2..3c1a3afea3b 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -24,17 +24,21 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::cmp; -use super::{ManifestData, StateRebuilder, Rebuilder, RestorationStatus, SnapshotService, MAX_CHUNK_SIZE}; +use super::{StateRebuilder, RestorationStatus, SnapshotService, MAX_CHUNK_SIZE}; use super::io::{SnapshotReader, LooseReader, SnapshotWriter, LooseWriter}; use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler}; -use client::{BlockChainClient, Client, ChainInfo, ClientIoMessage}; -use client_traits::BlockInfo; -use engines::Engine; +use client::{Client, ClientIoMessage}; +use client_traits::{ + BlockInfo, BlockChainClient, ChainInfo +}; +use engine::Engine; +use engine::snapshot::Rebuilder; use hash::keccak; use types::{ errors::{EthcoreError as Error, SnapshotError, SnapshotError::UnlinkedAncientBlockChain}, ids::BlockId, + snapshot::{ManifestData, Progress}, }; use io::IoChannel; @@ -245,7 +249,7 @@ pub struct Service { state_chunks: AtomicUsize, block_chunks: AtomicUsize, client: Arc, - progress: super::Progress, + progress: Progress, taking_snapshot: AtomicBool, restoring_snapshot: AtomicBool, } diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index 053e8813f33..d1931d911da 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -25,8 +25,9 @@ use hash::{KECCAK_NULL_RLP}; use account_db::AccountDBMut; use types::basic_account::BasicAccount; use blockchain::{BlockChain, BlockChainDB}; -use client::{Client, ChainInfo}; -use engines::Engine; +use client::Client; +use client_traits::ChainInfo; +use engine::Engine; use snapshot::{StateRebuilder}; use snapshot::io::{SnapshotReader, PackedWriter, PackedReader}; diff --git a/ethcore/src/snapshot/tests/proof_of_authority.rs b/ethcore/src/snapshot/tests/proof_of_authority.rs index f16357b0f37..a0161acdf98 100644 --- a/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -21,7 +21,8 @@ use std::sync::Arc; use std::str::FromStr; use accounts::AccountProvider; -use client::{Client, BlockChainClient, ChainInfo}; +use client::Client; +use client_traits::{BlockChainClient, ChainInfo}; use ethkey::Secret; use snapshot::tests::helpers as snapshot_helpers; use spec::Spec; diff --git a/ethcore/src/snapshot/tests/proof_of_work.rs b/ethcore/src/snapshot/tests/proof_of_work.rs index eee12a0c271..6e7726a6a0c 100644 --- a/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/ethcore/src/snapshot/tests/proof_of_work.rs @@ -18,7 +18,10 @@ use std::sync::atomic::AtomicBool; use tempdir::TempDir; -use types::errors::EthcoreError as Error; +use types::{ + errors::EthcoreError as Error, + engines::ForkChoice, +}; use blockchain::generator::{BlockGenerator, BlockBuilder}; use blockchain::{BlockChain, ExtrasInsert}; @@ -50,7 +53,7 @@ fn chunk_and_restore(amount: u64) { let mut batch = DBTransaction::new(); for block in generator { bc.insert_block(&mut batch, block.encoded(), vec![], ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: ForkChoice::New, is_finalized: false, }); bc.commit(); diff --git a/ethcore/src/snapshot/tests/service.rs b/ethcore/src/snapshot/tests/service.rs index 13ab94214ad..e9bc3b92bb7 100644 --- a/ethcore/src/snapshot/tests/service.rs +++ b/ethcore/src/snapshot/tests/service.rs @@ -21,19 +21,22 @@ use std::sync::Arc; use tempdir::TempDir; use blockchain::BlockProvider; -use client::{Client, ClientConfig, ImportBlock}; -use client_traits::BlockInfo; -use types::ids::BlockId; +use client::{Client, ClientConfig}; +use client_traits::{BlockInfo, ImportBlock}; +use types::{ + ids::BlockId, + snapshot::Progress, + verification::Unverified, +}; use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}; use snapshot::service::{Service, ServiceParams}; -use snapshot::{chunk_state, chunk_secondary, ManifestData, Progress, SnapshotService, RestorationStatus}; +use snapshot::{chunk_state, chunk_secondary, ManifestData, SnapshotService, RestorationStatus}; use crate::spec; use test_helpers::{new_db, new_temp_db, generate_dummy_client_with_spec_and_data, restoration_db_handler}; use parking_lot::Mutex; use io::IoChannel; use kvdb_rocksdb::DatabaseConfig; -use verification::queue::kind::blocks::Unverified; #[test] fn restored_is_equivalent() { diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 773119b3f0b..f5ffd543e60 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -39,8 +39,9 @@ use types::{ use vm::{EnvInfo, CallType, ActionValue, ActionParams, ParamsType}; use builtin::Builtin; +use engine::Engine; use engines::{ - Engine, NullEngine, InstantSeal, InstantSealParams, BasicAuthority, Clique, + NullEngine, InstantSeal, InstantSealParams, BasicAuthority, Clique, AuthorityRound, Ethash, }; use machine::{ diff --git a/ethcore/src/test_helpers.rs b/ethcore/src/test_helpers.rs index 2349b781cc6..32a5f7778da 100644 --- a/ethcore/src/test_helpers.rs +++ b/ethcore/src/test_helpers.rs @@ -33,20 +33,24 @@ use kvdb_rocksdb::{self, Database, DatabaseConfig}; use parking_lot::RwLock; use rlp::{self, RlpStream}; use tempdir::TempDir; -use types::transaction::{Action, Transaction, SignedTransaction}; -use types::encoded; -use types::header::Header; -use types::view; -use types::views::BlockView; +use types::{ + transaction::{Action, Transaction, SignedTransaction}, + encoded, + engines::ForkChoice, + header::Header, + view, + views::BlockView, + verification::Unverified, +}; use block::{OpenBlock, Drain}; -use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock}; +use client::{Client, ClientConfig, ChainNotify, ChainMessageType, PrepareOpenBlock}; +use client_traits::{ChainInfo, ImportBlock}; use trie_vm_factories::Factories; use miner::Miner; use spec::{Spec, self}; use account_state::*; use state_db::StateDB; -use verification::queue::kind::blocks::Unverified; /// Creates test block with corresponding header pub fn create_test_block(header: &Header) -> Bytes { @@ -375,7 +379,7 @@ pub fn generate_dummy_blockchain(block_number: u32) -> BlockChain { for block_order in 1..block_number { // Total difficulty is always 0 here. bc.insert_block(&mut batch, encoded::Block::new(create_unverifiable_block(block_order, bc.best_block_hash())), vec![], ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: ForkChoice::New, is_finalized: false, }); bc.commit(); @@ -393,7 +397,7 @@ pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> BlockChain { for block_order in 1..block_number { // Total difficulty is always 0 here. bc.insert_block(&mut batch, encoded::Block::new(create_unverifiable_block_with_extra(block_order, bc.best_block_hash(), None)), vec![], ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: ForkChoice::New, is_finalized: false, }); bc.commit(); diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 7c7b4c1d340..ea2aff7ae64 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -26,12 +26,13 @@ use types::{ ids::BlockId, transaction::{PendingTransaction, Transaction, Action, Condition}, filter::Filter, + verification::Unverified, view, views::BlockView, }; -use client::{BlockChainClient, BlockChainReset, Client, ClientConfig, ChainInfo, PrepareOpenBlock, ImportSealedBlock, ImportBlock}; -use client_traits::BlockInfo; +use client::{Client, ClientConfig, PrepareOpenBlock, ImportSealedBlock}; +use client_traits::{BlockInfo, BlockChainClient, BlockChainReset, ChainInfo, ImportBlock}; use crate::spec; use machine::executive::{Executive, TransactOptions}; use miner::{Miner, PendingOrdering, MinerService}; @@ -41,7 +42,6 @@ use test_helpers::{ generate_dummy_client, push_blocks_to_client, get_test_client_with_blocks, get_good_dummy_block_seq, generate_dummy_client_with_data, get_good_dummy_block, get_bad_state_dummy_block }; -use verification::queue::kind::blocks::Unverified; #[test] fn imports_from_empty() { @@ -210,7 +210,7 @@ fn can_generate_gas_price_histogram() { let client = generate_dummy_client_with_data(20, 1, slice_into![6354,8593,6065,4842,7845,7002,689,4958,4250,6098,5804,4320,643,8895,2296,8589,7145,2000,2512,1408]); let hist = client.gas_price_corpus(20).histogram(5).unwrap(); - let correct_hist = ::stats::Histogram { bucket_bounds: vec_into![643, 2294, 3945, 5596, 7247, 8898], counts: vec![4,2,4,6,4] }; + let correct_hist = stats::Histogram { bucket_bounds: vec_into![643, 2294, 3945, 5596, 7247, 8898], counts: vec![4,2,4,6,4] }; assert_eq!(hist, correct_hist); } @@ -327,7 +327,7 @@ fn does_not_propagate_delayed_transactions() { #[test] fn transaction_proof() { - use ::client::ProvingBlockChainClient; + use client_traits::ProvingBlockChainClient; let client = generate_dummy_client(0); let address = Address::random(); diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index 9f1326b4999..dd6fb8464d5 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -22,21 +22,21 @@ use block::*; use ethereum_types::{U256, Address}; use io::*; use crate::spec; -use client::*; use test_helpers::get_temp_state_db; -use client::{BlockChainClient, Client, ClientConfig}; +use client::{Client, ClientConfig}; +use client_traits::{BlockChainClient, ImportBlock}; use std::sync::Arc; use std::str::FromStr; use miner::Miner; use trace::{RewardType, LocalizedTrace}; use trace::trace::Action::Reward; use test_helpers; -use verification::queue::kind::blocks::Unverified; use types::{ ids::BlockId, transaction::{Action, Transaction}, trace_filter::Filter as TraceFilter, header::Header, + verification::Unverified, view, views::BlockView, }; diff --git a/ethcore/src/verification/canon_verifier.rs b/ethcore/src/verification/canon_verifier.rs index acf42b4510a..c0c60709700 100644 --- a/ethcore/src/verification/canon_verifier.rs +++ b/ethcore/src/verification/canon_verifier.rs @@ -18,7 +18,7 @@ use call_contract::CallContract; use client_traits::BlockInfo; -use engines::Engine; +use engine::Engine; use types::{ header::Header, errors::EthcoreError as Error, diff --git a/ethcore/src/verification/noop_verifier.rs b/ethcore/src/verification/noop_verifier.rs index 8bcbe1532d0..3f9a6210f40 100644 --- a/ethcore/src/verification/noop_verifier.rs +++ b/ethcore/src/verification/noop_verifier.rs @@ -18,7 +18,7 @@ use call_contract::CallContract; use client_traits::BlockInfo; -use engines::Engine; +use engine::Engine; use types::{ header::Header, errors::EthcoreError as Error diff --git a/ethcore/src/verification/queue/kind.rs b/ethcore/src/verification/queue/kind.rs index 106759ca3af..937d05abd18 100644 --- a/ethcore/src/verification/queue/kind.rs +++ b/ethcore/src/verification/queue/kind.rs @@ -16,7 +16,7 @@ //! Definition of valid items for the verification queue. -use engines::Engine; +use engine::Engine; use parity_util_mem::MallocSizeOf; use ethereum_types::{H256, U256}; @@ -69,18 +69,15 @@ pub trait Kind: 'static + Sized + Send + Sync { pub mod blocks { use super::{Kind, BlockLike}; - use engines::Engine; + use engine::Engine; use types::{ block::PreverifiedBlock, - header::Header, errors::{EthcoreError as Error, BlockError}, - transaction::UnverifiedTransaction + verification::Unverified, }; use verification::{verify_block_basic, verify_block_unordered}; - use parity_util_mem::MallocSizeOf; use ethereum_types::{H256, U256}; - use bytes::Bytes; /// A mode for verifying blocks. pub struct Blocks; @@ -116,40 +113,6 @@ pub mod blocks { } } - /// An unverified block. - #[derive(PartialEq, Debug, MallocSizeOf)] - pub struct Unverified { - /// Unverified block header. - pub header: Header, - /// Unverified block transactions. - pub transactions: Vec, - /// Unverified block uncles. - pub uncles: Vec
, - /// Raw block bytes. - pub bytes: Bytes, - } - - impl Unverified { - /// Create an `Unverified` from raw bytes. - pub fn from_rlp(bytes: Bytes) -> Result { - use rlp::Rlp; - let (header, transactions, uncles) = { - let rlp = Rlp::new(&bytes); - let header = rlp.val_at(0)?; - let transactions = rlp.list_at(1)?; - let uncles = rlp.list_at(2)?; - (header, transactions, uncles) - }; - - Ok(Unverified { - header, - transactions, - uncles, - bytes, - }) - } - } - impl BlockLike for Unverified { fn hash(&self) -> H256 { self.header.hash() @@ -183,7 +146,7 @@ pub mod blocks { pub mod headers { use super::{Kind, BlockLike}; - use engines::Engine; + use engine::Engine; use types::{ header::Header, errors::EthcoreError as Error, diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 9b736807d09..5bd96442aed 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -26,14 +26,14 @@ use parity_util_mem::{MallocSizeOf, MallocSizeOfExt}; use ethereum_types::{H256, U256}; use parking_lot::{Condvar, Mutex, RwLock}; use io::*; -use engines::Engine; +use engine::Engine; use client::ClientIoMessage; use len_caching_lock::LenCachingMutex; use types::errors::{BlockError, EthcoreError as Error, ImportError}; use self::kind::{BlockLike, Kind}; -pub use types::verification_queue_info::VerificationQueueInfo as QueueInfo; +pub use types::verification::VerificationQueueInfo as QueueInfo; pub mod kind; @@ -735,13 +735,13 @@ impl Drop for VerificationQueue { mod tests { use io::*; use super::{BlockQueue, Config, State}; - use super::kind::blocks::Unverified; use test_helpers::{get_good_dummy_block_seq, get_good_dummy_block}; use bytes::Bytes; use types::{ + errors::{EthcoreError, ImportError}, + verification::Unverified, view, views::BlockView, - errors::{EthcoreError, ImportError}, }; use crate::spec; diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 2042e70afc5..28cc87e5e6d 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -32,15 +32,15 @@ use unexpected::{Mismatch, OutOfBounds}; use blockchain::*; use call_contract::CallContract; use client_traits::BlockInfo; -use engines::Engine; +use engine::Engine; use types::{ BlockNumber, header::Header, errors::{EthcoreError as Error, BlockError}, engines::MAX_UNCLE_AGE, block::PreverifiedBlock, + verification::Unverified, }; -use verification::queue::kind::blocks::Unverified; use time_utils::CheckedSystemTime; @@ -370,7 +370,7 @@ mod tests { use blockchain::{BlockDetails, TransactionAddress, BlockReceipts}; use bytes::Bytes; use hash::keccak; - use engines::Engine; + use engine::Engine; use ethkey::{Random, Generator}; use crate::spec; use test_helpers::{create_test_block_with_data, create_test_block}; diff --git a/ethcore/src/verification/verifier.rs b/ethcore/src/verification/verifier.rs index 17bb96a2cab..ced7f564967 100644 --- a/ethcore/src/verification/verifier.rs +++ b/ethcore/src/verification/verifier.rs @@ -18,7 +18,7 @@ use call_contract::CallContract; use client_traits::BlockInfo; -use engines::Engine; +use engine::Engine; use types::{ header::Header, errors::EthcoreError as Error, diff --git a/ethcore/sync/Cargo.toml b/ethcore/sync/Cargo.toml index 5e2cf1cadaa..df35a4bab96 100644 --- a/ethcore/sync/Cargo.toml +++ b/ethcore/sync/Cargo.toml @@ -10,6 +10,7 @@ authors = ["Parity Technologies "] [dependencies] client-traits = { path = "../client-traits" } common-types = { path = "../types" } +engine = { path = "../engine" } enum_primitive = "0.1.1" ethcore = { path = ".." } ethcore-io = { path = "../../util/io" } diff --git a/ethcore/sync/src/api.rs b/ethcore/sync/src/api.rs index 9a8c6a8bf3a..3a662f8cb6a 100644 --- a/ethcore/sync/src/api.rs +++ b/ethcore/sync/src/api.rs @@ -32,7 +32,8 @@ use futures::sync::mpsc as futures_mpsc; use futures::Stream; use io::{TimerToken}; use ethkey::Secret; -use ethcore::client::{BlockChainClient, ChainNotify, NewBlocks, ChainMessageType}; +use ethcore::client::{ChainNotify, NewBlocks, ChainMessageType}; +use client_traits::BlockChainClient; use ethcore::snapshot::SnapshotService; use types::BlockNumber; use sync_io::NetSyncIo; diff --git a/ethcore/sync/src/blocks.rs b/ethcore/sync/src/blocks.rs index e5b89253668..0dd672786dc 100644 --- a/ethcore/sync/src/blocks.rs +++ b/ethcore/sync/src/blocks.rs @@ -22,9 +22,11 @@ use triehash_ethereum::ordered_trie_root; use bytes::Bytes; use rlp::{Rlp, RlpStream, DecoderError}; use network; -use ethcore::verification::queue::kind::blocks::Unverified; -use types::transaction::UnverifiedTransaction; -use types::header::Header as BlockHeader; +use types::{ + transaction::UnverifiedTransaction, + header::Header as BlockHeader, + verification::Unverified, +}; malloc_size_of_is_0!(HeaderId); @@ -541,12 +543,13 @@ impl BlockCollection { #[cfg(test)] mod test { use super::{BlockCollection, SyncHeader}; - use ethcore::client::{TestBlockChainClient, EachBlockWith, BlockChainClient}; + use client_traits::BlockChainClient; + use ethcore::client::{TestBlockChainClient, EachBlockWith}; use types::{ ids::BlockId, - BlockNumber + BlockNumber, + verification::Unverified, }; - use ethcore::verification::queue::kind::blocks::Unverified; use rlp::*; fn is_empty(bc: &BlockCollection) -> bool { diff --git a/ethcore/sync/src/chain/handler.rs b/ethcore/sync/src/chain/handler.rs index 15fd65e0f1a..659720e3f6d 100644 --- a/ethcore/sync/src/chain/handler.rs +++ b/ethcore/sync/src/chain/handler.rs @@ -19,7 +19,6 @@ use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAc use bytes::Bytes; use enum_primitive::FromPrimitive; use ethcore::snapshot::{ManifestData, RestorationStatus}; -use ethcore::verification::queue::kind::blocks::Unverified; use ethereum_types::{H256, U256}; use hash::keccak; use network::PeerId; @@ -34,6 +33,7 @@ use types::{ block_status::BlockStatus, ids::BlockId, errors::{EthcoreError, ImportError, BlockError}, + verification::Unverified, }; use super::sync_packet::{PacketInfo, SyncPacket}; @@ -742,9 +742,10 @@ impl SyncHandler { #[cfg(test)] mod tests { - use ethcore::client::{ChainInfo, EachBlockWith, TestBlockChainClient}; + use client_traits::ChainInfo; + use ethcore::client::{EachBlockWith, TestBlockChainClient}; use parking_lot::RwLock; - use rlp::{Rlp}; + use rlp::Rlp; use std::collections::{VecDeque}; use tests::helpers::{TestIo}; use tests::snapshot::TestSnapshotService; diff --git a/ethcore/sync/src/chain/mod.rs b/ethcore/sync/src/chain/mod.rs index 1ca7fe0a744..1b40649ecb5 100644 --- a/ethcore/sync/src/chain/mod.rs +++ b/ethcore/sync/src/chain/mod.rs @@ -108,7 +108,7 @@ use bytes::Bytes; use rlp::{RlpStream, DecoderError}; use network::{self, PeerId, PacketId}; use network::client_version::ClientVersion; -use ethcore::client::{BlockChainClient, BlockStatus, BlockChainInfo, BlockQueueInfo}; +use client_traits::BlockChainClient; use ethcore::snapshot::RestorationStatus; use sync_io::SyncIo; use super::{WarpSync, SyncConfig}; @@ -121,7 +121,10 @@ use transactions_stats::{TransactionsStats, Stats as TransactionStats}; use types::{ BlockNumber, ids::BlockId, - transaction::UnverifiedTransaction + transaction::UnverifiedTransaction, + verification::VerificationQueueInfo as BlockQueueInfo, + blockchain_info::BlockChainInfo, + block_status::BlockStatus, }; use self::handler::SyncHandler; @@ -1373,8 +1376,8 @@ pub mod tests { use super::*; use ::SyncConfig; use super::{PeerInfo, PeerAsking}; - use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient, ChainInfo}; - use client_traits::BlockInfo; + use ethcore::client::{EachBlockWith, TestBlockChainClient}; + use client_traits::{BlockInfo, BlockChainClient, ChainInfo}; use ethcore::miner::{MinerService, PendingOrdering}; use types::header::Header; diff --git a/ethcore/sync/src/chain/propagator.rs b/ethcore/sync/src/chain/propagator.rs index eb554cd5de7..e347d81c8d9 100644 --- a/ethcore/sync/src/chain/propagator.rs +++ b/ethcore/sync/src/chain/propagator.rs @@ -335,8 +335,8 @@ impl SyncPropagator { #[cfg(test)] mod tests { - use ethcore::client::{ChainInfo, EachBlockWith, TestBlockChainClient}; - use client_traits::BlockInfo; + use client_traits::{BlockInfo, ChainInfo}; + use ethcore::client::{EachBlockWith, TestBlockChainClient}; use parking_lot::RwLock; use rlp::Rlp; use std::collections::VecDeque; diff --git a/ethcore/sync/src/chain/supplier.rs b/ethcore/sync/src/chain/supplier.rs index 34cb7161798..e802cb0e0a5 100644 --- a/ethcore/sync/src/chain/supplier.rs +++ b/ethcore/sync/src/chain/supplier.rs @@ -376,7 +376,8 @@ mod test { use rlp::{Rlp, RlpStream}; use super::{*, super::tests::*}; use blocks::SyncHeader; - use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient}; + use client_traits::BlockChainClient; + use ethcore::client::{EachBlockWith, TestBlockChainClient}; use std::str::FromStr; #[test] diff --git a/ethcore/sync/src/lib.rs b/ethcore/sync/src/lib.rs index 4f71170bce4..674f0db4443 100644 --- a/ethcore/sync/src/lib.rs +++ b/ethcore/sync/src/lib.rs @@ -21,6 +21,7 @@ //! https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol //! +extern crate client_traits; extern crate common_types as types; extern crate ethcore; extern crate ethcore_io as io; @@ -46,8 +47,8 @@ extern crate ethcore_light as light; #[cfg(test)] extern crate kvdb_memorydb; #[cfg(test)] extern crate rustc_hex; #[cfg(test)] extern crate rand_xorshift; -#[cfg(test)] extern crate client_traits; #[cfg(test)] extern crate machine; +#[cfg(test)] extern crate engine; #[macro_use] extern crate enum_primitive; diff --git a/ethcore/sync/src/sync_io.rs b/ethcore/sync/src/sync_io.rs index 73f95caf9f5..b7a25bafda8 100644 --- a/ethcore/sync/src/sync_io.rs +++ b/ethcore/sync/src/sync_io.rs @@ -19,7 +19,7 @@ use chain::sync_packet::{PacketInfo, SyncPacket}; use network::{NetworkContext, PeerId, PacketId, Error, SessionInfo, ProtocolId}; use network::client_version::ClientVersion; use bytes::Bytes; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use types::BlockNumber; use ethcore::snapshot::SnapshotService; use parking_lot::RwLock; diff --git a/ethcore/sync/src/tests/chain.rs b/ethcore/sync/src/tests/chain.rs index 1ae9922a5be..0f67321df68 100644 --- a/ethcore/sync/src/tests/chain.rs +++ b/ethcore/sync/src/tests/chain.rs @@ -16,7 +16,8 @@ use std::sync::Arc; use types::ids::BlockId; -use ethcore::client::{TestBlockChainClient, BlockChainClient, EachBlockWith, ChainInfo}; +use client_traits::{BlockChainClient, ChainInfo}; +use ethcore::client::{TestBlockChainClient, EachBlockWith}; use client_traits::BlockInfo; use chain::SyncState; use super::helpers::*; diff --git a/ethcore/sync/src/tests/consensus.rs b/ethcore/sync/src/tests/consensus.rs index 8f17ecb156b..f991d4692e4 100644 --- a/ethcore/sync/src/tests/consensus.rs +++ b/ethcore/sync/src/tests/consensus.rs @@ -18,8 +18,9 @@ use std::sync::Arc; use hash::keccak; use ethereum_types::{U256, Address}; use io::{IoHandler, IoChannel}; -use ethcore::client::{ChainInfo, ClientIoMessage}; -use ethcore::engines; +use client_traits::ChainInfo; +use engine::signer; +use ethcore::client::{ClientIoMessage}; use ethcore::spec; use ethcore::miner::{self, MinerService}; use ethkey::{KeyPair, Secret}; @@ -49,8 +50,8 @@ fn authority_round() { let io_handler0: Arc> = Arc::new(TestIoHandler::new(net.peer(0).chain.clone())); let io_handler1: Arc> = Arc::new(TestIoHandler::new(net.peer(1).chain.clone())); // Push transaction to both clients. Only one of them gets lucky to produce a block. - net.peer(0).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s0.clone()))); - net.peer(1).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s1.clone()))); + net.peer(0).miner.set_author(miner::Author::Sealer(signer::from_keypair(s0.clone()))); + net.peer(1).miner.set_author(miner::Author::Sealer(signer::from_keypair(s1.clone()))); net.peer(0).chain.engine().register_client(Arc::downgrade(&net.peer(0).chain) as _); net.peer(1).chain.engine().register_client(Arc::downgrade(&net.peer(1).chain) as _); net.peer(0).chain.set_io_channel(IoChannel::to_handler(Arc::downgrade(&io_handler1))); diff --git a/ethcore/sync/src/tests/helpers.rs b/ethcore/sync/src/tests/helpers.rs index 135161a381a..017e8b3ee24 100644 --- a/ethcore/sync/src/tests/helpers.rs +++ b/ethcore/sync/src/tests/helpers.rs @@ -22,7 +22,8 @@ use bytes::Bytes; use network::{self, PeerId, ProtocolId, PacketId, SessionInfo}; use network::client_version::ClientVersion; use tests::snapshot::*; -use ethcore::client::{TestBlockChainClient, BlockChainClient, Client as EthcoreClient, +use client_traits::BlockChainClient; +use ethcore::client::{TestBlockChainClient, Client as EthcoreClient, ClientConfig, ChainNotify, NewBlocks, ChainMessageType, ClientIoMessage}; use ethcore::snapshot::SnapshotService; use ethcore::spec::{self, Spec}; diff --git a/ethcore/sync/src/tests/private.rs b/ethcore/sync/src/tests/private.rs index c62a4ae35a0..1d91e212403 100644 --- a/ethcore/sync/src/tests/private.rs +++ b/ethcore/sync/src/tests/private.rs @@ -19,10 +19,11 @@ use hash::keccak; use io::{IoHandler, IoChannel}; use types::transaction::{Transaction, Action}; use types::ids::BlockId; +use client_traits::BlockChainClient; +use engine::signer; use ethcore::{ CreateContractAddress, - client::{ClientIoMessage, BlockChainClient}, - engines, + client::ClientIoMessage, miner::{self, MinerService}, spec::Spec, test_helpers::push_block_with_transactions, @@ -54,8 +55,8 @@ fn send_private_transaction() { let io_handler0: Arc> = Arc::new(TestIoHandler::new(net.peer(0).chain.clone())); let io_handler1: Arc> = Arc::new(TestIoHandler::new(net.peer(1).chain.clone())); - net.peer(0).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s0.clone()))); - net.peer(1).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s1.clone()))); + net.peer(0).miner.set_author(miner::Author::Sealer(signer::from_keypair(s0.clone()))); + net.peer(1).miner.set_author(miner::Author::Sealer(signer::from_keypair(s1.clone()))); net.peer(0).chain.engine().register_client(Arc::downgrade(&net.peer(0).chain) as _); net.peer(1).chain.engine().register_client(Arc::downgrade(&net.peer(1).chain) as _); net.peer(0).chain.set_io_channel(IoChannel::to_handler(Arc::downgrade(&io_handler0))); diff --git a/ethcore/types/src/client_types.rs b/ethcore/types/src/client_types.rs new file mode 100644 index 00000000000..ad90e0db0d6 --- /dev/null +++ b/ethcore/types/src/client_types.rs @@ -0,0 +1,49 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . + +//! Client related types. + +use std::{ + fmt::{Display, Formatter, Error as FmtError}, + time::Duration, +}; + +/// Operating mode for the client. +#[derive(Debug, Eq, PartialEq, Clone)] +pub enum Mode { + /// Always on. + Active, + /// Goes offline after client is inactive for some (given) time, but + /// comes back online after a while of inactivity. + Passive(Duration, Duration), + /// Goes offline after client is inactive for some (given) time and + /// stays inactive. + Dark(Duration), + /// Always off. + Off, +} + +impl Display for Mode { + fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { + match *self { + Mode::Active => write!(f, "active"), + Mode::Passive(..) => write!(f, "passive"), + Mode::Dark(..) => write!(f, "dark"), + Mode::Off => write!(f, "offline"), + } + } +} + diff --git a/ethcore/types/src/engines/machine.rs b/ethcore/types/src/engines/machine.rs index be0a5ef9c01..db952aebc0a 100644 --- a/ethcore/types/src/engines/machine.rs +++ b/ethcore/types/src/engines/machine.rs @@ -16,9 +16,14 @@ //! State machine types -use ethereum_types::Address; +use ethereum_types::{Address, U256}; +use bytes::Bytes; -use crate::receipt; +use crate::{ + log_entry::LogEntry, + receipt, + state_diff::StateDiff, +}; /// Type alias for a function we can make calls through synchronously. /// Returns the call result and state proof for each call. @@ -44,3 +49,47 @@ pub struct AuxiliaryData<'a> { /// The block receipts. pub receipts: Option<&'a [receipt::Receipt]>, } + + +/// Transaction execution receipt. +#[derive(Debug, PartialEq, Clone)] +pub struct Executed { + /// True if the outer call/create resulted in an exceptional exit. + pub exception: Option, + + /// Gas paid up front for execution of transaction. + pub gas: U256, + + /// Gas used during execution of transaction. + pub gas_used: U256, + + /// Gas refunded after the execution of transaction. + /// To get gas that was required up front, add `refunded` and `gas_used`. + pub refunded: U256, + + /// Cumulative gas used in current block so far. + /// + /// `cumulative_gas_used = gas_used(t0) + gas_used(t1) + ... gas_used(tn)` + /// + /// where `tn` is current transaction. + pub cumulative_gas_used: U256, + + /// Vector of logs generated by transaction. + pub logs: Vec, + + /// Addresses of contracts created during execution of transaction. + /// Ordered from earliest creation. + /// + /// eg. sender creates contract A and A in constructor creates contract B + /// + /// B creation ends first, and it will be the first element of the vector. + pub contracts_created: Vec
, + /// Transaction output. + pub output: Bytes, + /// The trace of this transaction. + pub trace: Vec, + /// The VM trace of this transaction. + pub vm_trace: Option, + /// The state diff, if we traced it. + pub state_diff: Option, +} diff --git a/ethcore/types/src/engines/mod.rs b/ethcore/types/src/engines/mod.rs index ac8a20d290d..3a1564b9ab1 100644 --- a/ethcore/types/src/engines/mod.rs +++ b/ethcore/types/src/engines/mod.rs @@ -17,6 +17,7 @@ //! Engine-specific types. use ethereum_types::{Address, H256}; +use bytes::Bytes; use ethjson; use crate::BlockNumber; @@ -25,6 +26,15 @@ pub mod epoch; pub mod params; pub mod machine; +/// Seal type. +#[derive(Debug, PartialEq, Eq)] +pub enum Seal { + /// Regular block seal; should be part of the blockchain. + Regular(Vec), + /// Engine does not generate seal for this block right now. + None, +} + /// The type of sealing the engine is currently able to perform. #[derive(Debug, PartialEq, Eq)] pub enum SealingState { diff --git a/ethcore/types/src/lib.rs b/ethcore/types/src/lib.rs index d209b3d25a4..99153a205b0 100644 --- a/ethcore/types/src/lib.rs +++ b/ethcore/types/src/lib.rs @@ -64,6 +64,7 @@ pub mod block; pub mod block_status; pub mod blockchain_info; pub mod call_analytics; +pub mod client_types; pub mod encoded; pub mod engines; pub mod errors; @@ -75,12 +76,12 @@ pub mod pruning_info; pub mod receipt; pub mod restoration_status; pub mod security_level; -pub mod snapshot_manifest; +pub mod snapshot; pub mod state_diff; pub mod trace_filter; pub mod transaction; pub mod tree_route; -pub mod verification_queue_info; +pub mod verification; /// Type for block number. pub type BlockNumber = u64; diff --git a/ethcore/types/src/snapshot_manifest.rs b/ethcore/types/src/snapshot.rs similarity index 57% rename from ethcore/types/src/snapshot_manifest.rs rename to ethcore/types/src/snapshot.rs index 8ed19fcfc20..dd58279e267 100644 --- a/ethcore/types/src/snapshot_manifest.rs +++ b/ethcore/types/src/snapshot.rs @@ -14,12 +14,55 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Snapshot manifest type definition +//! Snapshot type definitions + +use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU64, Ordering}; use ethereum_types::H256; use rlp::{Rlp, RlpStream, DecoderError}; use bytes::Bytes; +/// A progress indicator for snapshots. +#[derive(Debug, Default)] +pub struct Progress { + /// Number of accounts processed so far + pub accounts: AtomicUsize, + /// Number of blocks processed so far + pub blocks: AtomicUsize, + /// Size in bytes of a all compressed chunks processed so far + pub size: AtomicU64, + /// Signals that the snapshotting process is completed + pub done: AtomicBool, + /// Signal snapshotting process to abort + pub abort: AtomicBool, +} + +impl Progress { + /// Reset the progress. + pub fn reset(&self) { + self.accounts.store(0, Ordering::Release); + self.blocks.store(0, Ordering::Release); + self.size.store(0, Ordering::Release); + self.abort.store(false, Ordering::Release); + + // atomic fence here to ensure the others are written first? + // logs might very rarely get polluted if not. + self.done.store(false, Ordering::Release); + } + + /// Get the number of accounts snapshotted thus far. + pub fn accounts(&self) -> usize { self.accounts.load(Ordering::Acquire) } + + /// Get the number of blocks snapshotted thus far. + pub fn blocks(&self) -> usize { self.blocks.load(Ordering::Acquire) } + + /// Get the written size of the snapshot in bytes. + pub fn size(&self) -> u64 { self.size.load(Ordering::Acquire) } + + /// Whether the snapshot is complete. + pub fn done(&self) -> bool { self.done.load(Ordering::Acquire) } +} + /// Manifest data. #[derive(Debug, Clone, PartialEq, Eq)] pub struct ManifestData { @@ -67,12 +110,15 @@ impl ManifestData { let block_hash: H256 = decoder.val_at(start + 4)?; Ok(ManifestData { - version: version, - state_hashes: state_hashes, - block_hashes: block_hashes, - state_root: state_root, - block_number: block_number, - block_hash: block_hash, + version, + state_hashes, + block_hashes, + state_root, + block_number, + block_hash, }) } } + +/// A sink for produced chunks. +pub type ChunkSink<'a> = dyn FnMut(&[u8]) -> std::io::Result<()> + 'a; diff --git a/ethcore/types/src/verification_queue_info.rs b/ethcore/types/src/verification.rs similarity index 67% rename from ethcore/types/src/verification_queue_info.rs rename to ethcore/types/src/verification.rs index b89cfe20c0d..dedf4549298 100644 --- a/ethcore/types/src/verification_queue_info.rs +++ b/ethcore/types/src/verification.rs @@ -14,7 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Verification queue info types +//! Verification types + +use crate::{ + header::Header, + transaction::UnverifiedTransaction, +}; +use bytes::Bytes; +use parity_util_mem::MallocSizeOf; /// Verification queue status #[derive(Debug, Clone)] @@ -48,3 +55,38 @@ impl VerificationQueueInfo { self.unverified_queue_size + self.verified_queue_size + self.verifying_queue_size == 0 } } + +/// An unverified block. +#[derive(PartialEq, Debug, MallocSizeOf)] +pub struct Unverified { + /// Unverified block header. + pub header: Header, + /// Unverified block transactions. + pub transactions: Vec, + /// Unverified block uncles. + pub uncles: Vec
, + /// Raw block bytes. + pub bytes: Bytes, +} + +impl Unverified { + /// Create an `Unverified` from raw bytes. + pub fn from_rlp(bytes: Bytes) -> Result { + use rlp::Rlp; + let (header, transactions, uncles) = { + let rlp = Rlp::new(&bytes); + let header = rlp.val_at(0)?; + let transactions = rlp.list_at(1)?; + let uncles = rlp.list_at(2)?; + (header, transactions, uncles) + }; + + Ok(Unverified { + header, + transactions, + uncles, + bytes, + }) + } +} + diff --git a/ipfs/Cargo.toml b/ipfs/Cargo.toml index 3df59d012f0..44902200e9d 100644 --- a/ipfs/Cargo.toml +++ b/ipfs/Cargo.toml @@ -6,6 +6,7 @@ license = "GPL-3.0" authors = ["Parity Technologies "] [dependencies] +client-traits = { path = "../ethcore/client-traits" } common-types = { path = "../ethcore/types" } ethcore = { path = "../ethcore" } parity-bytes = "0.1" diff --git a/ipfs/src/lib.rs b/ipfs/src/lib.rs index 635fd4c76ea..40ff2bd1891 100644 --- a/ipfs/src/lib.rs +++ b/ipfs/src/lib.rs @@ -19,6 +19,7 @@ extern crate cid; extern crate unicase; extern crate rlp; +extern crate client_traits; extern crate common_types; extern crate ethcore; extern crate parity_bytes as bytes; @@ -35,7 +36,7 @@ use std::net::{SocketAddr, IpAddr}; use core::futures::future::{self, FutureResult}; use core::futures::{self, Future}; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use http::hyper::{self, server, Method, StatusCode, Body, header::{self, HeaderValue}, }; diff --git a/miner/src/pool/local_transactions.rs b/miner/src/pool/local_transactions.rs index 346877d0301..a83af5b72e4 100644 --- a/miner/src/pool/local_transactions.rs +++ b/miner/src/pool/local_transactions.rs @@ -66,7 +66,7 @@ pub struct LocalTransactionsList { max_old: usize, transactions: LinkedHashMap, pending: usize, - in_chain: Option bool + Send + Sync>>, + in_chain: Option bool + Send + Sync>>, } impl fmt::Debug for LocalTransactionsList { diff --git a/parity/account_utils.rs b/parity/account_utils.rs index 88a8dcfd484..9c380c2f56e 100644 --- a/parity/account_utils.rs +++ b/parity/account_utils.rs @@ -133,7 +133,7 @@ mod accounts { } pub fn miner_author(spec: &SpecType, dirs: &Directories, account_provider: &Arc, engine_signer: Address, passwords: &[Password]) -> Result, String> { - use ethcore::engines::EngineSigner; + use engine::signer::EngineSigner; // Check if engine signer exists if !account_provider.has_account(engine_signer) { diff --git a/parity/blockchain.rs b/parity/blockchain.rs index 7d19333be0b..d5e66676803 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -26,13 +26,12 @@ use hash::{keccak, KECCAK_NULL_RLP}; use ethereum_types::{U256, H256, Address}; use bytes::ToPretty; use rlp::PayloadInfo; -use client_traits::BlockInfo; -use ethcore::client::{ - Mode, DatabaseCompactionProfile, VMType, Nonce, Balance, BlockChainClient, ImportBlock, BlockChainReset +use client_traits::{BlockInfo, BlockChainReset, Nonce, Balance, BlockChainClient, ImportBlock}; +use ethcore::{ + client::{DatabaseCompactionProfile, VMType}, + miner::Miner, + verification::queue::VerifierSettings, }; -use ethcore::miner::Miner; -use ethcore::verification::queue::VerifierSettings; -use ethcore::verification::queue::kind::blocks::Unverified; use ethcore_service::ClientService; use cache::CacheConfig; use informant::{Informant, FullNodeInformantData, MillisecondDuration}; @@ -45,7 +44,9 @@ use db; use ansi_term::Colour; use types::{ ids::BlockId, - errors::{ImportError, EthcoreError} + errors::{ImportError, EthcoreError}, + client_types::Mode, + verification::Unverified, }; #[derive(Debug, PartialEq)] diff --git a/parity/helpers.rs b/parity/helpers.rs index 1c9494e3ddf..ebcdf87bcd4 100644 --- a/parity/helpers.rs +++ b/parity/helpers.rs @@ -21,7 +21,7 @@ use std::fs::File; use std::collections::HashSet; use ethereum_types::{U256, Address}; use journaldb::Algorithm; -use ethcore::client::{Mode, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType}; +use ethcore::client::{VMType, DatabaseCompactionProfile, ClientConfig, VerifierType}; use ethcore::miner::{PendingSet, Penalization}; use miner::pool::PrioritizationStrategy; use cache::CacheConfig; @@ -32,7 +32,10 @@ use sync::{validate_node_url, self}; use db::migrate; use path; use ethkey::Password; -use types::ids::BlockId; +use types::{ + ids::BlockId, + client_types::Mode, +}; pub fn to_duration(s: &str) -> Result { to_seconds(s).map(Duration::from_secs) @@ -348,10 +351,12 @@ mod tests { use std::collections::HashSet; use tempdir::TempDir; use ethereum_types::U256; - use ethcore::client::Mode; use ethcore::miner::PendingSet; use ethkey::Password; - use types::ids::BlockId; + use types::{ + ids::BlockId, + client_types::Mode, + }; use super::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_address, to_addresses, to_price, geth_ipc_path, to_bootnodes, join_set, password_from_file}; #[test] diff --git a/parity/informant.rs b/parity/informant.rs index cd2690b23bb..683c67c4bd1 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -24,13 +24,14 @@ use std::time::{Instant, Duration}; use atty; use ethcore::client::{ - ChainInfo, BlockChainInfo, BlockChainClient, - BlockQueueInfo, ChainNotify, NewBlocks, ClientReport, Client, ClientIoMessage + ChainNotify, NewBlocks, ClientReport, Client, ClientIoMessage }; -use client_traits::BlockInfo; +use client_traits::{BlockInfo, ChainInfo, BlockChainClient}; use types::{ BlockNumber, ids::BlockId, + blockchain_info::BlockChainInfo, + verification::VerificationQueueInfo as BlockQueueInfo, }; use ethcore::snapshot::{RestorationStatus, SnapshotService as SS}; use ethcore::snapshot::service::Service as SnapshotService; diff --git a/parity/ipfs.rs b/parity/ipfs.rs index 0923a1e7d40..f8062f52a1c 100644 --- a/parity/ipfs.rs +++ b/parity/ipfs.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use parity_ipfs_api::{self, AccessControlAllowOrigin, Host, Listening}; use parity_ipfs_api::error::ServerError; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; #[derive(Debug, PartialEq, Clone)] pub struct Configuration { diff --git a/parity/lib.rs b/parity/lib.rs index 2e5e5c1b838..86abde9da24 100644 --- a/parity/lib.rs +++ b/parity/lib.rs @@ -44,6 +44,7 @@ extern crate cli_signer; extern crate client_traits; extern crate common_types as types; +extern crate engine; extern crate ethcore; extern crate ethcore_call_contract as call_contract; extern crate ethcore_db; diff --git a/parity/light_helpers/epoch_fetch.rs b/parity/light_helpers/epoch_fetch.rs index 95eea58586d..f73aec57dcf 100644 --- a/parity/light_helpers/epoch_fetch.rs +++ b/parity/light_helpers/epoch_fetch.rs @@ -16,11 +16,13 @@ use std::sync::{Arc, Weak}; -use ethcore::engines::{Engine, StateDependentProof}; +use engine::{Engine, StateDependentProof}; use sync::{LightSync, LightNetworkDispatcher}; -use types::encoded; -use types::header::Header; -use types::receipt::Receipt; +use types::{ + header::Header, + encoded, + receipt::Receipt, +}; use futures::{future, Future}; use futures::future::Either; diff --git a/parity/modules.rs b/parity/modules.rs index 8c86cda9b95..f8607b827ff 100644 --- a/parity/modules.rs +++ b/parity/modules.rs @@ -16,7 +16,7 @@ use std::sync::{Arc, mpsc}; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use sync::{self, SyncConfig, NetworkConfiguration, Params, ConnectionFilter}; use ethcore::snapshot::SnapshotService; use light::Provider; diff --git a/parity/params.rs b/parity/params.rs index 65b8d77ee7a..e4d1e7548f6 100644 --- a/parity/params.rs +++ b/parity/params.rs @@ -18,7 +18,6 @@ use std::collections::HashSet; use std::time::Duration; use std::{str, fs, fmt}; -use ethcore::client::Mode; use ethcore::spec::{Spec, SpecParams, self}; use ethereum_types::{U256, Address}; use parity_runtime::Executor; @@ -28,6 +27,7 @@ use miner::gas_pricer::GasPricer; use miner::gas_price_calibrator::{GasPriceCalibratorOptions, GasPriceCalibrator}; use parity_version::version_data; use user_defaults::UserDefaults; +use types::client_types::Mode; #[derive(Debug, PartialEq)] pub enum SpecType { diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index b3aec40dcc2..0b9d4d9f58b 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -25,7 +25,7 @@ use account_utils::{self, AccountProvider}; use ethcore::client::Client; use ethcore::miner::Miner; use ethcore::snapshot::SnapshotService; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use sync::SyncState; use ethcore_logger::RotatingLogger; use ethcore_private_tx::Provider as PrivateTransactionManager; diff --git a/parity/run.rs b/parity/run.rs index 6f1c441f18e..82ae9694f73 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -22,8 +22,8 @@ use std::thread; use ansi_term::Colour; use bytes::Bytes; use call_contract::CallContract; -use client_traits::BlockInfo; -use ethcore::client::{Client, Mode, DatabaseCompactionProfile, VMType, BlockChainClient}; +use client_traits::{BlockInfo, BlockChainClient}; +use ethcore::client::{Client, DatabaseCompactionProfile, VMType}; use ethcore::miner::{self, stratum, Miner, MinerService, MinerOptions}; use ethcore::snapshot::{self, SnapshotConfiguration}; use ethcore::spec::{SpecParams, OptimizeFor}; @@ -41,7 +41,10 @@ use miner::work_notify::WorkPoster; use node_filter::NodeFilter; use parity_runtime::Runtime; use sync::{self, SyncConfig, PrivateTxHandler}; -use types::ids::BlockId; +use types::{ + client_types::Mode, + ids::BlockId, +}; use parity_rpc::{ Origin, Metadata, NetworkSettings, informant, PubSubSession, FutureResult, FutureResponse, FutureOutput }; diff --git a/parity/snapshot.rs b/parity/snapshot.rs index c1d2a77e3fd..19cfb489718 100644 --- a/parity/snapshot.rs +++ b/parity/snapshot.rs @@ -21,13 +21,17 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use hash::keccak; -use ethcore::snapshot::{Progress, RestorationStatus, SnapshotConfiguration, SnapshotService as SS}; +use ethcore::snapshot::{RestorationStatus, SnapshotConfiguration, SnapshotService as SS}; use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter}; use ethcore::snapshot::service::Service as SnapshotService; -use ethcore::client::{Mode, DatabaseCompactionProfile, VMType}; +use ethcore::client::{DatabaseCompactionProfile, VMType}; use ethcore::miner::Miner; use ethcore_service::ClientService; -use types::ids::BlockId; +use types::{ + ids::BlockId, + snapshot::Progress, + client_types::Mode, +}; use cache::CacheConfig; use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool}; diff --git a/parity/user_defaults.rs b/parity/user_defaults.rs index bdd5d9efb33..34e68dd824d 100644 --- a/parity/user_defaults.rs +++ b/parity/user_defaults.rs @@ -22,7 +22,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_json::de::from_reader; use serde_json::ser::to_string; use journaldb::Algorithm; -use ethcore::client::{Mode as ClientMode}; +use types::client_types::Mode as ClientMode; #[derive(Clone)] pub struct Seconds(Duration); diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index fc5baa868be..507b821ef24 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -35,7 +35,9 @@ jsonrpc-ws-server = "12.0.0" jsonrpc-ipc-server = "12.0.0" jsonrpc-pubsub = "12.0.0" +client-traits = { path = "../ethcore/client-traits" } common-types = { path = "../ethcore/types" } +engine = { path = "../ethcore/engine" } ethash = { path = "../ethash" } ethcore = { path = "../ethcore", features = ["test-helpers"] } ethcore-accounts = { path = "../accounts", optional = true } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 37749cf43d7..897df8d96c1 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -61,7 +61,9 @@ extern crate jsonrpc_http_server as http; extern crate jsonrpc_ipc_server as ipc; extern crate jsonrpc_pubsub; +extern crate client_traits; extern crate common_types as types; +extern crate engine; extern crate ethash; extern crate ethcore; extern crate fastmap; @@ -121,8 +123,6 @@ extern crate fake_fetch; #[cfg(test)] extern crate ethcore_io as io; -#[cfg(test)] -extern crate client_traits; pub extern crate jsonrpc_ws_server as ws; diff --git a/rpc/src/v1/helpers/block_import.rs b/rpc/src/v1/helpers/block_import.rs index 8e8dba28f7b..a062e11786f 100644 --- a/rpc/src/v1/helpers/block_import.rs +++ b/rpc/src/v1/helpers/block_import.rs @@ -16,7 +16,7 @@ //! Block import analysis functions. -use ethcore::client::BlockQueueInfo; +use types::verification::VerificationQueueInfo as BlockQueueInfo; use sync::SyncState; /// Check if client is during major sync or during block import and allows defining whether 'waiting for peers' should diff --git a/rpc/src/v1/helpers/dispatch/full.rs b/rpc/src/v1/helpers/dispatch/full.rs index d958416cbf2..8c23f720822 100644 --- a/rpc/src/v1/helpers/dispatch/full.rs +++ b/rpc/src/v1/helpers/dispatch/full.rs @@ -16,7 +16,7 @@ use std::sync::Arc; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use ethcore::miner::{self, MinerService}; use ethereum_types::{H256, U256, Address}; use types::transaction::{SignedTransaction, PendingTransaction}; diff --git a/rpc/src/v1/helpers/dispatch/mod.rs b/rpc/src/v1/helpers/dispatch/mod.rs index 3f247f0c6c0..fa82385087b 100644 --- a/rpc/src/v1/helpers/dispatch/mod.rs +++ b/rpc/src/v1/helpers/dispatch/mod.rs @@ -75,7 +75,7 @@ use std::ops::Deref; use std::sync::Arc; use bytes::Bytes; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use ethcore::miner::MinerService; use ethereum_types::{H520, H256, U256, Address}; use ethkey::{Password, Signature}; diff --git a/rpc/src/v1/helpers/engine_signer.rs b/rpc/src/v1/helpers/engine_signer.rs index 4cc3608cb96..fd40dc95e24 100644 --- a/rpc/src/v1/helpers/engine_signer.rs +++ b/rpc/src/v1/helpers/engine_signer.rs @@ -33,7 +33,7 @@ impl EngineSigner { } } -impl ethcore::engines::EngineSigner for EngineSigner { +impl engine::signer::EngineSigner for EngineSigner { fn sign(&self, message: ethkey::Message) -> Result { match self.accounts.sign(self.address, Some(self.password.clone()), message) { Ok(ok) => Ok(ok), diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index a9f8ab8fc4e..791d7e3b941 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -24,7 +24,7 @@ use types::transaction::Error as TransactionError; use ethcore_private_tx::Error as PrivateTransactionError; use vm::Error as VMError; use light::on_demand::error::{Error as OnDemandError}; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use types::{ ids::BlockId, blockchain_info::BlockChainInfo, diff --git a/rpc/src/v1/helpers/light_fetch.rs b/rpc/src/v1/helpers/light_fetch.rs index 2a78f46f4d3..f2e67f86c9d 100644 --- a/rpc/src/v1/helpers/light_fetch.rs +++ b/rpc/src/v1/helpers/light_fetch.rs @@ -741,7 +741,7 @@ where tx: EthTransaction, hdr: encoded::Header, env_info: ::vm::EnvInfo, - engine: Arc<::ethcore::engines::Engine>, + engine: Arc, on_demand: Arc, sync: Arc, } diff --git a/rpc/src/v1/impls/debug.rs b/rpc/src/v1/impls/debug.rs index e46dd628d1e..64e2acac6c2 100644 --- a/rpc/src/v1/impls/debug.rs +++ b/rpc/src/v1/impls/debug.rs @@ -18,7 +18,7 @@ use std::sync::Arc; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use types::header::Header; use types::transaction::LocalizedTransaction; diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 0511c52410f..f50d79b5a54 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -24,8 +24,9 @@ use rlp::Rlp; use ethereum_types::{Address, H64, H160, H256, U64, U256, BigEndianHash}; use parking_lot::Mutex; +use client_traits::{BlockChainClient, StateClient, ProvingBlockChainClient, StateOrBlock}; use ethash::{self, SeedHashCompute}; -use ethcore::client::{BlockChainClient, StateOrBlock, StateClient, StateInfo, Call, EngineInfo, ProvingBlockChainClient}; +use ethcore::client::{StateInfo, Call, EngineInfo}; use ethcore::miner::{self, MinerService}; use ethcore::snapshot::SnapshotService; use hash::keccak; diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index b205dde572c..8bab9005883 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use std::collections::{BTreeSet, VecDeque}; -use ethcore::client::BlockChainClient; +use client_traits::BlockChainClient; use ethcore::miner::{self, MinerService}; use ethereum_types::{H256, U256}; use parking_lot::Mutex; diff --git a/rpc/src/v1/impls/eth_pubsub.rs b/rpc/src/v1/impls/eth_pubsub.rs index fd557b09615..d9fe2329e91 100644 --- a/rpc/src/v1/impls/eth_pubsub.rs +++ b/rpc/src/v1/impls/eth_pubsub.rs @@ -31,7 +31,8 @@ use v1::traits::EthPubSub; use v1::types::{pubsub, RichHeader, Log}; use sync::{SyncState, Notification}; -use ethcore::client::{BlockChainClient, ChainNotify, NewBlocks, ChainRouteType}; +use ethcore::client::{ChainNotify, NewBlocks, ChainRouteType}; +use client_traits::BlockChainClient; use ethereum_types::H256; use light::cache::Cache; use light::client::{LightChainClient, LightChainNotify}; diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 305205644b4..75e69dcbfb0 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -20,7 +20,8 @@ use std::collections::BTreeMap; use crypto::DEFAULT_MAC; use ethereum_types::{H64, H160, H256, H512, U64, U256}; -use ethcore::client::{BlockChainClient, StateClient, Call}; +use ethcore::client::Call; +use client_traits::{BlockChainClient, StateClient}; use ethcore::miner::{self, MinerService, FilterOptions}; use ethcore::snapshot::{SnapshotService, RestorationStatus}; use account_state::state::StateInfo; @@ -30,7 +31,10 @@ use ethstore::random_phrase; use jsonrpc_core::futures::future; use jsonrpc_core::{BoxFuture, Result}; use sync::{SyncProvider, ManageNetwork}; -use types::ids::BlockId; +use types::{ + ids::BlockId, + verification::Unverified, +}; use updater::{Service as UpdateService}; use version::version_data; @@ -48,7 +52,6 @@ use v1::types::{ block_number_to_id }; use Host; -use ethcore::verification::queue::kind::blocks::Unverified; /// Parity implementation. pub struct ParityClient { diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index b7cef6c6b8c..25d06ed8514 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -19,7 +19,8 @@ use std::io; use std::sync::Arc; use std::time::Duration; -use ethcore::client::{BlockChainClient, Mode}; +use client_traits::BlockChainClient; +use types::client_types::Mode; use ethcore::miner::{self, MinerService}; use ethereum_types::{H160, H256, U256}; use ethkey; @@ -161,7 +162,7 @@ impl ParitySet for ParitySetClient where fn set_engine_signer_secret(&self, secret: H256) -> Result { let keypair = ethkey::KeyPair::from_secret(secret.into()).map_err(|e| errors::account("Invalid secret", e))?; - self.miner.set_author(miner::Author::Sealer(ethcore::engines::signer::from_keypair(keypair))); + self.miner.set_author(miner::Author::Sealer(engine::signer::from_keypair(keypair))); Ok(true) } diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index b279c127dc7..4d0ccc1a90c 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -18,7 +18,8 @@ use std::sync::Arc; -use ethcore::client::{BlockChainClient, StateClient, StateInfo, Call}; +use ethcore::client::{StateInfo, Call}; +use client_traits::{BlockChainClient, StateClient}; use ethereum_types::H256; use rlp::Rlp; use types::{ diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index c1981ce0101..23aedbe50ec 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -19,12 +19,12 @@ use std::env; use std::sync::Arc; use accounts::AccountProvider; -use ethcore::client::{BlockChainClient, Client, ClientConfig, ChainInfo, ImportBlock}; +use client_traits::{BlockChainClient, ChainInfo, ImportBlock}; +use ethcore::client::{Client, ClientConfig}; use ethcore::miner::Miner; use ethcore::spec::{Genesis, Spec, self}; use ethcore::test_helpers; use ethcore::verification::VerifierType; -use ethcore::verification::queue::kind::blocks::Unverified; use ethereum_types::{Address, H256, U256}; use ethjson::blockchain::BlockChain; use ethjson::spec::ForkSpec; @@ -32,7 +32,10 @@ use io::IoChannel; use miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; -use types::ids::BlockId; +use types::{ + ids::BlockId, + verification::Unverified, +}; use jsonrpc_core::IoHandler; use v1::helpers::dispatch::{self, FullDispatcher}; @@ -114,7 +117,7 @@ impl EthTester { let runtime = Runtime::with_thread_count(1); let account_provider = account_provider(); let ap = account_provider.clone(); - let accounts = Arc::new(move || ap.accounts().unwrap_or_default()) as _; + let accounts = Arc::new(move || ap.accounts().unwrap_or_default()) as _; let miner_service = miner_service(&spec); let snapshot_service = snapshot_service(); @@ -215,8 +218,7 @@ fn eth_get_proof() { }"#; let res_latest = r#","address":"0xaaaf5374fce5edbc8e2a8697c15331677e6ebaaa","balance":"0x9","codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","nonce":"0x0","storageHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","storageProof":[]},"id":1}"#.to_owned(); - assert!(tester.handler.handle_request_sync(req_latest).unwrap().to_string().ends_with(res_latest.as_str())); - + assert!(tester.handler.handle_request_sync(req_latest).unwrap().to_string().ends_with(res_latest.as_str())); // non-existant account let req_new_acc = r#"{ "jsonrpc": "2.0", @@ -226,7 +228,7 @@ fn eth_get_proof() { }"#; let res_new_acc = r#","address":"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","balance":"0x0","codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","nonce":"0x0","storageHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","storageProof":[]},"id":3}"#.to_owned(); - assert!(tester.handler.handle_request_sync(req_new_acc).unwrap().to_string().ends_with(res_new_acc.as_str())); + assert!(tester.handler.handle_request_sync(req_new_acc).unwrap().to_string().ends_with(res_new_acc.as_str())); } #[test] diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index 5f7d3eed4b5..8bff84dc3b2 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -20,15 +20,15 @@ use std::sync::Arc; use std::collections::{BTreeMap, BTreeSet, HashMap}; use bytes::Bytes; +use client_traits::{Nonce, StateClient}; +use engine::{Engine, signer::EngineSigner}; use ethcore::block::SealedBlock; -use ethcore::client::{Nonce, PrepareOpenBlock, StateClient, EngineInfo, TestState}; -use ethcore::engines::{Engine, signer::EngineSigner}; +use ethcore::client::{PrepareOpenBlock, EngineInfo, TestState}; use ethcore::miner::{self, MinerService, AuthoringParams, FilterOptions}; use ethereum_types::{H256, U256, Address}; use miner::pool::local_transactions::Status as LocalTransactionStatus; use miner::pool::{verifier, VerifiedTransaction, QueueStatus}; use parking_lot::{RwLock, Mutex}; -use types::transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction}; use txpool; use types::{ BlockNumber, @@ -37,6 +37,7 @@ use types::{ errors::EthcoreError as Error, ids::BlockId, receipt::RichReceipt, + transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction}, }; /// Test miner service. diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 34925ddce13..7477eec696e 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -20,7 +20,8 @@ use std::sync::Arc; use std::time::{Instant, Duration, SystemTime, UNIX_EPOCH}; use accounts::AccountProvider; -use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient}; +use client_traits::BlockChainClient; +use ethcore::client::{EachBlockWith, TestBlockChainClient}; use ethcore::miner::{self, MinerService}; use ethereum_types::{H160, H256, U256, Address, Bloom}; use machine::executed::Executed; diff --git a/rpc/src/v1/types/histogram.rs b/rpc/src/v1/types/histogram.rs index d7f14c514e6..41ac8730190 100644 --- a/rpc/src/v1/types/histogram.rs +++ b/rpc/src/v1/types/histogram.rs @@ -17,6 +17,7 @@ //! Gas prices histogram. use ethereum_types::U256; +use stats; /// Values of RPC settings. #[derive(Serialize, Deserialize)] @@ -25,12 +26,12 @@ use ethereum_types::U256; pub struct Histogram { /// Gas prices for bucket edges. pub bucket_bounds: Vec, - /// Transacion counts for each bucket. + /// Transaction counts for each bucket. pub counts: Vec, } -impl From<::stats::Histogram<::ethereum_types::U256>> for Histogram { - fn from(h: ::stats::Histogram<::ethereum_types::U256>) -> Self { +impl From> for Histogram { + fn from(h: stats::Histogram) -> Self { Histogram { bucket_bounds: h.bucket_bounds.into_iter().map(Into::into).collect(), counts: h.counts diff --git a/rpc/src/v1/types/trace_filter.rs b/rpc/src/v1/types/trace_filter.rs index 42bad70e88c..4f11308c51c 100644 --- a/rpc/src/v1/types/trace_filter.rs +++ b/rpc/src/v1/types/trace_filter.rs @@ -16,7 +16,6 @@ //! Trace filter deserialization. -use ethcore::client; use ethereum_types::H160; use types::{ ids::BlockId, diff --git a/secret-store/Cargo.toml b/secret-store/Cargo.toml index 06f13663fc1..76a0df44a2d 100644 --- a/secret-store/Cargo.toml +++ b/secret-store/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Parity Technologies "] [dependencies] byteorder = "1.0" +client-traits = { path = "../ethcore/client-traits" } common-types = { path = "../ethcore/types" } ethabi = "8.0" ethabi-contract = "8.0" diff --git a/secret-store/src/helpers.rs b/secret-store/src/helpers.rs index 3dfe7ae8b66..cdb235ac91c 100644 --- a/secret-store/src/helpers.rs +++ b/secret-store/src/helpers.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethcore::client::{Client, BlockChainClient}; +use ethcore::client::Client; +use client_traits::BlockChainClient; use common_types::ids::BlockId; use ethereum_types::H256; diff --git a/secret-store/src/key_server_set.rs b/secret-store/src/key_server_set.rs index b57df0a8ba4..5ffaa7fb767 100644 --- a/secret-store/src/key_server_set.rs +++ b/secret-store/src/key_server_set.rs @@ -20,7 +20,8 @@ use std::collections::{BTreeMap, HashSet}; use parking_lot::Mutex; use call_contract::CallContract; use ethabi::FunctionOutputDecoder; -use ethcore::client::{Client, BlockChainClient, ChainNotify, NewBlocks}; +use ethcore::client::{Client, ChainNotify, NewBlocks}; +use client_traits::BlockChainClient; use common_types::ids::BlockId; use ethereum_types::{H256, Address}; use ethkey::public_to_address; diff --git a/secret-store/src/lib.rs b/secret-store/src/lib.rs index 02571670460..2999b4ebd85 100644 --- a/secret-store/src/lib.rs +++ b/secret-store/src/lib.rs @@ -15,6 +15,7 @@ // along with Parity Ethereum. If not, see . extern crate byteorder; +extern crate client_traits; extern crate common_types; extern crate ethabi; extern crate ethcore; diff --git a/secret-store/src/listener/service_contract.rs b/secret-store/src/listener/service_contract.rs index caac9065a51..3d24ff79839 100644 --- a/secret-store/src/listener/service_contract.rs +++ b/secret-store/src/listener/service_contract.rs @@ -20,7 +20,8 @@ use common_types::filter::Filter; use ethabi::RawLog; use ethabi::FunctionOutputDecoder; use call_contract::CallContract; -use ethcore::client::{Client, BlockChainClient}; +use ethcore::client::Client; +use client_traits::BlockChainClient; use common_types::ids::BlockId; use ethkey::{Public, public_to_address}; use hash::keccak; diff --git a/secret-store/src/trusted_client.rs b/secret-store/src/trusted_client.rs index 70ca6f420cb..a058f056420 100644 --- a/secret-store/src/trusted_client.rs +++ b/secret-store/src/trusted_client.rs @@ -22,7 +22,8 @@ use common_types::{ transaction::{Transaction, SignedTransaction, Action}, }; use ethereum_types::Address; -use ethcore::client::{Client, ChainInfo, Nonce}; +use ethcore::client::Client; +use client_traits::{ChainInfo, Nonce}; use ethcore::miner::{Miner, MinerService}; use sync::SyncProvider; use helpers::{get_confirmed_block_hash, REQUEST_CONFIRMATIONS_REQUIRED}; @@ -43,9 +44,9 @@ pub struct TrustedClient { impl TrustedClient { /// Create new trusted client. - pub fn new(self_key_pair: Arc, client: Arc, sync: Arc, miner: Arc) -> Self { + pub fn new(self_key_pair: Arc, client: Arc, sync: Arc, miner: Arc) -> Self { TrustedClient { - self_key_pair: self_key_pair, + self_key_pair, client: Arc::downgrade(&client), sync: Arc::downgrade(&sync), miner: Arc::downgrade(&miner), diff --git a/updater/Cargo.toml b/updater/Cargo.toml index 2229f376ebd..3ea95d5987f 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -6,6 +6,7 @@ license = "GPL-3.0" authors = ["Parity Technologies "] [dependencies] +client-traits = { path = "../ethcore/client-traits" } common-types = { path = "../ethcore/types" } ethabi = "8.0" ethabi-contract = "8.0" diff --git a/updater/src/lib.rs b/updater/src/lib.rs index f6fad17199a..7bc4eab7df9 100644 --- a/updater/src/lib.rs +++ b/updater/src/lib.rs @@ -18,6 +18,7 @@ #![warn(missing_docs)] +extern crate client_traits; extern crate common_types; extern crate ethabi; extern crate ethcore; diff --git a/updater/src/updater.rs b/updater/src/updater.rs index f9558876d93..ec51ffd9aa0 100644 --- a/updater/src/updater.rs +++ b/updater/src/updater.rs @@ -30,7 +30,8 @@ use common_types::{ ids::BlockId, filter::Filter, }; -use ethcore::client::{BlockChainClient, ChainNotify, NewBlocks}; +use ethcore::client::{ChainNotify, NewBlocks}; +use client_traits::BlockChainClient; use ethereum_types::{H256, H160}; use hash_fetch::{self as fetch, HashFetch}; use parity_path::restrict_permissions_owner;