ethcore-service (#8089)

* ethcore test::helpers cleanup

* ethcore-service
This commit is contained in:
Marek Kotewicz 2018-03-13 11:49:57 +01:00 committed by GitHub
parent e0f71b0c17
commit de72643898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 151 additions and 64 deletions

15
Cargo.lock generated
View File

@ -715,6 +715,20 @@ dependencies = [
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "ethcore-stratum" name = "ethcore-stratum"
version = "1.11.0" version = "1.11.0"
@ -1948,6 +1962,7 @@ dependencies = [
"ethcore-miner 1.11.0", "ethcore-miner 1.11.0",
"ethcore-network 1.11.0", "ethcore-network 1.11.0",
"ethcore-secretstore 1.0.0", "ethcore-secretstore 1.0.0",
"ethcore-service 0.1.0",
"ethcore-stratum 1.11.0", "ethcore-stratum 1.11.0",
"ethcore-transaction 0.1.0", "ethcore-transaction 0.1.0",
"ethereum-types 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -43,6 +43,7 @@ ethcore-logger = { path = "logger" }
ethcore-migrations = { path = "ethcore/migrations" } ethcore-migrations = { path = "ethcore/migrations" }
ethcore-miner = { path = "miner" } ethcore-miner = { path = "miner" }
ethcore-network = { path = "util/network" } ethcore-network = { path = "util/network" }
ethcore-service = { path = "ethcore/service" }
ethcore-stratum = { path = "stratum" } ethcore-stratum = { path = "stratum" }
ethcore-transaction = { path = "ethcore/transaction" } ethcore-transaction = { path = "ethcore/transaction" }
ethereum-types = "0.2" ethereum-types = "0.2"
@ -132,6 +133,5 @@ members = [
"evmbin", "evmbin",
"miner", "miner",
"transaction-pool", "transaction-pool",
"whisper", "whisper"
"util/rlp_compress"
] ]

View File

@ -19,7 +19,7 @@
use std::sync::{Weak, Arc}; use std::sync::{Weak, Arc};
use ethcore::block_status::BlockStatus; 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::engines::{epoch, EthEngine, EpochChange, EpochTransition, Proof};
use ethcore::machine::EthereumMachine; use ethcore::machine::EthereumMachine;
use ethcore::error::BlockImportError; use ethcore::error::BlockImportError;
@ -28,7 +28,6 @@ use ethcore::header::{BlockNumber, Header};
use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::verification::queue::{self, HeaderQueue};
use ethcore::blockchain_info::BlockChainInfo; use ethcore::blockchain_info::BlockChainInfo;
use ethcore::spec::Spec; use ethcore::spec::Spec;
use ethcore::service::ClientIoMessage;
use ethcore::encoded; use ethcore::encoded;
use io::IoChannel; use io::IoChannel;
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};

View File

@ -20,8 +20,8 @@
use std::fmt; use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use ethcore::client::ClientIoMessage;
use ethcore::db; use ethcore::db;
use ethcore::service::ClientIoMessage;
use ethcore::spec::Spec; use ethcore::spec::Spec;
use io::{IoContext, IoError, IoHandler, IoService}; use io::{IoContext, IoError, IoHandler, IoService};
use kvdb::{self, KeyValueDB}; use kvdb::{self, KeyValueDB};

View File

@ -0,0 +1,16 @@
[package]
name = "ethcore-service"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[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"

View File

@ -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 <http://www.gnu.org/licenses/>.
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;

View File

@ -18,41 +18,20 @@
use std::sync::Arc; use std::sync::Arc;
use std::path::Path; use std::path::Path;
use ethereum_types::H256;
use ansi_term::Colour;
use io::{IoContext, TimerToken, IoHandler, IoService, IoError};
use kvdb::KeyValueDB; use kvdb::KeyValueDB;
use kvdb_rocksdb::{Database, DatabaseConfig}; 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; use stop_guard::StopGuard;
/// Message type for external and internal events use ethcore::client::{self, Client, ClientConfig, ChainNotify, ClientIoMessage};
#[derive(Clone, PartialEq, Eq, Debug)] use ethcore::db;
pub enum ClientIoMessage { use ethcore::error::Error;
/// Best Block Hash in chain has been changed use ethcore::miner::Miner;
NewChainHead, use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
/// A block is ready use ethcore::snapshot::{RestorationStatus};
BlockVerified, use ethcore::spec::Spec;
/// New transaction RLPs are ready to be imported
NewTransactions(Vec<Bytes>, 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)
}
/// Client service setup. Creates and registers client and network services with the IO subsystem. /// Client service setup. Creates and registers client and network services with the IO subsystem.
pub struct ClientService { 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())); 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.memory_budget = config.db_cache_size;
db_config.compaction = config.db_compaction.compaction_profile(client_path); db_config.compaction = config.db_compaction.compaction_profile(client_path);
@ -87,7 +66,7 @@ impl ClientService {
let db = Arc::new(Database::open( let db = Arc::new(Database::open(
&db_config, &db_config,
&client_path.to_str().expect("DB path could not be converted to string.") &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; let pruning = config.pruning;
@ -173,7 +152,7 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) { fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) {
match timer { match timer {
CLIENT_TICK_TIMER => { CLIENT_TICK_TIMER => {
use snapshot::SnapshotService; use ethcore::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)
}, },
@ -221,14 +200,16 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::{time, thread};
use spec::Spec;
use super::*;
use client::ClientConfig;
use std::sync::Arc; use std::sync::Arc;
use miner::Miner; use std::{time, thread};
use tempdir::TempDir; use tempdir::TempDir;
use ethcore::client::ClientConfig;
use ethcore::miner::Miner;
use ethcore::spec::Spec;
use super::*;
#[test] #[test]
fn it_can_be_started() { fn it_can_be_started() {
let tempdir = TempDir::new("").unwrap(); let tempdir = TempDir::new("").unwrap();

View File

@ -37,8 +37,11 @@ use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute, Transaction
use client::ancient_import::AncientVerifier; use client::ancient_import::AncientVerifier;
use client::Error as ClientError; use client::Error as ClientError;
use client::{ use client::{
Nonce, Balance, ChainInfo, BlockInfo, CallContract, TransactionInfo, RegistryInfo, ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, Nonce, Balance, ChainInfo, BlockInfo, CallContract, TransactionInfo,
StateOrBlock, StateInfo, StateClient, Call, AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter RegistryInfo, ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock,
BroadcastProposalBlock, ImportBlock, StateOrBlock, StateInfo, StateClient, Call,
AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter,
ClientIoMessage
}; };
use client::{ use client::{
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient, BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
@ -60,7 +63,6 @@ use parking_lot::{Mutex, RwLock};
use rand::OsRng; use rand::OsRng;
use receipt::{Receipt, LocalizedReceipt}; use receipt::{Receipt, LocalizedReceipt};
use rlp::UntrustedRlp; use rlp::UntrustedRlp;
use service::ClientIoMessage;
use snapshot::{self, io as snapshot_io}; use snapshot::{self, io as snapshot_io};
use spec::Spec; use spec::Spec;
use state_db::StateDB; use state_db::StateDB;

View File

@ -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 <http://www.gnu.org/licenses/>.
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<Bytes>, 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)
}

View File

@ -17,17 +17,19 @@
//! Blockchain database client. //! Blockchain database client.
mod ancient_import; mod ancient_import;
mod client;
mod config; mod config;
mod error; mod error;
mod evm_test_client; mod evm_test_client;
mod io_message;
mod test_client; mod test_client;
mod trace; mod trace;
mod client;
pub use self::client::*; pub use self::client::*;
pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType}; pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType};
pub use self::error::Error; pub use self::error::Error;
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactResult}; 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::test_client::{TestBlockChainClient, EachBlockWith};
pub use self::chain_notify::ChainNotify; pub use self::chain_notify::ChainNotify;
pub use self::traits::{ pub use self::traits::{

View File

@ -148,7 +148,6 @@ pub mod header;
pub mod machine; pub mod machine;
pub mod miner; pub mod miner;
pub mod pod_state; pub mod pod_state;
pub mod service;
pub mod snapshot; pub mod snapshot;
pub mod spec; pub mod spec;
pub mod state; pub mod state;

View File

@ -27,11 +27,10 @@ use super::{ManifestData, StateRebuilder, Rebuilder, RestorationStatus, Snapshot
use super::io::{SnapshotReader, LooseReader, SnapshotWriter, LooseWriter}; use super::io::{SnapshotReader, LooseReader, SnapshotWriter, LooseWriter};
use blockchain::BlockChain; use blockchain::BlockChain;
use client::{Client, ChainInfo}; use client::{Client, ChainInfo, ClientIoMessage};
use engines::EthEngine; use engines::EthEngine;
use error::Error; use error::Error;
use ids::BlockId; use ids::BlockId;
use service::ClientIoMessage;
use io::IoChannel; use io::IoChannel;
@ -631,7 +630,7 @@ impl Drop for Service {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::sync::Arc; use std::sync::Arc;
use service::ClientIoMessage; use client::ClientIoMessage;
use io::{IoService}; use io::{IoService};
use spec::Spec; use spec::Spec;
use journaldb::Algorithm; use journaldb::Algorithm;

View File

@ -17,9 +17,8 @@
//! Watcher for snapshot-related chain events. //! Watcher for snapshot-related chain events.
use parking_lot::Mutex; use parking_lot::Mutex;
use client::{BlockInfo, Client, ChainNotify}; use client::{BlockInfo, Client, ChainNotify, ClientIoMessage};
use ids::BlockId; use ids::BlockId;
use service::ClientIoMessage;
use io::IoChannel; use io::IoChannel;
use ethereum_types::H256; use ethereum_types::H256;

View File

@ -28,7 +28,7 @@ use parking_lot::{Condvar, Mutex, RwLock};
use io::*; use io::*;
use error::*; use error::*;
use engines::EthEngine; use engines::EthEngine;
use service::*; use client::ClientIoMessage;
use self::kind::{BlockLike, Kind}; use self::kind::{BlockLike, Kind};

View File

@ -23,7 +23,7 @@ use transaction::{
SignedTransaction, PendingTransaction, UnverifiedTransaction, SignedTransaction, PendingTransaction, UnverifiedTransaction,
Condition as TransactionCondition Condition as TransactionCondition
}; };
use ethcore::service::ClientIoMessage; use ethcore::client::ClientIoMessage;
use io::IoHandler; use io::IoHandler;
use rlp::UntrustedRlp; use rlp::UntrustedRlp;
use kvdb::KeyValueDB; use kvdb::KeyValueDB;

View File

@ -25,12 +25,12 @@ use hash::{keccak, KECCAK_NULL_RLP};
use ethereum_types::{U256, H256, Address}; use ethereum_types::{U256, H256, Address};
use bytes::ToPretty; use bytes::ToPretty;
use rlp::PayloadInfo; use rlp::PayloadInfo;
use ethcore::service::ClientService;
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, Nonce, Balance, BlockChainClient, BlockId, BlockInfo, ImportBlock}; use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, Nonce, Balance, BlockChainClient, BlockId, BlockInfo, ImportBlock};
use ethcore::db::NUM_COLUMNS; use ethcore::db::NUM_COLUMNS;
use ethcore::error::ImportError; use ethcore::error::ImportError;
use ethcore::miner::Miner; use ethcore::miner::Miner;
use ethcore::verification::queue::VerifierSettings; use ethcore::verification::queue::VerifierSettings;
use ethcore_service::ClientService;
use cache::CacheConfig; use cache::CacheConfig;
use informant::{Informant, FullNodeInformantData, MillisecondDuration}; use informant::{Informant, FullNodeInformantData, MillisecondDuration};
use kvdb_rocksdb::{Database, DatabaseConfig}; use kvdb_rocksdb::{Database, DatabaseConfig};

View File

@ -22,9 +22,11 @@ use std::sync::{Arc};
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering}; use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
use std::time::{Instant, Duration}; 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::header::BlockNumber;
use ethcore::service::ClientIoMessage;
use ethcore::snapshot::{RestorationStatus, SnapshotService as SS}; use ethcore::snapshot::{RestorationStatus, SnapshotService as SS};
use ethcore::snapshot::service::Service as SnapshotService; use ethcore::snapshot::service::Service as SnapshotService;
use ethsync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork}; use ethsync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork};

View File

@ -19,7 +19,7 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use ethcore::service::ClientIoMessage; use ethcore::client::ClientIoMessage;
use ethsync::LightSync; use ethsync::LightSync;
use io::{IoContext, IoHandler, TimerToken}; use io::{IoContext, IoHandler, TimerToken};

View File

@ -54,6 +54,7 @@ extern crate ethcore_logger;
extern crate ethcore_migrations as migrations; extern crate ethcore_migrations as migrations;
extern crate ethcore_miner as miner; extern crate ethcore_miner as miner;
extern crate ethcore_network as network; extern crate ethcore_network as network;
extern crate ethcore_service;
extern crate ethcore_transaction as transaction; extern crate ethcore_transaction as transaction;
extern crate ethereum_types; extern crate ethereum_types;
extern crate migration as migr; extern crate migration as migr;

View File

@ -28,11 +28,11 @@ use ethcore::db::NUM_COLUMNS;
use ethcore::ethstore::ethkey; use ethcore::ethstore::ethkey;
use ethcore::miner::{Miner, MinerService, MinerOptions}; use ethcore::miner::{Miner, MinerService, MinerOptions};
use ethcore::miner::{StratumOptions, Stratum}; use ethcore::miner::{StratumOptions, Stratum};
use ethcore::service::ClientService;
use ethcore::snapshot; use ethcore::snapshot;
use ethcore::spec::{SpecParams, OptimizeFor}; use ethcore::spec::{SpecParams, OptimizeFor};
use ethcore::verification::queue::VerifierSettings; use ethcore::verification::queue::VerifierSettings;
use ethcore_logger::{Config as LogConfig, RotatingLogger}; use ethcore_logger::{Config as LogConfig, RotatingLogger};
use ethcore_service::ClientService;
use ethsync::{self, SyncConfig}; use ethsync::{self, SyncConfig};
use fdlimit::raise_fd_limit; use fdlimit::raise_fd_limit;
use hash_fetch::fetch::{Fetch, Client as FetchClient}; use hash_fetch::fetch::{Fetch, Client as FetchClient};

View File

@ -24,10 +24,10 @@ use hash::keccak;
use ethcore::snapshot::{Progress, RestorationStatus, SnapshotService as SS}; use ethcore::snapshot::{Progress, RestorationStatus, SnapshotService as SS};
use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter}; use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter};
use ethcore::snapshot::service::Service as SnapshotService; use ethcore::snapshot::service::Service as SnapshotService;
use ethcore::service::ClientService;
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType}; use ethcore::client::{Mode, DatabaseCompactionProfile, VMType};
use ethcore::miner::Miner; use ethcore::miner::Miner;
use ethcore::ids::BlockId; use ethcore::ids::BlockId;
use ethcore_service::ClientService;
use cache::CacheConfig; use cache::CacheConfig;
use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool}; use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool};

View File

@ -18,8 +18,7 @@ use std::sync::Arc;
use hash::keccak; use hash::keccak;
use ethereum_types::{U256, Address}; use ethereum_types::{U256, Address};
use io::{IoHandler, IoContext, IoChannel}; use io::{IoHandler, IoContext, IoChannel};
use ethcore::client::{Client, ChainInfo}; use ethcore::client::{Client, ChainInfo, ClientIoMessage};
use ethcore::service::ClientIoMessage;
use ethcore::spec::Spec; use ethcore::spec::Spec;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;