pezsc_cli/params/
transaction_pool_params.rs

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