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 },
38 TransactionPoolType::ForkAware => sc_transaction_pool::TransactionPoolType::ForkAware,
39 }
40 }
41}
42
43/// Parameters used to create the pool configuration.
44#[derive(Debug, Clone, Args)]
45pub struct TransactionPoolParams {
46 /// Maximum number of transactions in the transaction pool.
47 #[arg(long, value_name = "COUNT", default_value_t = 8192)]
48 pub pool_limit: usize,
49
50 /// Maximum number of kilobytes of all transactions stored in the pool.
51 #[arg(long, value_name = "COUNT", default_value_t = 20480)]
52 pub pool_kbytes: usize,
53
54 /// How long a transaction is banned for.
55 ///
56 /// If it is considered invalid. Defaults to 1800s.
57 #[arg(long, value_name = "SECONDS")]
58 pub tx_ban_seconds: Option<u64>,
59
60 /// The type of transaction pool to be instantiated.
61 #[arg(long, value_enum, default_value_t = TransactionPoolType::ForkAware)]
62 pub pool_type: TransactionPoolType,
63}
64
65impl TransactionPoolParams {
66 /// Fill the given `PoolConfiguration` by looking at the cli parameters.
67 pub fn transaction_pool(&self, is_dev: bool) -> TransactionPoolOptions {
68 TransactionPoolOptions::new_with_params(
69 self.pool_limit,
70 self.pool_kbytes * 1024,
71 self.tx_ban_seconds,
72 self.pool_type.into(),
73 is_dev,
74 )
75 }
76}