Allow Poll Lifetime to be configured via CLI (#8885)
... rather than it being a hard-coded constant. fixes #5484 .
This commit is contained in:
committed by
Marek Kotewicz
parent
4ef71f8a82
commit
609d83f92c
@@ -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<F, T = StandardTimer> where T: Timer {
|
||||
}
|
||||
|
||||
impl<F> PollManager<F, StandardTimer> {
|
||||
/// 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<F, T> PollManager<F, T> 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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ pub struct EthFilterClient<C, M> {
|
||||
|
||||
impl<C, M> EthFilterClient<C, M> {
|
||||
/// Creates new Eth filter client.
|
||||
pub fn new(client: Arc<C>, miner: Arc<M>) -> Self {
|
||||
pub fn new(client: Arc<C>, miner: Arc<M>, poll_lifetime: u32) -> Self {
|
||||
EthFilterClient {
|
||||
client: client,
|
||||
miner: miner,
|
||||
polls: Mutex::new(PollManager::new()),
|
||||
polls: Mutex::new(PollManager::new(poll_lifetime)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ pub struct EthClient<T> {
|
||||
accounts: Arc<AccountProvider>,
|
||||
cache: Arc<Mutex<LightDataCache>>,
|
||||
polls: Mutex<PollManager<PollFilter>>,
|
||||
poll_lifetime: u32,
|
||||
gas_price_percentile: usize,
|
||||
}
|
||||
|
||||
@@ -92,7 +93,8 @@ impl<T> Clone for EthClient<T> {
|
||||
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<T: LightChainClient + 'static> EthClient<T> {
|
||||
accounts: Arc<AccountProvider>,
|
||||
cache: Arc<Mutex<LightDataCache>>,
|
||||
gas_price_percentile: usize,
|
||||
poll_lifetime: u32
|
||||
) -> Self {
|
||||
EthClient {
|
||||
sync,
|
||||
@@ -117,7 +120,8 @@ impl<T: LightChainClient + 'static> EthClient<T> {
|
||||
transaction_queue,
|
||||
accounts,
|
||||
cache,
|
||||
polls: Mutex::new(PollManager::new()),
|
||||
polls: Mutex::new(PollManager::new(poll_lifetime)),
|
||||
poll_lifetime,
|
||||
gas_price_percentile,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user