diff --git a/ethcore/build.rs b/ethcore/build.rs
index 9f61851d4..25b559b43 100644
--- a/ethcore/build.rs
+++ b/ethcore/build.rs
@@ -44,4 +44,18 @@ fn main() {
codegen::register(&mut registry);
registry.expand("", &intermediate, &dst).unwrap();
}
+
+ // chain notify interface
+ {
+ let src = Path::new("src/client/chain_notify.rs");
+ let intermediate = Path::new(&out_dir).join("chain_notify.intermediate.rs.in");
+ let mut registry = syntex::Registry::new();
+ codegen::register(&mut registry);
+ registry.expand("", &src, &intermediate).unwrap();
+
+ let dst = Path::new(&out_dir).join("chain_notify.ipc.rs");
+ let mut registry = syntex::Registry::new();
+ codegen::register(&mut registry);
+ registry.expand("", &intermediate, &dst).unwrap();
+ }
}
diff --git a/ethcore/src/client/chain_notify.rs b/ethcore/src/client/chain_notify.rs
index 2b1d8d562..966388f9a 100644
--- a/ethcore/src/client/chain_notify.rs
+++ b/ethcore/src/client/chain_notify.rs
@@ -15,8 +15,13 @@
// along with Parity. If not, see .
use util::numbers::*;
+use ipc::{IpcConfig, BinaryConvertError};
+use std::sync::Arc;
+use std::collections::VecDeque;
+use std::mem;
/// Represents what has to be handled by actor listening to chain events
+#[derive(Ipc)]
pub trait ChainNotify : Send + Sync {
/// fires when chain has new blocks
fn new_blocks(&self,
@@ -38,3 +43,5 @@ pub trait ChainNotify : Send + Sync {
// does nothing by default
}
}
+
+impl IpcConfig for Arc { }
diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs
index a7ad99e80..b8426c9f3 100644
--- a/ethcore/src/client/mod.rs
+++ b/ethcore/src/client/mod.rs
@@ -20,7 +20,6 @@ mod config;
mod error;
mod test_client;
mod trace;
-mod chain_notify;
pub use self::client::*;
pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockQueueConfig, BlockChainConfig, Switch, VMType};
@@ -60,6 +59,13 @@ pub mod client {
include!(concat!(env!("OUT_DIR"), "/client.ipc.rs"));
}
+pub mod chain_notify {
+ //! Chain notify interface
+
+ #![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
+ include!(concat!(env!("OUT_DIR"), "/chain_notify.ipc.rs"));
+}
+
/// Blockchain database client. Owns and manages a blockchain and a block queue.
pub trait BlockChainClient : Sync + Send {
diff --git a/parity/io_handler.rs b/parity/io_handler.rs
index da989a000..d0b33a470 100644
--- a/parity/io_handler.rs
+++ b/parity/io_handler.rs
@@ -17,7 +17,7 @@
use std::sync::Arc;
use ethcore::client::Client;
use ethcore::service::ClientIoMessage;
-use ethsync::{EthSync, SyncProvider, ManageNetwork};
+use ethsync::{SyncProvider, ManageNetwork};
use ethcore::account_provider::AccountProvider;
use util::{TimerToken, IoHandler, IoContext};
@@ -27,7 +27,8 @@ const INFO_TIMER: TimerToken = 0;
pub struct ClientIoHandler {
pub client: Arc,
- pub sync: Arc,
+ pub sync: Arc,
+ pub net: Arc,
pub accounts: Arc,
pub info: Informant,
}
@@ -40,7 +41,7 @@ impl IoHandler for ClientIoHandler {
fn timeout(&self, _io: &IoContext, timer: TimerToken) {
if let INFO_TIMER = timer {
let sync_status = self.sync.status();
- let network_config = self.sync.network_config();
+ let network_config = self.net.network_config();
self.info.tick(&self.client, Some((sync_status, network_config)));
}
}
diff --git a/parity/main.rs b/parity/main.rs
index b25603922..ebd982b25 100644
--- a/parity/main.rs
+++ b/parity/main.rs
@@ -85,12 +85,11 @@ use rustc_serialize::hex::FromHex;
use ctrlc::CtrlC;
use util::{H256, ToPretty, PayloadInfo, Bytes, Colour, Applyable, version, journaldb};
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
-use ethcore::client::{BlockID, BlockChainClient, ClientConfig, get_db_path, BlockImportError,
- ChainNotify, Mode};
+use ethcore::client::{BlockID, BlockChainClient, ClientConfig, get_db_path, BlockImportError, Mode};
use ethcore::error::{ImportError};
use ethcore::service::ClientService;
use ethcore::spec::Spec;
-use ethsync::{EthSync, NetworkConfiguration};
+use ethsync::{NetworkConfiguration};
use ethcore::miner::{Miner, MinerService, ExternalMiner};
use migration::migrate;
use informant::Informant;
@@ -249,27 +248,32 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
let network_settings = Arc::new(conf.network_settings());
// Sync
- let sync = EthSync::new(sync_config, client.clone(), NetworkConfiguration::from(net_settings))
- .unwrap_or_else(|e| die_with_error("Sync", ethcore::error::Error::Util(e)));
- service.set_notify(&(sync.clone() as Arc));
+ let (sync_provider, manage_network, chain_notify) =
+ modules::sync(sync_config, NetworkConfiguration::from(net_settings), client.clone())
+ .unwrap_or_else(|e| die_with_error("Sync", e));
+//
+// let sync = EthSync::new(sync_config, client.clone(), NetworkConfiguration::from(net_settings))
+// .unwrap_or_else(|e| die_with_error("Sync", ethcore::error::Error::Util(e)));
+ service.set_notify(&chain_notify);
// if network is active by default
if match conf.mode() { Mode::Dark(..) => false, _ => !conf.args.flag_no_network } {
- sync.start();
+ chain_notify.start();
}
let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies {
signer_port: conf.signer_port(),
signer_queue: Arc::new(rpc_apis::ConfirmationsQueue::default()),
client: client.clone(),
- sync: sync.clone(),
+ sync: sync_provider.clone(),
+ net: manage_network.clone(),
secret_store: account_service.clone(),
miner: miner.clone(),
external_miner: external_miner.clone(),
logger: logger.clone(),
settings: network_settings.clone(),
allow_pending_receipt_query: !conf.args.flag_geth,
- net_service: sync.clone(),
+ net_service: manage_network.clone(),
});
let dependencies = rpc::Dependencies {
@@ -317,7 +321,8 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
let io_handler = Arc::new(ClientIoHandler {
client: service.client(),
info: Informant::new(conf.have_color()),
- sync: sync.clone(),
+ sync: sync_provider.clone(),
+ net: manage_network.clone(),
accounts: account_service.clone(),
});
service.register_io_handler(io_handler).expect("Error registering IO handler");
diff --git a/parity/modules.rs b/parity/modules.rs
index 04e74bf20..e0960dc6e 100644
--- a/parity/modules.rs
+++ b/parity/modules.rs
@@ -20,17 +20,16 @@ use ethcore::client::{ChainNotify, BlockChainClient};
use ethcore;
#[cfg(feature="ipc")]
-fn sync(
+pub fn sync(
sync_cfg: SyncConfig,
net_cfg: NetworkConfiguration,
client: Arc)
-> Result<(Arc, Arc, Arc), ethcore::error::Error>
{
-
}
#[cfg(not(feature="ipc"))]
-fn sync(
+pub fn sync(
sync_cfg: SyncConfig,
net_cfg: NetworkConfiguration,
client: Arc)
diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs
index 16ba2e8cb..5670d7c94 100644
--- a/parity/rpc_apis.rs
+++ b/parity/rpc_apis.rs
@@ -18,7 +18,7 @@ use std::collections::BTreeMap;
use std::str::FromStr;
use std::sync::Arc;
-use ethsync::{EthSync, ManageNetwork};
+use ethsync::{ManageNetwork, SyncProvider};
use ethcore::miner::{Miner, ExternalMiner};
use ethcore::client::Client;
use util::RotatingLogger;
@@ -76,7 +76,8 @@ pub struct Dependencies {
pub signer_port: Option,
pub signer_queue: Arc,
pub client: Arc,
- pub sync: Arc,
+ pub sync: Arc,
+ pub net: Arc,
pub secret_store: Arc,
pub miner: Arc,
pub external_miner: Arc,
diff --git a/parity/sync/main.rs b/parity/sync/main.rs
index 563ef0c4a..8b98bdcb6 100644
--- a/parity/sync/main.rs
+++ b/parity/sync/main.rs
@@ -28,11 +28,11 @@ extern crate ethcore;
extern crate ethcore_util as util;
use std::sync::Arc;
-use hypervisor::{HypervisorServiceClient, CLIENT_MODULE_ID, SYNC_MODULE_ID, HYPERVISOR_IPC_URL};
+use hypervisor::{HypervisorServiceClient, SYNC_MODULE_ID, HYPERVISOR_IPC_URL};
use ctrlc::CtrlC;
use std::sync::atomic::*;
use docopt::Docopt;
-use ethcore::client::{BlockChainClient, RemoteClient};
+use ethcore::client::{RemoteClient, ChainNotify};
use nanoipc::*;
use ethsync::{SyncProvider, SyncConfig, EthSync, ManageNetwork, NetworkConfiguration};
use std::thread;
@@ -74,7 +74,7 @@ impl Args {
let mut sync_config = SyncConfig::default();
sync_config.network_id = U256::from_str(&self.arg_network_id).unwrap();
- let mut network_config = NetworkConfiguration {
+ let network_config = NetworkConfiguration {
udp_port: self.flag_udp_port,
nat_enabled: self.arg_nat_enabled,
boot_nodes: self.flag_boot_nodes,
@@ -106,8 +106,6 @@ fn run_service(addr: &str, stop_guard: Arc));
run_service("ipc:///tmp/parity-manage-net.ipc", stop.clone(), &(sync.clone() as Arc));
+ run_service("ipc:///tmp/parity-sync-notify.ipc", stop.clone(), &(sync.clone() as Arc));
let hypervisor_client = nanoipc::init_client::>(HYPERVISOR_IPC_URL).unwrap();
hypervisor_client.handshake().unwrap();
diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs
index 9133393e9..58872666f 100644
--- a/rpc/src/v1/impls/eth.rs
+++ b/rpc/src/v1/impls/eth.rs
@@ -46,7 +46,7 @@ use v1::impls::{default_gas_price, dispatch_transaction, error_codes};
use serde;
/// Eth rpc implementation.
-pub struct EthClient where
+pub struct EthClient where
C: MiningBlockChainClient,
S: SyncProvider,
M: MinerService,
@@ -61,7 +61,7 @@ pub struct EthClient where
allow_pending_receipt_query: bool,
}
-impl EthClient where
+impl EthClient where
C: MiningBlockChainClient,
S: SyncProvider,
M: MinerService,
@@ -242,7 +242,7 @@ fn no_author_err() -> Error {
}
}
-impl EthClient where
+impl EthClient where
C: MiningBlockChainClient + 'static,
S: SyncProvider + 'static,
M: MinerService + 'static,
@@ -255,7 +255,7 @@ impl EthClient where
}
}
-impl Eth for EthClient where
+impl Eth for EthClient where
C: MiningBlockChainClient + 'static,
S: SyncProvider + 'static,
M: MinerService + 'static,
diff --git a/rpc/src/v1/impls/net.rs b/rpc/src/v1/impls/net.rs
index 20447ac92..0bbfeca6c 100644
--- a/rpc/src/v1/impls/net.rs
+++ b/rpc/src/v1/impls/net.rs
@@ -21,11 +21,11 @@ use ethsync::SyncProvider;
use v1::traits::Net;
/// Net rpc implementation.
-pub struct NetClient where S: SyncProvider {
+pub struct NetClient where S: SyncProvider {
sync: Weak
}
-impl NetClient where S: SyncProvider {
+impl NetClient where S: SyncProvider {
/// Creates new NetClient.
pub fn new(sync: &Arc) -> Self {
NetClient {
@@ -34,7 +34,7 @@ impl NetClient where S: SyncProvider {
}
}
-impl Net for NetClient where S: SyncProvider + 'static {
+impl Net for NetClient where S: SyncProvider + 'static {
fn version(&self, _: Params) -> Result {
Ok(Value::String(format!("{}", take_weak!(self.sync).status().network_id).to_owned()))
}