dusk_node/mempool/
conf.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7use std::fmt::Formatter;
8use std::time::Duration;
9
10use serde::{Deserialize, Serialize};
11
12/// Mempool configuration parameters
13pub const DEFAULT_EXPIRY_TIME: Duration = Duration::from_secs(3 * 60 * 60 * 24); /* 3 days */
14pub const DEFAULT_IDLE_INTERVAL: Duration = Duration::from_secs(60 * 60); /* 1 hour */
15pub const DEFAULT_DOWNLOAD_REDUNDANCY: usize = 5;
16
17#[derive(Serialize, Deserialize, Copy, Clone)]
18pub struct Params {
19    /// Number of pending to be processed transactions
20    pub max_queue_size: usize,
21
22    /// Maximum number of transactions that can be accepted/stored in mempool
23    pub max_mempool_txn_count: usize,
24
25    /// Interval to check for expired transactions
26    #[serde(with = "humantime_serde")]
27    pub idle_interval: Option<Duration>,
28
29    /// Duration after which a transaction is removed from the mempool
30    #[serde(with = "humantime_serde")]
31    pub mempool_expiry: Option<Duration>,
32
33    /// max number of peers to request mempool from
34    pub mempool_download_redundancy: Option<usize>,
35}
36
37impl Default for Params {
38    fn default() -> Self {
39        Self {
40            max_queue_size: 1000,
41            max_mempool_txn_count: 10_000,
42            idle_interval: Some(DEFAULT_IDLE_INTERVAL),
43            mempool_expiry: Some(DEFAULT_EXPIRY_TIME),
44            mempool_download_redundancy: Some(DEFAULT_DOWNLOAD_REDUNDANCY),
45        }
46    }
47}
48
49impl std::fmt::Display for Params {
50    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
51        write!(
52            f,
53            "max_queue_size: {}, max_mempool_txn_count: {},
54         idle_interval: {:?}, mempool_expiry: {:?}, mempool_download_redundancy: {:?}",
55            self.max_queue_size,
56            self.max_mempool_txn_count,
57            self.idle_interval,
58            self.mempool_expiry,
59            self.mempool_download_redundancy
60        )
61    }
62}