2021-10-12 10:31:54 -07:00
|
|
|
//! User-configurable mempool parameters.
|
|
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
/// Mempool configuration section.
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2021-10-13 08:04:49 -07:00
|
|
|
#[serde(deny_unknown_fields, default)]
|
2021-10-12 10:31:54 -07:00
|
|
|
pub struct Config {
|
|
|
|
/// The mempool transaction cost limit.
|
|
|
|
///
|
|
|
|
/// This limits the total serialized byte size of all transactions in the mempool.
|
|
|
|
///
|
2021-10-26 17:21:19 -07:00
|
|
|
/// Consensus rule:
|
|
|
|
/// > There MUST be a configuration option mempooltxcostlimit, which SHOULD default to 80000000.
|
|
|
|
///
|
2021-10-12 10:31:54 -07:00
|
|
|
/// This corresponds to `mempooltxcostlimit` from [ZIP-401](https://zips.z.cash/zip-0401#specification).
|
2021-10-26 17:21:19 -07:00
|
|
|
pub tx_cost_limit: u64,
|
2021-10-12 10:31:54 -07:00
|
|
|
|
|
|
|
/// The mempool transaction eviction age limit.
|
|
|
|
///
|
|
|
|
/// This limits the maximum amount of time evicted transaction IDs stay in the mempool rejection list.
|
|
|
|
/// Transactions are randomly evicted from the mempool when the mempool reaches [`tx_cost_limit`].
|
|
|
|
///
|
|
|
|
/// (Transactions can also be rejected by the mempool for other reasons.
|
|
|
|
/// Different rejection reasons can have different age limits.)
|
|
|
|
///
|
|
|
|
/// This corresponds to `mempoolevictionmemoryminutes` from
|
|
|
|
/// [ZIP-401](https://zips.z.cash/zip-0401#specification).
|
2022-06-13 23:21:24 -07:00
|
|
|
#[serde(with = "humantime_serde")]
|
2021-10-12 10:31:54 -07:00
|
|
|
pub eviction_memory_time: Duration,
|
2022-06-13 23:21:24 -07:00
|
|
|
|
|
|
|
/// If the state's best chain tip has reached this height, always enable the mempool,
|
|
|
|
/// regardless of Zebra's sync status.
|
|
|
|
///
|
|
|
|
/// Set to `None` by default: Zebra always checks the sync status before enabling the mempool.
|
|
|
|
//
|
|
|
|
// TODO:
|
|
|
|
// - allow the mempool to be enabled before the genesis block is committed?
|
|
|
|
// we could replace `Option` with an enum that has an `AlwaysEnable` variant
|
|
|
|
pub debug_enable_at_height: Option<u32>,
|
2021-10-12 10:31:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-11-01 07:32:48 -07:00
|
|
|
// [ZIP-401] Consensus rules:
|
|
|
|
//
|
|
|
|
// > There MUST be a configuration option mempooltxcostlimit,
|
|
|
|
// > which SHOULD default to 80000000.
|
|
|
|
// >
|
|
|
|
// > There MUST be a configuration option mempoolevictionmemoryminutes,
|
|
|
|
// > which SHOULD default to 60 [minutes].
|
|
|
|
//
|
|
|
|
// [ZIP-401]: https://zips.z.cash/zip-0401#specification
|
2021-10-12 10:31:54 -07:00
|
|
|
tx_cost_limit: 80_000_000,
|
|
|
|
eviction_memory_time: Duration::from_secs(60 * 60),
|
2021-10-13 08:04:49 -07:00
|
|
|
|
|
|
|
debug_enable_at_height: None,
|
2021-10-12 10:31:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|