zebrad/components/mempool/
config.rs

1//! User-configurable mempool parameters.
2
3use std::time::Duration;
4
5use serde::{Deserialize, Serialize};
6
7/// Mempool configuration section.
8#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
9#[serde(deny_unknown_fields, default)]
10pub struct Config {
11    /// The mempool transaction cost limit.
12    ///
13    /// This limits the total serialized byte size of all transactions in the mempool.
14    ///
15    /// Consensus rule:
16    /// > There MUST be a configuration option mempooltxcostlimit, which SHOULD default to 80000000.
17    ///
18    /// This corresponds to `mempooltxcostlimit` from [ZIP-401](https://zips.z.cash/zip-0401#specification).
19    pub tx_cost_limit: u64,
20
21    /// The mempool transaction eviction age limit.
22    ///
23    /// This limits the maximum amount of time evicted transaction IDs stay in
24    /// the mempool rejection list. Transactions are randomly evicted from the
25    /// mempool when the mempool reaches [`Self::tx_cost_limit`].
26    ///
27    /// (Transactions can also be rejected by the mempool for other reasons.
28    /// Different rejection reasons can have different age limits.)
29    ///
30    /// This corresponds to `mempoolevictionmemoryminutes` from
31    /// [ZIP-401](https://zips.z.cash/zip-0401#specification).
32    #[serde(with = "humantime_serde")]
33    pub eviction_memory_time: Duration,
34
35    /// If the state's best chain tip has reached this height, always enable the mempool,
36    /// regardless of Zebra's sync status.
37    ///
38    /// Set to `None` by default: Zebra always checks the sync status before enabling the mempool.
39    //
40    // TODO:
41    // - allow the mempool to be enabled before the genesis block is committed?
42    //   we could replace `Option` with an enum that has an `AlwaysEnable` variant
43    pub debug_enable_at_height: Option<u32>,
44}
45
46impl Default for Config {
47    fn default() -> Self {
48        Self {
49            // [ZIP-401] Consensus rules:
50            //
51            // > There MUST be a configuration option mempooltxcostlimit,
52            // > which SHOULD default to 80000000.
53            // >
54            // > There MUST be a configuration option mempoolevictionmemoryminutes,
55            // > which SHOULD default to 60 [minutes].
56            //
57            // [ZIP-401]: https://zips.z.cash/zip-0401#specification
58            tx_cost_limit: 80_000_000,
59            eviction_memory_time: Duration::from_secs(60 * 60),
60
61            debug_enable_at_height: None,
62        }
63    }
64}