Skip to main content

soil_cli/params/
transaction_pool_params.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7use clap::{Args, ValueEnum};
8use soil_txpool::TransactionPoolOptions;
9
10/// Type of transaction pool to be used
11#[derive(Debug, Clone, Copy, ValueEnum)]
12#[value(rename_all = "kebab-case")]
13pub enum TransactionPoolType {
14	/// Uses a legacy, single-state transaction pool.
15	SingleState,
16	/// Uses a fork-aware transaction pool.
17	ForkAware,
18}
19
20impl Into<soil_txpool::TransactionPoolType> for TransactionPoolType {
21	fn into(self) -> soil_txpool::TransactionPoolType {
22		match self {
23			TransactionPoolType::SingleState => soil_txpool::TransactionPoolType::SingleState,
24			TransactionPoolType::ForkAware => soil_txpool::TransactionPoolType::ForkAware,
25		}
26	}
27}
28
29/// Parameters used to create the pool configuration.
30#[derive(Debug, Clone, Args)]
31pub struct TransactionPoolParams {
32	/// Maximum number of transactions in the transaction pool.
33	#[arg(long, value_name = "COUNT", default_value_t = 8192)]
34	pub pool_limit: usize,
35
36	/// Maximum number of kilobytes of all transactions stored in the pool.
37	#[arg(long, value_name = "COUNT", default_value_t = 20480)]
38	pub pool_kbytes: usize,
39
40	/// How long a transaction is banned for.
41	///
42	/// If it is considered invalid. Defaults to 1800s.
43	#[arg(long, value_name = "SECONDS")]
44	pub tx_ban_seconds: Option<u64>,
45
46	/// The type of transaction pool to be instantiated.
47	#[arg(long, value_enum, default_value_t = TransactionPoolType::ForkAware)]
48	pub pool_type: TransactionPoolType,
49}
50
51impl TransactionPoolParams {
52	/// Fill the given `PoolConfiguration` by looking at the cli parameters.
53	pub fn transaction_pool(&self, is_dev: bool) -> TransactionPoolOptions {
54		TransactionPoolOptions::new_with_params(
55			self.pool_limit,
56			self.pool_kbytes * 1024,
57			self.tx_ban_seconds,
58			self.pool_type.into(),
59			is_dev,
60		)
61	}
62}