rpc dependencies relayout
This commit is contained in:
parent
98ddff1326
commit
4cb1c906b0
@ -44,4 +44,18 @@ fn main() {
|
|||||||
codegen::register(&mut registry);
|
codegen::register(&mut registry);
|
||||||
registry.expand("", &intermediate, &dst).unwrap();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,13 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::numbers::*;
|
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
|
/// Represents what has to be handled by actor listening to chain events
|
||||||
|
#[derive(Ipc)]
|
||||||
pub trait ChainNotify : Send + Sync {
|
pub trait ChainNotify : Send + Sync {
|
||||||
/// fires when chain has new blocks
|
/// fires when chain has new blocks
|
||||||
fn new_blocks(&self,
|
fn new_blocks(&self,
|
||||||
@ -38,3 +43,5 @@ pub trait ChainNotify : Send + Sync {
|
|||||||
// does nothing by default
|
// does nothing by default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IpcConfig<ChainNotify> for Arc<ChainNotify> { }
|
||||||
|
@ -20,7 +20,6 @@ mod config;
|
|||||||
mod error;
|
mod error;
|
||||||
mod test_client;
|
mod test_client;
|
||||||
mod trace;
|
mod trace;
|
||||||
mod chain_notify;
|
|
||||||
|
|
||||||
pub use self::client::*;
|
pub use self::client::*;
|
||||||
pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockQueueConfig, BlockChainConfig, Switch, VMType};
|
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"));
|
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.
|
/// Blockchain database client. Owns and manages a blockchain and a block queue.
|
||||||
pub trait BlockChainClient : Sync + Send {
|
pub trait BlockChainClient : Sync + Send {
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use ethcore::client::Client;
|
use ethcore::client::Client;
|
||||||
use ethcore::service::ClientIoMessage;
|
use ethcore::service::ClientIoMessage;
|
||||||
use ethsync::{EthSync, SyncProvider, ManageNetwork};
|
use ethsync::{SyncProvider, ManageNetwork};
|
||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use util::{TimerToken, IoHandler, IoContext};
|
use util::{TimerToken, IoHandler, IoContext};
|
||||||
|
|
||||||
@ -27,7 +27,8 @@ const INFO_TIMER: TimerToken = 0;
|
|||||||
|
|
||||||
pub struct ClientIoHandler {
|
pub struct ClientIoHandler {
|
||||||
pub client: Arc<Client>,
|
pub client: Arc<Client>,
|
||||||
pub sync: Arc<EthSync>,
|
pub sync: Arc<SyncProvider>,
|
||||||
|
pub net: Arc<ManageNetwork>,
|
||||||
pub accounts: Arc<AccountProvider>,
|
pub accounts: Arc<AccountProvider>,
|
||||||
pub info: Informant,
|
pub info: Informant,
|
||||||
}
|
}
|
||||||
@ -40,7 +41,7 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
|
|||||||
fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) {
|
fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) {
|
||||||
if let INFO_TIMER = timer {
|
if let INFO_TIMER = timer {
|
||||||
let sync_status = self.sync.status();
|
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)));
|
self.info.tick(&self.client, Some((sync_status, network_config)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,12 +85,11 @@ use rustc_serialize::hex::FromHex;
|
|||||||
use ctrlc::CtrlC;
|
use ctrlc::CtrlC;
|
||||||
use util::{H256, ToPretty, PayloadInfo, Bytes, Colour, Applyable, version, journaldb};
|
use util::{H256, ToPretty, PayloadInfo, Bytes, Colour, Applyable, version, journaldb};
|
||||||
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
|
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
|
||||||
use ethcore::client::{BlockID, BlockChainClient, ClientConfig, get_db_path, BlockImportError,
|
use ethcore::client::{BlockID, BlockChainClient, ClientConfig, get_db_path, BlockImportError, Mode};
|
||||||
ChainNotify, Mode};
|
|
||||||
use ethcore::error::{ImportError};
|
use ethcore::error::{ImportError};
|
||||||
use ethcore::service::ClientService;
|
use ethcore::service::ClientService;
|
||||||
use ethcore::spec::Spec;
|
use ethcore::spec::Spec;
|
||||||
use ethsync::{EthSync, NetworkConfiguration};
|
use ethsync::{NetworkConfiguration};
|
||||||
use ethcore::miner::{Miner, MinerService, ExternalMiner};
|
use ethcore::miner::{Miner, MinerService, ExternalMiner};
|
||||||
use migration::migrate;
|
use migration::migrate;
|
||||||
use informant::Informant;
|
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());
|
let network_settings = Arc::new(conf.network_settings());
|
||||||
|
|
||||||
// Sync
|
// Sync
|
||||||
let sync = EthSync::new(sync_config, client.clone(), NetworkConfiguration::from(net_settings))
|
let (sync_provider, manage_network, chain_notify) =
|
||||||
.unwrap_or_else(|e| die_with_error("Sync", ethcore::error::Error::Util(e)));
|
modules::sync(sync_config, NetworkConfiguration::from(net_settings), client.clone())
|
||||||
service.set_notify(&(sync.clone() as Arc<ChainNotify>));
|
.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 network is active by default
|
||||||
if match conf.mode() { Mode::Dark(..) => false, _ => !conf.args.flag_no_network } {
|
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 {
|
let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies {
|
||||||
signer_port: conf.signer_port(),
|
signer_port: conf.signer_port(),
|
||||||
signer_queue: Arc::new(rpc_apis::ConfirmationsQueue::default()),
|
signer_queue: Arc::new(rpc_apis::ConfirmationsQueue::default()),
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
sync: sync.clone(),
|
sync: sync_provider.clone(),
|
||||||
|
net: manage_network.clone(),
|
||||||
secret_store: account_service.clone(),
|
secret_store: account_service.clone(),
|
||||||
miner: miner.clone(),
|
miner: miner.clone(),
|
||||||
external_miner: external_miner.clone(),
|
external_miner: external_miner.clone(),
|
||||||
logger: logger.clone(),
|
logger: logger.clone(),
|
||||||
settings: network_settings.clone(),
|
settings: network_settings.clone(),
|
||||||
allow_pending_receipt_query: !conf.args.flag_geth,
|
allow_pending_receipt_query: !conf.args.flag_geth,
|
||||||
net_service: sync.clone(),
|
net_service: manage_network.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let dependencies = rpc::Dependencies {
|
let dependencies = rpc::Dependencies {
|
||||||
@ -317,7 +321,8 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
|||||||
let io_handler = Arc::new(ClientIoHandler {
|
let io_handler = Arc::new(ClientIoHandler {
|
||||||
client: service.client(),
|
client: service.client(),
|
||||||
info: Informant::new(conf.have_color()),
|
info: Informant::new(conf.have_color()),
|
||||||
sync: sync.clone(),
|
sync: sync_provider.clone(),
|
||||||
|
net: manage_network.clone(),
|
||||||
accounts: account_service.clone(),
|
accounts: account_service.clone(),
|
||||||
});
|
});
|
||||||
service.register_io_handler(io_handler).expect("Error registering IO handler");
|
service.register_io_handler(io_handler).expect("Error registering IO handler");
|
||||||
|
@ -20,17 +20,16 @@ use ethcore::client::{ChainNotify, BlockChainClient};
|
|||||||
use ethcore;
|
use ethcore;
|
||||||
|
|
||||||
#[cfg(feature="ipc")]
|
#[cfg(feature="ipc")]
|
||||||
fn sync(
|
pub fn sync(
|
||||||
sync_cfg: SyncConfig,
|
sync_cfg: SyncConfig,
|
||||||
net_cfg: NetworkConfiguration,
|
net_cfg: NetworkConfiguration,
|
||||||
client: Arc<BlockChainClient>)
|
client: Arc<BlockChainClient>)
|
||||||
-> Result<(Arc<SyncProvider>, Arc<ManageNetwork>, Arc<ChainNotify>), ethcore::error::Error>
|
-> Result<(Arc<SyncProvider>, Arc<ManageNetwork>, Arc<ChainNotify>), ethcore::error::Error>
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature="ipc"))]
|
#[cfg(not(feature="ipc"))]
|
||||||
fn sync(
|
pub fn sync(
|
||||||
sync_cfg: SyncConfig,
|
sync_cfg: SyncConfig,
|
||||||
net_cfg: NetworkConfiguration,
|
net_cfg: NetworkConfiguration,
|
||||||
client: Arc<BlockChainClient>)
|
client: Arc<BlockChainClient>)
|
||||||
|
@ -18,7 +18,7 @@ use std::collections::BTreeMap;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ethsync::{EthSync, ManageNetwork};
|
use ethsync::{ManageNetwork, SyncProvider};
|
||||||
use ethcore::miner::{Miner, ExternalMiner};
|
use ethcore::miner::{Miner, ExternalMiner};
|
||||||
use ethcore::client::Client;
|
use ethcore::client::Client;
|
||||||
use util::RotatingLogger;
|
use util::RotatingLogger;
|
||||||
@ -76,7 +76,8 @@ pub struct Dependencies {
|
|||||||
pub signer_port: Option<u16>,
|
pub signer_port: Option<u16>,
|
||||||
pub signer_queue: Arc<ConfirmationsQueue>,
|
pub signer_queue: Arc<ConfirmationsQueue>,
|
||||||
pub client: Arc<Client>,
|
pub client: Arc<Client>,
|
||||||
pub sync: Arc<EthSync>,
|
pub sync: Arc<SyncProvider>,
|
||||||
|
pub net: Arc<ManageNetwork>,
|
||||||
pub secret_store: Arc<AccountProvider>,
|
pub secret_store: Arc<AccountProvider>,
|
||||||
pub miner: Arc<Miner>,
|
pub miner: Arc<Miner>,
|
||||||
pub external_miner: Arc<ExternalMiner>,
|
pub external_miner: Arc<ExternalMiner>,
|
||||||
|
@ -28,11 +28,11 @@ extern crate ethcore;
|
|||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
|
|
||||||
use std::sync::Arc;
|
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 ctrlc::CtrlC;
|
||||||
use std::sync::atomic::*;
|
use std::sync::atomic::*;
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use ethcore::client::{BlockChainClient, RemoteClient};
|
use ethcore::client::{RemoteClient, ChainNotify};
|
||||||
use nanoipc::*;
|
use nanoipc::*;
|
||||||
use ethsync::{SyncProvider, SyncConfig, EthSync, ManageNetwork, NetworkConfiguration};
|
use ethsync::{SyncProvider, SyncConfig, EthSync, ManageNetwork, NetworkConfiguration};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
@ -74,7 +74,7 @@ impl Args {
|
|||||||
let mut sync_config = SyncConfig::default();
|
let mut sync_config = SyncConfig::default();
|
||||||
sync_config.network_id = U256::from_str(&self.arg_network_id).unwrap();
|
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,
|
udp_port: self.flag_udp_port,
|
||||||
nat_enabled: self.arg_nat_enabled,
|
nat_enabled: self.arg_nat_enabled,
|
||||||
boot_nodes: self.flag_boot_nodes,
|
boot_nodes: self.flag_boot_nodes,
|
||||||
@ -106,8 +106,6 @@ fn run_service<T: ?Sized + Send + Sync + 'static>(addr: &str, stop_guard: Arc<At
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
let args: Args = Docopt::new(USAGE)
|
let args: Args = Docopt::new(USAGE)
|
||||||
.and_then(|d| d.decode())
|
.and_then(|d| d.decode())
|
||||||
.unwrap_or_else(|e| e.exit());
|
.unwrap_or_else(|e| e.exit());
|
||||||
@ -121,6 +119,7 @@ fn main() {
|
|||||||
|
|
||||||
run_service("ipc:///tmp/parity-sync.ipc", stop.clone(), &(sync.clone() as Arc<SyncProvider>));
|
run_service("ipc:///tmp/parity-sync.ipc", stop.clone(), &(sync.clone() as Arc<SyncProvider>));
|
||||||
run_service("ipc:///tmp/parity-manage-net.ipc", stop.clone(), &(sync.clone() as Arc<ManageNetwork>));
|
run_service("ipc:///tmp/parity-manage-net.ipc", stop.clone(), &(sync.clone() as Arc<ManageNetwork>));
|
||||||
|
run_service("ipc:///tmp/parity-sync-notify.ipc", stop.clone(), &(sync.clone() as Arc<ChainNotify>));
|
||||||
|
|
||||||
let hypervisor_client = nanoipc::init_client::<HypervisorServiceClient<_>>(HYPERVISOR_IPC_URL).unwrap();
|
let hypervisor_client = nanoipc::init_client::<HypervisorServiceClient<_>>(HYPERVISOR_IPC_URL).unwrap();
|
||||||
hypervisor_client.handshake().unwrap();
|
hypervisor_client.handshake().unwrap();
|
||||||
|
@ -46,7 +46,7 @@ use v1::impls::{default_gas_price, dispatch_transaction, error_codes};
|
|||||||
use serde;
|
use serde;
|
||||||
|
|
||||||
/// Eth rpc implementation.
|
/// Eth rpc implementation.
|
||||||
pub struct EthClient<C, S, M, EM> where
|
pub struct EthClient<C, S: ?Sized, M, EM> where
|
||||||
C: MiningBlockChainClient,
|
C: MiningBlockChainClient,
|
||||||
S: SyncProvider,
|
S: SyncProvider,
|
||||||
M: MinerService,
|
M: MinerService,
|
||||||
@ -61,7 +61,7 @@ pub struct EthClient<C, S, M, EM> where
|
|||||||
allow_pending_receipt_query: bool,
|
allow_pending_receipt_query: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, S, M, EM> EthClient<C, S, M, EM> where
|
impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
|
||||||
C: MiningBlockChainClient,
|
C: MiningBlockChainClient,
|
||||||
S: SyncProvider,
|
S: SyncProvider,
|
||||||
M: MinerService,
|
M: MinerService,
|
||||||
@ -242,7 +242,7 @@ fn no_author_err() -> Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, S, M, EM> EthClient<C, S, M, EM> where
|
impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
|
||||||
C: MiningBlockChainClient + 'static,
|
C: MiningBlockChainClient + 'static,
|
||||||
S: SyncProvider + 'static,
|
S: SyncProvider + 'static,
|
||||||
M: MinerService + 'static,
|
M: MinerService + 'static,
|
||||||
@ -255,7 +255,7 @@ impl<C, S, M, EM> EthClient<C, S, M, EM> where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
|
impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||||
C: MiningBlockChainClient + 'static,
|
C: MiningBlockChainClient + 'static,
|
||||||
S: SyncProvider + 'static,
|
S: SyncProvider + 'static,
|
||||||
M: MinerService + 'static,
|
M: MinerService + 'static,
|
||||||
|
@ -21,11 +21,11 @@ use ethsync::SyncProvider;
|
|||||||
use v1::traits::Net;
|
use v1::traits::Net;
|
||||||
|
|
||||||
/// Net rpc implementation.
|
/// Net rpc implementation.
|
||||||
pub struct NetClient<S> where S: SyncProvider {
|
pub struct NetClient<S: ?Sized> where S: SyncProvider {
|
||||||
sync: Weak<S>
|
sync: Weak<S>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> NetClient<S> where S: SyncProvider {
|
impl<S: ?Sized> NetClient<S> where S: SyncProvider {
|
||||||
/// Creates new NetClient.
|
/// Creates new NetClient.
|
||||||
pub fn new(sync: &Arc<S>) -> Self {
|
pub fn new(sync: &Arc<S>) -> Self {
|
||||||
NetClient {
|
NetClient {
|
||||||
@ -34,7 +34,7 @@ impl<S> NetClient<S> where S: SyncProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Net for NetClient<S> where S: SyncProvider + 'static {
|
impl<S: ?Sized> Net for NetClient<S> where S: SyncProvider + 'static {
|
||||||
fn version(&self, _: Params) -> Result<Value, Error> {
|
fn version(&self, _: Params) -> Result<Value, Error> {
|
||||||
Ok(Value::String(format!("{}", take_weak!(self.sync).status().network_id).to_owned()))
|
Ok(Value::String(format!("{}", take_weak!(self.sync).status().network_id).to_owned()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user