sc_cli/params/
transaction_pool_params.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19use clap::Args;
20use sc_service::config::TransactionPoolOptions;
21
22/// Parameters used to create the pool configuration.
23#[derive(Debug, Clone, Args)]
24pub struct TransactionPoolParams {
25	/// Maximum number of transactions in the transaction pool.
26	#[arg(long, value_name = "COUNT", default_value_t = 8192)]
27	pub pool_limit: usize,
28
29	/// Maximum number of kilobytes of all transactions stored in the pool.
30	#[arg(long, value_name = "COUNT", default_value_t = 20480)]
31	pub pool_kbytes: usize,
32
33	/// How long a transaction is banned for.
34	///
35	/// If it is considered invalid. Defaults to 1800s.
36	#[arg(long, value_name = "SECONDS")]
37	pub tx_ban_seconds: Option<u64>,
38}
39
40impl TransactionPoolParams {
41	/// Fill the given `PoolConfiguration` by looking at the cli parameters.
42	pub fn transaction_pool(&self, is_dev: bool) -> TransactionPoolOptions {
43		let mut opts = TransactionPoolOptions::default();
44
45		// ready queue
46		opts.ready.count = self.pool_limit;
47		opts.ready.total_bytes = self.pool_kbytes * 1024;
48
49		// future queue
50		let factor = 10;
51		opts.future.count = self.pool_limit / factor;
52		opts.future.total_bytes = self.pool_kbytes * 1024 / factor;
53
54		opts.ban_time = if let Some(ban_seconds) = self.tx_ban_seconds {
55			std::time::Duration::from_secs(ban_seconds)
56		} else if is_dev {
57			std::time::Duration::from_secs(0)
58		} else {
59			std::time::Duration::from_secs(30 * 60)
60		};
61
62		opts
63	}
64}