embedded_td/config/
mempool.rs

1use time::Duration;
2
3use super::{define_build_mode_setter, define_to_str_for_enum};
4
5#[derive(Debug, Clone, Default)]
6pub enum MempoolVersion {
7    #[default]
8    FIFO,
9    Priority,
10}
11
12define_to_str_for_enum!(
13    MempoolVersion,
14    FIFO => "v0",
15    Priority => "v1"
16);
17
18#[derive(Debug, Clone)]
19pub struct MempoolConfig {
20    /// Mempool version
21    pub version: MempoolVersion,
22
23    /// Recheck tx.
24    pub recheck: bool,
25
26    /// Broadcast to other node's mempool
27    pub broadcast: bool,
28
29    /// Size of mempool
30    pub size: u64,
31
32    /// Limit the total size of all txs in the mempool.
33    /// This only accounts for raw transactions (e.g. given 1MB transactions and
34    /// max_txs_bytes=5MB, mempool will only accept 5 transactions).
35    pub max_txs_bytes: u64,
36
37    /// Size of the cache (used to filter transactions we saw earlier) in transactions
38    pub cache_size: u64,
39
40    /// Do not remove invalid transactions from the cache (default: false)
41    /// Set to true if it's not possible for any invalid transaction to become valid
42    /// again in the future.
43    pub keep_invalid_txs_in_cache: bool,
44
45    /// Maximum size of a single transaction.
46    /// NOTE: the max size of a tx transmitted over the network is {max_tx_bytes}.
47    pub max_tx_bytes: u64,
48
49    /// ttl-duration, if non-zero, defines the maximum amount of time a transaction
50    /// can exist for in the mempool.
51    ///
52    /// Note, if ttl-num-blocks is also defined, a transaction will be removed if it
53    /// has existed in the mempool at least ttl-num-blocks number of blocks or if it's
54    /// insertion time into the mempool is beyond ttl-duration.
55    pub ttl_duration: Duration,
56
57    /// ttl-num-blocks, if non-zero, defines the maximum number of blocks a transaction
58    /// can exist for in the mempool.
59    ///
60    /// Note, if ttl-duration is also defined, a transaction will be removed if it
61    /// has existed in the mempool at least ttl-num-blocks number of blocks or if
62    /// it's insertion time into the mempool is beyond ttl-duration.
63    pub ttl_num_blocks: u64,
64}
65
66impl Default for MempoolConfig {
67    fn default() -> Self {
68        Self {
69            version: Default::default(),
70            recheck: true,
71            broadcast: true,
72            size: 5000,
73            max_txs_bytes: 1073741824,
74            cache_size: 10000,
75            keep_invalid_txs_in_cache: false,
76            max_tx_bytes: 1048576,
77            ttl_duration: Duration::new(0, 0),
78            ttl_num_blocks: 0,
79        }
80    }
81}
82
83impl MempoolConfig {
84    define_build_mode_setter!(version, MempoolVersion);
85
86    define_build_mode_setter!(recheck, bool);
87
88    define_build_mode_setter!(broadcast, bool);
89
90    define_build_mode_setter!(size, u64);
91
92    define_build_mode_setter!(max_tx_bytes, u64);
93
94    define_build_mode_setter!(cache_size, u64);
95
96    define_build_mode_setter!(keep_invalid_txs_in_cache, bool);
97
98    define_build_mode_setter!(ttl_duration, Duration);
99
100    define_build_mode_setter!(ttl_num_blocks, u64);
101}