From e8ce616eb238a512d75a405aec1128b687b2b277 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 13 Jun 2018 12:32:58 +0200 Subject: [PATCH] Allow Poll Lifetime to be configured via CLI ... rather than it being a hard-coded constant. fixes #5484 . --- parity/cli/mod.rs | 7 +++++++ parity/configuration.rs | 2 ++ parity/rpc_apis.rs | 6 +++++- parity/run.rs | 3 +++ rpc/src/v1/helpers/poll_manager.rs | 15 ++++++--------- rpc/src/v1/impls/eth.rs | 3 +++ rpc/src/v1/impls/eth_filter.rs | 4 ++-- rpc/src/v1/impls/light/eth.rs | 8 ++++++-- rpc/src/v1/tests/mocked/eth.rs | 3 ++- 9 files changed, 36 insertions(+), 15 deletions(-) diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index b5f29dbad90..4faf12946df 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -732,6 +732,10 @@ usage! { "--gas-price-percentile=[PCT]", "Set PCT percentile gas price value from last 100 blocks as default gas price when sending transactions.", + ARG arg_poll_lifetime: (u32) = 60u32, or |c: &Config| c.mining.as_ref()?.poll_lifetime.clone(), + "--poll-lifetime=[S]", + "Set the lifetime of the internal index filter to S seconds.", + ARG arg_author: (Option) = None, or |c: &Config| c.mining.as_ref()?.author.clone(), "--author=[ADDRESS]", "Specify the block author (aka \"coinbase\") address for sending block rewards from sealed blocks. NOTE: MINING WILL NOT WORK WITHOUT THIS OPTION.", // Sealing/Mining Option @@ -1241,6 +1245,7 @@ struct Mining { relay_set: Option, min_gas_price: Option, gas_price_percentile: Option, + poll_lifetime: Option, usd_per_tx: Option, usd_per_eth: Option, price_update_period: Option, @@ -1664,6 +1669,7 @@ mod tests { arg_min_gas_price: Some(0u64), arg_usd_per_tx: "0.0001".into(), arg_gas_price_percentile: 50usize, + arg_poll_lifetime: 60u32, arg_usd_per_eth: "auto".into(), arg_price_update_period: "hourly".into(), arg_gas_floor_target: "4700000".into(), @@ -1924,6 +1930,7 @@ mod tests { relay_set: None, min_gas_price: None, gas_price_percentile: None, + poll_lifetime: None, usd_per_tx: None, usd_per_eth: None, price_update_period: Some("hourly".into()), diff --git a/parity/configuration.rs b/parity/configuration.rs index 2b8bd820f18..8019be516f7 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -356,6 +356,7 @@ impl Configuration { logger_config: logger_config.clone(), miner_options: self.miner_options()?, gas_price_percentile: self.args.arg_gas_price_percentile, + poll_lifetime: self.args.arg_poll_lifetime, ntp_servers: self.ntp_servers(), ws_conf: ws_conf, http_conf: http_conf, @@ -1398,6 +1399,7 @@ mod tests { logger_config: Default::default(), miner_options: Default::default(), gas_price_percentile: 50, + poll_lifetime: 60, ntp_servers: vec![ "0.parity.pool.ntp.org:123".into(), "1.parity.pool.ntp.org:123".into(), diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index 31af69eaa06..d76438b1594 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -235,6 +235,7 @@ pub struct FullDependencies { pub remote: parity_reactor::Remote, pub whisper_rpc: Option<::whisper::RpcFactory>, pub gas_price_percentile: usize, + pub poll_lifetime: u32, } impl FullDependencies { @@ -288,12 +289,13 @@ impl FullDependencies { allow_pending_receipt_query: !self.geth_compatibility, send_block_number_in_get_work: !self.geth_compatibility, gas_price_percentile: self.gas_price_percentile, + poll_lifetime: self.poll_lifetime } ); handler.extend_with(client.to_delegate()); if !for_generic_pubsub { - let filter_client = EthFilterClient::new(self.client.clone(), self.miner.clone()); + let filter_client = EthFilterClient::new(self.client.clone(), self.miner.clone(), self.poll_lifetime); handler.extend_with(filter_client.to_delegate()); add_signing_methods!(EthSigning, handler, self, nonces.clone()); @@ -447,6 +449,7 @@ pub struct LightDependencies { pub whisper_rpc: Option<::whisper::RpcFactory>, pub private_tx_service: Option>, pub gas_price_percentile: usize, + pub poll_lifetime: u32, } impl LightDependencies { @@ -504,6 +507,7 @@ impl LightDependencies { self.secret_store.clone(), self.cache.clone(), self.gas_price_percentile, + self.poll_lifetime, ); handler.extend_with(Eth::to_delegate(client.clone())); diff --git a/parity/run.rs b/parity/run.rs index 366715078bc..e6c10e9c7e7 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -90,6 +90,7 @@ pub struct RunCmd { pub logger_config: LogConfig, pub miner_options: MinerOptions, pub gas_price_percentile: usize, + pub poll_lifetime: u32, pub ntp_servers: Vec, pub ws_conf: rpc::WsConfiguration, pub http_conf: rpc::HttpConfiguration, @@ -350,6 +351,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc) -> Result(cmd: RunCmd, logger: Arc, on_client_rq: whisper_rpc: whisper_factory, private_tx_service: Some(private_tx_service.clone()), gas_price_percentile: cmd.gas_price_percentile, + poll_lifetime: cmd.poll_lifetime, }); let dependencies = rpc::Dependencies { diff --git a/rpc/src/v1/helpers/poll_manager.rs b/rpc/src/v1/helpers/poll_manager.rs index e176ed440e5..03387a70939 100644 --- a/rpc/src/v1/helpers/poll_manager.rs +++ b/rpc/src/v1/helpers/poll_manager.rs @@ -18,9 +18,6 @@ use transient_hashmap::{TransientHashMap, Timer, StandardTimer}; -/// Lifetime of poll (in seconds). -const POLL_LIFETIME: u32 = 60; - pub type PollId = usize; /// Indexes all poll requests. @@ -32,17 +29,17 @@ pub struct PollManager where T: Timer { } impl PollManager { - /// Creates new instance of indexer. - pub fn new() -> Self { - PollManager::new_with_timer(Default::default()) + /// Creates new instance of indexer + pub fn new(lifetime: u32) -> Self { + PollManager::new_with_timer(Default::default(), lifetime) } } impl PollManager where T: Timer { - pub fn new_with_timer(timer: T) -> Self { + pub fn new_with_timer(timer: T, lifetime: u32) -> Self { PollManager { - polls: TransientHashMap::new_with_timer(POLL_LIFETIME, timer), + polls: TransientHashMap::new_with_timer(lifetime, timer), next_available_id: 0, } } @@ -102,7 +99,7 @@ mod tests { time: &time, }; - let mut indexer = PollManager::new_with_timer(timer); + let mut indexer = PollManager::new_with_timer(timer,60); assert_eq!(indexer.create_poll(20), 0); assert_eq!(indexer.create_poll(20), 1); diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 8de5783aa32..8cd0afc5bd5 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -65,6 +65,8 @@ pub struct EthClientOptions { pub send_block_number_in_get_work: bool, /// Gas Price Percentile used as default gas price. pub gas_price_percentile: usize, + /// Set the timeout for the internal poll manager + pub poll_lifetime: u32 } impl EthClientOptions { @@ -83,6 +85,7 @@ impl Default for EthClientOptions { pending_nonce_from_queue: false, allow_pending_receipt_query: true, send_block_number_in_get_work: true, + poll_lifetime: 60u32, gas_price_percentile: 50, } } diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index ed75eeb8674..b79456cd8db 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -66,11 +66,11 @@ pub struct EthFilterClient { impl EthFilterClient { /// Creates new Eth filter client. - pub fn new(client: Arc, miner: Arc) -> Self { + pub fn new(client: Arc, miner: Arc, poll_lifetime: u32) -> Self { EthFilterClient { client: client, miner: miner, - polls: Mutex::new(PollManager::new()), + polls: Mutex::new(PollManager::new(poll_lifetime)), } } } diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index fe4cd8613f9..7c47967b277 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -62,6 +62,7 @@ pub struct EthClient { accounts: Arc, cache: Arc>, polls: Mutex>, + poll_lifetime: u32, gas_price_percentile: usize, } @@ -92,7 +93,8 @@ impl Clone for EthClient { transaction_queue: self.transaction_queue.clone(), accounts: self.accounts.clone(), cache: self.cache.clone(), - polls: Mutex::new(PollManager::new()), + polls: Mutex::new(PollManager::new(self.poll_lifetime)), + poll_lifetime: self.poll_lifetime, gas_price_percentile: self.gas_price_percentile, } } @@ -109,6 +111,7 @@ impl EthClient { accounts: Arc, cache: Arc>, gas_price_percentile: usize, + poll_lifetime: u32 ) -> Self { EthClient { sync, @@ -117,7 +120,8 @@ impl EthClient { transaction_queue, accounts, cache, - polls: Mutex::new(PollManager::new()), + polls: Mutex::new(PollManager::new(poll_lifetime)), + poll_lifetime, gas_price_percentile, } } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index e7c05d56fa0..87ca18fe241 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -92,8 +92,9 @@ impl EthTester { let hashrates = Arc::new(Mutex::new(HashMap::new())); let external_miner = Arc::new(ExternalMiner::new(hashrates.clone())); let gas_price_percentile = options.gas_price_percentile; + let poll_lifetime = options.poll_lifetime; let eth = EthClient::new(&client, &snapshot, &sync, &opt_ap, &miner, &external_miner, options).to_delegate(); - let filter = EthFilterClient::new(client.clone(), miner.clone()).to_delegate(); + let filter = EthFilterClient::new(client.clone(), miner.clone(), poll_lifetime).to_delegate(); let reservations = Arc::new(Mutex::new(nonce::Reservations::new())); let dispatcher = FullDispatcher::new(client.clone(), miner.clone(), reservations, gas_price_percentile);