From de7264389836cf4ca7ace70be21749623b469d6a Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 13 Mar 2018 11:49:57 +0100 Subject: [PATCH] ethcore-service (#8089) * ethcore test::helpers cleanup * ethcore-service --- Cargo.lock | 15 +++++++ Cargo.toml | 4 +- ethcore/light/src/client/mod.rs | 3 +- ethcore/light/src/client/service.rs | 2 +- ethcore/service/Cargo.toml | 16 ++++++++ ethcore/service/src/lib.rs | 32 +++++++++++++++ ethcore/{ => service}/src/service.rs | 59 +++++++++------------------ ethcore/src/client/client.rs | 8 ++-- ethcore/src/client/io_message.rs | 41 +++++++++++++++++++ ethcore/src/client/mod.rs | 4 +- ethcore/src/lib.rs | 1 - ethcore/src/snapshot/service.rs | 5 +-- ethcore/src/snapshot/watcher.rs | 3 +- ethcore/src/verification/queue/mod.rs | 2 +- local-store/src/lib.rs | 2 +- parity/blockchain.rs | 2 +- parity/informant.rs | 6 ++- parity/light_helpers/queue_cull.rs | 2 +- parity/main.rs | 1 + parity/run.rs | 2 +- parity/snapshot.rs | 2 +- sync/src/tests/consensus.rs | 3 +- 22 files changed, 151 insertions(+), 64 deletions(-) create mode 100644 ethcore/service/Cargo.toml create mode 100644 ethcore/service/src/lib.rs rename ethcore/{ => service}/src/service.rs (85%) create mode 100644 ethcore/src/client/io_message.rs diff --git a/Cargo.lock b/Cargo.lock index 3c350befe..b97803e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -715,6 +715,20 @@ dependencies = [ "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ethcore-service" +version = "0.1.0" +dependencies = [ + "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethcore 1.11.0", + "ethcore-io 1.11.0", + "kvdb 0.1.0", + "kvdb-rocksdb 0.1.0", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "stop-guard 0.1.0", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ethcore-stratum" version = "1.11.0" @@ -1948,6 +1962,7 @@ dependencies = [ "ethcore-miner 1.11.0", "ethcore-network 1.11.0", "ethcore-secretstore 1.0.0", + "ethcore-service 0.1.0", "ethcore-stratum 1.11.0", "ethcore-transaction 0.1.0", "ethereum-types 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index dad49a073..9e11794e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ ethcore-logger = { path = "logger" } ethcore-migrations = { path = "ethcore/migrations" } ethcore-miner = { path = "miner" } ethcore-network = { path = "util/network" } +ethcore-service = { path = "ethcore/service" } ethcore-stratum = { path = "stratum" } ethcore-transaction = { path = "ethcore/transaction" } ethereum-types = "0.2" @@ -132,6 +133,5 @@ members = [ "evmbin", "miner", "transaction-pool", - "whisper", - "util/rlp_compress" + "whisper" ] diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index c8f627731..f0a68af7e 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -19,7 +19,7 @@ use std::sync::{Weak, Arc}; use ethcore::block_status::BlockStatus; -use ethcore::client::{ClientReport, EnvInfo}; +use ethcore::client::{ClientReport, EnvInfo, ClientIoMessage}; use ethcore::engines::{epoch, EthEngine, EpochChange, EpochTransition, Proof}; use ethcore::machine::EthereumMachine; use ethcore::error::BlockImportError; @@ -28,7 +28,6 @@ use ethcore::header::{BlockNumber, Header}; use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::blockchain_info::BlockChainInfo; use ethcore::spec::Spec; -use ethcore::service::ClientIoMessage; use ethcore::encoded; use io::IoChannel; use parking_lot::{Mutex, RwLock}; diff --git a/ethcore/light/src/client/service.rs b/ethcore/light/src/client/service.rs index 8be009a65..b8f9779a1 100644 --- a/ethcore/light/src/client/service.rs +++ b/ethcore/light/src/client/service.rs @@ -20,8 +20,8 @@ use std::fmt; use std::sync::Arc; +use ethcore::client::ClientIoMessage; use ethcore::db; -use ethcore::service::ClientIoMessage; use ethcore::spec::Spec; use io::{IoContext, IoError, IoHandler, IoService}; use kvdb::{self, KeyValueDB}; diff --git a/ethcore/service/Cargo.toml b/ethcore/service/Cargo.toml new file mode 100644 index 000000000..634769d0b --- /dev/null +++ b/ethcore/service/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ethcore-service" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] +ansi_term = "0.10" +ethcore = { path = ".." } +ethcore-io = { path = "../../util/io" } +kvdb = { path = "../../util/kvdb" } +kvdb-rocksdb = { path = "../../util/kvdb-rocksdb" } +log = "0.3" +stop-guard = { path = "../../util/stop-guard" } + +[dev-dependencies] +tempdir = "0.3" diff --git a/ethcore/service/src/lib.rs b/ethcore/service/src/lib.rs new file mode 100644 index 000000000..907009ba3 --- /dev/null +++ b/ethcore/service/src/lib.rs @@ -0,0 +1,32 @@ +// Copyright 2015-2018 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +extern crate ansi_term; +extern crate ethcore; +extern crate ethcore_io as io; +extern crate kvdb; +extern crate kvdb_rocksdb; +extern crate stop_guard; + +#[macro_use] +extern crate log; + +#[cfg(test)] +extern crate tempdir; + +mod service; + +pub use service::ClientService; diff --git a/ethcore/src/service.rs b/ethcore/service/src/service.rs similarity index 85% rename from ethcore/src/service.rs rename to ethcore/service/src/service.rs index 5a523c6ea..f190d6e6a 100644 --- a/ethcore/src/service.rs +++ b/ethcore/service/src/service.rs @@ -18,41 +18,20 @@ use std::sync::Arc; use std::path::Path; -use ethereum_types::H256; + +use ansi_term::Colour; +use io::{IoContext, TimerToken, IoHandler, IoService, IoError}; use kvdb::KeyValueDB; use kvdb_rocksdb::{Database, DatabaseConfig}; -use bytes::Bytes; -use io::*; -use spec::Spec; -use error::*; -use client::{Client, ClientConfig, ChainNotify}; -use miner::Miner; - -use snapshot::{ManifestData, RestorationStatus}; -use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; -use ansi_term::Colour; use stop_guard::StopGuard; -/// Message type for external and internal events -#[derive(Clone, PartialEq, Eq, Debug)] -pub enum ClientIoMessage { - /// Best Block Hash in chain has been changed - NewChainHead, - /// A block is ready - BlockVerified, - /// New transaction RLPs are ready to be imported - NewTransactions(Vec, usize), - /// Begin snapshot restoration - BeginRestoration(ManifestData), - /// Feed a state chunk to the snapshot service - FeedStateChunk(H256, Bytes), - /// Feed a block chunk to the snapshot service - FeedBlockChunk(H256, Bytes), - /// Take a snapshot for the block with given number. - TakeSnapshot(u64), - /// New consensus message received. - NewMessage(Bytes) -} +use ethcore::client::{self, Client, ClientConfig, ChainNotify, ClientIoMessage}; +use ethcore::db; +use ethcore::error::Error; +use ethcore::miner::Miner; +use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; +use ethcore::snapshot::{RestorationStatus}; +use ethcore::spec::Spec; /// Client service setup. Creates and registers client and network services with the IO subsystem. pub struct ClientService { @@ -78,7 +57,7 @@ impl ClientService { info!("Configured for {} using {} engine", Colour::White.bold().paint(spec.name.clone()), Colour::Yellow.bold().paint(spec.engine.name())); - let mut db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS); + let mut db_config = DatabaseConfig::with_columns(db::NUM_COLUMNS); db_config.memory_budget = config.db_cache_size; db_config.compaction = config.db_compaction.compaction_profile(client_path); @@ -87,7 +66,7 @@ impl ClientService { let db = Arc::new(Database::open( &db_config, &client_path.to_str().expect("DB path could not be converted to string.") - ).map_err(::client::Error::Database)?); + ).map_err(client::Error::Database)?); let pruning = config.pruning; @@ -173,7 +152,7 @@ impl IoHandler for ClientIoHandler { fn timeout(&self, _io: &IoContext, timer: TimerToken) { match timer { CLIENT_TICK_TIMER => { - use snapshot::SnapshotService; + use ethcore::snapshot::SnapshotService; let snapshot_restoration = if let RestorationStatus::Ongoing{..} = self.snapshot.status() { true } else { false }; self.client.tick(snapshot_restoration) }, @@ -221,14 +200,16 @@ impl IoHandler for ClientIoHandler { #[cfg(test)] mod tests { - use std::{time, thread}; - use spec::Spec; - use super::*; - use client::ClientConfig; use std::sync::Arc; - use miner::Miner; + use std::{time, thread}; + use tempdir::TempDir; + use ethcore::client::ClientConfig; + use ethcore::miner::Miner; + use ethcore::spec::Spec; + use super::*; + #[test] fn it_can_be_started() { let tempdir = TempDir::new("").unwrap(); diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index f04bbb092..be34b86e5 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -37,8 +37,11 @@ use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute, Transaction use client::ancient_import::AncientVerifier; use client::Error as ClientError; use client::{ - Nonce, Balance, ChainInfo, BlockInfo, CallContract, TransactionInfo, RegistryInfo, ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, - StateOrBlock, StateInfo, StateClient, Call, AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter + Nonce, Balance, ChainInfo, BlockInfo, CallContract, TransactionInfo, + RegistryInfo, ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock, + BroadcastProposalBlock, ImportBlock, StateOrBlock, StateInfo, StateClient, Call, + AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter, + ClientIoMessage }; use client::{ BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient, @@ -60,7 +63,6 @@ use parking_lot::{Mutex, RwLock}; use rand::OsRng; use receipt::{Receipt, LocalizedReceipt}; use rlp::UntrustedRlp; -use service::ClientIoMessage; use snapshot::{self, io as snapshot_io}; use spec::Spec; use state_db::StateDB; diff --git a/ethcore/src/client/io_message.rs b/ethcore/src/client/io_message.rs new file mode 100644 index 000000000..c2823a39f --- /dev/null +++ b/ethcore/src/client/io_message.rs @@ -0,0 +1,41 @@ +// Copyright 2015-2018 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +use ethereum_types::H256; +use bytes::Bytes; +use snapshot::ManifestData; + +/// Message type for external and internal events +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum ClientIoMessage { + /// Best Block Hash in chain has been changed + NewChainHead, + /// A block is ready + BlockVerified, + /// New transaction RLPs are ready to be imported + NewTransactions(Vec, usize), + /// Begin snapshot restoration + BeginRestoration(ManifestData), + /// Feed a state chunk to the snapshot service + FeedStateChunk(H256, Bytes), + /// Feed a block chunk to the snapshot service + FeedBlockChunk(H256, Bytes), + /// Take a snapshot for the block with given number. + TakeSnapshot(u64), + /// New consensus message received. + NewMessage(Bytes) +} + diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 56eb5ae1d..b92240591 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -17,17 +17,19 @@ //! Blockchain database client. mod ancient_import; +mod client; mod config; mod error; mod evm_test_client; +mod io_message; mod test_client; mod trace; -mod client; pub use self::client::*; pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType}; pub use self::error::Error; pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactResult}; +pub use self::io_message::ClientIoMessage; pub use self::test_client::{TestBlockChainClient, EachBlockWith}; pub use self::chain_notify::ChainNotify; pub use self::traits::{ diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 7ee2c07b6..0d2ea0f5c 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -148,7 +148,6 @@ pub mod header; pub mod machine; pub mod miner; pub mod pod_state; -pub mod service; pub mod snapshot; pub mod spec; pub mod state; diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index 25356f78c..7def518f3 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -27,11 +27,10 @@ use super::{ManifestData, StateRebuilder, Rebuilder, RestorationStatus, Snapshot use super::io::{SnapshotReader, LooseReader, SnapshotWriter, LooseWriter}; use blockchain::BlockChain; -use client::{Client, ChainInfo}; +use client::{Client, ChainInfo, ClientIoMessage}; use engines::EthEngine; use error::Error; use ids::BlockId; -use service::ClientIoMessage; use io::IoChannel; @@ -631,7 +630,7 @@ impl Drop for Service { #[cfg(test)] mod tests { use std::sync::Arc; - use service::ClientIoMessage; + use client::ClientIoMessage; use io::{IoService}; use spec::Spec; use journaldb::Algorithm; diff --git a/ethcore/src/snapshot/watcher.rs b/ethcore/src/snapshot/watcher.rs index 44783551f..841fa1982 100644 --- a/ethcore/src/snapshot/watcher.rs +++ b/ethcore/src/snapshot/watcher.rs @@ -17,9 +17,8 @@ //! Watcher for snapshot-related chain events. use parking_lot::Mutex; -use client::{BlockInfo, Client, ChainNotify}; +use client::{BlockInfo, Client, ChainNotify, ClientIoMessage}; use ids::BlockId; -use service::ClientIoMessage; use io::IoChannel; use ethereum_types::H256; diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 63193020b..58b1bb7bb 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -28,7 +28,7 @@ use parking_lot::{Condvar, Mutex, RwLock}; use io::*; use error::*; use engines::EthEngine; -use service::*; +use client::ClientIoMessage; use self::kind::{BlockLike, Kind}; diff --git a/local-store/src/lib.rs b/local-store/src/lib.rs index d61bdec85..9120b8694 100644 --- a/local-store/src/lib.rs +++ b/local-store/src/lib.rs @@ -23,7 +23,7 @@ use transaction::{ SignedTransaction, PendingTransaction, UnverifiedTransaction, Condition as TransactionCondition }; -use ethcore::service::ClientIoMessage; +use ethcore::client::ClientIoMessage; use io::IoHandler; use rlp::UntrustedRlp; use kvdb::KeyValueDB; diff --git a/parity/blockchain.rs b/parity/blockchain.rs index 594bffe2b..a9aee3810 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -25,12 +25,12 @@ use hash::{keccak, KECCAK_NULL_RLP}; use ethereum_types::{U256, H256, Address}; use bytes::ToPretty; use rlp::PayloadInfo; -use ethcore::service::ClientService; use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, Nonce, Balance, BlockChainClient, BlockId, BlockInfo, ImportBlock}; use ethcore::db::NUM_COLUMNS; use ethcore::error::ImportError; use ethcore::miner::Miner; use ethcore::verification::queue::VerifierSettings; +use ethcore_service::ClientService; use cache::CacheConfig; use informant::{Informant, FullNodeInformantData, MillisecondDuration}; use kvdb_rocksdb::{Database, DatabaseConfig}; diff --git a/parity/informant.rs b/parity/informant.rs index 0d2539713..b834b018d 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -22,9 +22,11 @@ use std::sync::{Arc}; use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering}; use std::time::{Instant, Duration}; -use ethcore::client::{BlockId, BlockChainClient, ChainInfo, BlockInfo, BlockChainInfo, BlockQueueInfo, ChainNotify, ClientReport, Client}; +use ethcore::client::{ + BlockId, BlockChainClient, ChainInfo, BlockInfo, BlockChainInfo, + BlockQueueInfo, ChainNotify, ClientReport, Client, ClientIoMessage +}; use ethcore::header::BlockNumber; -use ethcore::service::ClientIoMessage; use ethcore::snapshot::{RestorationStatus, SnapshotService as SS}; use ethcore::snapshot::service::Service as SnapshotService; use ethsync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork}; diff --git a/parity/light_helpers/queue_cull.rs b/parity/light_helpers/queue_cull.rs index 6ac40baf8..091953ad5 100644 --- a/parity/light_helpers/queue_cull.rs +++ b/parity/light_helpers/queue_cull.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use std::time::Duration; -use ethcore::service::ClientIoMessage; +use ethcore::client::ClientIoMessage; use ethsync::LightSync; use io::{IoContext, IoHandler, TimerToken}; diff --git a/parity/main.rs b/parity/main.rs index 38a502a7a..fc45c1a6d 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -54,6 +54,7 @@ extern crate ethcore_logger; extern crate ethcore_migrations as migrations; extern crate ethcore_miner as miner; extern crate ethcore_network as network; +extern crate ethcore_service; extern crate ethcore_transaction as transaction; extern crate ethereum_types; extern crate migration as migr; diff --git a/parity/run.rs b/parity/run.rs index a1d067052..155fcd143 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -28,11 +28,11 @@ use ethcore::db::NUM_COLUMNS; use ethcore::ethstore::ethkey; use ethcore::miner::{Miner, MinerService, MinerOptions}; use ethcore::miner::{StratumOptions, Stratum}; -use ethcore::service::ClientService; use ethcore::snapshot; use ethcore::spec::{SpecParams, OptimizeFor}; use ethcore::verification::queue::VerifierSettings; use ethcore_logger::{Config as LogConfig, RotatingLogger}; +use ethcore_service::ClientService; use ethsync::{self, SyncConfig}; use fdlimit::raise_fd_limit; use hash_fetch::fetch::{Fetch, Client as FetchClient}; diff --git a/parity/snapshot.rs b/parity/snapshot.rs index 34aa3252f..bda5059f7 100644 --- a/parity/snapshot.rs +++ b/parity/snapshot.rs @@ -24,10 +24,10 @@ use hash::keccak; use ethcore::snapshot::{Progress, RestorationStatus, SnapshotService as SS}; use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter}; use ethcore::snapshot::service::Service as SnapshotService; -use ethcore::service::ClientService; use ethcore::client::{Mode, DatabaseCompactionProfile, VMType}; use ethcore::miner::Miner; use ethcore::ids::BlockId; +use ethcore_service::ClientService; use cache::CacheConfig; use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool}; diff --git a/sync/src/tests/consensus.rs b/sync/src/tests/consensus.rs index 33ecbb7f4..951c027af 100644 --- a/sync/src/tests/consensus.rs +++ b/sync/src/tests/consensus.rs @@ -18,8 +18,7 @@ use std::sync::Arc; use hash::keccak; use ethereum_types::{U256, Address}; use io::{IoHandler, IoContext, IoChannel}; -use ethcore::client::{Client, ChainInfo}; -use ethcore::service::ClientIoMessage; +use ethcore::client::{Client, ChainInfo, ClientIoMessage}; use ethcore::spec::Spec; use ethcore::miner::MinerService; use ethcore::account_provider::AccountProvider;