Skip to main content

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    /// Maximum size in bytes of an OP_RETURN script that is considered standard.
46    ///
47    /// If unset, defaults to [`DEFAULT_MAX_DATACARRIER_BYTES`]. This size includes the OP_RETURN
48    /// opcode and pushdata overhead. Matches zcashd's `-datacarriersize` default behavior.
49    pub max_datacarrier_bytes: Option<u32>,
50}
51
52impl Default for Config {
53    fn default() -> Self {
54        Self {
55            // [ZIP-401] Consensus rules:
56            //
57            // > There MUST be a configuration option mempooltxcostlimit,
58            // > which SHOULD default to 80000000.
59            // >
60            // > There MUST be a configuration option mempoolevictionmemoryminutes,
61            // > which SHOULD default to 60 [minutes].
62            //
63            // [ZIP-401]: https://zips.z.cash/zip-0401#specification
64            tx_cost_limit: 80_000_000,
65            eviction_memory_time: Duration::from_secs(60 * 60),
66
67            debug_enable_at_height: None,
68
69            max_datacarrier_bytes: Some(DEFAULT_MAX_DATACARRIER_BYTES),
70        }
71    }
72}
73
74/// Default maximum size of data carrier scripts (OP_RETURN), in bytes.
75///
76/// Equivalent to zcashd's `MAX_OP_RETURN_RELAY`:
77/// <https://github.com/zcash/zcash/blob/v6.10.0/src/script/standard.h#L22-L26>
78pub const DEFAULT_MAX_DATACARRIER_BYTES: u32 = 83;