Merge branch 'master' into issues/4673
This commit is contained in:
@@ -107,8 +107,8 @@ usd_per_eth = "auto"
|
||||
price_update_period = "hourly"
|
||||
gas_floor_target = "4700000"
|
||||
gas_cap = "6283184"
|
||||
tx_queue_size = 1024
|
||||
tx_queue_gas = "auto"
|
||||
tx_queue_size = 8192
|
||||
tx_queue_gas = "off"
|
||||
tx_queue_strategy = "gas_factor"
|
||||
tx_queue_ban_count = 1
|
||||
tx_queue_ban_time = 180 #s
|
||||
@@ -145,3 +145,7 @@ jit = false
|
||||
logging = "own_tx=trace"
|
||||
log_file = "/var/log/parity.log"
|
||||
color = true
|
||||
|
||||
[whisper]
|
||||
enabled = false
|
||||
pool_size = 20
|
||||
|
||||
@@ -56,8 +56,8 @@ reseal_on_txs = "all"
|
||||
reseal_min_period = 4000
|
||||
reseal_max_period = 60000
|
||||
price_update_period = "hourly"
|
||||
tx_queue_size = 1024
|
||||
tx_queue_gas = "auto"
|
||||
tx_queue_size = 8192
|
||||
tx_queue_gas = "off"
|
||||
|
||||
[footprint]
|
||||
tracing = "on"
|
||||
@@ -84,3 +84,7 @@ log_file = "/var/log/parity.log"
|
||||
color = true
|
||||
ports_shift = 0
|
||||
unsafe_expose = false
|
||||
|
||||
[whisper]
|
||||
enabled = true
|
||||
pool_size = 50
|
||||
|
||||
@@ -179,7 +179,7 @@ usage! {
|
||||
or |c: &Config| otry!(c.rpc).interface.clone(),
|
||||
flag_jsonrpc_cors: Option<String> = None,
|
||||
or |c: &Config| otry!(c.rpc).cors.clone().map(Some),
|
||||
flag_jsonrpc_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc,secretstore",
|
||||
flag_jsonrpc_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc,secretstore,shh,shh_pubsub",
|
||||
or |c: &Config| otry!(c.rpc).apis.as_ref().map(|vec| vec.join(",")),
|
||||
flag_jsonrpc_hosts: String = "none",
|
||||
or |c: &Config| otry!(c.rpc).hosts.as_ref().map(|vec| vec.join(",")),
|
||||
@@ -195,7 +195,7 @@ usage! {
|
||||
or |c: &Config| otry!(c.websockets).port.clone(),
|
||||
flag_ws_interface: String = "local",
|
||||
or |c: &Config| otry!(c.websockets).interface.clone(),
|
||||
flag_ws_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc,secretstore",
|
||||
flag_ws_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc,secretstore,shh,shh_pubsub",
|
||||
or |c: &Config| otry!(c.websockets).apis.as_ref().map(|vec| vec.join(",")),
|
||||
flag_ws_origins: String = "chrome-extension://*",
|
||||
or |c: &Config| otry!(c.websockets).origins.as_ref().map(|vec| vec.join(",")),
|
||||
@@ -207,7 +207,7 @@ usage! {
|
||||
or |c: &Config| otry!(c.ipc).disable.clone(),
|
||||
flag_ipc_path: String = if cfg!(windows) { r"\\.\pipe\jsonrpc.ipc" } else { "$BASE/jsonrpc.ipc" },
|
||||
or |c: &Config| otry!(c.ipc).path.clone(),
|
||||
flag_ipc_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,parity_accounts,traces,rpc,secretstore",
|
||||
flag_ipc_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,parity_accounts,traces,rpc,secretstore,shh,shh_pubsub",
|
||||
or |c: &Config| otry!(c.ipc).apis.as_ref().map(|vec| vec.join(",")),
|
||||
|
||||
// DAPPS
|
||||
@@ -283,9 +283,11 @@ usage! {
|
||||
or |c: &Config| otry!(c.mining).gas_cap.clone(),
|
||||
flag_extra_data: Option<String> = None,
|
||||
or |c: &Config| otry!(c.mining).extra_data.clone().map(Some),
|
||||
flag_tx_queue_size: usize = 1024usize,
|
||||
flag_tx_queue_size: usize = 8192usize,
|
||||
or |c: &Config| otry!(c.mining).tx_queue_size.clone(),
|
||||
flag_tx_queue_gas: String = "auto",
|
||||
flag_tx_queue_mem_limit: u32 = 2u32,
|
||||
or |c: &Config| otry!(c.mining).tx_queue_mem_limit.clone(),
|
||||
flag_tx_queue_gas: String = "off",
|
||||
or |c: &Config| otry!(c.mining).tx_queue_gas.clone(),
|
||||
flag_tx_queue_strategy: String = "gas_price",
|
||||
or |c: &Config| otry!(c.mining).tx_queue_strategy.clone(),
|
||||
@@ -368,6 +370,12 @@ usage! {
|
||||
flag_no_color: bool = false,
|
||||
or |c: &Config| otry!(c.misc).color.map(|c| !c).clone(),
|
||||
|
||||
// -- Whisper options
|
||||
flag_whisper: bool = false,
|
||||
or |c: &Config| otry!(c.whisper).enabled,
|
||||
flag_whisper_pool_size: usize = 10usize,
|
||||
or |c: &Config| otry!(c.whisper).pool_size.clone(),
|
||||
|
||||
// -- Legacy Options supported in configs
|
||||
flag_dapps_port: Option<u16> = None,
|
||||
or |c: &Config| otry!(c.dapps).port.clone().map(Some),
|
||||
@@ -410,6 +418,7 @@ struct Config {
|
||||
vm: Option<VM>,
|
||||
misc: Option<Misc>,
|
||||
stratum: Option<Stratum>,
|
||||
whisper: Option<Whisper>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
@@ -552,6 +561,7 @@ struct Mining {
|
||||
gas_cap: Option<String>,
|
||||
extra_data: Option<String>,
|
||||
tx_queue_size: Option<usize>,
|
||||
tx_queue_mem_limit: Option<u32>,
|
||||
tx_queue_gas: Option<String>,
|
||||
tx_queue_strategy: Option<String>,
|
||||
tx_queue_ban_count: Option<u16>,
|
||||
@@ -606,12 +616,18 @@ struct Misc {
|
||||
unsafe_expose: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
struct Whisper {
|
||||
enabled: Option<bool>,
|
||||
pool_size: Option<usize>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
Args, ArgsError,
|
||||
Config, Operating, Account, Ui, Network, Ws, Rpc, Ipc, Dapps, Ipfs, Mining, Footprint,
|
||||
Snapshots, VM, Misc, SecretStore,
|
||||
Snapshots, VM, Misc, Whisper, SecretStore,
|
||||
};
|
||||
use toml;
|
||||
|
||||
@@ -818,8 +834,9 @@ mod tests {
|
||||
flag_gas_floor_target: "4700000".into(),
|
||||
flag_gas_cap: "6283184".into(),
|
||||
flag_extra_data: Some("Parity".into()),
|
||||
flag_tx_queue_size: 1024usize,
|
||||
flag_tx_queue_gas: "auto".into(),
|
||||
flag_tx_queue_size: 8192usize,
|
||||
flag_tx_queue_mem_limit: 2u32,
|
||||
flag_tx_queue_gas: "off".into(),
|
||||
flag_tx_queue_strategy: "gas_factor".into(),
|
||||
flag_tx_queue_ban_count: 1u16,
|
||||
flag_tx_queue_ban_time: 180u16,
|
||||
@@ -865,6 +882,10 @@ mod tests {
|
||||
// -- Virtual Machine Options
|
||||
flag_jitvm: false,
|
||||
|
||||
// -- Whisper options.
|
||||
flag_whisper: false,
|
||||
flag_whisper_pool_size: 20,
|
||||
|
||||
// -- Legacy Options
|
||||
flag_geth: false,
|
||||
flag_testnet: false,
|
||||
@@ -1045,8 +1066,9 @@ mod tests {
|
||||
price_update_period: Some("hourly".into()),
|
||||
gas_floor_target: None,
|
||||
gas_cap: None,
|
||||
tx_queue_size: Some(1024),
|
||||
tx_queue_gas: Some("auto".into()),
|
||||
tx_queue_size: Some(8192),
|
||||
tx_queue_mem_limit: None,
|
||||
tx_queue_gas: Some("off".into()),
|
||||
tx_queue_strategy: None,
|
||||
tx_queue_ban_count: None,
|
||||
tx_queue_ban_time: None,
|
||||
@@ -1087,6 +1109,10 @@ mod tests {
|
||||
ports_shift: Some(0),
|
||||
unsafe_expose: Some(false),
|
||||
}),
|
||||
whisper: Some(Whisper {
|
||||
enabled: Some(true),
|
||||
pool_size: Some(50),
|
||||
}),
|
||||
stratum: None,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -316,6 +316,9 @@ Sealing/Mining Options:
|
||||
block due to transaction volume (default: {flag_gas_cap}).
|
||||
--extra-data STRING Specify a custom extra-data for authored blocks, no
|
||||
more than 32 characters. (default: {flag_extra_data:?})
|
||||
--tx-queue-mem-limit MB Maximum amount of memory that can be used by the
|
||||
transaction queue. Setting this parameter to 0
|
||||
disables limiting (default: {flag_tx_queue_mem_limit}).
|
||||
--tx-queue-size LIMIT Maximum amount of transactions in the queue (waiting
|
||||
to be included in next block) (default: {flag_tx_queue_size}).
|
||||
--tx-queue-gas LIMIT Maximum amount of total gas for external transactions in
|
||||
@@ -427,6 +430,11 @@ Snapshot Options:
|
||||
Virtual Machine Options:
|
||||
--jitvm Enable the JIT VM. (default: {flag_jitvm})
|
||||
|
||||
Whisper Options:
|
||||
--whisper Enable the Whisper network. (default: {flag_whisper})
|
||||
--whisper-pool-size MB Target size of the whisper message pool in megabytes.
|
||||
(default: {flag_whisper_pool_size})
|
||||
|
||||
Legacy Options:
|
||||
--geth Run in Geth-compatibility mode. Sets the IPC path
|
||||
to be the same as Geth's. Overrides the --ipc-path
|
||||
|
||||
@@ -331,6 +331,7 @@ impl Configuration {
|
||||
};
|
||||
|
||||
let verifier_settings = self.verifier_settings();
|
||||
let whisper_config = self.whisper_config();
|
||||
|
||||
let run_cmd = RunCmd {
|
||||
cache_config: cache_config,
|
||||
@@ -377,6 +378,7 @@ impl Configuration {
|
||||
serve_light: !self.args.flag_no_serve_light,
|
||||
light: self.args.flag_light,
|
||||
no_persistent_txqueue: self.args.flag_no_persistent_txqueue,
|
||||
whisper: whisper_config,
|
||||
};
|
||||
Cmd::Run(run_cmd)
|
||||
};
|
||||
@@ -401,7 +403,6 @@ impl Configuration {
|
||||
extra_data: self.extra_data()?,
|
||||
gas_floor_target: to_u256(&self.args.flag_gas_floor_target)?,
|
||||
gas_ceil_target: to_u256(&self.args.flag_gas_cap)?,
|
||||
transactions_limit: self.args.flag_tx_queue_size,
|
||||
engine_signer: self.engine_signer()?,
|
||||
};
|
||||
|
||||
@@ -526,6 +527,9 @@ impl Configuration {
|
||||
None => U256::max_value(),
|
||||
},
|
||||
tx_queue_size: self.args.flag_tx_queue_size,
|
||||
tx_queue_memory_limit: if self.args.flag_tx_queue_mem_limit > 0 {
|
||||
Some(self.args.flag_tx_queue_mem_limit as usize * 1024 * 1024)
|
||||
} else { None },
|
||||
tx_queue_gas_limit: to_gas_limit(&self.args.flag_tx_queue_gas)?,
|
||||
tx_queue_strategy: to_queue_strategy(&self.args.flag_tx_queue_strategy)?,
|
||||
pending_set: to_pending_set(&self.args.flag_relay_set)?,
|
||||
@@ -1062,6 +1066,13 @@ impl Configuration {
|
||||
|
||||
settings
|
||||
}
|
||||
|
||||
fn whisper_config(&self) -> ::whisper::Config {
|
||||
::whisper::Config {
|
||||
enabled: self.args.flag_whisper,
|
||||
target_message_pool_size: self.args.flag_whisper_pool_size * 1024 * 1024,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1293,7 +1304,7 @@ mod tests {
|
||||
public_node: false,
|
||||
warp_sync: true,
|
||||
acc_conf: Default::default(),
|
||||
gas_pricer: Default::default(),
|
||||
gas_pricer_conf: Default::default(),
|
||||
miner_extras: Default::default(),
|
||||
update_policy: UpdatePolicy { enable_downloading: true, require_consensus: true, filter: UpdateFilter::Critical, track: ReleaseTrack::Unknown, path: default_hypervisor_path() },
|
||||
mode: Default::default(),
|
||||
@@ -1320,6 +1331,7 @@ mod tests {
|
||||
serve_light: true,
|
||||
light: false,
|
||||
no_persistent_txqueue: false,
|
||||
whisper: Default::default(),
|
||||
};
|
||||
expected.secretstore_conf.enabled = cfg!(feature = "secretstore");
|
||||
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Run(expected));
|
||||
@@ -1588,7 +1600,7 @@ mod tests {
|
||||
match conf.into_command().unwrap().cmd {
|
||||
Cmd::Run(c) => {
|
||||
assert_eq!(c.net_settings.chain, "dev");
|
||||
assert_eq!(c.gas_pricer, GasPricerConfig::Fixed(0.into()));
|
||||
assert_eq!(c.gas_pricer_conf, GasPricerConfig::Fixed(0.into()));
|
||||
assert_eq!(c.miner_options.reseal_min_period, Duration::from_millis(0));
|
||||
},
|
||||
_ => panic!("Should be Cmd::Run"),
|
||||
|
||||
@@ -254,21 +254,24 @@ impl<T: InformantData> Informant<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
*self.last_tick.write() = Instant::now();
|
||||
|
||||
let (client_report, full_report) = {
|
||||
let mut last_report = self.last_report.lock();
|
||||
let full_report = self.target.report();
|
||||
let diffed = full_report.client_report.clone() - &*last_report;
|
||||
*last_report = full_report.client_report.clone();
|
||||
(diffed, full_report)
|
||||
};
|
||||
|
||||
let Report {
|
||||
importing,
|
||||
chain_info,
|
||||
client_report,
|
||||
queue_info,
|
||||
cache_sizes,
|
||||
sync_info,
|
||||
} = self.target.report();
|
||||
|
||||
let client_report = {
|
||||
let mut last_report = self.last_report.lock();
|
||||
let diffed = client_report.clone() - &*last_report;
|
||||
*last_report = client_report.clone();
|
||||
diffed
|
||||
};
|
||||
..
|
||||
} = full_report;
|
||||
|
||||
let rpc_stats = self.rpc_stats.as_ref();
|
||||
|
||||
@@ -284,8 +287,6 @@ impl<T: InformantData> Informant<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
*self.last_tick.write() = Instant::now();
|
||||
|
||||
let paint = |c: Style, t: String| match self.with_color && stdout_isatty() {
|
||||
true => format!("{}", c.paint(t)),
|
||||
false => t,
|
||||
|
||||
@@ -63,6 +63,7 @@ extern crate parity_local_store as local_store;
|
||||
extern crate parity_reactor;
|
||||
extern crate parity_rpc;
|
||||
extern crate parity_updater as updater;
|
||||
extern crate parity_whisper;
|
||||
extern crate path;
|
||||
extern crate rpc_cli;
|
||||
|
||||
@@ -110,6 +111,7 @@ mod snapshot;
|
||||
mod upgrade;
|
||||
mod url;
|
||||
mod user_defaults;
|
||||
mod whisper;
|
||||
|
||||
#[cfg(feature="ipc")]
|
||||
mod boot;
|
||||
@@ -364,4 +366,3 @@ fn main() {
|
||||
process::exit(main_direct(can_restart));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::path::Path;
|
||||
|
||||
use ethcore::client::BlockChainClient;
|
||||
use hypervisor::Hypervisor;
|
||||
use ethsync::{SyncConfig, NetworkConfiguration, NetworkError, Params};
|
||||
use ethsync::{AttachedProtocol, SyncConfig, NetworkConfiguration, NetworkError, Params};
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use light::Provider;
|
||||
|
||||
@@ -151,6 +151,7 @@ pub fn sync(
|
||||
_snapshot_service: Arc<SnapshotService>,
|
||||
_provider: Arc<Provider>,
|
||||
log_settings: &LogConfig,
|
||||
_attached_protos: Vec<AttachedProtocol>,
|
||||
) -> Result<SyncModules, NetworkError> {
|
||||
let mut hypervisor = hypervisor_ref.take().expect("There should be hypervisor for ipc configuration");
|
||||
let args = sync_arguments(&hypervisor.io_path, sync_cfg, net_cfg, log_settings);
|
||||
@@ -181,6 +182,7 @@ pub fn sync(
|
||||
snapshot_service: Arc<SnapshotService>,
|
||||
provider: Arc<Provider>,
|
||||
_log_settings: &LogConfig,
|
||||
attached_protos: Vec<AttachedProtocol>,
|
||||
) -> Result<SyncModules, NetworkError> {
|
||||
let eth_sync = EthSync::new(Params {
|
||||
config: sync_cfg,
|
||||
@@ -188,6 +190,7 @@ pub fn sync(
|
||||
provider: provider,
|
||||
snapshot_service: snapshot_service,
|
||||
network_config: net_cfg,
|
||||
attached_protos: attached_protos,
|
||||
})?;
|
||||
|
||||
Ok((eth_sync.clone() as Arc<SyncProvider>, eth_sync.clone() as Arc<ManageNetwork>, eth_sync.clone() as Arc<ChainNotify>))
|
||||
|
||||
@@ -22,6 +22,7 @@ use ethcore::spec::Spec;
|
||||
use ethcore::ethereum;
|
||||
use ethcore::client::Mode;
|
||||
use ethcore::miner::{GasPricer, GasPriceCalibratorOptions};
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -226,15 +227,18 @@ impl Default for GasPricerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<GasPricer> for GasPricerConfig {
|
||||
fn into(self) -> GasPricer {
|
||||
match self {
|
||||
impl GasPricerConfig {
|
||||
pub fn to_gas_pricer(&self, fetch: FetchClient) -> GasPricer {
|
||||
match *self {
|
||||
GasPricerConfig::Fixed(u) => GasPricer::Fixed(u),
|
||||
GasPricerConfig::Calibrated { usd_per_tx, recalibration_period, .. } => {
|
||||
GasPricer::new_calibrated(GasPriceCalibratorOptions {
|
||||
usd_per_tx: usd_per_tx,
|
||||
recalibration_period: recalibration_period,
|
||||
})
|
||||
GasPricer::new_calibrated(
|
||||
GasPriceCalibratorOptions {
|
||||
usd_per_tx: usd_per_tx,
|
||||
recalibration_period: recalibration_period,
|
||||
},
|
||||
fetch
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,7 +250,6 @@ pub struct MinerExtras {
|
||||
pub extra_data: Vec<u8>,
|
||||
pub gas_floor_target: U256,
|
||||
pub gas_ceil_target: U256,
|
||||
pub transactions_limit: usize,
|
||||
pub engine_signer: Address,
|
||||
}
|
||||
|
||||
@@ -257,7 +260,6 @@ impl Default for MinerExtras {
|
||||
extra_data: version_data(),
|
||||
gas_floor_target: U256::from(4_700_000),
|
||||
gas_ceil_target: U256::from(6_283_184),
|
||||
transactions_limit: 1024,
|
||||
engine_signer: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ pub use parity_rpc::{IpcServer, HttpServer, RequestMiddleware};
|
||||
pub use parity_rpc::ws::Server as WsServer;
|
||||
pub use parity_rpc::informant::CpuPool;
|
||||
|
||||
|
||||
pub const DAPPS_DOMAIN: &'static str = "web3.site";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -168,7 +167,6 @@ impl Default for WsConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl WsConfiguration {
|
||||
pub fn address(&self) -> Option<(String, u16)> {
|
||||
match self.enabled {
|
||||
|
||||
@@ -67,6 +67,12 @@ pub enum Api {
|
||||
Rpc,
|
||||
/// SecretStore (Safe)
|
||||
SecretStore,
|
||||
/// Whisper (Safe)
|
||||
// TODO: _if_ someone guesses someone else's key or filter IDs they can remove
|
||||
// BUT these are all ephemeral so it seems fine.
|
||||
Whisper,
|
||||
/// Whisper Pub-Sub (Safe but same concerns as above).
|
||||
WhisperPubSub,
|
||||
}
|
||||
|
||||
impl FromStr for Api {
|
||||
@@ -89,6 +95,8 @@ impl FromStr for Api {
|
||||
"traces" => Ok(Traces),
|
||||
"rpc" => Ok(Rpc),
|
||||
"secretstore" => Ok(SecretStore),
|
||||
"shh" => Ok(Whisper),
|
||||
"shh_pubsub" => Ok(WhisperPubSub),
|
||||
api => Err(format!("Unknown api: {}", api))
|
||||
}
|
||||
}
|
||||
@@ -172,6 +180,8 @@ fn to_modules(apis: &HashSet<Api>) -> BTreeMap<String, String> {
|
||||
Api::Traces => ("traces", "1.0"),
|
||||
Api::Rpc => ("rpc", "1.0"),
|
||||
Api::SecretStore => ("secretstore", "1.0"),
|
||||
Api::Whisper => ("shh", "1.0"),
|
||||
Api::WhisperPubSub => ("shh_pubsub", "1.0"),
|
||||
};
|
||||
modules.insert(name.into(), version.into());
|
||||
}
|
||||
@@ -213,6 +223,7 @@ pub struct FullDependencies {
|
||||
pub ws_address: Option<(String, u16)>,
|
||||
pub fetch: FetchClient,
|
||||
pub remote: parity_reactor::Remote,
|
||||
pub whisper_rpc: Option<::whisper::RpcFactory>,
|
||||
}
|
||||
|
||||
impl FullDependencies {
|
||||
@@ -335,6 +346,18 @@ impl FullDependencies {
|
||||
Api::SecretStore => {
|
||||
handler.extend_with(SecretStoreClient::new(&self.secret_store).to_delegate());
|
||||
},
|
||||
Api::Whisper => {
|
||||
if let Some(ref whisper_rpc) = self.whisper_rpc {
|
||||
let whisper = whisper_rpc.make_handler();
|
||||
handler.extend_with(::parity_whisper::rpc::Whisper::to_delegate(whisper));
|
||||
}
|
||||
}
|
||||
Api::WhisperPubSub => {
|
||||
if let Some(ref whisper_rpc) = self.whisper_rpc {
|
||||
let whisper = whisper_rpc.make_handler();
|
||||
handler.extend_with(::parity_whisper::rpc::WhisperPubSub::to_delegate(whisper));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -383,6 +406,7 @@ pub struct LightDependencies {
|
||||
pub fetch: FetchClient,
|
||||
pub geth_compatibility: bool,
|
||||
pub remote: parity_reactor::Remote,
|
||||
pub whisper_rpc: Option<::whisper::RpcFactory>,
|
||||
}
|
||||
|
||||
impl LightDependencies {
|
||||
@@ -516,6 +540,18 @@ impl LightDependencies {
|
||||
let secret_store = Some(self.secret_store.clone());
|
||||
handler.extend_with(SecretStoreClient::new(&secret_store).to_delegate());
|
||||
},
|
||||
Api::Whisper => {
|
||||
if let Some(ref whisper_rpc) = self.whisper_rpc {
|
||||
let whisper = whisper_rpc.make_handler();
|
||||
handler.extend_with(::parity_whisper::rpc::Whisper::to_delegate(whisper));
|
||||
}
|
||||
}
|
||||
Api::WhisperPubSub => {
|
||||
if let Some(ref whisper_rpc) = self.whisper_rpc {
|
||||
let whisper = whisper_rpc.make_handler();
|
||||
handler.extend_with(::parity_whisper::rpc::WhisperPubSub::to_delegate(whisper));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -543,8 +579,17 @@ impl ApiSet {
|
||||
|
||||
pub fn list_apis(&self) -> HashSet<Api> {
|
||||
let mut public_list = [
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::Rpc, Api::SecretStore,
|
||||
Api::Web3,
|
||||
Api::Net,
|
||||
Api::Eth,
|
||||
Api::EthPubSub,
|
||||
Api::Parity,
|
||||
Api::Rpc,
|
||||
Api::SecretStore,
|
||||
Api::Whisper,
|
||||
Api::WhisperPubSub,
|
||||
].into_iter().cloned().collect();
|
||||
|
||||
match *self {
|
||||
ApiSet::List(ref apis) => apis.clone(),
|
||||
ApiSet::PublicContext => public_list,
|
||||
@@ -605,6 +650,8 @@ mod test {
|
||||
assert_eq!(Api::Traces, "traces".parse().unwrap());
|
||||
assert_eq!(Api::Rpc, "rpc".parse().unwrap());
|
||||
assert_eq!(Api::SecretStore, "secretstore".parse().unwrap());
|
||||
assert_eq!(Api::Whisper, "shh".parse().unwrap());
|
||||
assert_eq!(Api::WhisperPubSub, "shh_pubsub".parse().unwrap());
|
||||
assert!("rp".parse::<Api>().is_err());
|
||||
}
|
||||
|
||||
@@ -622,7 +669,7 @@ mod test {
|
||||
fn test_api_set_unsafe_context() {
|
||||
let expected = vec![
|
||||
// make sure this list contains only SAFE methods
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore, Api::Whisper, Api::WhisperPubSub,
|
||||
].into_iter().collect();
|
||||
assert_eq!(ApiSet::UnsafeContext.list_apis(), expected);
|
||||
}
|
||||
@@ -631,7 +678,7 @@ mod test {
|
||||
fn test_api_set_ipc_context() {
|
||||
let expected = vec![
|
||||
// safe
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore,
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore, Api::Whisper, Api::WhisperPubSub,
|
||||
// semi-safe
|
||||
Api::ParityAccounts
|
||||
].into_iter().collect();
|
||||
@@ -642,7 +689,7 @@ mod test {
|
||||
fn test_api_set_safe_context() {
|
||||
let expected = vec![
|
||||
// safe
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore,
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore, Api::Whisper, Api::WhisperPubSub,
|
||||
// semi-safe
|
||||
Api::ParityAccounts,
|
||||
// Unsafe
|
||||
@@ -654,7 +701,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_all_apis() {
|
||||
assert_eq!("all".parse::<ApiSet>().unwrap(), ApiSet::List(vec![
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore,
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore, Api::Whisper, Api::WhisperPubSub,
|
||||
Api::ParityAccounts,
|
||||
Api::ParitySet, Api::Signer,
|
||||
Api::Personal
|
||||
@@ -664,7 +711,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_all_without_personal_apis() {
|
||||
assert_eq!("personal,all,-personal".parse::<ApiSet>().unwrap(), ApiSet::List(vec![
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore,
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore, Api::Whisper, Api::WhisperPubSub,
|
||||
Api::ParityAccounts,
|
||||
Api::ParitySet, Api::Signer,
|
||||
].into_iter().collect()));
|
||||
@@ -673,7 +720,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_safe_parsing() {
|
||||
assert_eq!("safe".parse::<ApiSet>().unwrap(), ApiSet::List(vec![
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore,
|
||||
Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity, Api::ParityPubSub, Api::Traces, Api::Rpc, Api::SecretStore, Api::Whisper, Api::WhisperPubSub,
|
||||
].into_iter().collect()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ pub struct RunCmd {
|
||||
pub warp_sync: bool,
|
||||
pub public_node: bool,
|
||||
pub acc_conf: AccountsConfig,
|
||||
pub gas_pricer: GasPricerConfig,
|
||||
pub gas_pricer_conf: GasPricerConfig,
|
||||
pub miner_extras: MinerExtras,
|
||||
pub update_policy: UpdatePolicy,
|
||||
pub mode: Option<Mode>,
|
||||
@@ -115,6 +115,7 @@ pub struct RunCmd {
|
||||
pub serve_light: bool,
|
||||
pub light: bool,
|
||||
pub no_persistent_txqueue: bool,
|
||||
pub whisper: ::whisper::Config
|
||||
}
|
||||
|
||||
pub fn open_ui(ws_conf: &rpc::WsConfiguration, ui_conf: &rpc::UiConfiguration) -> Result<(), String> {
|
||||
@@ -230,6 +231,17 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
|
||||
// start on_demand service.
|
||||
let on_demand = Arc::new(::light::on_demand::OnDemand::new(cache.clone()));
|
||||
|
||||
let mut attached_protos = Vec::new();
|
||||
let whisper_factory = if cmd.whisper.enabled {
|
||||
let (whisper_net, whisper_factory) = ::whisper::setup(cmd.whisper.target_message_pool_size)
|
||||
.map_err(|e| format!("Failed to initialize whisper: {}", e))?;
|
||||
|
||||
attached_protos.push(whisper_net);
|
||||
whisper_factory
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// set network path.
|
||||
net_conf.net_config_path = Some(db_dirs.network_path().to_string_lossy().into_owned());
|
||||
let sync_params = LightSyncParams {
|
||||
@@ -238,6 +250,7 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
|
||||
network_id: cmd.network_id.unwrap_or(spec.network_id()),
|
||||
subprotocol_name: ethsync::LIGHT_PROTOCOL,
|
||||
handlers: vec![on_demand.clone()],
|
||||
attached_protos: attached_protos,
|
||||
};
|
||||
let light_sync = LightSync::new(sync_params).map_err(|e| format!("Error starting network: {}", e))?;
|
||||
let light_sync = Arc::new(light_sync);
|
||||
@@ -318,6 +331,7 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
|
||||
fetch: fetch,
|
||||
geth_compatibility: cmd.geth_compatibility,
|
||||
remote: event_loop.remote(),
|
||||
whisper_rpc: whisper_factory,
|
||||
});
|
||||
|
||||
let dependencies = rpc::Dependencies {
|
||||
@@ -466,14 +480,16 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
// prepare account provider
|
||||
let account_provider = Arc::new(prepare_account_provider(&cmd.spec, &cmd.dirs, &spec.data_dir, cmd.acc_conf, &passwords)?);
|
||||
|
||||
// fetch service
|
||||
let fetch = FetchClient::new().map_err(|e| format!("Error starting fetch client: {:?}", e))?;
|
||||
|
||||
// create miner
|
||||
let initial_min_gas_price = cmd.gas_pricer.initial_min();
|
||||
let miner = Miner::new(cmd.miner_options, cmd.gas_pricer.into(), &spec, Some(account_provider.clone()));
|
||||
let initial_min_gas_price = cmd.gas_pricer_conf.initial_min();
|
||||
let miner = Miner::new(cmd.miner_options, cmd.gas_pricer_conf.to_gas_pricer(fetch.clone()), &spec, Some(account_provider.clone()));
|
||||
miner.set_author(cmd.miner_extras.author);
|
||||
miner.set_gas_floor_target(cmd.miner_extras.gas_floor_target);
|
||||
miner.set_gas_ceil_target(cmd.miner_extras.gas_ceil_target);
|
||||
miner.set_extra_data(cmd.miner_extras.extra_data);
|
||||
miner.set_transactions_limit(cmd.miner_extras.transactions_limit);
|
||||
miner.set_minimal_gas_price(initial_min_gas_price);
|
||||
miner.recalibrate_minimal_gas_price();
|
||||
let engine_signer = cmd.miner_extras.engine_signer;
|
||||
@@ -590,6 +606,18 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
.map_err(|e| format!("Stratum start error: {:?}", e))?;
|
||||
}
|
||||
|
||||
let mut attached_protos = Vec::new();
|
||||
|
||||
let whisper_factory = if cmd.whisper.enabled {
|
||||
let (whisper_net, whisper_factory) = ::whisper::setup(cmd.whisper.target_message_pool_size)
|
||||
.map_err(|e| format!("Failed to initialize whisper: {}", e))?;
|
||||
|
||||
attached_protos.push(whisper_net);
|
||||
whisper_factory
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// create sync object
|
||||
let (sync_provider, manage_network, chain_notify) = modules::sync(
|
||||
&mut hypervisor,
|
||||
@@ -599,6 +627,7 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
snapshot_service.clone(),
|
||||
client.clone(),
|
||||
&cmd.logger_config,
|
||||
attached_protos,
|
||||
).map_err(|e| format!("Sync error: {}", e))?;
|
||||
|
||||
service.add_notify(chain_notify.clone());
|
||||
@@ -611,9 +640,6 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
// spin up event loop
|
||||
let event_loop = EventLoop::spawn();
|
||||
|
||||
// fetch service
|
||||
let fetch = FetchClient::new().map_err(|e| format!("Error starting fetch client: {:?}", e))?;
|
||||
|
||||
// the updater service
|
||||
let updater = Updater::new(
|
||||
Arc::downgrade(&(service.client() as Arc<BlockChainClient>)),
|
||||
@@ -682,6 +708,7 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
ws_address: cmd.ws_conf.address(),
|
||||
fetch: fetch.clone(),
|
||||
remote: event_loop.remote(),
|
||||
whisper_rpc: whisper_factory,
|
||||
});
|
||||
|
||||
let dependencies = rpc::Dependencies {
|
||||
|
||||
@@ -52,11 +52,12 @@ pub fn main() {
|
||||
let remote_provider = dependency!(LightProviderClient, &service_urls::with_base(&service_config.io_path, service_urls::LIGHT_PROVIDER));
|
||||
|
||||
let sync = EthSync::new(Params {
|
||||
config: service_config.sync,
|
||||
chain: remote_client.service().clone(),
|
||||
snapshot_service: remote_snapshot.service().clone(),
|
||||
config: service_config.sync,
|
||||
chain: remote_client.service().clone(),
|
||||
snapshot_service: remote_snapshot.service().clone(),
|
||||
provider: remote_provider.service().clone(),
|
||||
network_config: service_config.net
|
||||
attached_protos: Vec::new(),
|
||||
}).unwrap();
|
||||
|
||||
let _ = boot::main_thread();
|
||||
|
||||
77
parity/whisper.rs
Normal file
77
parity/whisper.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright 2015-2017 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 std::sync::Arc;
|
||||
use std::io;
|
||||
|
||||
use ethsync::AttachedProtocol;
|
||||
use parity_rpc::Metadata;
|
||||
use parity_whisper::net::{self as whisper_net, PoolHandle, Network as WhisperNetwork};
|
||||
use parity_whisper::rpc::{WhisperClient, FilterManager};
|
||||
|
||||
/// Whisper config.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Config {
|
||||
pub enabled: bool,
|
||||
pub target_message_pool_size: usize,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
enabled: false,
|
||||
target_message_pool_size: 10 * 1024 * 1024,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Factory for standard whisper RPC.
|
||||
pub struct RpcFactory {
|
||||
net: Arc<WhisperNetwork<Arc<FilterManager>>>,
|
||||
manager: Arc<FilterManager>,
|
||||
}
|
||||
|
||||
impl RpcFactory {
|
||||
pub fn make_handler(&self) -> WhisperClient<PoolHandle, Metadata> {
|
||||
WhisperClient::new(self.net.handle(), self.manager.clone())
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets up whisper protocol and RPC handler.
|
||||
///
|
||||
/// Will target the given pool size.
|
||||
#[cfg(not(feature = "ipc"))]
|
||||
pub fn setup(target_pool_size: usize) -> io::Result<(AttachedProtocol, Option<RpcFactory>)> {
|
||||
let manager = Arc::new(FilterManager::new()?);
|
||||
let net = Arc::new(WhisperNetwork::new(target_pool_size, manager.clone()));
|
||||
|
||||
let proto = AttachedProtocol {
|
||||
handler: net.clone() as Arc<_>,
|
||||
packet_count: whisper_net::PACKET_COUNT,
|
||||
versions: whisper_net::SUPPORTED_VERSIONS,
|
||||
protocol_id: *b"shh",
|
||||
};
|
||||
|
||||
let factory = RpcFactory { net: net, manager: manager };
|
||||
|
||||
Ok((proto, Some(factory)))
|
||||
}
|
||||
|
||||
// TODO: make it possible to attach generic protocols in IPC.
|
||||
#[cfg(feature = "ipc")]
|
||||
pub fn setup(_pool: usize) -> (AttachedProtocol, Option<RpcFactory>) {
|
||||
Ok((AttachedProtocol, None))
|
||||
}
|
||||
Reference in New Issue
Block a user