Reformat the source code
This commit is contained in:
@@ -19,13 +19,13 @@
|
||||
#![allow(deprecated)]
|
||||
|
||||
use ethcore;
|
||||
use io;
|
||||
use ethcore_private_tx;
|
||||
use io;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
Ethcore(ethcore::error::Error);
|
||||
IoError(io::IoError);
|
||||
PrivateTransactions(ethcore_private_tx::Error);
|
||||
}
|
||||
foreign_links {
|
||||
Ethcore(ethcore::error::Error);
|
||||
IoError(io::IoError);
|
||||
PrivateTransactions(ethcore_private_tx::Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,198 +16,205 @@
|
||||
|
||||
//! Creates and registers client and network services.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use std::{path::Path, sync::Arc, time::Duration};
|
||||
|
||||
use ansi_term::Colour;
|
||||
use ethereum_types::H256;
|
||||
use io::{IoContext, TimerToken, IoHandler, IoService, IoError};
|
||||
use io::{IoContext, IoError, IoHandler, IoService, TimerToken};
|
||||
use stop_guard::StopGuard;
|
||||
|
||||
use sync::PrivateTxHandler;
|
||||
use blockchain::{BlockChainDB, BlockChainDBHandler};
|
||||
use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage};
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
|
||||
use ethcore::snapshot::{SnapshotService as _SnapshotService, RestorationStatus, Error as SnapshotError};
|
||||
use ethcore::spec::Spec;
|
||||
use ethcore::error::{Error as EthcoreError, ErrorKind};
|
||||
|
||||
use ethcore::{
|
||||
client::{ChainNotify, Client, ClientConfig, ClientIoMessage},
|
||||
error::{Error as EthcoreError, ErrorKind},
|
||||
miner::Miner,
|
||||
snapshot::{
|
||||
service::{Service as SnapshotService, ServiceParams as SnapServiceParams},
|
||||
Error as SnapshotError, RestorationStatus, SnapshotService as _SnapshotService,
|
||||
},
|
||||
spec::Spec,
|
||||
};
|
||||
use sync::PrivateTxHandler;
|
||||
|
||||
use ethcore_private_tx::{self, Importer, Signer};
|
||||
use Error;
|
||||
|
||||
pub struct PrivateTxService {
|
||||
provider: Arc<ethcore_private_tx::Provider>,
|
||||
provider: Arc<ethcore_private_tx::Provider>,
|
||||
}
|
||||
|
||||
impl PrivateTxService {
|
||||
fn new(provider: Arc<ethcore_private_tx::Provider>) -> Self {
|
||||
PrivateTxService {
|
||||
provider,
|
||||
}
|
||||
}
|
||||
fn new(provider: Arc<ethcore_private_tx::Provider>) -> Self {
|
||||
PrivateTxService { provider }
|
||||
}
|
||||
|
||||
/// Returns underlying provider.
|
||||
pub fn provider(&self) -> Arc<ethcore_private_tx::Provider> {
|
||||
self.provider.clone()
|
||||
}
|
||||
/// Returns underlying provider.
|
||||
pub fn provider(&self) -> Arc<ethcore_private_tx::Provider> {
|
||||
self.provider.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl PrivateTxHandler for PrivateTxService {
|
||||
fn import_private_transaction(&self, rlp: &[u8]) -> Result<H256, String> {
|
||||
match self.provider.import_private_transaction(rlp) {
|
||||
Ok(import_result) => Ok(import_result),
|
||||
Err(err) => {
|
||||
warn!(target: "privatetx", "Unable to import private transaction packet: {}", err);
|
||||
bail!(err.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
fn import_private_transaction(&self, rlp: &[u8]) -> Result<H256, String> {
|
||||
match self.provider.import_private_transaction(rlp) {
|
||||
Ok(import_result) => Ok(import_result),
|
||||
Err(err) => {
|
||||
warn!(target: "privatetx", "Unable to import private transaction packet: {}", err);
|
||||
bail!(err.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn import_signed_private_transaction(&self, rlp: &[u8]) -> Result<H256, String> {
|
||||
match self.provider.import_signed_private_transaction(rlp) {
|
||||
Ok(import_result) => Ok(import_result),
|
||||
Err(err) => {
|
||||
warn!(target: "privatetx", "Unable to import signed private transaction packet: {}", err);
|
||||
bail!(err.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
fn import_signed_private_transaction(&self, rlp: &[u8]) -> Result<H256, String> {
|
||||
match self.provider.import_signed_private_transaction(rlp) {
|
||||
Ok(import_result) => Ok(import_result),
|
||||
Err(err) => {
|
||||
warn!(target: "privatetx", "Unable to import signed private transaction packet: {}", err);
|
||||
bail!(err.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Client service setup. Creates and registers client and network services with the IO subsystem.
|
||||
pub struct ClientService {
|
||||
io_service: Arc<IoService<ClientIoMessage>>,
|
||||
client: Arc<Client>,
|
||||
snapshot: Arc<SnapshotService>,
|
||||
private_tx: Arc<PrivateTxService>,
|
||||
database: Arc<BlockChainDB>,
|
||||
_stop_guard: StopGuard,
|
||||
io_service: Arc<IoService<ClientIoMessage>>,
|
||||
client: Arc<Client>,
|
||||
snapshot: Arc<SnapshotService>,
|
||||
private_tx: Arc<PrivateTxService>,
|
||||
database: Arc<BlockChainDB>,
|
||||
_stop_guard: StopGuard,
|
||||
}
|
||||
|
||||
impl ClientService {
|
||||
/// Start the `ClientService`.
|
||||
pub fn start(
|
||||
config: ClientConfig,
|
||||
spec: &Spec,
|
||||
blockchain_db: Arc<BlockChainDB>,
|
||||
snapshot_path: &Path,
|
||||
restoration_db_handler: Box<BlockChainDBHandler>,
|
||||
_ipc_path: &Path,
|
||||
miner: Arc<Miner>,
|
||||
signer: Arc<Signer>,
|
||||
encryptor: Box<ethcore_private_tx::Encryptor>,
|
||||
private_tx_conf: ethcore_private_tx::ProviderConfig,
|
||||
private_encryptor_conf: ethcore_private_tx::EncryptorConfig,
|
||||
) -> Result<ClientService, Error>
|
||||
{
|
||||
let io_service = IoService::<ClientIoMessage>::start()?;
|
||||
/// Start the `ClientService`.
|
||||
pub fn start(
|
||||
config: ClientConfig,
|
||||
spec: &Spec,
|
||||
blockchain_db: Arc<BlockChainDB>,
|
||||
snapshot_path: &Path,
|
||||
restoration_db_handler: Box<BlockChainDBHandler>,
|
||||
_ipc_path: &Path,
|
||||
miner: Arc<Miner>,
|
||||
signer: Arc<Signer>,
|
||||
encryptor: Box<ethcore_private_tx::Encryptor>,
|
||||
private_tx_conf: ethcore_private_tx::ProviderConfig,
|
||||
private_encryptor_conf: ethcore_private_tx::EncryptorConfig,
|
||||
) -> Result<ClientService, Error> {
|
||||
let io_service = IoService::<ClientIoMessage>::start()?;
|
||||
|
||||
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 pruning = config.pruning;
|
||||
let client = Client::new(
|
||||
config,
|
||||
&spec,
|
||||
blockchain_db.clone(),
|
||||
miner.clone(),
|
||||
io_service.channel(),
|
||||
)?;
|
||||
miner.set_io_channel(io_service.channel());
|
||||
miner.set_in_chain_checker(&client.clone());
|
||||
let pruning = config.pruning;
|
||||
let client = Client::new(
|
||||
config,
|
||||
&spec,
|
||||
blockchain_db.clone(),
|
||||
miner.clone(),
|
||||
io_service.channel(),
|
||||
)?;
|
||||
miner.set_io_channel(io_service.channel());
|
||||
miner.set_in_chain_checker(&client.clone());
|
||||
|
||||
let snapshot_params = SnapServiceParams {
|
||||
engine: spec.engine.clone(),
|
||||
genesis_block: spec.genesis_block(),
|
||||
restoration_db_handler: restoration_db_handler,
|
||||
pruning: pruning,
|
||||
channel: io_service.channel(),
|
||||
snapshot_root: snapshot_path.into(),
|
||||
client: client.clone(),
|
||||
};
|
||||
let snapshot = Arc::new(SnapshotService::new(snapshot_params)?);
|
||||
let snapshot_params = SnapServiceParams {
|
||||
engine: spec.engine.clone(),
|
||||
genesis_block: spec.genesis_block(),
|
||||
restoration_db_handler: restoration_db_handler,
|
||||
pruning: pruning,
|
||||
channel: io_service.channel(),
|
||||
snapshot_root: snapshot_path.into(),
|
||||
client: client.clone(),
|
||||
};
|
||||
let snapshot = Arc::new(SnapshotService::new(snapshot_params)?);
|
||||
|
||||
let private_keys = Arc::new(ethcore_private_tx::SecretStoreKeys::new(
|
||||
client.clone(),
|
||||
private_encryptor_conf.key_server_account,
|
||||
));
|
||||
let provider = Arc::new(ethcore_private_tx::Provider::new(
|
||||
client.clone(),
|
||||
miner,
|
||||
signer,
|
||||
encryptor,
|
||||
private_tx_conf,
|
||||
io_service.channel(),
|
||||
private_keys,
|
||||
));
|
||||
let private_tx = Arc::new(PrivateTxService::new(provider));
|
||||
let private_keys = Arc::new(ethcore_private_tx::SecretStoreKeys::new(
|
||||
client.clone(),
|
||||
private_encryptor_conf.key_server_account,
|
||||
));
|
||||
let provider = Arc::new(ethcore_private_tx::Provider::new(
|
||||
client.clone(),
|
||||
miner,
|
||||
signer,
|
||||
encryptor,
|
||||
private_tx_conf,
|
||||
io_service.channel(),
|
||||
private_keys,
|
||||
));
|
||||
let private_tx = Arc::new(PrivateTxService::new(provider));
|
||||
|
||||
let client_io = Arc::new(ClientIoHandler {
|
||||
client: client.clone(),
|
||||
snapshot: snapshot.clone(),
|
||||
});
|
||||
io_service.register_handler(client_io)?;
|
||||
let client_io = Arc::new(ClientIoHandler {
|
||||
client: client.clone(),
|
||||
snapshot: snapshot.clone(),
|
||||
});
|
||||
io_service.register_handler(client_io)?;
|
||||
|
||||
spec.engine.register_client(Arc::downgrade(&client) as _);
|
||||
spec.engine.register_client(Arc::downgrade(&client) as _);
|
||||
|
||||
let stop_guard = StopGuard::new();
|
||||
let stop_guard = StopGuard::new();
|
||||
|
||||
Ok(ClientService {
|
||||
io_service: Arc::new(io_service),
|
||||
client: client,
|
||||
snapshot: snapshot,
|
||||
private_tx,
|
||||
database: blockchain_db,
|
||||
_stop_guard: stop_guard,
|
||||
})
|
||||
}
|
||||
Ok(ClientService {
|
||||
io_service: Arc::new(io_service),
|
||||
client: client,
|
||||
snapshot: snapshot,
|
||||
private_tx,
|
||||
database: blockchain_db,
|
||||
_stop_guard: stop_guard,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get general IO interface
|
||||
pub fn register_io_handler(&self, handler: Arc<IoHandler<ClientIoMessage> + Send>) -> Result<(), IoError> {
|
||||
self.io_service.register_handler(handler)
|
||||
}
|
||||
/// Get general IO interface
|
||||
pub fn register_io_handler(
|
||||
&self,
|
||||
handler: Arc<IoHandler<ClientIoMessage> + Send>,
|
||||
) -> Result<(), IoError> {
|
||||
self.io_service.register_handler(handler)
|
||||
}
|
||||
|
||||
/// Get client interface
|
||||
pub fn client(&self) -> Arc<Client> {
|
||||
self.client.clone()
|
||||
}
|
||||
/// Get client interface
|
||||
pub fn client(&self) -> Arc<Client> {
|
||||
self.client.clone()
|
||||
}
|
||||
|
||||
/// Get snapshot interface.
|
||||
pub fn snapshot_service(&self) -> Arc<SnapshotService> {
|
||||
self.snapshot.clone()
|
||||
}
|
||||
/// Get snapshot interface.
|
||||
pub fn snapshot_service(&self) -> Arc<SnapshotService> {
|
||||
self.snapshot.clone()
|
||||
}
|
||||
|
||||
/// Get private transaction service.
|
||||
pub fn private_tx_service(&self) -> Arc<PrivateTxService> {
|
||||
self.private_tx.clone()
|
||||
}
|
||||
/// Get private transaction service.
|
||||
pub fn private_tx_service(&self) -> Arc<PrivateTxService> {
|
||||
self.private_tx.clone()
|
||||
}
|
||||
|
||||
/// Get network service component
|
||||
pub fn io(&self) -> Arc<IoService<ClientIoMessage>> {
|
||||
self.io_service.clone()
|
||||
}
|
||||
/// Get network service component
|
||||
pub fn io(&self) -> Arc<IoService<ClientIoMessage>> {
|
||||
self.io_service.clone()
|
||||
}
|
||||
|
||||
/// Set the actor to be notified on certain chain events
|
||||
pub fn add_notify(&self, notify: Arc<ChainNotify>) {
|
||||
self.client.add_notify(notify);
|
||||
}
|
||||
/// Set the actor to be notified on certain chain events
|
||||
pub fn add_notify(&self, notify: Arc<ChainNotify>) {
|
||||
self.client.add_notify(notify);
|
||||
}
|
||||
|
||||
/// Get a handle to the database.
|
||||
pub fn db(&self) -> Arc<BlockChainDB> { self.database.clone() }
|
||||
/// Get a handle to the database.
|
||||
pub fn db(&self) -> Arc<BlockChainDB> {
|
||||
self.database.clone()
|
||||
}
|
||||
|
||||
/// Shutdown the Client Service
|
||||
pub fn shutdown(&self) {
|
||||
trace!(target: "shutdown", "Shutting down Client Service");
|
||||
self.snapshot.shutdown();
|
||||
}
|
||||
/// Shutdown the Client Service
|
||||
pub fn shutdown(&self) {
|
||||
trace!(target: "shutdown", "Shutting down Client Service");
|
||||
self.snapshot.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/// IO interface for the Client handler
|
||||
struct ClientIoHandler {
|
||||
client: Arc<Client>,
|
||||
snapshot: Arc<SnapshotService>,
|
||||
client: Arc<Client>,
|
||||
snapshot: Arc<SnapshotService>,
|
||||
}
|
||||
|
||||
const CLIENT_TICK_TIMER: TimerToken = 0;
|
||||
@@ -217,118 +224,125 @@ const CLIENT_TICK: Duration = Duration::from_secs(5);
|
||||
const SNAPSHOT_TICK: Duration = Duration::from_secs(10);
|
||||
|
||||
impl IoHandler<ClientIoMessage> for ClientIoHandler {
|
||||
fn initialize(&self, io: &IoContext<ClientIoMessage>) {
|
||||
io.register_timer(CLIENT_TICK_TIMER, CLIENT_TICK).expect("Error registering client timer");
|
||||
io.register_timer(SNAPSHOT_TICK_TIMER, SNAPSHOT_TICK).expect("Error registering snapshot timer");
|
||||
}
|
||||
fn initialize(&self, io: &IoContext<ClientIoMessage>) {
|
||||
io.register_timer(CLIENT_TICK_TIMER, CLIENT_TICK)
|
||||
.expect("Error registering client timer");
|
||||
io.register_timer(SNAPSHOT_TICK_TIMER, SNAPSHOT_TICK)
|
||||
.expect("Error registering snapshot timer");
|
||||
}
|
||||
|
||||
fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) {
|
||||
trace_time!("service::read");
|
||||
match timer {
|
||||
CLIENT_TICK_TIMER => {
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
let snapshot_restoration = if let RestorationStatus::Ongoing{..} = self.snapshot.status() { true } else { false };
|
||||
self.client.tick(snapshot_restoration)
|
||||
},
|
||||
SNAPSHOT_TICK_TIMER => self.snapshot.tick(),
|
||||
_ => warn!("IO service triggered unregistered timer '{}'", timer),
|
||||
}
|
||||
}
|
||||
fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) {
|
||||
trace_time!("service::read");
|
||||
match timer {
|
||||
CLIENT_TICK_TIMER => {
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
let snapshot_restoration =
|
||||
if let RestorationStatus::Ongoing { .. } = self.snapshot.status() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
self.client.tick(snapshot_restoration)
|
||||
}
|
||||
SNAPSHOT_TICK_TIMER => self.snapshot.tick(),
|
||||
_ => warn!("IO service triggered unregistered timer '{}'", timer),
|
||||
}
|
||||
}
|
||||
|
||||
fn message(&self, _io: &IoContext<ClientIoMessage>, net_message: &ClientIoMessage) {
|
||||
trace_time!("service::message");
|
||||
use std::thread;
|
||||
fn message(&self, _io: &IoContext<ClientIoMessage>, net_message: &ClientIoMessage) {
|
||||
trace_time!("service::message");
|
||||
use std::thread;
|
||||
|
||||
match *net_message {
|
||||
ClientIoMessage::BlockVerified => {
|
||||
self.client.import_verified_blocks();
|
||||
}
|
||||
ClientIoMessage::BeginRestoration(ref manifest) => {
|
||||
if let Err(e) = self.snapshot.init_restore(manifest.clone(), true) {
|
||||
warn!("Failed to initialize snapshot restoration: {}", e);
|
||||
}
|
||||
}
|
||||
ClientIoMessage::FeedStateChunk(ref hash, ref chunk) => {
|
||||
self.snapshot.feed_state_chunk(*hash, chunk)
|
||||
}
|
||||
ClientIoMessage::FeedBlockChunk(ref hash, ref chunk) => {
|
||||
self.snapshot.feed_block_chunk(*hash, chunk)
|
||||
}
|
||||
ClientIoMessage::TakeSnapshot(num) => {
|
||||
let client = self.client.clone();
|
||||
let snapshot = self.snapshot.clone();
|
||||
match *net_message {
|
||||
ClientIoMessage::BlockVerified => {
|
||||
self.client.import_verified_blocks();
|
||||
}
|
||||
ClientIoMessage::BeginRestoration(ref manifest) => {
|
||||
if let Err(e) = self.snapshot.init_restore(manifest.clone(), true) {
|
||||
warn!("Failed to initialize snapshot restoration: {}", e);
|
||||
}
|
||||
}
|
||||
ClientIoMessage::FeedStateChunk(ref hash, ref chunk) => {
|
||||
self.snapshot.feed_state_chunk(*hash, chunk)
|
||||
}
|
||||
ClientIoMessage::FeedBlockChunk(ref hash, ref chunk) => {
|
||||
self.snapshot.feed_block_chunk(*hash, chunk)
|
||||
}
|
||||
ClientIoMessage::TakeSnapshot(num) => {
|
||||
let client = self.client.clone();
|
||||
let snapshot = self.snapshot.clone();
|
||||
|
||||
let res = thread::Builder::new().name("Periodic Snapshot".into()).spawn(move || {
|
||||
if let Err(e) = snapshot.take_snapshot(&*client, num) {
|
||||
match e {
|
||||
EthcoreError(ErrorKind::Snapshot(SnapshotError::SnapshotAborted), _) => info!("Snapshot aborted"),
|
||||
_ => warn!("Failed to take snapshot at block #{}: {}", num, e),
|
||||
}
|
||||
let res = thread::Builder::new()
|
||||
.name("Periodic Snapshot".into())
|
||||
.spawn(move || {
|
||||
if let Err(e) = snapshot.take_snapshot(&*client, num) {
|
||||
match e {
|
||||
EthcoreError(
|
||||
ErrorKind::Snapshot(SnapshotError::SnapshotAborted),
|
||||
_,
|
||||
) => info!("Snapshot aborted"),
|
||||
_ => warn!("Failed to take snapshot at block #{}: {}", num, e),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if let Err(e) = res {
|
||||
debug!(target: "snapshot", "Failed to initialize periodic snapshot thread: {:?}", e);
|
||||
}
|
||||
},
|
||||
ClientIoMessage::Execute(ref exec) => {
|
||||
(*exec.0)(&self.client);
|
||||
}
|
||||
_ => {} // ignore other messages
|
||||
}
|
||||
}
|
||||
if let Err(e) = res {
|
||||
debug!(target: "snapshot", "Failed to initialize periodic snapshot thread: {:?}", e);
|
||||
}
|
||||
}
|
||||
ClientIoMessage::Execute(ref exec) => {
|
||||
(*exec.0)(&self.client);
|
||||
}
|
||||
_ => {} // ignore other messages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::{time, thread};
|
||||
use std::{sync::Arc, thread, time};
|
||||
|
||||
use tempdir::TempDir;
|
||||
use tempdir::TempDir;
|
||||
|
||||
use ethcore_db::NUM_COLUMNS;
|
||||
use ethcore::client::ClientConfig;
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::spec::Spec;
|
||||
use ethcore::test_helpers;
|
||||
use kvdb_rocksdb::{DatabaseConfig, CompactionProfile};
|
||||
use super::*;
|
||||
use super::*;
|
||||
use ethcore::{client::ClientConfig, miner::Miner, spec::Spec, test_helpers};
|
||||
use ethcore_db::NUM_COLUMNS;
|
||||
use kvdb_rocksdb::{CompactionProfile, DatabaseConfig};
|
||||
|
||||
use ethcore_private_tx;
|
||||
use ethcore_private_tx;
|
||||
|
||||
#[test]
|
||||
fn it_can_be_started() {
|
||||
let tempdir = TempDir::new("").unwrap();
|
||||
let client_path = tempdir.path().join("client");
|
||||
let snapshot_path = tempdir.path().join("snapshot");
|
||||
#[test]
|
||||
fn it_can_be_started() {
|
||||
let tempdir = TempDir::new("").unwrap();
|
||||
let client_path = tempdir.path().join("client");
|
||||
let snapshot_path = tempdir.path().join("snapshot");
|
||||
|
||||
let client_config = ClientConfig::default();
|
||||
let mut client_db_config = DatabaseConfig::with_columns(NUM_COLUMNS);
|
||||
let client_config = ClientConfig::default();
|
||||
let mut client_db_config = DatabaseConfig::with_columns(NUM_COLUMNS);
|
||||
|
||||
client_db_config.memory_budget = client_config.db_cache_size;
|
||||
client_db_config.compaction = CompactionProfile::auto(&client_path);
|
||||
client_db_config.memory_budget = client_config.db_cache_size;
|
||||
client_db_config.compaction = CompactionProfile::auto(&client_path);
|
||||
|
||||
let client_db_handler = test_helpers::restoration_db_handler(client_db_config.clone());
|
||||
let client_db = client_db_handler.open(&client_path).unwrap();
|
||||
let restoration_db_handler = test_helpers::restoration_db_handler(client_db_config);
|
||||
let client_db_handler = test_helpers::restoration_db_handler(client_db_config.clone());
|
||||
let client_db = client_db_handler.open(&client_path).unwrap();
|
||||
let restoration_db_handler = test_helpers::restoration_db_handler(client_db_config);
|
||||
|
||||
let spec = Spec::new_test();
|
||||
let service = ClientService::start(
|
||||
ClientConfig::default(),
|
||||
&spec,
|
||||
client_db,
|
||||
&snapshot_path,
|
||||
restoration_db_handler,
|
||||
tempdir.path(),
|
||||
Arc::new(Miner::new_for_tests(&spec, None)),
|
||||
Arc::new(ethcore_private_tx::DummySigner),
|
||||
Box::new(ethcore_private_tx::NoopEncryptor),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
assert!(service.is_ok());
|
||||
drop(service.unwrap());
|
||||
thread::park_timeout(time::Duration::from_millis(100));
|
||||
}
|
||||
let spec = Spec::new_test();
|
||||
let service = ClientService::start(
|
||||
ClientConfig::default(),
|
||||
&spec,
|
||||
client_db,
|
||||
&snapshot_path,
|
||||
restoration_db_handler,
|
||||
tempdir.path(),
|
||||
Arc::new(Miner::new_for_tests(&spec, None)),
|
||||
Arc::new(ethcore_private_tx::DummySigner),
|
||||
Box::new(ethcore_private_tx::NoopEncryptor),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
assert!(service.is_ok());
|
||||
drop(service.unwrap());
|
||||
thread::park_timeout(time::Duration::from_millis(100));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,25 +16,24 @@
|
||||
|
||||
//! Stop guard mod
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::*;
|
||||
use std::sync::{atomic::*, Arc};
|
||||
|
||||
/// Stop guard that will set a stop flag on drop
|
||||
pub struct StopGuard {
|
||||
flag: Arc<AtomicBool>,
|
||||
flag: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl StopGuard {
|
||||
/// Create a stop guard
|
||||
pub fn new() -> StopGuard {
|
||||
StopGuard {
|
||||
flag: Arc::new(AtomicBool::new(false))
|
||||
}
|
||||
}
|
||||
/// Create a stop guard
|
||||
pub fn new() -> StopGuard {
|
||||
StopGuard {
|
||||
flag: Arc::new(AtomicBool::new(false)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for StopGuard {
|
||||
fn drop(&mut self) {
|
||||
self.flag.store(true, Ordering::Relaxed)
|
||||
}
|
||||
fn drop(&mut self) {
|
||||
self.flag.store(true, Ordering::Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user