Extract snapshot to own crate (#11010)

* Move snapshot to own crate
Sort out imports

* WIP cargo toml

* Make snapshotting generic over the client
Sort out tests

* Sort out types from blockchain and client

* Sort out sync

* Sort out imports and generics

* Sort out main binary

* Fix sync test-helpers

* Sort out import for secret-store

* Sort out more imports

* Fix easy todos

* cleanup

* Cleanup

* remove unneded workspace member

* cleanup

* Sort out test-helpers dependency on account-db

* Update ethcore/client-traits/src/lib.rs

Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Update ethcore/snapshot/Cargo.toml
This commit is contained in:
David 2019-09-03 11:29:25 +02:00 committed by GitHub
parent 396ccdbcc1
commit d193ddde19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
68 changed files with 627 additions and 486 deletions

58
Cargo.lock generated
View File

@ -1020,7 +1020,6 @@ dependencies = [
"client-traits 0.1.0", "client-traits 0.1.0",
"common-types 0.1.0", "common-types 0.1.0",
"criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "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", "engine 0.1.0",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1029,7 +1028,6 @@ dependencies = [
"ethash 1.12.0", "ethash 1.12.0",
"ethcore-accounts 0.1.0", "ethcore-accounts 0.1.0",
"ethcore-blockchain 0.1.0", "ethcore-blockchain 0.1.0",
"ethcore-bloom-journal 0.1.0",
"ethcore-builtin 0.1.0", "ethcore-builtin 0.1.0",
"ethcore-call-contract 0.1.0", "ethcore-call-contract 0.1.0",
"ethcore-db 0.1.0", "ethcore-db 0.1.0",
@ -1047,7 +1045,6 @@ dependencies = [
"itertools 0.5.10 (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", "journaldb 0.2.0",
"keccak-hash 0.2.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 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)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1057,10 +1054,8 @@ dependencies = [
"macros 0.1.0", "macros 0.1.0",
"memory-cache 0.1.0", "memory-cache 0.1.0",
"null-engine 0.1.0", "null-engine 0.1.0",
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 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)",
"parity-runtime 0.1.0", "parity-runtime 0.1.0",
"parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.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", "patricia-trie-ethereum 0.1.0",
"pod 0.1.0", "pod 0.1.0",
@ -1074,6 +1069,7 @@ dependencies = [
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 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.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"snapshot 0.1.0",
"spec 0.1.0", "spec 0.1.0",
"state-db 0.1.0", "state-db 0.1.0",
"stats 0.1.0", "stats 0.1.0",
@ -1462,6 +1458,7 @@ dependencies = [
"kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"snapshot 0.1.0",
"spec 0.1.0", "spec 0.1.0",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1518,6 +1515,7 @@ dependencies = [
"rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"snapshot 0.1.0",
"spec 0.1.0", "spec 0.1.0",
"trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"triehash-ethereum 0.2.0", "triehash-ethereum 0.2.0",
@ -3034,6 +3032,7 @@ dependencies = [
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 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.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"snapshot 0.1.0",
"spec 0.1.0", "spec 0.1.0",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3182,6 +3181,7 @@ dependencies = [
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 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.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"snapshot 0.1.0",
"spec 0.1.0", "spec 0.1.0",
"stats 0.1.0", "stats 0.1.0",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4202,6 +4202,54 @@ name = "smallvec"
version = "0.6.10" version = "0.6.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "snapshot"
version = "0.1.0"
dependencies = [
"account-db 0.1.0",
"account-state 0.1.0",
"client-traits 0.1.0",
"common-types 0.1.0",
"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.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi-contract 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethcore 1.12.0",
"ethcore-accounts 0.1.0",
"ethcore-blockchain 0.1.0",
"ethcore-bloom-journal 0.1.0",
"ethcore-db 0.1.0",
"ethcore-io 1.12.0",
"ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethkey 0.3.0",
"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)",
"keccak-hasher 0.1.1",
"kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.1 (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)",
"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)",
"rand_xorshift 0.1.1 (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",
"spec 0.1.0",
"state-db 0.1.0",
"tempdir 0.3.7 (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)",
"triehash-ethereum 0.2.0",
]
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.3.8" version = "0.3.8"

View File

@ -69,6 +69,7 @@ semver = "0.9"
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
snapshot = { path = "ethcore/snapshot" }
spec = { path = "ethcore/spec" } spec = { path = "ethcore/spec" }
term_size = "0.3" term_size = "0.3"
textwrap = "0.9" textwrap = "0.9"

View File

@ -7,14 +7,13 @@ version = "1.12.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
[dependencies] [dependencies]
account-db = { path = "account-db" } account-db = { path = "account-db", optional = true }
account-state = { path = "account-state" } account-state = { path = "account-state" }
ansi_term = "0.11" ansi_term = "0.11"
basic-authority = { path = "./engines/basic-authority", optional = true} # used by test-helpers feature basic-authority = { path = "./engines/basic-authority", optional = true} # used by test-helpers feature
blooms-db = { path = "../util/blooms-db", optional = true } blooms-db = { path = "../util/blooms-db", optional = true }
client-traits = { path = "./client-traits" } client-traits = { path = "./client-traits" }
common-types = { path = "types" } common-types = { path = "types" }
crossbeam-utils = "0.6"
engine = { path = "./engine" } engine = { path = "./engine" }
env_logger = { version = "0.5", optional = true } env_logger = { version = "0.5", optional = true }
ethabi = "8.0" ethabi = "8.0"
@ -24,7 +23,6 @@ ethash = { path = "../ethash", optional = true }
ethjson = { path = "../json", optional = true } ethjson = { path = "../json", optional = true }
ethkey = { path = "../accounts/ethkey", optional = true } ethkey = { path = "../accounts/ethkey", optional = true }
ethcore-blockchain = { path = "./blockchain" } ethcore-blockchain = { path = "./blockchain" }
ethcore-bloom-journal = { path = "../util/bloom" }
ethcore-call-contract = { path = "./call-contract" } ethcore-call-contract = { path = "./call-contract" }
ethcore-db = { path = "./db" } ethcore-db = { path = "./db" }
ethcore-io = { path = "../util/io" } ethcore-io = { path = "../util/io" }
@ -38,7 +36,6 @@ hash-db = "0.15.0"
itertools = "0.5" itertools = "0.5"
journaldb = { path = "../util/journaldb" } journaldb = { path = "../util/journaldb" }
keccak-hash = "0.2.0" keccak-hash = "0.2.0"
keccak-hasher = { path = "../util/keccak-hasher" }
kvdb = "0.1" kvdb = "0.1"
kvdb-memorydb = { version = "0.1", optional = true } kvdb-memorydb = { version = "0.1", optional = true }
kvdb-rocksdb = { version = "0.1.3", optional = true } kvdb-rocksdb = { version = "0.1.3", optional = true }
@ -47,9 +44,7 @@ log = "0.4"
macros = { path = "../util/macros", optional = true } macros = { path = "../util/macros", optional = true }
machine = { path = "./machine" } machine = { path = "./machine" }
memory-cache = { path = "../util/memory-cache" } memory-cache = { path = "../util/memory-cache" }
num_cpus = "1.2"
parity-bytes = "0.1" parity-bytes = "0.1"
parity-snappy = "0.1"
parking_lot = "0.8" parking_lot = "0.8"
pod = { path = "pod", optional = true } pod = { path = "pod", optional = true }
trie-db = "0.15.0" trie-db = "0.15.0"
@ -62,6 +57,7 @@ rlp_derive = { path = "../util/rlp-derive" }
rustc-hex = { version = "1", optional = true } rustc-hex = { version = "1", optional = true }
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
snapshot = { path = "snapshot" }
spec = { path = "spec" } spec = { path = "spec" }
state-db = { path = "state-db" } state-db = { path = "state-db" }
tempdir = { version = "0.3", optional = true } tempdir = { version = "0.3", optional = true }
@ -75,6 +71,7 @@ verification = { path = "./verification" }
vm = { path = "vm" } vm = { path = "vm" }
[dev-dependencies] [dev-dependencies]
account-db = { path = "account-db" }
blooms-db = { path = "../util/blooms-db" } blooms-db = { path = "../util/blooms-db" }
ethcore-builtin = { path = "./builtin" } ethcore-builtin = { path = "./builtin" }
criterion = "0.2" criterion = "0.2"
@ -129,7 +126,20 @@ ci-skip-tests = []
test-heavy = [] test-heavy = []
# Compile test helpers # Compile test helpers
# note[dvdplm]: "basic-authority/test-helpers" is needed so that `generate_dummy_client_with_spec` works # note[dvdplm]: "basic-authority/test-helpers" is needed so that `generate_dummy_client_with_spec` works
test-helpers = ["tempdir", "kvdb-memorydb", "kvdb-rocksdb", "blooms-db", "ethash", "ethjson", "ethkey", "macros", "pod", "rustc-hex", "basic-authority/test-helpers"] test-helpers = [
"account-db",
"blooms-db",
"ethash",
"ethjson",
"ethkey",
"kvdb-memorydb",
"kvdb-rocksdb",
"macros",
"pod",
"rustc-hex",
"tempdir",
"basic-authority/test-helpers"
]
[[bench]] [[bench]]
name = "builtin" name = "builtin"

View File

@ -1,54 +0,0 @@
// 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 <http://www.gnu.org/licenses/>.
use ethereum_types::{H256, U256};
use common_types::BlockNumber;
/// Brief info about inserted block.
#[derive(Clone)]
pub struct BlockInfo {
/// Block hash.
pub hash: H256,
/// Block number.
pub number: BlockNumber,
/// Total block difficulty.
pub total_difficulty: U256,
/// Block location in blockchain.
pub location: BlockLocation
}
/// Describes location of newly inserted block.
#[derive(Debug, Clone, PartialEq)]
pub enum BlockLocation {
/// It's part of the canon chain.
CanonChain,
/// It's not a part of the canon chain.
Branch,
/// It's part of the fork which should become canon chain,
/// because its total difficulty is higher than current
/// canon chain difficulty.
BranchBecomingCanonChain(BranchBecomingCanonChainData),
}
#[derive(Debug, Clone, PartialEq)]
pub struct BranchBecomingCanonChainData {
/// Hash of the newest common ancestor with old canon chain.
pub ancestor: H256,
/// Hashes of the blocks between ancestor and this block.
pub enacted: Vec<H256>,
/// Hashes of the blocks which were invalidated.
pub retracted: Vec<H256>,
}

View File

@ -23,18 +23,22 @@ use std::sync::Arc;
use ansi_term::Colour; use ansi_term::Colour;
use blooms_db; use blooms_db;
use common_types::BlockNumber; use common_types::{
use common_types::blockchain_info::BlockChainInfo; BlockNumber,
use common_types::encoded; blockchain_info::BlockChainInfo,
use common_types::engines::ForkChoice; block::{BlockInfo, BlockLocation, BranchBecomingCanonChainData},
use common_types::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; encoded,
use common_types::header::{Header, ExtendedHeader}; engines::ForkChoice,
use common_types::log_entry::{LogEntry, LocalizedLogEntry}; engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition},
use common_types::receipt::Receipt; header::{Header, ExtendedHeader},
use common_types::transaction::LocalizedTransaction; import_route::ImportRoute,
use common_types::tree_route::TreeRoute; log_entry::{LogEntry, LocalizedLogEntry},
use common_types::view; receipt::Receipt,
use common_types::views::{BlockView, HeaderView}; transaction::LocalizedTransaction,
tree_route::TreeRoute,
view,
views::{BlockView, HeaderView},
};
use ethcore_db::cache_manager::CacheManager; use ethcore_db::cache_manager::CacheManager;
use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress, EPOCH_KEY_PREFIX, EpochTransitions}; use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress, EPOCH_KEY_PREFIX, EpochTransitions};
use ethcore_db::{self as db, Writable, Readable, CacheUpdatePolicy}; use ethcore_db::{self as db, Writable, Readable, CacheUpdatePolicy};
@ -50,9 +54,8 @@ use rlp::RlpStream;
use rlp_compress::{compress, decompress, blocks_swapper}; use rlp_compress::{compress, decompress, blocks_swapper};
use crate::best_block::{BestBlock, BestAncientBlock}; use crate::best_block::{BestBlock, BestAncientBlock};
use crate::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData};
use crate::update::{ExtrasUpdate, ExtrasInsert}; use crate::update::{ExtrasUpdate, ExtrasInsert};
use crate::{CacheSize, ImportRoute, Config}; use crate::{CacheSize, Config};
/// Database backing `BlockChain`. /// Database backing `BlockChain`.
pub trait BlockChainDB: Send + Sync { pub trait BlockChainDB: Send + Sync {

View File

@ -22,11 +22,9 @@ extern crate parity_util_mem as util_mem;
extern crate parity_util_mem as malloc_size_of; extern crate parity_util_mem as malloc_size_of;
mod best_block; mod best_block;
mod block_info;
mod blockchain; mod blockchain;
mod cache; mod cache;
mod config; mod config;
mod import_route;
mod update; mod update;
pub mod generator; pub mod generator;
@ -35,7 +33,6 @@ pub use crate::{
blockchain::{BlockProvider, BlockChain, BlockChainDB, BlockChainDBHandler}, blockchain::{BlockProvider, BlockChain, BlockChainDB, BlockChainDBHandler},
cache::CacheSize, cache::CacheSize,
config::Config, config::Config,
import_route::ImportRoute,
update::ExtrasInsert, update::ExtrasInsert,
}; };
pub use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress, BlockNumberKey}; pub use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress, BlockNumberKey};

View File

@ -16,14 +16,15 @@
use std::collections::HashMap; use std::collections::HashMap;
use common_types::BlockNumber; use common_types::{
use common_types::encoded::Block; BlockNumber,
use common_types::engines::ForkChoice; encoded::Block,
engines::ForkChoice,
block::BlockInfo,
};
use ethcore_db::keys::{BlockDetails, BlockReceipts, TransactionAddress}; use ethcore_db::keys::{BlockDetails, BlockReceipts, TransactionAddress};
use ethereum_types::{H256, Bloom}; use ethereum_types::{H256, Bloom};
use crate::block_info::BlockInfo;
/// Block extras update info. /// Block extras update info.
pub struct ExtrasUpdate { pub struct ExtrasUpdate {
/// Block info. /// Block info.

View File

@ -29,6 +29,7 @@ use common_types::{
blockchain_info::BlockChainInfo, blockchain_info::BlockChainInfo,
BlockNumber, BlockNumber,
call_analytics::CallAnalytics, call_analytics::CallAnalytics,
chain_notify::{NewBlocks, ChainMessageType},
client_types::Mode, client_types::Mode,
encoded, encoded,
engines::{epoch::Transition as EpochTransition, machine::Executed}, engines::{epoch::Transition as EpochTransition, machine::Executed},
@ -40,7 +41,7 @@ use common_types::{
pruning_info::PruningInfo, pruning_info::PruningInfo,
receipt::LocalizedReceipt, receipt::LocalizedReceipt,
trace_filter::Filter as TraceFilter, trace_filter::Filter as TraceFilter,
transaction::{self, LocalizedTransaction, CallError, SignedTransaction}, transaction::{self, LocalizedTransaction, CallError, SignedTransaction, UnverifiedTransaction},
tree_route::TreeRoute, tree_route::TreeRoute,
verification::{VerificationQueueInfo, Unverified}, verification::{VerificationQueueInfo, Unverified},
}; };
@ -119,7 +120,7 @@ pub trait ChainInfo {
} }
/// Provides various information on a block by it's ID /// Provides various information on a block by it's ID
pub trait BlockInfo { pub trait BlockInfo: Send + Sync {
/// Get raw block header data by block id. /// Get raw block header data by block id.
fn block_header(&self, id: BlockId) -> Option<encoded::Header>; fn block_header(&self, id: BlockId) -> Option<encoded::Header>;
@ -474,3 +475,38 @@ pub trait SnapshotWriter {
/// with the chunks written. /// with the chunks written.
fn finish(self, manifest: common_types::snapshot::ManifestData) -> std::io::Result<()> where Self: Sized; fn finish(self, manifest: common_types::snapshot::ManifestData) -> std::io::Result<()> where Self: Sized;
} }
/// Represents what has to be handled by actor listening to chain events
pub trait ChainNotify: Send + Sync {
/// fires when chain has new blocks.
fn new_blocks(&self, _new_blocks: NewBlocks) {
// does nothing by default
}
/// fires when chain achieves active mode
fn start(&self) {
// does nothing by default
}
/// fires when chain achieves passive mode
fn stop(&self) {
// does nothing by default
}
/// fires when chain broadcasts a message
fn broadcast(&self, _message_type: ChainMessageType) {
// does nothing by default
}
/// fires when new block is about to be imported
/// implementations should be light
fn block_pre_import(&self, _bytes: &Bytes, _hash: &H256, _difficulty: &U256) {
// does nothing by default
}
/// fires when new transactions are received from a peer
fn transactions_received(&self, _txs: &[UnverifiedTransaction], _peer_id: usize) {
// does nothing by default
}
}

View File

@ -42,9 +42,11 @@ extern crate log;
use std::collections::{HashMap, VecDeque}; use std::collections::{HashMap, VecDeque};
use std::sync::Weak; use std::sync::Weak;
use common_types::ids::BlockId; use common_types::{
use ethcore::client::{ChainNotify, NewBlocks}; ids::BlockId,
use client_traits::BlockChainClient; chain_notify::NewBlocks,
};
use client_traits::{BlockChainClient, ChainNotify};
use ethereum_types::{H256, Address}; use ethereum_types::{H256, Address};
use ethabi::FunctionOutputDecoder; use ethabi::FunctionOutputDecoder;
use network::{ConnectionFilter, ConnectionDirection}; use network::{ConnectionFilter, ConnectionDirection};
@ -159,7 +161,7 @@ mod test {
Arc::new(Miner::new_for_tests(&spec, None)), Arc::new(Miner::new_for_tests(&spec, None)),
IoChannel::disconnected(), IoChannel::disconnected(),
).unwrap(); ).unwrap();
let filter = NodeFilter::new(Arc::downgrade(&client) as Weak<BlockChainClient>, contract_addr); let filter = NodeFilter::new(Arc::downgrade(&client) as Weak<dyn BlockChainClient>, contract_addr);
let self1 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002").unwrap(); let self1 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002").unwrap();
let self2 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003").unwrap(); let self2 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003").unwrap();
let node1 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012").unwrap(); let node1 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012").unwrap();

View File

@ -103,15 +103,14 @@ use machine::{
executed::Executed as FlatExecuted, executed::Executed as FlatExecuted,
}; };
use types::{ use types::{
chain_notify::{NewBlocks, ChainMessageType},
ids::BlockId, ids::BlockId,
io_message::ClientIoMessage, io_message::ClientIoMessage,
transaction::{SignedTransaction, Transaction, Action, UnverifiedTransaction}, transaction::{SignedTransaction, Transaction, Action, UnverifiedTransaction},
engines::machine::Executed, engines::machine::Executed,
}; };
use ethcore::client::{ use ethcore::client::{Client, Call};
Client, ChainNotify, NewBlocks, ChainMessageType, Call use client_traits::{BlockInfo, ChainNotify};
};
use client_traits::BlockInfo;
use ethcore::miner::{self, Miner, MinerService, pool_client::NonceCache}; use ethcore::miner::{self, Miner, MinerService, pool_client::NonceCache};
use state_db::StateDB; use state_db::StateDB;
use account_state::State; use account_state::State;

View File

@ -6,8 +6,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies] [dependencies]
ansi_term = "0.11" ansi_term = "0.11"
common-types = { path = "../types" }
client-traits = { path = "../client-traits" } client-traits = { path = "../client-traits" }
common-types = { path = "../types" }
ethcore = { path = ".." } ethcore = { path = ".." }
ethcore-blockchain = { path = "../blockchain" } ethcore-blockchain = { path = "../blockchain" }
ethcore-io = { path = "../../util/io" } ethcore-io = { path = "../../util/io" }
@ -16,11 +16,12 @@ ethcore-sync = { path = "../sync" }
ethereum-types = "0.6.0" ethereum-types = "0.6.0"
kvdb = "0.1" kvdb = "0.1"
log = "0.4" log = "0.4"
snapshot = { path = "../snapshot" }
spec = { path = "../spec" } spec = { path = "../spec" }
trace-time = "0.1" trace-time = "0.1"
[dev-dependencies] [dev-dependencies]
ethcore-db = { path = "../db" }
ethcore = { path = "..", features = ["test-helpers"] } ethcore = { path = "..", features = ["test-helpers"] }
tempdir = "0.3" ethcore-db = { path = "../db" }
kvdb-rocksdb = "0.1.3" kvdb-rocksdb = "0.1.3"
tempdir = "0.3"

View File

@ -25,6 +25,7 @@ extern crate ethcore_sync as sync;
extern crate ethereum_types; extern crate ethereum_types;
extern crate kvdb; extern crate kvdb;
extern crate spec; extern crate spec;
extern crate snapshot;
#[macro_use] #[macro_use]
extern crate log; extern crate log;

View File

@ -23,13 +23,13 @@ use std::time::Duration;
use ansi_term::Colour; use ansi_term::Colour;
use ethereum_types::H256; use ethereum_types::H256;
use io::{IoContext, TimerToken, IoHandler, IoService, IoError}; use io::{IoContext, TimerToken, IoHandler, IoService, IoError};
use client_traits::ChainNotify;
use sync::PrivateTxHandler; use sync::PrivateTxHandler;
use blockchain::{BlockChainDB, BlockChainDBHandler}; use blockchain::{BlockChainDB, BlockChainDBHandler};
use ethcore::client::{Client, ClientConfig, ChainNotify}; use ethcore::client::{Client, ClientConfig};
use ethcore::miner::Miner; use ethcore::miner::Miner;
use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
use ethcore::snapshot::{SnapshotService as _SnapshotService}; use snapshot::{SnapshotService as _SnapshotService};
use spec::Spec; use spec::Spec;
use common_types::{ use common_types::{
io_message::ClientIoMessage, io_message::ClientIoMessage,
@ -94,7 +94,7 @@ impl PrivateTxHandler for PrivateTxService {
pub struct ClientService { pub struct ClientService {
io_service: Arc<IoService<ClientIoMessage<Client>>>, io_service: Arc<IoService<ClientIoMessage<Client>>>,
client: Arc<Client>, client: Arc<Client>,
snapshot: Arc<SnapshotService>, snapshot: Arc<SnapshotService<Client>>,
private_tx: Arc<PrivateTxService>, private_tx: Arc<PrivateTxService>,
database: Arc<dyn BlockChainDB>, database: Arc<dyn BlockChainDB>,
} }
@ -185,7 +185,7 @@ impl ClientService {
} }
/// Get snapshot interface. /// Get snapshot interface.
pub fn snapshot_service(&self) -> Arc<SnapshotService> { pub fn snapshot_service(&self) -> Arc<SnapshotService<Client>> {
self.snapshot.clone() self.snapshot.clone()
} }
@ -215,9 +215,9 @@ impl ClientService {
} }
/// IO interface for the Client handler /// IO interface for the Client handler
struct ClientIoHandler<C> { struct ClientIoHandler<C: Send + Sync + 'static> {
client: Arc<C>, client: Arc<C>,
snapshot: Arc<SnapshotService>, snapshot: Arc<SnapshotService<C>>,
} }
const CLIENT_TICK_TIMER: TimerToken = 0; const CLIENT_TICK_TIMER: TimerToken = 0;
@ -239,7 +239,7 @@ where
trace_time!("service::read"); trace_time!("service::read");
match timer { match timer {
CLIENT_TICK_TIMER => { CLIENT_TICK_TIMER => {
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
let snapshot_restoration = if let RestorationStatus::Ongoing{..} = self.snapshot.status() { true } else { false }; let snapshot_restoration = if let RestorationStatus::Ongoing{..} = self.snapshot.status() { true } else { false };
self.client.tick(snapshot_restoration) self.client.tick(snapshot_restoration)
}, },

View File

@ -0,0 +1,54 @@
[package]
description = "Take and restore snapshots of the blockchain and read/write it in chunks from/to disk"
name = "snapshot"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0"
[dependencies]
account-db = { path = "../account-db" }
account-state = { path = "../account-state" }
blockchain = { package = "ethcore-blockchain", path = "../blockchain" }
bloom-journal = { package = "ethcore-bloom-journal", path = "../../util/bloom" }
bytes = { package = "parity-bytes", version = "0.1.0" }
client-traits = { path = "../client-traits" }
common-types = { path = "../types" }
crossbeam-utils = "0.6"
engine = { path = "../engine" }
ethcore-db = { path = "../db" }
ethcore-io = { path = "../../util/io" }
ethereum-types = "0.6.0"
ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" }
hash-db = "0.15.0"
itertools = "0.5"
journaldb = { path = "../../util/journaldb" }
keccak-hash = "0.2.0"
keccak-hasher = { path = "../../util/keccak-hasher" }
kvdb = "0.1.0"
log = "0.4.8"
num_cpus = "1.10.1"
parking_lot = "0.8.0"
rand = "0.6"
rand_xorshift = "0.1.1"
rlp = "0.4.2"
rlp_derive = { path = "../../util/rlp-derive" }
snappy = { package = "parity-snappy", version ="0.1.0" }
state-db = { path = "../state-db" }
trie-db = "0.15.0"
triehash = { package = "triehash-ethereum", version = "0.2", path = "../../util/triehash-ethereum" }
[dev-dependencies]
accounts = { package = "ethcore-accounts", path = "../../accounts" }
engine = { path = "../engine", features = ["test-helpers"] }
env_logger = "0.5"
ethabi = "8.0"
ethabi-contract = "8.0"
ethabi-derive = "8.0"
ethcore = { path = "..", features = ["test-helpers"] }
ethkey = { path = "../../accounts/ethkey" }
kvdb-rocksdb = { version = "0.1.3" }
lazy_static = { version = "1.3" }
spec = { path = "../spec" }
tempdir = "0.3"
trie-standardmap = "0.15.0"

View File

@ -16,21 +16,23 @@
//! Account state encoding and decoding //! Account state encoding and decoding
use std::collections::HashSet;
use std::sync::atomic::Ordering;
use account_db::{AccountDB, AccountDBMut}; use account_db::{AccountDB, AccountDBMut};
use types::{ use bytes::Bytes;
use common_types::{
basic_account::BasicAccount, basic_account::BasicAccount,
snapshot::Progress, snapshot::Progress,
errors::SnapshotError as Error, errors::SnapshotError as Error,
}; };
use bytes::Bytes;
use ethereum_types::{H256, U256}; use ethereum_types::{H256, U256};
use ethtrie::{TrieDB, TrieDBMut}; use ethtrie::{TrieDB, TrieDBMut};
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP};
use hash_db::HashDB; use hash_db::HashDB;
use keccak_hash::{KECCAK_EMPTY, KECCAK_NULL_RLP};
use log::{trace, warn};
use rlp::{RlpStream, Rlp}; use rlp::{RlpStream, Rlp};
use std::collections::HashSet; use trie_db::{Trie, TrieMut};
use trie::{Trie, TrieMut};
use std::sync::atomic::Ordering;
// An empty account -- these were replaced with RLP null data for a space optimization in v1. // An empty account -- these were replaced with RLP null data for a space optimization in v1.
const ACC_EMPTY: BasicAccount = BasicAccount { const ACC_EMPTY: BasicAccount = BasicAccount {
@ -246,12 +248,12 @@ pub fn from_fat_rlp(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use account_db::{AccountDB, AccountDBMut}; use account_db::{AccountDB, AccountDBMut};
use types::basic_account::BasicAccount; use common_types::basic_account::BasicAccount;
use test_helpers::get_temp_state_db; use ethcore::test_helpers::get_temp_state_db;
use snapshot::tests::helpers::fill_storage; use crate::tests::helpers::fill_storage;
use snapshot::Progress; use common_types::snapshot::Progress;
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak}; use keccak_hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
use ethereum_types::{H256, Address}; use ethereum_types::{H256, Address};
use hash_db::{HashDB, EMPTY_PREFIX}; use hash_db::{HashDB, EMPTY_PREFIX};
use kvdb::DBValue; use kvdb::DBValue;

View File

@ -17,18 +17,20 @@
//! Block RLP compression. //! Block RLP compression.
use bytes::Bytes; use bytes::Bytes;
use common_types::{
block::Block,
header::Header,
views::BlockView,
};
use ethereum_types::H256; use ethereum_types::H256;
use hash::keccak; use keccak_hash::keccak;
use rlp::{DecoderError, RlpStream, Rlp}; use rlp::{DecoderError, RlpStream, Rlp};
use triehash::ordered_trie_root; use triehash::ordered_trie_root;
use types::block::Block;
use types::header::Header;
use types::views::BlockView;
const HEADER_FIELDS: usize = 8; const HEADER_FIELDS: usize = 8;
const BLOCK_FIELDS: usize = 2; const BLOCK_FIELDS: usize = 2;
pub struct AbridgedBlock { pub(crate) struct AbridgedBlock {
rlp: Bytes, rlp: Bytes,
} }
@ -122,11 +124,7 @@ impl AbridgedBlock {
header.set_seal(seal_fields); header.set_seal(seal_fields);
Ok(Block { Ok(Block { header, transactions, uncles })
header: header,
transactions: transactions,
uncles: uncles,
})
} }
} }
@ -136,10 +134,12 @@ mod tests {
use bytes::Bytes; use bytes::Bytes;
use ethereum_types::{H256, U256, Address}; use ethereum_types::{H256, U256, Address};
use types::transaction::{Action, Transaction}; use common_types::{
use types::block::Block; transaction::{Action, Transaction},
use types::view; block::Block,
use types::views::BlockView; view,
views::BlockView,
};
fn encode_block(b: &Block) -> Bytes { fn encode_block(b: &Block) -> Bytes {
b.rlp_bytes() b.rlp_bytes()

View File

@ -22,14 +22,9 @@
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
use engine::{Engine, EpochVerifier};
use blockchain::{BlockChain, BlockChainDB, BlockProvider}; use blockchain::{BlockChain, BlockChainDB, BlockProvider};
use bytes::Bytes; use bytes::Bytes;
use ethereum_types::{H256, U256}; use common_types::{
use itertools::{Position, Itertools};
use kvdb::KeyValueDB;
use rlp::{RlpStream, Rlp};
use types::{
encoded, encoded,
engines::epoch::Transition as EpochTransition, engines::epoch::Transition as EpochTransition,
header::Header, header::Header,
@ -38,8 +33,15 @@ use types::{
receipt::Receipt, receipt::Receipt,
snapshot::{ChunkSink, Progress, ManifestData} snapshot::{ChunkSink, Progress, ManifestData}
}; };
use engine::{Engine, EpochVerifier};
use ethereum_types::{H256, U256};
use itertools::{Position, Itertools};
use kvdb::KeyValueDB;
use log::trace;
use rlp::{RlpStream, Rlp};
use crate::{SnapshotComponents, Rebuilder};
use snapshot::{SnapshotComponents, Rebuilder};
/// Snapshot creation and restoration for PoA chains. /// Snapshot creation and restoration for PoA chains.
/// Chunk format: /// Chunk format:
@ -320,7 +322,7 @@ impl Rebuilder for ChunkRebuilder {
} }
if is_last_chunk { if is_last_chunk {
use types::block::Block; use common_types::block::Block;
let last_rlp = rlp.at(num_items - 1)?; let last_rlp = rlp.at(num_items - 1)?;
let block = Block { let block = Block {

View File

@ -23,8 +23,8 @@ mod work;
pub use self::authority::*; pub use self::authority::*;
pub use self::work::*; pub use self::work::*;
use snapshot::SnapshotComponents; use crate::SnapshotComponents;
use types::snapshot::Snapshotting::{self, *}; use common_types::snapshot::Snapshotting::{self, *};
/// Create a factory for building snapshot chunks and restoring from them. /// Create a factory for building snapshot chunks and restoring from them.
/// `None` indicates that the engine doesn't support snapshot creation. /// `None` indicates that the engine doesn't support snapshot creation.

View File

@ -25,21 +25,27 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
use blockchain::{BlockChain, BlockChainDB, BlockProvider}; use blockchain::{BlockChain, BlockChainDB, BlockProvider};
use engine::Engine;
use snapshot::block::AbridgedBlock;
use ethereum_types::H256;
use kvdb::KeyValueDB;
use bytes::Bytes; use bytes::Bytes;
use rlp::{RlpStream, Rlp}; use common_types::{
use rand::rngs::OsRng;
use types::{
encoded, encoded,
engines::epoch::Transition as EpochTransition, engines::epoch::Transition as EpochTransition,
errors::{SnapshotError, EthcoreError}, errors::{SnapshotError, EthcoreError},
snapshot::{ChunkSink, ManifestData, Progress}, snapshot::{ChunkSink, ManifestData, Progress},
receipt::Receipt,
}; };
use engine::Engine;
use ethereum_types::{H256, U256};
use kvdb::KeyValueDB;
use log::trace;
use rand::rngs::OsRng;
use rlp::{RlpStream, Rlp};
use triehash::ordered_trie_root;
use snapshot::{SnapshotComponents, Rebuilder}; use crate::{
SnapshotComponents, Rebuilder,
block::AbridgedBlock,
verify_old_block
};
/// Snapshot creation and restoration for PoW chains. /// Snapshot creation and restoration for PoW chains.
/// This includes blocks from the head of the chain as a /// This includes blocks from the head of the chain as a
@ -93,8 +99,8 @@ impl SnapshotComponents for PowSnapshot {
).map(|r| Box::new(r) as Box<_>) ).map(|r| Box::new(r) as Box<_>)
} }
fn min_supported_version(&self) -> u64 { ::snapshot::MIN_SUPPORTED_STATE_CHUNK_VERSION } fn min_supported_version(&self) -> u64 { crate::MIN_SUPPORTED_STATE_CHUNK_VERSION }
fn current_version(&self) -> u64 { ::snapshot::STATE_CHUNK_VERSION } fn current_version(&self) -> u64 { crate::STATE_CHUNK_VERSION }
} }
/// Used to build block chunks. /// Used to build block chunks.
@ -231,10 +237,6 @@ impl Rebuilder for PowRebuilder {
/// Feed the rebuilder an uncompressed block chunk. /// Feed the rebuilder an uncompressed block chunk.
/// Returns the number of blocks fed or any errors. /// Returns the number of blocks fed or any errors.
fn feed(&mut self, chunk: &[u8], engine: &dyn Engine, abort_flag: &AtomicBool) -> Result<(), EthcoreError> { fn feed(&mut self, chunk: &[u8], engine: &dyn Engine, abort_flag: &AtomicBool) -> Result<(), EthcoreError> {
use snapshot::verify_old_block;
use ethereum_types::U256;
use triehash::ordered_trie_root;
let rlp = Rlp::new(chunk); let rlp = Rlp::new(chunk);
let item_count = rlp.item_count()?; let item_count = rlp.item_count()?;
let num_blocks = (item_count - 3) as u64; let num_blocks = (item_count - 3) as u64;
@ -256,7 +258,7 @@ impl Rebuilder for PowRebuilder {
let pair = rlp.at(idx)?; let pair = rlp.at(idx)?;
let abridged_rlp = pair.at(0)?.as_raw().to_owned(); let abridged_rlp = pair.at(0)?.as_raw().to_owned();
let abridged_block = AbridgedBlock::from_raw(abridged_rlp); let abridged_block = AbridgedBlock::from_raw(abridged_rlp);
let receipts: Vec<::types::receipt::Receipt> = pair.list_at(1)?; let receipts: Vec<Receipt> = pair.list_at(1)?;
let receipts_root = ordered_trie_root(pair.at(1)?.iter().map(|r| r.as_raw())); let receipts_root = ordered_trie_root(pair.at(1)?.iter().map(|r| r.as_raw()));
let block = abridged_block.to_block(parent_hash, cur_number, receipts_root)?; let block = abridged_block.to_block(parent_hash, cur_number, receipts_root)?;

View File

@ -27,16 +27,17 @@ use std::path::{Path, PathBuf};
use bytes::Bytes; use bytes::Bytes;
use client_traits::SnapshotWriter; use client_traits::SnapshotWriter;
use ethereum_types::H256; use common_types::{
use rlp::{RlpStream, Rlp};
use types::{
errors::{SnapshotError, EthcoreError}, errors::{SnapshotError, EthcoreError},
snapshot::ManifestData, snapshot::ManifestData,
}; };
use ethereum_types::H256;
use log::trace;
use rlp::{RlpStream, Rlp};
use rlp_derive::*;
const SNAPSHOT_VERSION: u64 = 2; const SNAPSHOT_VERSION: u64 = 2;
// (hash, len, offset) // (hash, len, offset)
#[derive(RlpEncodable, RlpDecodable)] #[derive(RlpEncodable, RlpDecodable)]
struct ChunkInfo(H256, u64, u64); struct ChunkInfo(H256, u64, u64);
@ -320,9 +321,9 @@ impl SnapshotReader for LooseReader {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use tempdir::TempDir; use tempdir::TempDir;
use hash::keccak; use keccak_hash::keccak;
use snapshot::ManifestData; use common_types::snapshot::ManifestData;
use super::{SnapshotWriter, SnapshotReader, PackedWriter, PackedReader, LooseWriter, LooseReader, SNAPSHOT_VERSION}; use super::{SnapshotWriter, SnapshotReader, PackedWriter, PackedReader, LooseWriter, LooseReader, SNAPSHOT_VERSION};
const STATE_CHUNKS: &'static [&'static [u8]] = &[b"dog", b"cat", b"hello world", b"hi", b"notarealchunk"]; const STATE_CHUNKS: &'static [&'static [u8]] = &[b"dog", b"cat", b"hello world", b"hi", b"notarealchunk"];
@ -351,8 +352,8 @@ mod tests {
let manifest = ManifestData { let manifest = ManifestData {
version: SNAPSHOT_VERSION, version: SNAPSHOT_VERSION,
state_hashes: state_hashes, state_hashes,
block_hashes: block_hashes, block_hashes,
state_root: keccak(b"notarealroot"), state_root: keccak(b"notarealroot"),
block_number: 12345678987654321, block_number: 12345678987654321,
block_hash: keccak(b"notarealblock"), block_hash: keccak(b"notarealblock"),

View File

@ -23,46 +23,44 @@ use std::collections::{HashMap, HashSet};
use std::cmp; use std::cmp;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY};
use keccak_hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY};
use account_db::{AccountDB, AccountDBMut}; use account_db::{AccountDB, AccountDBMut};
use account_state::Account as StateAccount;
use blockchain::{BlockChain, BlockProvider}; use blockchain::{BlockChain, BlockProvider};
use types::{ use bloom_journal::Bloom;
use bytes::Bytes;
// todo[dvdplm] put back in snapshots once it's extracted
use client_traits::SnapshotWriter;
use common_types::{
ids::BlockId, ids::BlockId,
header::Header, header::Header,
errors::{SnapshotError as Error, EthcoreError}, errors::{SnapshotError as Error, EthcoreError},
snapshot::Progress, snapshot::{Progress, ManifestData},
}; };
use ethereum_types::{H256, U256};
use hash_db::HashDB;
use keccak_hasher::KeccakHasher;
use snappy;
use bytes::Bytes;
use parking_lot::Mutex;
use journaldb::{self, Algorithm, JournalDB};
use kvdb::{KeyValueDB, DBValue};
use trie::{Trie, TrieMut};
use ethtrie::{TrieDB, TrieDBMut};
use rlp::{RlpStream, Rlp};
use bloom_journal::Bloom;
use num_cpus;
use types::snapshot::ManifestData;
// todo[dvdplm] put back in snapshots once it's extracted
use client_traits::SnapshotWriter;
use super::state_db::StateDB;
use account_state::Account as StateAccount;
use engine::Engine;
use crossbeam_utils::thread; use crossbeam_utils::thread;
use engine::Engine;
use ethereum_types::{H256, U256};
use ethtrie::{TrieDB, TrieDBMut};
use hash_db::HashDB;
use journaldb::{self, Algorithm, JournalDB};
use keccak_hasher::KeccakHasher;
use parking_lot::Mutex;
use kvdb::{KeyValueDB, DBValue};
use log::{debug, info, trace};
use num_cpus;
use rand::{Rng, rngs::OsRng}; use rand::{Rng, rngs::OsRng};
use rlp::{RlpStream, Rlp};
use snappy;
use state_db::StateDB;
use trie_db::{Trie, TrieMut};
pub use self::consensus::*; pub use self::consensus::*;
pub use self::service::Service; pub use self::service::Service;
pub use self::traits::{SnapshotService, SnapshotComponents, Rebuilder}; pub use self::traits::{SnapshotService, SnapshotComponents, Rebuilder};
pub use self::watcher::Watcher; pub use self::watcher::Watcher;
pub use types::basic_account::BasicAccount; pub use common_types::basic_account::BasicAccount;
pub mod io; pub mod io;
pub mod service; pub mod service;
@ -377,7 +375,7 @@ impl StateRebuilder {
/// Create a new state rebuilder to write into the given backing DB. /// Create a new state rebuilder to write into the given backing DB.
pub fn new(db: Arc<dyn KeyValueDB>, pruning: Algorithm) -> Self { pub fn new(db: Arc<dyn KeyValueDB>, pruning: Algorithm) -> Self {
StateRebuilder { StateRebuilder {
db: journaldb::new(db.clone(), pruning, ::db::COL_STATE), db: journaldb::new(db.clone(), pruning, ethcore_db::COL_STATE),
state_root: KECCAK_NULL_RLP, state_root: KECCAK_NULL_RLP,
known_code: HashMap::new(), known_code: HashMap::new(),
missing_code: HashMap::new(), missing_code: HashMap::new(),

View File

@ -24,6 +24,27 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::cmp; use std::cmp;
use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler};
use bytes::Bytes;
use common_types::{
io_message::ClientIoMessage,
errors::{EthcoreError as Error, SnapshotError, SnapshotError::UnlinkedAncientBlockChain},
ids::BlockId,
snapshot::{ManifestData, Progress, RestorationStatus},
};
// todo[dvdplm] put SnapshotWriter back in snapshots once extracted
use client_traits::{ChainInfo, SnapshotClient, SnapshotWriter};
use engine::Engine;
use ethereum_types::H256;
use ethcore_io::IoChannel;
use journaldb::Algorithm;
use keccak_hash::keccak;
use kvdb::DBTransaction;
use log::{error, info, trace, warn};
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
use snappy;
use trie_db::TrieError;
use super::{ use super::{
StateRebuilder, StateRebuilder,
SnapshotService, SnapshotService,
@ -33,31 +54,6 @@ use super::{
chunker, chunker,
}; };
use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler};
use client::Client;
// todo[dvdplm] put SnapshotWriter back in snapshots once extracted
use client_traits::{
BlockInfo, BlockChainClient, ChainInfo,
SnapshotClient, SnapshotWriter, DatabaseRestore,
};
use engine::Engine;
use hash::keccak;
use types::{
io_message::ClientIoMessage,
errors::{EthcoreError as Error, SnapshotError, SnapshotError::UnlinkedAncientBlockChain},
ids::BlockId,
snapshot::{ManifestData, Progress, RestorationStatus},
};
use io::IoChannel;
use ethereum_types::H256;
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
use bytes::Bytes;
use journaldb::Algorithm;
use kvdb::DBTransaction;
use snappy;
/// Helper for removing directories in case of error. /// Helper for removing directories in case of error.
struct Guard(bool, PathBuf); struct Guard(bool, PathBuf);
@ -140,7 +136,7 @@ impl Restoration {
let expected_len = snappy::decompressed_len(chunk)?; let expected_len = snappy::decompressed_len(chunk)?;
if expected_len > MAX_CHUNK_SIZE { if expected_len > MAX_CHUNK_SIZE {
trace!(target: "snapshot", "Discarding large chunk: {} vs {}", expected_len, MAX_CHUNK_SIZE); trace!(target: "snapshot", "Discarding large chunk: {} vs {}", expected_len, MAX_CHUNK_SIZE);
return Err(::snapshot::Error::ChunkTooLarge.into()); return Err(SnapshotError::ChunkTooLarge.into());
} }
let len = snappy::decompress_into(chunk, &mut self.snappy_buffer)?; let len = snappy::decompress_into(chunk, &mut self.snappy_buffer)?;
@ -162,7 +158,7 @@ impl Restoration {
let expected_len = snappy::decompressed_len(chunk)?; let expected_len = snappy::decompressed_len(chunk)?;
if expected_len > MAX_CHUNK_SIZE { if expected_len > MAX_CHUNK_SIZE {
trace!(target: "snapshot", "Discarding large chunk: {} vs {}", expected_len, MAX_CHUNK_SIZE); trace!(target: "snapshot", "Discarding large chunk: {} vs {}", expected_len, MAX_CHUNK_SIZE);
return Err(::snapshot::Error::ChunkTooLarge.into()); return Err(SnapshotError::ChunkTooLarge.into());
} }
let len = snappy::decompress_into(chunk, &mut self.snappy_buffer)?; let len = snappy::decompress_into(chunk, &mut self.snappy_buffer)?;
@ -179,8 +175,6 @@ impl Restoration {
// finish up restoration. // finish up restoration.
fn finalize(mut self) -> Result<(), Error> { fn finalize(mut self) -> Result<(), Error> {
use trie::TrieError;
if !self.is_done() { return Ok(()) } if !self.is_done() { return Ok(()) }
// verify final state root. // verify final state root.
@ -212,10 +206,10 @@ impl Restoration {
} }
/// Type alias for client io channel. /// Type alias for client io channel.
pub type Channel = IoChannel<ClientIoMessage<Client>>; pub type Channel<C> = IoChannel<ClientIoMessage<C>>;
/// Snapshot service parameters. /// Snapshot service parameters.
pub struct ServiceParams { pub struct ServiceParams<C: 'static> {
/// The consensus engine this is built on. /// The consensus engine this is built on.
pub engine: Arc<dyn Engine>, pub engine: Arc<dyn Engine>,
/// The chain's genesis block. /// The chain's genesis block.
@ -225,21 +219,21 @@ pub struct ServiceParams {
/// Handler for opening a restoration DB. /// Handler for opening a restoration DB.
pub restoration_db_handler: Box<dyn BlockChainDBHandler>, pub restoration_db_handler: Box<dyn BlockChainDBHandler>,
/// Async IO channel for sending messages. /// Async IO channel for sending messages.
pub channel: Channel, pub channel: Channel<C>,
/// The directory to put snapshots in. /// The directory to put snapshots in.
/// Usually "<chain hash>/snapshot" /// Usually "<chain hash>/snapshot"
pub snapshot_root: PathBuf, pub snapshot_root: PathBuf,
/// A handle for database restoration. /// A handle for database restoration.
pub client: Arc<Client>, pub client: Arc<C>,
} }
/// `SnapshotService` implementation. /// `SnapshotService` implementation.
/// This controls taking snapshots and restoring from them. /// This controls taking snapshots and restoring from them.
pub struct Service { pub struct Service<C: Send + Sync + 'static> {
restoration: Mutex<Option<Restoration>>, restoration: Mutex<Option<Restoration>>,
restoration_db_handler: Box<dyn BlockChainDBHandler>, restoration_db_handler: Box<dyn BlockChainDBHandler>,
snapshot_root: PathBuf, snapshot_root: PathBuf,
io_channel: Mutex<Channel>, io_channel: Mutex<Channel<C>>,
pruning: Algorithm, pruning: Algorithm,
status: Mutex<RestorationStatus>, status: Mutex<RestorationStatus>,
reader: RwLock<Option<LooseReader>>, reader: RwLock<Option<LooseReader>>,
@ -247,15 +241,15 @@ pub struct Service {
genesis_block: Bytes, genesis_block: Bytes,
state_chunks: AtomicUsize, state_chunks: AtomicUsize,
block_chunks: AtomicUsize, block_chunks: AtomicUsize,
client: Arc<Client>, client: Arc<C>,
progress: Progress, progress: Progress,
taking_snapshot: AtomicBool, taking_snapshot: AtomicBool,
restoring_snapshot: AtomicBool, restoring_snapshot: AtomicBool,
} }
impl Service { impl<C> Service<C> where C: SnapshotClient + ChainInfo {
/// Create a new snapshot service from the given parameters. /// Create a new snapshot service from the given parameters.
pub fn new(params: ServiceParams) -> Result<Self, Error> { pub fn new(params: ServiceParams<C>) -> Result<Self, Error> {
let mut service = Service { let mut service = Service {
restoration: Mutex::new(None), restoration: Mutex::new(None),
restoration_db_handler: params.restoration_db_handler, restoration_db_handler: params.restoration_db_handler,
@ -479,10 +473,7 @@ impl Service {
/// calling this while a restoration is in progress or vice versa /// calling this while a restoration is in progress or vice versa
/// will lead to a race condition where the first one to finish will /// will lead to a race condition where the first one to finish will
/// have their produced snapshot overwritten. /// have their produced snapshot overwritten.
pub fn take_snapshot<C>(&self, client: &C, num: u64) -> Result<(), Error> pub fn take_snapshot(&self, client: &C, num: u64) -> Result<(), Error> {
where
C: ChainInfo + SnapshotClient
{
if self.taking_snapshot.compare_and_swap(false, true, Ordering::SeqCst) { if self.taking_snapshot.compare_and_swap(false, true, Ordering::SeqCst) {
info!("Skipping snapshot at #{} as another one is currently in-progress.", num); info!("Skipping snapshot at #{} as another one is currently in-progress.", num);
return Ok(()); return Ok(());
@ -797,7 +788,7 @@ impl Service {
} }
} }
impl SnapshotService for Service { impl<C: Send + Sync> SnapshotService for Service<C> {
fn manifest(&self) -> Option<ManifestData> { fn manifest(&self) -> Option<ManifestData> {
self.reader.read().as_ref().map(|r| r.manifest().clone()) self.reader.read().as_ref().map(|r| r.manifest().clone())
} }
@ -807,10 +798,6 @@ impl SnapshotService for Service {
.map(|c| (c.min_supported_version(), c.current_version())) .map(|c| (c.min_supported_version(), c.current_version()))
} }
fn chunk(&self, hash: H256) -> Option<Bytes> {
self.reader.read().as_ref().and_then(|r| r.chunk(hash).ok())
}
fn completed_chunks(&self) -> Option<Vec<H256>> { fn completed_chunks(&self) -> Option<Vec<H256>> {
let restoration = self.restoration.lock(); let restoration = self.restoration.lock();
@ -833,6 +820,10 @@ impl SnapshotService for Service {
} }
} }
fn chunk(&self, hash: H256) -> Option<Bytes> {
self.reader.read().as_ref().and_then(|r| r.chunk(hash).ok())
}
fn status(&self) -> RestorationStatus { fn status(&self) -> RestorationStatus {
let mut cur_status = self.status.lock(); let mut cur_status = self.status.lock();
@ -892,7 +883,7 @@ impl SnapshotService for Service {
} }
} }
impl Drop for Service { impl<C: Send + Sync> Drop for Service<C> {
fn drop(&mut self) { fn drop(&mut self) {
trace!(target: "shutdown", "Dropping Service"); trace!(target: "shutdown", "Dropping Service");
self.abort_restore(); self.abort_restore();
@ -904,18 +895,18 @@ impl Drop for Service {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use client::Client; use ethcore::client::Client;
use io::{IoService}; use ethcore_io::IoService;
use spec; use spec;
use journaldb::Algorithm; use journaldb::Algorithm;
use snapshot::SnapshotService; use crate::SnapshotService;
use super::*; use super::*;
use types::{ use common_types::{
io_message::ClientIoMessage, io_message::ClientIoMessage,
snapshot::{ManifestData, RestorationStatus} snapshot::{ManifestData, RestorationStatus}
}; };
use tempdir::TempDir; use tempdir::TempDir;
use test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler}; use ethcore::test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler};
#[test] #[test]
fn sends_async_messages() { fn sends_async_messages() {
@ -968,7 +959,7 @@ mod tests {
let state_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect(); let state_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect();
let block_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect(); let block_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect();
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let db_config = DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS);
let gb = spec.genesis_block(); let gb = spec.genesis_block();
let flag = ::std::sync::atomic::AtomicBool::new(true); let flag = ::std::sync::atomic::AtomicBool::new(true);

View File

@ -17,32 +17,33 @@
//! Snapshot test helpers. These are used to build blockchains and state tries //! Snapshot test helpers. These are used to build blockchains and state tries
//! which can be queried before and after a full snapshot/restore cycle. //! which can be queried before and after a full snapshot/restore cycle.
extern crate trie_standardmap;
use std::sync::Arc; use std::sync::Arc;
use hash::{KECCAK_NULL_RLP}; use std::sync::atomic::AtomicBool;
use keccak_hash::{KECCAK_NULL_RLP};
use account_db::AccountDBMut; use account_db::AccountDBMut;
use types::basic_account::BasicAccount; use common_types::basic_account::BasicAccount;
use blockchain::{BlockChain, BlockChainDB}; use blockchain::{BlockChain, BlockChainDB};
use client::Client; use ethcore::client::Client;
use client_traits::{ChainInfo, SnapshotClient}; use client_traits::{ChainInfo, SnapshotClient};
use engine::Engine; use engine::Engine;
use snapshot::{StateRebuilder}; use crate::{
use snapshot::io::{SnapshotReader, PackedWriter, PackedReader}; StateRebuilder,
io::{SnapshotReader, PackedWriter, PackedReader},
};
use tempdir::TempDir; use tempdir::TempDir;
use rand::Rng; use rand::Rng;
use log::trace;
use kvdb::DBValue; use kvdb::DBValue;
use ethereum_types::H256; use ethereum_types::H256;
use hash_db::HashDB; use hash_db::HashDB;
use keccak_hasher::KeccakHasher; use keccak_hasher::KeccakHasher;
use journaldb; use journaldb;
use trie::{TrieMut, Trie}; use trie_db::{TrieMut, Trie};
use ethtrie::{SecTrieDBMut, TrieDB, TrieDBMut}; use ethtrie::{SecTrieDBMut, TrieDB, TrieDBMut};
use self::trie_standardmap::{Alphabet, StandardMap, ValueMode}; use trie_standardmap::{Alphabet, StandardMap, ValueMode};
use types::errors::EthcoreError; use common_types::errors::EthcoreError;
// the proportion of accounts we will alter each tick. // the proportion of accounts we will alter each tick.
const ACCOUNT_CHURN: f32 = 0.01; const ACCOUNT_CHURN: f32 = 0.01;
@ -135,7 +136,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) {
/// Take a snapshot from the given client into a temporary file. /// Take a snapshot from the given client into a temporary file.
/// Return a snapshot reader for it. /// Return a snapshot reader for it.
pub fn snap(client: &Client) -> (Box<dyn SnapshotReader>, TempDir) { pub fn snap(client: &Client) -> (Box<dyn SnapshotReader>, TempDir) {
use types::ids::BlockId; use common_types::ids::BlockId;
let tempdir = TempDir::new("").unwrap(); let tempdir = TempDir::new("").unwrap();
let path = tempdir.path().join("file"); let path = tempdir.path().join("file");
@ -158,10 +159,8 @@ pub fn restore(
reader: &dyn SnapshotReader, reader: &dyn SnapshotReader,
genesis: &[u8], genesis: &[u8],
) -> Result<(), EthcoreError> { ) -> Result<(), EthcoreError> {
use std::sync::atomic::AtomicBool;
let flag = AtomicBool::new(true); let flag = AtomicBool::new(true);
let chunker = crate::snapshot::chunker(engine.snapshot_mode()).expect("the engine used here supports snapshots"); let chunker = crate::chunker(engine.snapshot_mode()).expect("the engine used here supports snapshots");
let manifest = reader.manifest(); let manifest = reader.manifest();
let mut state = StateRebuilder::new(db.key_value().clone(), journaldb::Algorithm::Archive); let mut state = StateRebuilder::new(db.key_value().clone(), journaldb::Algorithm::Archive);

View File

@ -23,7 +23,7 @@ mod service;
pub mod helpers; pub mod helpers;
use super::ManifestData; use common_types::snapshot::ManifestData;
#[test] #[test]
fn manifest_rlp() { fn manifest_rlp() {

View File

@ -21,26 +21,32 @@ use std::sync::Arc;
use std::str::FromStr; use std::str::FromStr;
use accounts::AccountProvider; use accounts::AccountProvider;
use client::Client; use ethcore::client::Client;
use client_traits::{BlockChainClient, ChainInfo}; use client_traits::{BlockChainClient, ChainInfo};
use ethkey::Secret; use ethkey::Secret;
use snapshot::tests::helpers as snapshot_helpers; use crate::tests::helpers as snapshot_helpers;
use spec::Spec; use spec::Spec;
use test_helpers::generate_dummy_client_with_spec; use ethcore::test_helpers::generate_dummy_client_with_spec;
use types::transaction::{Transaction, Action, SignedTransaction}; use common_types::transaction::{Transaction, Action, SignedTransaction};
use tempdir::TempDir; use tempdir::TempDir;
use log::trace;
use ethereum_types::Address; use ethereum_types::Address;
use test_helpers; use ethcore::{
test_helpers,
miner::{self, MinerService},
};
use keccak_hash::keccak;
use ethabi_contract::use_contract;
use lazy_static::lazy_static;
use_contract!(test_validator_set, "res/contracts/test_validator_set.json"); use_contract!(test_validator_set, "../res/contracts/test_validator_set.json");
const PASS: &'static str = ""; const PASS: &'static str = "";
const TRANSITION_BLOCK_1: usize = 2; // block at which the contract becomes activated. const TRANSITION_BLOCK_1: usize = 2; // block at which the contract becomes activated.
const TRANSITION_BLOCK_2: usize = 10; // block at which the second contract activates. const TRANSITION_BLOCK_2: usize = 10; // block at which the second contract activates.
macro_rules! secret { macro_rules! secret {
($e: expr) => { Secret::from($crate::hash::keccak($e).0) } ($e: expr) => { Secret::from(keccak($e).0) }
} }
lazy_static! { lazy_static! {
@ -100,8 +106,6 @@ fn make_chain(accounts: Arc<AccountProvider>, blocks_beyond: usize, transitions:
{ {
// push a block with given number, signed by one of the signers, with given transactions. // push a block with given number, signed by one of the signers, with given transactions.
let push_block = |signers: &[Address], n, txs: Vec<SignedTransaction>| { let push_block = |signers: &[Address], n, txs: Vec<SignedTransaction>| {
use miner::{self, MinerService};
let idx = n as usize % signers.len(); let idx = n as usize % signers.len();
trace!(target: "snapshot", "Pushing block #{}, {} txs, author={}", trace!(target: "snapshot", "Pushing block #{}, {} txs, author={}",
n, txs.len(), signers[idx]); n, txs.len(), signers[idx]);

View File

@ -18,25 +18,29 @@
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use tempdir::TempDir; use tempdir::TempDir;
use types::{ use common_types::{
errors::EthcoreError as Error, errors::EthcoreError as Error,
engines::ForkChoice, engines::ForkChoice,
snapshot::Progress, snapshot::{Progress, ManifestData},
}; };
use blockchain::generator::{BlockGenerator, BlockBuilder}; use blockchain::generator::{BlockGenerator, BlockBuilder};
use blockchain::{BlockChain, ExtrasInsert}; use blockchain::{BlockChain, ExtrasInsert};
use client_traits::SnapshotWriter; use client_traits::SnapshotWriter;
use snapshot::{chunk_secondary, Error as SnapshotError, SnapshotComponents}; use crate::{
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader}; chunk_secondary,
Error as SnapshotError, SnapshotComponents,
io::{PackedReader, PackedWriter, SnapshotReader},
PowSnapshot,
};
use parking_lot::Mutex; use parking_lot::Mutex;
use snappy; use snappy;
use keccak_hash::KECCAK_NULL_RLP;
use kvdb::DBTransaction; use kvdb::DBTransaction;
use test_helpers; use ethcore::test_helpers;
use spec; use spec;
const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { blocks: 30000, max_restore_blocks: 30000 }; const SNAPSHOT_MODE: PowSnapshot = PowSnapshot { blocks: 30000, max_restore_blocks: 30000 };
fn chunk_and_restore(amount: u64) { fn chunk_and_restore(amount: u64) {
let genesis = BlockBuilder::genesis(); let genesis = BlockBuilder::genesis();
@ -75,11 +79,11 @@ fn chunk_and_restore(amount: u64) {
&Progress::default() &Progress::default()
).unwrap(); ).unwrap();
let manifest = ::snapshot::ManifestData { let manifest = ManifestData {
version: 2, version: 2,
state_hashes: Vec::new(), state_hashes: Vec::new(),
block_hashes: block_hashes, block_hashes,
state_root: ::hash::KECCAK_NULL_RLP, state_root: KECCAK_NULL_RLP,
block_number: amount, block_number: amount,
block_hash: best_hash, block_hash: best_hash,
}; };
@ -137,11 +141,11 @@ fn checks_flag() {
let engine = spec::new_test().engine; let engine = spec::new_test().engine;
let chain = BlockChain::new(Default::default(), genesis.last().encoded().raw(), db.clone()); let chain = BlockChain::new(Default::default(), genesis.last().encoded().raw(), db.clone());
let manifest = ::snapshot::ManifestData { let manifest = ManifestData {
version: 2, version: 2,
state_hashes: Vec::new(), state_hashes: Vec::new(),
block_hashes: Vec::new(), block_hashes: Vec::new(),
state_root: ::hash::KECCAK_NULL_RLP, state_root: KECCAK_NULL_RLP,
block_number: 102, block_number: 102,
block_hash: H256::zero(), block_hash: H256::zero(),
}; };

View File

@ -21,22 +21,28 @@ use std::sync::Arc;
use tempdir::TempDir; use tempdir::TempDir;
use blockchain::BlockProvider; use blockchain::BlockProvider;
use client::{Client, ClientConfig}; use ethcore::client::{Client, ClientConfig};
use client_traits::{BlockInfo, ImportBlock, SnapshotWriter}; use client_traits::{BlockInfo, ImportBlock, SnapshotWriter};
use types::{ use common_types::{
ids::BlockId, ids::BlockId,
snapshot::Progress, snapshot::Progress,
verification::Unverified, verification::Unverified,
snapshot::{ManifestData, RestorationStatus}, snapshot::{ManifestData, RestorationStatus},
}; };
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader}; use crate::{
use snapshot::service::{Service, ServiceParams}; chunk_state, chunk_secondary, SnapshotService,
use snapshot::{chunk_state, chunk_secondary, SnapshotService}; io::{PackedReader, PackedWriter, SnapshotReader},
service::{Service, ServiceParams},
PowSnapshot,
};
use spec; use spec;
use test_helpers::{new_db, new_temp_db, generate_dummy_client_with_spec_and_data, restoration_db_handler}; use ethcore::{
miner,
test_helpers::{new_db, new_temp_db, generate_dummy_client_with_spec_and_data, restoration_db_handler}
};
use parking_lot::Mutex; use parking_lot::Mutex;
use io::IoChannel; use ethcore_io::IoChannel;
use kvdb_rocksdb::DatabaseConfig; use kvdb_rocksdb::DatabaseConfig;
#[test] #[test]
@ -53,7 +59,7 @@ fn restored_is_equivalent() {
let client_db = tempdir.path().join("client_db"); let client_db = tempdir.path().join("client_db");
let path = tempdir.path().join("snapshot"); let path = tempdir.path().join("snapshot");
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let db_config = DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS);
let restoration = restoration_db_handler(db_config); let restoration = restoration_db_handler(db_config);
let blockchain_db = restoration.open(&client_db).unwrap(); let blockchain_db = restoration.open(&client_db).unwrap();
@ -62,7 +68,7 @@ fn restored_is_equivalent() {
Default::default(), Default::default(),
&spec, &spec,
blockchain_db, blockchain_db,
Arc::new(::miner::Miner::new_for_tests(&spec, None)), Arc::new(miner::Miner::new_for_tests(&spec, None)),
IoChannel::disconnected(), IoChannel::disconnected(),
).unwrap(); ).unwrap();
@ -118,7 +124,7 @@ fn guards_delete_folders() {
let service_params = ServiceParams { let service_params = ServiceParams {
engine: spec.engine.clone(), engine: spec.engine.clone(),
genesis_block: spec.genesis_block(), genesis_block: spec.genesis_block(),
restoration_db_handler: restoration_db_handler(DatabaseConfig::with_columns(::db::NUM_COLUMNS)), restoration_db_handler: restoration_db_handler(DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS)),
pruning: ::journaldb::Algorithm::Archive, pruning: ::journaldb::Algorithm::Archive,
channel: IoChannel::disconnected(), channel: IoChannel::disconnected(),
snapshot_root: tempdir.path().to_owned(), snapshot_root: tempdir.path().to_owned(),
@ -157,11 +163,10 @@ fn guards_delete_folders() {
#[test] #[test]
fn keep_ancient_blocks() { fn keep_ancient_blocks() {
let _ = ::env_logger::try_init(); let _ = ::env_logger::try_init();
// Test variables // Test variables
const NUM_BLOCKS: u64 = 500; const NUM_BLOCKS: u64 = 500;
const NUM_SNAPSHOT_BLOCKS: u64 = 300; const NUM_SNAPSHOT_BLOCKS: u64 = 300;
const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { blocks: NUM_SNAPSHOT_BLOCKS, max_restore_blocks: NUM_SNAPSHOT_BLOCKS }; const SNAPSHOT_MODE: PowSnapshot = PowSnapshot { blocks: NUM_SNAPSHOT_BLOCKS, max_restore_blocks: NUM_SNAPSHOT_BLOCKS };
// Temporary folders // Temporary folders
let tempdir = TempDir::new("").unwrap(); let tempdir = TempDir::new("").unwrap();
@ -197,7 +202,7 @@ fn keep_ancient_blocks() {
0 0
).unwrap(); ).unwrap();
let manifest = ::snapshot::ManifestData { let manifest = ManifestData {
version: 2, version: 2,
state_hashes, state_hashes,
state_root, state_root,
@ -209,13 +214,13 @@ fn keep_ancient_blocks() {
writer.into_inner().finish(manifest.clone()).unwrap(); writer.into_inner().finish(manifest.clone()).unwrap();
// Initialize the Client // Initialize the Client
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let db_config = DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS);
let client_db = new_temp_db(&tempdir.path()); let client_db = new_temp_db(&tempdir.path());
let client2 = Client::new( let client2 = Client::new(
ClientConfig::default(), ClientConfig::default(),
&spec, &spec,
client_db, client_db,
Arc::new(::miner::Miner::new_for_tests(&spec, None)), Arc::new(miner::Miner::new_for_tests(&spec, None)),
IoChannel::disconnected(), IoChannel::disconnected(),
).unwrap(); ).unwrap();
@ -283,13 +288,13 @@ fn recover_aborted_recovery() {
let spec = spec::new_null(); let spec = spec::new_null();
let tempdir = TempDir::new("").unwrap(); let tempdir = TempDir::new("").unwrap();
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let db_config = DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS);
let client_db = new_db(); let client_db = new_db();
let client2 = Client::new( let client2 = Client::new(
Default::default(), Default::default(),
&spec, &spec,
client_db, client_db,
Arc::new(::miner::Miner::new_for_tests(&spec, None)), Arc::new(miner::Miner::new_for_tests(&spec, None)),
IoChannel::disconnected(), IoChannel::disconnected(),
).unwrap(); ).unwrap();
let service_params = ServiceParams { let service_params = ServiceParams {

View File

@ -18,17 +18,20 @@
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use hash::{KECCAK_NULL_RLP, keccak}; use keccak_hash::{KECCAK_NULL_RLP, keccak};
use types::{ use common_types::{
basic_account::BasicAccount, basic_account::BasicAccount,
errors::EthcoreError as Error, errors::EthcoreError as Error,
snapshot::ManifestData,
}; };
use client_traits::SnapshotWriter; use client_traits::SnapshotWriter;
use snapshot::account; use crate::{
use snapshot::{chunk_state, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS}; account,
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader}; {chunk_state, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS},
use super::helpers::StateProducer; io::{PackedReader, PackedWriter, SnapshotReader},
tests::helpers::StateProducer,
};
use rand::SeedableRng; use rand::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use ethereum_types::H256; use ethereum_types::H256;
@ -45,7 +48,7 @@ fn snap_and_restore() {
let mut producer = StateProducer::new(); let mut producer = StateProducer::new();
let mut rng = XorShiftRng::from_seed(RNG_SEED); let mut rng = XorShiftRng::from_seed(RNG_SEED);
let mut old_db = journaldb::new_memory_db(); let mut old_db = journaldb::new_memory_db();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let db_cfg = DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS);
for _ in 0..150 { for _ in 0..150 {
producer.tick(&mut rng, &mut old_db); producer.tick(&mut rng, &mut old_db);
@ -63,11 +66,11 @@ fn snap_and_restore() {
state_hashes.append(&mut hashes); state_hashes.append(&mut hashes);
} }
writer.into_inner().finish(::snapshot::ManifestData { writer.into_inner().finish(ManifestData {
version: 2, version: 2,
state_hashes: state_hashes, state_hashes,
block_hashes: Vec::new(), block_hashes: Vec::new(),
state_root: state_root, state_root,
block_number: 1000, block_number: 1000,
block_hash: H256::zero(), block_hash: H256::zero(),
}).unwrap(); }).unwrap();
@ -82,7 +85,7 @@ fn snap_and_restore() {
for chunk_hash in &reader.manifest().state_hashes { for chunk_hash in &reader.manifest().state_hashes {
let raw = reader.chunk(*chunk_hash).unwrap(); let raw = reader.chunk(*chunk_hash).unwrap();
let chunk = ::snappy::decompress(&raw).unwrap(); let chunk = snappy::decompress(&raw).unwrap();
rebuilder.feed(&chunk, &flag).unwrap(); rebuilder.feed(&chunk, &flag).unwrap();
} }
@ -93,7 +96,7 @@ fn snap_and_restore() {
new_db new_db
}; };
let new_db = journaldb::new(db, Algorithm::OverlayRecent, ::db::COL_STATE); let new_db = journaldb::new(db, Algorithm::OverlayRecent, ethcore_db::COL_STATE);
assert_eq!(new_db.earliest_era(), Some(1000)); assert_eq!(new_db.earliest_era(), Some(1000));
let keys = old_db.keys(); let keys = old_db.keys();
@ -141,7 +144,7 @@ fn get_code_from_prev_chunk() {
let chunk2 = make_chunk(acc, h2); let chunk2 = make_chunk(acc, h2);
let tempdir = TempDir::new("").unwrap(); let tempdir = TempDir::new("").unwrap();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let db_cfg = DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS);
let new_db = Arc::new(Database::open(&db_cfg, tempdir.path().to_str().unwrap()).unwrap()); let new_db = Arc::new(Database::open(&db_cfg, tempdir.path().to_str().unwrap()).unwrap());
{ {
@ -154,7 +157,7 @@ fn get_code_from_prev_chunk() {
rebuilder.finalize(1000, H256::random()).unwrap(); rebuilder.finalize(1000, H256::random()).unwrap();
} }
let state_db = journaldb::new(new_db, Algorithm::OverlayRecent, ::db::COL_STATE); let state_db = journaldb::new(new_db, Algorithm::OverlayRecent, ethcore_db::COL_STATE);
assert_eq!(state_db.earliest_era(), Some(1000)); assert_eq!(state_db.earliest_era(), Some(1000));
} }
@ -163,7 +166,7 @@ fn checks_flag() {
let mut producer = StateProducer::new(); let mut producer = StateProducer::new();
let mut rng = XorShiftRng::from_seed(RNG_SEED); let mut rng = XorShiftRng::from_seed(RNG_SEED);
let mut old_db = journaldb::new_memory_db(); let mut old_db = journaldb::new_memory_db();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS); let db_cfg = DatabaseConfig::with_columns(ethcore_db::NUM_COLUMNS);
for _ in 0..10 { for _ in 0..10 {
producer.tick(&mut rng, &mut old_db); producer.tick(&mut rng, &mut old_db);
@ -177,7 +180,7 @@ fn checks_flag() {
let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::default(), None, 0).unwrap(); let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::default(), None, 0).unwrap();
writer.into_inner().finish(::snapshot::ManifestData { writer.into_inner().finish(ManifestData {
version: 2, version: 2,
state_hashes, state_hashes,
block_hashes: Vec::new(), block_hashes: Vec::new(),
@ -197,7 +200,7 @@ fn checks_flag() {
for chunk_hash in &reader.manifest().state_hashes { for chunk_hash in &reader.manifest().state_hashes {
let raw = reader.chunk(*chunk_hash).unwrap(); let raw = reader.chunk(*chunk_hash).unwrap();
let chunk = ::snappy::decompress(&raw).unwrap(); let chunk = snappy::decompress(&raw).unwrap();
match rebuilder.feed(&chunk, &flag) { match rebuilder.feed(&chunk, &flag) {
Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {}, Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {},

View File

@ -18,11 +18,12 @@ use std::sync::{Arc, atomic::AtomicBool};
use blockchain::{BlockChain, BlockChainDB}; use blockchain::{BlockChain, BlockChainDB};
use bytes::Bytes; use bytes::Bytes;
use ethereum_types::H256; use common_types::{
use types::{
errors::{EthcoreError as Error, SnapshotError}, errors::{EthcoreError as Error, SnapshotError},
snapshot::{ManifestData, ChunkSink, Progress, RestorationStatus}, snapshot::{ManifestData, ChunkSink, Progress, RestorationStatus},
}; };
use engine::Engine;
use ethereum_types::H256;
/// The interface for a snapshot network service. /// The interface for a snapshot network service.
@ -69,8 +70,6 @@ pub trait SnapshotService : Sync + Send {
fn shutdown(&self); fn shutdown(&self);
} }
use crate::engine::Engine;
/// Restore from secondary snapshot chunks. /// Restore from secondary snapshot chunks.
pub trait Rebuilder: Send { pub trait Rebuilder: Send {
/// Feed a chunk, potentially out of order. /// Feed a chunk, potentially out of order.

View File

@ -16,18 +16,18 @@
//! Watcher for snapshot-related chain events. //! Watcher for snapshot-related chain events.
use parking_lot::Mutex; use std::sync::Arc;
use client::{Client, ChainNotify, NewBlocks};
use client_traits::BlockInfo; use client_traits::{BlockInfo, ChainNotify};
use types::{ use common_types::{
ids::BlockId, ids::BlockId,
io_message::ClientIoMessage, io_message::ClientIoMessage,
chain_notify::NewBlocks,
}; };
use io::IoChannel;
use ethereum_types::H256; use ethereum_types::H256;
use ethcore_io::IoChannel;
use std::sync::Arc; use log::{trace, warn};
use parking_lot::Mutex;
// helper trait for transforming hashes to numbers and checking if syncing. // helper trait for transforming hashes to numbers and checking if syncing.
trait Oracle: Send + Sync { trait Oracle: Send + Sync {
@ -37,7 +37,7 @@ trait Oracle: Send + Sync {
} }
struct StandardOracle<F> where F: 'static + Send + Sync + Fn() -> bool { struct StandardOracle<F> where F: 'static + Send + Sync + Fn() -> bool {
client: Arc<Client>, client: Arc<dyn BlockInfo>,
sync_status: F, sync_status: F,
} }
@ -58,7 +58,7 @@ trait Broadcast: Send + Sync {
fn take_at(&self, num: Option<u64>); fn take_at(&self, num: Option<u64>);
} }
impl Broadcast for Mutex<IoChannel<ClientIoMessage<Client>>> { impl<C: 'static> Broadcast for Mutex<IoChannel<ClientIoMessage<C>>> {
fn take_at(&self, num: Option<u64>) { fn take_at(&self, num: Option<u64>) {
let num = match num { let num = match num {
Some(n) => n, Some(n) => n,
@ -86,17 +86,16 @@ impl Watcher {
/// Create a new `Watcher` which will trigger a snapshot event /// Create a new `Watcher` which will trigger a snapshot event
/// once every `period` blocks, but only after that block is /// once every `period` blocks, but only after that block is
/// `history` blocks old. /// `history` blocks old.
pub fn new<F>(client: Arc<Client>, sync_status: F, channel: IoChannel<ClientIoMessage<Client>>, period: u64, history: u64) -> Self pub fn new<F, C>(client: Arc<dyn BlockInfo>, sync_status: F, channel: IoChannel<ClientIoMessage<C>>, period: u64, history: u64) -> Self
where F: 'static + Send + Sync + Fn() -> bool where
F: 'static + Send + Sync + Fn() -> bool,
C: 'static + Send + Sync,
{ {
Watcher { Watcher {
oracle: Box::new(StandardOracle { oracle: Box::new(StandardOracle { client, sync_status }),
client: client,
sync_status: sync_status,
}),
broadcast: Box::new(Mutex::new(channel)), broadcast: Box::new(Mutex::new(channel)),
period: period, period,
history: history, history,
} }
} }
} }
@ -123,14 +122,15 @@ impl ChainNotify for Watcher {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{Broadcast, Oracle, Watcher}; use std::collections::HashMap;
use std::time::Duration;
use client::{ChainNotify, NewBlocks, ChainRoute}; use client_traits::ChainNotify;
use common_types::chain_notify::{NewBlocks, ChainRoute};
use ethereum_types::{H256, U256, BigEndianHash}; use ethereum_types::{H256, U256, BigEndianHash};
use std::collections::HashMap; use super::{Broadcast, Oracle, Watcher};
use std::time::Duration;
struct TestOracle(HashMap<H256, u64>); struct TestOracle(HashMap<H256, u64>);
@ -161,8 +161,8 @@ mod tests {
let watcher = Watcher { let watcher = Watcher {
oracle: Box::new(TestOracle(map)), oracle: Box::new(TestOracle(map)),
broadcast: Box::new(TestBroadcast(expected)), broadcast: Box::new(TestBroadcast(expected)),
period: period, period,
history: history, history,
}; };
watcher.new_blocks(NewBlocks::new( watcher.new_blocks(NewBlocks::new(

View File

@ -21,7 +21,7 @@ use std::sync::{Arc, Weak};
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
use account_state::state::StateInfo; use account_state::state::StateInfo;
use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRoute, ImportRoute, TransactionAddress, ExtrasInsert, BlockNumberKey}; use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRoute, TransactionAddress, ExtrasInsert, BlockNumberKey};
use bytes::Bytes; use bytes::Bytes;
use call_contract::{CallContract, RegistryInfo}; use call_contract::{CallContract, RegistryInfo};
use ethcore_miner::pool::VerifiedTransaction; use ethcore_miner::pool::VerifiedTransaction;
@ -41,15 +41,15 @@ use block::{LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBl
use client::ancient_import::AncientVerifier; use client::ancient_import::AncientVerifier;
use client::{ use client::{
ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock, ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock,
Call, BlockProducer, SealedBlockImporter, ChainNotify, EngineInfo, Call, BlockProducer, SealedBlockImporter, EngineInfo,
ClientConfig, NewBlocks, ChainRoute, ChainMessageType, bad_blocks, ClientConfig, bad_blocks,
}; };
use client_traits::{ use client_traits::{
BlockInfo, ScheduleInfo, StateClient, BlockChainReset, BlockInfo, ScheduleInfo, StateClient, BlockChainReset,
Nonce, Balance, ChainInfo, TransactionInfo, ImportBlock, Nonce, Balance, ChainInfo, TransactionInfo, ImportBlock,
AccountData, BlockChain as BlockChainTrait, BlockChainClient, AccountData, BlockChain as BlockChainTrait, BlockChainClient,
IoClient, BadBlocks, ProvingBlockChainClient, SnapshotClient, IoClient, BadBlocks, ProvingBlockChainClient, SnapshotClient,
DatabaseRestore, SnapshotWriter, Tick, DatabaseRestore, SnapshotWriter, Tick, ChainNotify,
StateOrBlock, StateOrBlock,
}; };
use engine::Engine; use engine::Engine;
@ -72,7 +72,9 @@ use types::{
block::PreverifiedBlock, block::PreverifiedBlock,
block_status::BlockStatus, block_status::BlockStatus,
blockchain_info::BlockChainInfo, blockchain_info::BlockChainInfo,
chain_notify::{NewBlocks, ChainRoute, ChainMessageType},
client_types::ClientReport, client_types::ClientReport,
import_route::ImportRoute,
io_message::ClientIoMessage, io_message::ClientIoMessage,
encoded, encoded,
engines::{ engines::{
@ -986,12 +988,14 @@ impl Client {
self.importer.miner.clone() self.importer.miner.clone()
} }
#[cfg(test)] /// Access state from tests
#[cfg(any(test, feature = "test-helpers"))]
pub fn state_db(&self) -> ::parking_lot::RwLockReadGuard<StateDB> { pub fn state_db(&self) -> ::parking_lot::RwLockReadGuard<StateDB> {
self.state_db.read() self.state_db.read()
} }
#[cfg(test)] /// Access the BlockChain from tests
#[cfg(any(test, feature = "test-helpers"))]
pub fn chain(&self) -> Arc<BlockChain> { pub fn chain(&self) -> Arc<BlockChain> {
self.chain.read().clone() self.chain.read().clone()
} }

View File

@ -31,7 +31,6 @@ pub use self::config::{ClientConfig, DatabaseCompactionProfile, BlockChainConfig
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess};
#[cfg(any(test, feature = "test-helpers"))] #[cfg(any(test, feature = "test-helpers"))]
pub use self::test_client::{TestBlockChainClient, EachBlockWith, TestState}; pub use self::test_client::{TestBlockChainClient, EachBlockWith, TestState};
pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType};
pub use self::traits::{ pub use self::traits::{
ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock, ReopenBlock, PrepareOpenBlock, ImportSealedBlock, BroadcastProposalBlock,
Call, EngineInfo, BlockProducer, SealedBlockImporter, Call, EngineInfo, BlockProducer, SealedBlockImporter,
@ -40,4 +39,3 @@ pub use self::traits::{
pub use verification::VerifierType; pub use verification::VerifierType;
mod traits; mod traits;
mod chain_notify;

View File

@ -53,16 +53,13 @@
//! cargo build --release //! cargo build --release
//! ``` //! ```
extern crate account_db;
extern crate account_state; extern crate account_state;
extern crate ansi_term; extern crate ansi_term;
extern crate client_traits; extern crate client_traits;
extern crate common_types as types; extern crate common_types as types;
extern crate crossbeam_utils;
extern crate engine; extern crate engine;
extern crate ethabi; extern crate ethabi;
extern crate ethcore_blockchain as blockchain; extern crate ethcore_blockchain as blockchain;
extern crate ethcore_bloom_journal as bloom_journal;
extern crate ethcore_call_contract as call_contract; extern crate ethcore_call_contract as call_contract;
extern crate ethcore_db as db; extern crate ethcore_db as db;
extern crate ethcore_io as io; extern crate ethcore_io as io;
@ -74,13 +71,10 @@ extern crate hash_db;
extern crate itertools; extern crate itertools;
extern crate journaldb; extern crate journaldb;
extern crate keccak_hash as hash; extern crate keccak_hash as hash;
extern crate keccak_hasher;
extern crate kvdb; extern crate kvdb;
extern crate machine; extern crate machine;
extern crate memory_cache; extern crate memory_cache;
extern crate num_cpus;
extern crate parity_bytes as bytes; extern crate parity_bytes as bytes;
extern crate parity_snappy as snappy;
extern crate parking_lot; extern crate parking_lot;
extern crate trie_db as trie; extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie; extern crate patricia_trie_ethereum as ethtrie;
@ -88,6 +82,7 @@ extern crate rand;
extern crate rayon; extern crate rayon;
extern crate rlp; extern crate rlp;
extern crate serde; extern crate serde;
extern crate snapshot;
extern crate spec; extern crate spec;
extern crate state_db; extern crate state_db;
extern crate trace; extern crate trace;
@ -107,6 +102,8 @@ extern crate ethcore_stratum;
#[cfg(any(test, feature = "stratum"))] #[cfg(any(test, feature = "stratum"))]
extern crate ethash; extern crate ethash;
#[cfg(any(test, feature = "test-helpers"))]
extern crate account_db;
#[cfg(any(test, feature = "test-helpers"))] #[cfg(any(test, feature = "test-helpers"))]
extern crate ethkey; extern crate ethkey;
#[cfg(any(test, feature = "test-helpers"))] #[cfg(any(test, feature = "test-helpers"))]
@ -157,7 +154,6 @@ extern crate parity_runtime;
pub mod block; pub mod block;
pub mod client; pub mod client;
pub mod miner; pub mod miner;
pub mod snapshot;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View File

@ -34,6 +34,7 @@ use parking_lot::RwLock;
use rlp::{self, RlpStream}; use rlp::{self, RlpStream};
use tempdir::TempDir; use tempdir::TempDir;
use types::{ use types::{
chain_notify::ChainMessageType,
transaction::{Action, Transaction, SignedTransaction}, transaction::{Action, Transaction, SignedTransaction},
encoded, encoded,
engines::ForkChoice, engines::ForkChoice,
@ -44,8 +45,8 @@ use types::{
}; };
use block::{OpenBlock, Drain}; use block::{OpenBlock, Drain};
use client::{Client, ClientConfig, ChainNotify, ChainMessageType, PrepareOpenBlock}; use client::{Client, ClientConfig, PrepareOpenBlock};
use client_traits::{ChainInfo, ImportBlock}; use client_traits::{ChainInfo, ChainNotify, ImportBlock};
use trie_vm_factories::Factories; use trie_vm_factories::Factories;
use miner::Miner; use miner::Miner;
use spec::{Spec, self}; use spec::{Spec, self};

View File

@ -17,11 +17,12 @@ ethcore-io = { path = "../../util/io" }
ethcore-light = { path = "../light" } ethcore-light = { path = "../light" }
ethcore-network = { path = "../../util/network" } ethcore-network = { path = "../../util/network" }
ethcore-network-devp2p = { path = "../../util/network-devp2p" } ethcore-network-devp2p = { path = "../../util/network-devp2p" }
ethereum-types = "0.6.0"
ethcore-private-tx = { path = "../private-tx" } ethcore-private-tx = { path = "../private-tx" }
ethereum-types = "0.6.0"
ethkey = { path = "../../accounts/ethkey" } ethkey = { path = "../../accounts/ethkey" }
ethstore = { path = "../../accounts/ethstore" } ethstore = { path = "../../accounts/ethstore" }
fastmap = { path = "../../util/fastmap" } fastmap = { path = "../../util/fastmap" }
futures = "0.1"
hash-db = "0.15.0" hash-db = "0.15.0"
keccak-hash = "0.2.0" keccak-hash = "0.2.0"
keccak-hasher = { path = "../../util/keccak-hasher" } keccak-hasher = { path = "../../util/keccak-hasher" }
@ -30,20 +31,20 @@ log = "0.4"
machine = { path = "../machine" } machine = { path = "../machine" }
macros = { path = "../../util/macros" } macros = { path = "../../util/macros" }
parity-bytes = "0.1" parity-bytes = "0.1"
parking_lot = "0.8" parity-runtime = { path = "../../util/runtime" }
parity-util-mem = "0.2.0" parity-util-mem = "0.2.0"
parking_lot = "0.8"
rand = "0.6" rand = "0.6"
rlp = "0.4.0" rlp = "0.4.0"
snapshot = { path = "../snapshot" }
trace-time = "0.1" trace-time = "0.1"
triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" } triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" }
futures = "0.1"
parity-runtime = { path = "../../util/runtime" }
[dev-dependencies] [dev-dependencies]
env_logger = "0.5" env_logger = "0.5"
ethcore = { path = "..", features = ["test-helpers"] } ethcore = { path = "..", features = ["test-helpers"] }
ethcore-io = { path = "../../util/io", features = ["mio"] } ethcore-io = { path = "../../util/io", features = ["mio"] }
kvdb-memorydb = "0.1" kvdb-memorydb = "0.1"
rustc-hex = "1.0"
rand_xorshift = "0.1.1" rand_xorshift = "0.1.1"
rustc-hex = "1.0"
spec = { path = "../spec" } spec = { path = "../spec" }

View File

@ -25,16 +25,13 @@ use network::{NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error, NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error,
ConnectionFilter}; ConnectionFilter};
use network::client_version::ClientVersion; use network::client_version::ClientVersion;
use types::pruning_info::PruningInfo;
use ethereum_types::{H256, H512, U256}; use ethereum_types::{H256, H512, U256};
use futures::sync::mpsc as futures_mpsc; use futures::sync::mpsc as futures_mpsc;
use futures::Stream; use futures::Stream;
use io::{TimerToken}; use io::{TimerToken};
use ethkey::Secret; use ethkey::Secret;
use ethcore::client::{ChainNotify, NewBlocks, ChainMessageType}; use client_traits::{BlockChainClient, ChainNotify};
use client_traits::BlockChainClient; use snapshot::SnapshotService;
use ethcore::snapshot::SnapshotService;
use ethcore_private_tx::PrivateStateDB; use ethcore_private_tx::PrivateStateDB;
use types::BlockNumber; use types::BlockNumber;
use sync_io::NetSyncIo; use sync_io::NetSyncIo;
@ -55,7 +52,11 @@ use parity_runtime::Executor;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use network::IpFilter; use network::IpFilter;
use private_tx::PrivateTxHandler; use private_tx::PrivateTxHandler;
use types::transaction::UnverifiedTransaction; use types::{
chain_notify::{NewBlocks, ChainMessageType},
pruning_info::PruningInfo,
transaction::UnverifiedTransaction,
};
use super::light_sync::SyncInfo; use super::light_sync::SyncInfo;

View File

@ -23,10 +23,12 @@ use hash::keccak;
use network::PeerId; use network::PeerId;
use network::client_version::ClientVersion; use network::client_version::ClientVersion;
use rlp::Rlp; use rlp::Rlp;
use snapshot::ChunkType; use crate::{
snapshot_sync::ChunkType,
sync_io::SyncIo,
};
use std::time::Instant; use std::time::Instant;
use std::{mem, cmp}; use std::{mem, cmp};
use sync_io::SyncIo;
use types::{ use types::{
BlockNumber, BlockNumber,
block_status::BlockStatus, block_status::BlockStatus,

View File

@ -109,11 +109,13 @@ use rlp::{RlpStream, DecoderError};
use network::{self, PeerId, PacketId}; use network::{self, PeerId, PacketId};
use network::client_version::ClientVersion; use network::client_version::ClientVersion;
use client_traits::BlockChainClient; use client_traits::BlockChainClient;
use sync_io::SyncIo; use crate::{
sync_io::SyncIo,
snapshot_sync::Snapshot,
};
use super::{WarpSync, SyncConfig}; use super::{WarpSync, SyncConfig};
use block_sync::{BlockDownloader, DownloadAction}; use block_sync::{BlockDownloader, DownloadAction};
use rand::{Rng, seq::SliceRandom}; use rand::{Rng, seq::SliceRandom};
use snapshot::{Snapshot};
use api::{EthProtocolInfo as PeerInfoDigest, WARP_SYNC_PROTOCOL_ID, PriorityTask}; use api::{EthProtocolInfo as PeerInfoDigest, WARP_SYNC_PROTOCOL_ID, PriorityTask};
use private_tx::PrivateTxHandler; use private_tx::PrivateTxHandler;
use transactions_stats::{TransactionsStats, Stats as TransactionStats}; use transactions_stats::{TransactionsStats, Stats as TransactionStats};

View File

@ -27,19 +27,20 @@ extern crate ethcore;
extern crate ethcore_io as io; extern crate ethcore_io as io;
extern crate ethcore_network as network; extern crate ethcore_network as network;
extern crate ethcore_network_devp2p as devp2p; extern crate ethcore_network_devp2p as devp2p;
extern crate ethcore_private_tx;
extern crate ethereum_types; extern crate ethereum_types;
extern crate ethkey; extern crate ethkey;
extern crate ethstore; extern crate ethstore;
extern crate fastmap; extern crate fastmap;
extern crate futures;
extern crate keccak_hash as hash; extern crate keccak_hash as hash;
extern crate parity_bytes as bytes; extern crate parity_bytes as bytes;
extern crate parity_runtime; extern crate parity_runtime;
extern crate parking_lot; extern crate parking_lot;
extern crate ethcore_private_tx;
extern crate rand; extern crate rand;
extern crate rlp; extern crate rlp;
extern crate snapshot;
extern crate triehash_ethereum; extern crate triehash_ethereum;
extern crate futures;
extern crate ethcore_light as light; extern crate ethcore_light as light;
@ -69,7 +70,7 @@ mod blocks;
mod block_sync; mod block_sync;
mod sync_io; mod sync_io;
mod private_tx; mod private_tx;
mod snapshot; mod snapshot_sync;
mod transactions_stats; mod transactions_stats;
pub mod light_sync; pub mod light_sync;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>. // along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use ethereum_types::H256; use ethereum_types::H256;
use hash::keccak; use hash::keccak;
use types::snapshot::ManifestData; use types::snapshot::ManifestData;

View File

@ -23,7 +23,7 @@ use bytes::Bytes;
use client_traits::BlockChainClient; use client_traits::BlockChainClient;
use ethcore_private_tx::PrivateStateDB; use ethcore_private_tx::PrivateStateDB;
use types::BlockNumber; use types::BlockNumber;
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use parking_lot::RwLock; use parking_lot::RwLock;
/// IO interface for the syncing handler. /// IO interface for the syncing handler.

View File

@ -22,11 +22,17 @@ use bytes::Bytes;
use network::{self, PeerId, ProtocolId, PacketId, SessionInfo}; use network::{self, PeerId, ProtocolId, PacketId, SessionInfo};
use network::client_version::ClientVersion; use network::client_version::ClientVersion;
use tests::snapshot::*; use tests::snapshot::*;
use types::io_message::ClientIoMessage; use types::{
use client_traits::BlockChainClient; chain_notify::{NewBlocks, ChainMessageType},
use ethcore::client::{TestBlockChainClient, Client as EthcoreClient, io_message::ClientIoMessage,
ClientConfig, ChainNotify, NewBlocks, ChainMessageType}; };
use ethcore::snapshot::SnapshotService; use client_traits::{BlockChainClient, ChainNotify};
use ethcore::client::{
TestBlockChainClient,
Client as EthcoreClient,
ClientConfig,
};
use snapshot::SnapshotService;
use spec::{self, Spec}; use spec::{self, Spec};
use ethcore_private_tx::PrivateStateDB; use ethcore_private_tx::PrivateStateDB;
use ethcore::miner::Miner; use ethcore::miner::Miner;

View File

@ -20,7 +20,7 @@ use hash::keccak;
use ethereum_types::H256; use ethereum_types::H256;
use parking_lot::Mutex; use parking_lot::Mutex;
use bytes::Bytes; use bytes::Bytes;
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use ethcore::client::EachBlockWith; use ethcore::client::EachBlockWith;
use types::{ use types::{
BlockNumber, BlockNumber,

View File

@ -21,8 +21,10 @@
//! Other block types are found in `ethcore` //! Other block types are found in `ethcore`
use bytes::Bytes; use bytes::Bytes;
use ethereum_types::{H256, U256};
use parity_util_mem::MallocSizeOf; use parity_util_mem::MallocSizeOf;
use BlockNumber;
use header::Header; use header::Header;
use rlp::{Rlp, RlpStream, Decodable, DecoderError}; use rlp::{Rlp, RlpStream, Decodable, DecoderError};
use transaction::{UnverifiedTransaction, SignedTransaction}; use transaction::{UnverifiedTransaction, SignedTransaction};
@ -77,3 +79,40 @@ pub struct PreverifiedBlock {
/// Block bytes /// Block bytes
pub bytes: Bytes, pub bytes: Bytes,
} }
/// Brief info about inserted block.
#[derive(Clone)]
pub struct BlockInfo {
/// Block hash.
pub hash: H256,
/// Block number.
pub number: BlockNumber,
/// Total block difficulty.
pub total_difficulty: U256,
/// Block location in blockchain.
pub location: BlockLocation
}
/// Describes location of newly inserted block.
#[derive(Debug, Clone, PartialEq)]
pub enum BlockLocation {
/// It's part of the canon chain.
CanonChain,
/// It's not a part of the canon chain.
Branch,
/// It's part of the fork which should become canon chain,
/// because its total difficulty is higher than current
/// canon chain difficulty.
BranchBecomingCanonChain(BranchBecomingCanonChainData),
}
/// Info about heaviest fork
#[derive(Debug, Clone, PartialEq)]
pub struct BranchBecomingCanonChainData {
/// Hash of the newest common ancestor with old canon chain.
pub ancestor: H256,
/// Hashes of the blocks between ancestor and this block.
pub enacted: Vec<H256>,
/// Hashes of the blocks which were invalidated.
pub retracted: Vec<H256>,
}

View File

@ -14,10 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>. // along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Types pertaining to sending messages and finding routes through the chain. Used mostly by the
//! ChainNotify trait.
use bytes::Bytes; use bytes::Bytes;
use ethereum_types::{H256, U256}; use ethereum_types::H256;
use types::transaction::UnverifiedTransaction; use crate::{
use blockchain::ImportRoute; import_route::ImportRoute,
};
use std::time::Duration; use std::time::Duration;
use std::collections::HashMap; use std::collections::HashMap;
@ -116,7 +120,8 @@ impl ChainRoute {
} }
} }
/// Used by `ChainNotify` `new_blocks()` /// Used by `ChainNotify` `new_blocks()` and contains information about new blocks imported to the
/// chain.
pub struct NewBlocks { pub struct NewBlocks {
/// Imported blocks /// Imported blocks
pub imported: Vec<H256>, pub imported: Vec<H256>,
@ -156,40 +161,3 @@ impl NewBlocks {
} }
} }
} }
/// Represents what has to be handled by actor listening to chain events
pub trait ChainNotify : Send + Sync {
/// fires when chain has new blocks.
fn new_blocks(&self, _new_blocks: NewBlocks) {
// does nothing by default
}
/// fires when chain achieves active mode
fn start(&self) {
// does nothing by default
}
/// fires when chain achieves passive mode
fn stop(&self) {
// does nothing by default
}
/// fires when chain broadcasts a message
fn broadcast(&self, _message_type: ChainMessageType) {
// does nothing by default
}
/// fires when new block is about to be imported
/// implementations should be light
fn block_pre_import(&self, _bytes: &Bytes, _hash: &H256, _difficulty: &U256) {
// does nothing by default
}
/// fires when new transactions are received from a peer
fn transactions_received(&self,
_txs: &[UnverifiedTransaction],
_peer_id: usize,
) {
// does nothing by default
}
}

View File

@ -17,11 +17,12 @@
//! Client related types. //! Client related types.
use std::{ use std::{
cmp,
fmt::{Display, Formatter, Error as FmtError}, fmt::{Display, Formatter, Error as FmtError},
ops, ops,
cmp,
time::Duration, time::Duration,
}; };
use ethereum_types::U256; use ethereum_types::U256;
use crate::header::Header; use crate::header::Header;
@ -88,4 +89,3 @@ impl<'a> ops::Sub<&'a ClientReport> for ClientReport {
self self
} }
} }

View File

@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>. // along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Import route. //! Calculate import route for newly inserted blocks.
use ethereum_types::H256; use ethereum_types::H256;
use crate::block_info::{BlockInfo, BlockLocation}; use crate::block::{BlockInfo, BlockLocation};
/// Import route for newly inserted block. /// Import route for newly inserted block.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
@ -69,7 +69,7 @@ impl From<BlockInfo> for ImportRoute {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ethereum_types::{U256, BigEndianHash}; use ethereum_types::{U256, BigEndianHash};
use crate::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData}; use crate::block::{BlockInfo, BlockLocation, BranchBecomingCanonChainData};
use super::ImportRoute; use super::ImportRoute;
#[test] #[test]

View File

@ -64,6 +64,7 @@ pub mod block;
pub mod block_status; pub mod block_status;
pub mod blockchain_info; pub mod blockchain_info;
pub mod call_analytics; pub mod call_analytics;
pub mod chain_notify;
pub mod client_types; pub mod client_types;
pub mod encoded; pub mod encoded;
pub mod engines; pub mod engines;
@ -72,6 +73,7 @@ pub mod filter;
pub mod header; pub mod header;
pub mod ids; pub mod ids;
pub mod io_message; pub mod io_message;
pub mod import_route;
pub mod log_entry; pub mod log_entry;
pub mod pruning_info; pub mod pruning_info;
pub mod receipt; pub mod receipt;

View File

@ -31,7 +31,7 @@ use sync::{NetworkConfiguration, validate_node_url, self};
use ethkey::{Secret, Public}; use ethkey::{Secret, Public};
use ethcore::client::{VMType}; use ethcore::client::{VMType};
use ethcore::miner::{stratum, MinerOptions}; use ethcore::miner::{stratum, MinerOptions};
use ethcore::snapshot::SnapshotConfiguration; use snapshot::SnapshotConfiguration;
use miner::pool; use miner::pool;
use verification::queue::VerifierSettings; use verification::queue::VerifierSettings;
@ -52,7 +52,7 @@ use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, KillBlockcha
use export_hardcoded_sync::ExportHsyncCmd; use export_hardcoded_sync::ExportHsyncCmd;
use presale::ImportWallet; use presale::ImportWallet;
use account::{AccountCmd, NewAccount, ListAccounts, ImportAccounts, ImportFromGethAccounts}; use account::{AccountCmd, NewAccount, ListAccounts, ImportAccounts, ImportFromGethAccounts};
use snapshot::{self, SnapshotCommand}; use snapshot_cmd::{self, SnapshotCommand};
use network::{IpFilter}; use network::{IpFilter};
const DEFAULT_MAX_PEERS: u16 = 50; const DEFAULT_MAX_PEERS: u16 = 50;
@ -321,7 +321,7 @@ impl Configuration {
fat_db: fat_db, fat_db: fat_db,
compaction: compaction, compaction: compaction,
file_path: self.args.arg_snapshot_file.clone(), file_path: self.args.arg_snapshot_file.clone(),
kind: snapshot::Kind::Take, kind: snapshot_cmd::Kind::Take,
block_at: to_block_id(&self.args.arg_snapshot_at)?, block_at: to_block_id(&self.args.arg_snapshot_at)?,
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import, max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
snapshot_conf: snapshot_conf, snapshot_conf: snapshot_conf,
@ -339,7 +339,7 @@ impl Configuration {
fat_db: fat_db, fat_db: fat_db,
compaction: compaction, compaction: compaction,
file_path: self.args.arg_restore_file.clone(), file_path: self.args.arg_restore_file.clone(),
kind: snapshot::Kind::Restore, kind: snapshot_cmd::Kind::Restore,
block_at: to_block_id("latest")?, // unimportant. block_at: to_block_id("latest")?, // unimportant.
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import, max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
snapshot_conf: snapshot_conf, snapshot_conf: snapshot_conf,

View File

@ -23,10 +23,11 @@ use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
use atty; use atty;
use ethcore::client::{ChainNotify, NewBlocks, Client}; use ethcore::client::Client;
use client_traits::{BlockInfo, ChainInfo, BlockChainClient}; use client_traits::{BlockInfo, ChainInfo, BlockChainClient, ChainNotify};
use types::{ use types::{
BlockNumber, BlockNumber,
chain_notify::NewBlocks,
client_types::ClientReport, client_types::ClientReport,
ids::BlockId, ids::BlockId,
io_message::ClientIoMessage, io_message::ClientIoMessage,
@ -34,8 +35,8 @@ use types::{
verification::VerificationQueueInfo as BlockQueueInfo, verification::VerificationQueueInfo as BlockQueueInfo,
snapshot::RestorationStatus, snapshot::RestorationStatus,
}; };
use ethcore::snapshot::SnapshotService as SS; use snapshot::SnapshotService as SS;
use ethcore::snapshot::service::Service as SnapshotService; use snapshot::service::Service as SnapshotService;
use sync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork}; use sync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork};
use io::{TimerToken, IoContext, IoHandler}; use io::{TimerToken, IoContext, IoHandler};
use light::Cache as LightDataCache; use light::Cache as LightDataCache;
@ -224,7 +225,7 @@ pub struct Informant<T> {
last_tick: RwLock<Instant>, last_tick: RwLock<Instant>,
with_color: bool, with_color: bool,
target: T, target: T,
snapshot: Option<Arc<SnapshotService>>, snapshot: Option<Arc<SnapshotService<Client>>>,
rpc_stats: Option<Arc<RpcStats>>, rpc_stats: Option<Arc<RpcStats>>,
last_import: Mutex<Instant>, last_import: Mutex<Instant>,
skipped: AtomicUsize, skipped: AtomicUsize,
@ -237,16 +238,16 @@ impl<T: InformantData> Informant<T> {
/// Make a new instance potentially `with_color` output. /// Make a new instance potentially `with_color` output.
pub fn new( pub fn new(
target: T, target: T,
snapshot: Option<Arc<SnapshotService>>, snapshot: Option<Arc<SnapshotService<Client>>>,
rpc_stats: Option<Arc<RpcStats>>, rpc_stats: Option<Arc<RpcStats>>,
with_color: bool, with_color: bool,
) -> Self { ) -> Self {
Informant { Informant {
last_tick: RwLock::new(Instant::now()), last_tick: RwLock::new(Instant::now()),
with_color: with_color, with_color,
target: target, target,
snapshot: snapshot, snapshot,
rpc_stats: rpc_stats, rpc_stats,
last_import: Mutex::new(Instant::now()), last_import: Mutex::new(Instant::now()),
skipped: AtomicUsize::new(0), skipped: AtomicUsize::new(0),
skipped_txs: AtomicUsize::new(0), skipped_txs: AtomicUsize::new(0),

View File

@ -73,6 +73,7 @@ extern crate parity_runtime;
extern crate parity_updater as updater; extern crate parity_updater as updater;
extern crate parity_version; extern crate parity_version;
extern crate registrar; extern crate registrar;
extern crate snapshot;
extern crate spec; extern crate spec;
extern crate verification; extern crate verification;
@ -112,7 +113,7 @@ mod rpc_apis;
mod run; mod run;
mod secretstore; mod secretstore;
mod signer; mod signer;
mod snapshot; mod snapshot_cmd;
mod upgrade; mod upgrade;
mod user_defaults; mod user_defaults;
mod db; mod db;
@ -213,7 +214,7 @@ fn execute<Cr, Rr>(
Cmd::SignerSign { id, pwfile, port, authfile } => cli_signer::signer_sign(id, pwfile, port, authfile).map(|s| ExecutionAction::Instant(Some(s))), Cmd::SignerSign { id, pwfile, port, authfile } => cli_signer::signer_sign(id, pwfile, port, authfile).map(|s| ExecutionAction::Instant(Some(s))),
Cmd::SignerList { port, authfile } => cli_signer::signer_list(port, authfile).map(|s| ExecutionAction::Instant(Some(s))), Cmd::SignerList { port, authfile } => cli_signer::signer_list(port, authfile).map(|s| ExecutionAction::Instant(Some(s))),
Cmd::SignerReject { id, port, authfile } => cli_signer::signer_reject(id, port, authfile).map(|s| ExecutionAction::Instant(Some(s))), Cmd::SignerReject { id, port, authfile } => cli_signer::signer_reject(id, port, authfile).map(|s| ExecutionAction::Instant(Some(s))),
Cmd::Snapshot(snapshot_cmd) => snapshot::execute(snapshot_cmd).map(|s| ExecutionAction::Instant(Some(s))), Cmd::Snapshot(snapshot_cmd) => snapshot_cmd::execute(snapshot_cmd).map(|s| ExecutionAction::Instant(Some(s))),
Cmd::ExportHardcodedSync(export_hs_cmd) => export_hardcoded_sync::execute(export_hs_cmd).map(|s| ExecutionAction::Instant(Some(s))), Cmd::ExportHardcodedSync(export_hs_cmd) => export_hardcoded_sync::execute(export_hs_cmd).map(|s| ExecutionAction::Instant(Some(s))),
} }
} }

View File

@ -16,15 +16,14 @@
use std::sync::{Arc, mpsc}; use std::sync::{Arc, mpsc};
use client_traits::BlockChainClient; use client_traits::{BlockChainClient, ChainNotify};
use sync::{self, SyncConfig, NetworkConfiguration, Params, ConnectionFilter}; use sync::{self, SyncConfig, NetworkConfiguration, Params, ConnectionFilter};
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use ethcore_private_tx::PrivateStateDB; use ethcore_private_tx::PrivateStateDB;
use light::Provider; use light::Provider;
use parity_runtime::Executor; use parity_runtime::Executor;
pub use sync::{EthSync, SyncProvider, ManageNetwork, PrivateTxHandler}; pub use sync::{EthSync, SyncProvider, ManageNetwork, PrivateTxHandler};
pub use ethcore::client::ChainNotify;
use ethcore_logger::Config as LogConfig; use ethcore_logger::Config as LogConfig;
pub type SyncModules = ( pub type SyncModules = (

View File

@ -24,7 +24,7 @@ pub use parity_rpc::signer::SignerService;
use account_utils::{self, AccountProvider}; use account_utils::{self, AccountProvider};
use ethcore::client::Client; use ethcore::client::Client;
use ethcore::miner::Miner; use ethcore::miner::Miner;
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use client_traits::BlockChainClient; use client_traits::BlockChainClient;
use sync::SyncState; use sync::SyncState;
use ethcore_logger::RotatingLogger; use ethcore_logger::RotatingLogger;

View File

@ -25,7 +25,7 @@ use call_contract::CallContract;
use client_traits::{BlockInfo, BlockChainClient}; use client_traits::{BlockInfo, BlockChainClient};
use ethcore::client::{Client, DatabaseCompactionProfile, VMType}; use ethcore::client::{Client, DatabaseCompactionProfile, VMType};
use ethcore::miner::{self, stratum, Miner, MinerService, MinerOptions}; use ethcore::miner::{self, stratum, Miner, MinerService, MinerOptions};
use ethcore::snapshot::{self, SnapshotConfiguration}; use snapshot::{self, SnapshotConfiguration};
use spec::SpecParams; use spec::SpecParams;
use verification::queue::VerifierSettings; use verification::queue::VerifierSettings;
use ethcore_logger::{Config as LogConfig, RotatingLogger}; use ethcore_logger::{Config as LogConfig, RotatingLogger};

View File

@ -22,10 +22,10 @@ use std::sync::Arc;
use client_traits::SnapshotClient; use client_traits::SnapshotClient;
use hash::keccak; use hash::keccak;
use ethcore::snapshot::{SnapshotConfiguration, SnapshotService as SS}; use snapshot::{SnapshotConfiguration, SnapshotService as SS};
use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter}; use snapshot::io::{SnapshotReader, PackedReader, PackedWriter};
use ethcore::snapshot::service::Service as SnapshotService; use snapshot::service::Service as SnapshotService;
use ethcore::client::{DatabaseCompactionProfile, VMType}; use ethcore::client::{Client, DatabaseCompactionProfile, VMType};
use ethcore::miner::Miner; use ethcore::miner::Miner;
use ethcore_service::ClientService; use ethcore_service::ClientService;
use types::{ use types::{
@ -73,7 +73,7 @@ pub struct SnapshotCommand {
// helper for reading chunks from arbitrary reader and feeding them into the // helper for reading chunks from arbitrary reader and feeding them into the
// service. // service.
fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R, recover: bool) -> Result<(), String> { fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService<Client>>, reader: &R, recover: bool) -> Result<(), String> {
let manifest = reader.manifest(); let manifest = reader.manifest();
info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash); info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash);

View File

@ -64,6 +64,7 @@ parity-updater = { path = "../updater" }
parity-version = { path = "../util/version" } parity-version = { path = "../util/version" }
rlp = "0.4.0" rlp = "0.4.0"
account-state = { path = "../ethcore/account-state" } account-state = { path = "../ethcore/account-state" }
snapshot = { path = "../ethcore/snapshot" }
stats = { path = "../util/stats" } stats = { path = "../util/stats" }
trace = { path = "../ethcore/trace" } trace = { path = "../ethcore/trace" }
vm = { path = "../ethcore/vm" } vm = { path = "../ethcore/vm" }

View File

@ -87,6 +87,7 @@ extern crate rlp;
extern crate account_state; extern crate account_state;
extern crate stats; extern crate stats;
extern crate snapshot;
extern crate tempdir; extern crate tempdir;
extern crate trace; extern crate trace;
extern crate vm; extern crate vm;

View File

@ -29,7 +29,7 @@ use client_traits::{BlockChainClient, StateClient, ProvingBlockChainClient, Stat
use ethash::{self, SeedHashCompute}; use ethash::{self, SeedHashCompute};
use ethcore::client::{Call, EngineInfo}; use ethcore::client::{Call, EngineInfo};
use ethcore::miner::{self, MinerService}; use ethcore::miner::{self, MinerService};
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use hash::keccak; use hash::keccak;
use miner::external::ExternalMinerService; use miner::external::ExternalMinerService;
use sync::SyncProvider; use sync::SyncProvider;

View File

@ -31,8 +31,7 @@ use v1::traits::EthPubSub;
use v1::types::{pubsub, RichHeader, Log}; use v1::types::{pubsub, RichHeader, Log};
use sync::{SyncState, Notification}; use sync::{SyncState, Notification};
use ethcore::client::{ChainNotify, NewBlocks, ChainRouteType}; use client_traits::{BlockChainClient, ChainNotify};
use client_traits::BlockChainClient;
use ethereum_types::H256; use ethereum_types::H256;
use light::cache::Cache; use light::cache::Cache;
use light::client::{LightChainClient, LightChainNotify}; use light::client::{LightChainClient, LightChainNotify};
@ -43,6 +42,7 @@ use parking_lot::{RwLock, Mutex};
use sync::{LightSyncProvider, LightNetworkDispatcher, ManageNetwork}; use sync::{LightSyncProvider, LightNetworkDispatcher, ManageNetwork};
use types::{ use types::{
chain_notify::{NewBlocks, ChainRouteType},
ids::BlockId, ids::BlockId,
encoded, encoded,
filter::Filter as EthFilter, filter::Filter as EthFilter,

View File

@ -23,7 +23,7 @@ use ethereum_types::{H64, H160, H256, H512, U64, U256};
use ethcore::client::Call; use ethcore::client::Call;
use client_traits::{BlockChainClient, StateClient}; use client_traits::{BlockChainClient, StateClient};
use ethcore::miner::{self, MinerService, FilterOptions}; use ethcore::miner::{self, MinerService, FilterOptions};
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use account_state::state::StateInfo; use account_state::state::StateInfo;
use ethcore_logger::RotatingLogger; use ethcore_logger::RotatingLogger;
use ethkey::{crypto::ecies, Brain, Generator}; use ethkey::{crypto::ecies, Brain, Generator};

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>. // along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use ethcore::snapshot::SnapshotService; use snapshot::SnapshotService;
use bytes::Bytes; use bytes::Bytes;
use ethereum_types::H256; use ethereum_types::H256;

View File

@ -23,11 +23,12 @@ use jsonrpc_pubsub::Session;
use std::time::Duration; use std::time::Duration;
use v1::{EthPubSub, EthPubSubClient, Metadata}; use v1::{EthPubSub, EthPubSubClient, Metadata};
use ethcore::client::{TestBlockChainClient, EachBlockWith, ChainNotify, NewBlocks, ChainRoute, ChainRouteType}; use ethcore::client::{TestBlockChainClient, EachBlockWith};
use parity_runtime::Runtime; use parity_runtime::Runtime;
use ethereum_types::{Address, H256}; use ethereum_types::{Address, H256};
use client_traits::BlockInfo; use client_traits::{BlockInfo, ChainNotify};
use types::{ use types::{
chain_notify::{NewBlocks, ChainRoute, ChainRouteType},
log_entry::{LocalizedLogEntry, LogEntry}, log_entry::{LocalizedLogEntry, LogEntry},
ids::BlockId, ids::BlockId,
}; };

View File

@ -16,10 +16,13 @@
use std::sync::Arc; use std::sync::Arc;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use common_types::ids::BlockId; use common_types::{
chain_notify::NewBlocks,
ids::BlockId
};
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
use call_contract::CallContract; use call_contract::CallContract;
use ethcore::client::{ChainNotify, NewBlocks}; use client_traits::ChainNotify;
use ethereum_types::Address; use ethereum_types::Address;
use ethabi::FunctionOutputDecoder; use ethabi::FunctionOutputDecoder;
use trusted_client::TrustedClient; use trusted_client::TrustedClient;

View File

@ -20,9 +20,12 @@ use std::collections::{BTreeMap, HashSet};
use parking_lot::Mutex; use parking_lot::Mutex;
use call_contract::CallContract; use call_contract::CallContract;
use ethabi::FunctionOutputDecoder; use ethabi::FunctionOutputDecoder;
use ethcore::client::{Client, ChainNotify, NewBlocks}; use ethcore::client::Client;
use client_traits::BlockChainClient; use client_traits::{BlockChainClient, ChainNotify};
use common_types::ids::BlockId; use common_types::{
chain_notify::NewBlocks,
ids::BlockId,
};
use ethereum_types::{H256, Address}; use ethereum_types::{H256, Address};
use ethkey::public_to_address; use ethkey::public_to_address;
use bytes::Bytes; use bytes::Bytes;

View File

@ -18,10 +18,10 @@ use std::collections::HashSet;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread; use std::thread;
use parking_lot::Mutex; use client_traits::ChainNotify;
use ethcore::client::{ChainNotify, NewBlocks}; use common_types::chain_notify::NewBlocks;
use ethkey::{Public, public_to_address};
use bytes::Bytes; use bytes::Bytes;
use ethkey::{Public, public_to_address};
use ethereum_types::{H256, U256, Address, BigEndianHash as _}; use ethereum_types::{H256, U256, Address, BigEndianHash as _};
use key_server_set::KeyServerSet; use key_server_set::KeyServerSet;
use key_server_cluster::{NodeId, ClusterClient, ClusterSessionsListener, ClusterSession}; use key_server_cluster::{NodeId, ClusterClient, ClusterSessionsListener, ClusterSession};
@ -32,6 +32,7 @@ use key_server_cluster::decryption_session::SessionImpl as DecryptionSession;
use key_server_cluster::key_version_negotiation_session::{SessionImpl as KeyVersionNegotiationSession, use key_server_cluster::key_version_negotiation_session::{SessionImpl as KeyVersionNegotiationSession,
IsolatedSessionTransport as KeyVersionNegotiationTransport, FailedContinueAction}; IsolatedSessionTransport as KeyVersionNegotiationTransport, FailedContinueAction};
use key_storage::KeyStorage; use key_storage::KeyStorage;
use parking_lot::Mutex;
use acl_storage::AclStorage; use acl_storage::AclStorage;
use listener::service_contract::ServiceContract; use listener::service_contract::ServiceContract;
use listener::tasks_queue::TasksQueue; use listener::tasks_queue::TasksQueue;

View File

@ -29,9 +29,9 @@ use common_types::{
BlockNumber, BlockNumber,
ids::BlockId, ids::BlockId,
filter::Filter, filter::Filter,
chain_notify::NewBlocks,
}; };
use ethcore::client::{ChainNotify, NewBlocks}; use client_traits::{BlockChainClient, ChainNotify};
use client_traits::BlockChainClient;
use ethereum_types::{H256, H160}; use ethereum_types::{H256, H160};
use hash_fetch::{self as fetch, HashFetch}; use hash_fetch::{self as fetch, HashFetch};
use parity_path::restrict_permissions_owner; use parity_path::restrict_permissions_owner;