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, ValueEnum};
20use sc_transaction_pool::TransactionPoolOptions;
21
22/// Type of transaction pool to be used
23#[derive(Debug, Clone, Copy, ValueEnum)]
24#[value(rename_all = "kebab-case")]
25pub enum TransactionPoolType {
26 /// Uses a legacy, single-state transaction pool.
27 SingleState,
28 /// Uses a fork-aware transaction pool.
29 ForkAware,
30}
31
32impl Into<sc_transaction_pool::TransactionPoolType> for TransactionPoolType {
33 fn into(self) -> sc_transaction_pool::TransactionPoolType {
34 match self {
35 TransactionPoolType::SingleState =>
36 sc_transaction_pool::TransactionPoolType::SingleState,
37 TransactionPoolType::ForkAware => sc_transaction_pool::TransactionPoolType::ForkAware,
38 }
39 }
40}
41
42/// Parameters used to create the pool configuration.
43#[derive(Debug, Clone, Args)]
44pub struct TransactionPoolParams {
45 /// Maximum number of transactions in the transaction pool.
46 #[arg(long, value_name = "COUNT", default_value_t = 8192)]
47 pub pool_limit: usize,
48
49 /// Maximum number of kilobytes of all transactions stored in the pool.
50 #[arg(long, value_name = "COUNT", default_value_t = 20480)]
51 pub pool_kbytes: usize,
52
53 /// How long a transaction is banned for.
54 ///
55 /// If it is considered invalid. Defaults to 1800s.
56 #[arg(long, value_name = "SECONDS")]
57 pub tx_ban_seconds: Option<u64>,
58
59 /// The type of transaction pool to be instantiated.
60 #[arg(long, value_enum, default_value_t = TransactionPoolType::ForkAware)]
61 pub pool_type: TransactionPoolType,
62}
63
64impl TransactionPoolParams {
65 /// Fill the given `PoolConfiguration` by looking at the cli parameters.
66 pub fn transaction_pool(&self, is_dev: bool) -> TransactionPoolOptions {
67 TransactionPoolOptions::new_with_params(
68 self.pool_limit,
69 self.pool_kbytes * 1024,
70 self.tx_ban_seconds,
71 self.pool_type.into(),
72 is_dev,
73 )
74 }
75}