CLI flag to configure tx ban duration (#11786)

* add tx-ban-seconds

* fix

* trigger CI

* trigger CI

* remove test print

* Update client/cli/src/params/transaction_pool_params.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Xiliang Chen
2022-07-12 23:19:13 +12:00
committed by GitHub
parent a1c60f0909
commit 47b27c292f
7 changed files with 31 additions and 7 deletions
@@ -29,11 +29,15 @@ pub struct TransactionPoolParams {
/// Maximum number of kilobytes of all transactions stored in the pool.
#[clap(long, value_name = "COUNT", default_value = "20480")]
pub pool_kbytes: usize,
/// How long a transaction is banned for, if it is considered invalid. Defaults to 1800s.
#[clap(long, value_name = "SECONDS")]
pub tx_ban_seconds: Option<u64>,
}
impl TransactionPoolParams {
/// Fill the given `PoolConfiguration` by looking at the cli parameters.
pub fn transaction_pool(&self) -> TransactionPoolOptions {
pub fn transaction_pool(&self, is_dev: bool) -> TransactionPoolOptions {
let mut opts = TransactionPoolOptions::default();
// ready queue
@@ -45,6 +49,14 @@ impl TransactionPoolParams {
opts.future.count = self.pool_limit / factor;
opts.future.total_bytes = self.pool_kbytes * 1024 / factor;
opts.ban_time = if let Some(ban_seconds) = self.tx_ban_seconds {
std::time::Duration::from_secs(ban_seconds)
} else if is_dev {
std::time::Duration::from_secs(0)
} else {
std::time::Duration::from_secs(30 * 60)
};
opts
}
}