Skip to main content

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;
16pub const DEFAULT_MAX_MOONLIGHT_FUTURE_NONCE_PER_ACCOUNT: usize = 64;
17
18#[derive(Serialize, Deserialize, Copy, Clone)]
19pub struct Params {
20    /// Number of pending to be processed transactions
21    pub max_queue_size: usize,
22
23    /// Maximum number of transactions that can be accepted/stored in mempool
24    pub max_mempool_txn_count: usize,
25
26    /// Maximum number of non-consecutive Moonlight transactions to keep in the
27    /// pre-admission future-nonce queue for a single account.
28    #[serde(default = "default_max_moonlight_future_nonce_per_account")]
29    pub max_moonlight_future_nonce_per_account: usize,
30
31    /// Interval to check for expired transactions
32    #[serde(with = "humantime_serde")]
33    pub idle_interval: Option<Duration>,
34
35    /// Duration after which a transaction is removed from the mempool
36    #[serde(with = "humantime_serde")]
37    pub mempool_expiry: Option<Duration>,
38
39    /// max number of peers to request mempool from
40    pub mempool_download_redundancy: Option<usize>,
41}
42
43impl Default for Params {
44    fn default() -> Self {
45        Self {
46            max_queue_size: 1000,
47            max_mempool_txn_count: 10_000,
48            max_moonlight_future_nonce_per_account:
49                DEFAULT_MAX_MOONLIGHT_FUTURE_NONCE_PER_ACCOUNT,
50            idle_interval: Some(DEFAULT_IDLE_INTERVAL),
51            mempool_expiry: Some(DEFAULT_EXPIRY_TIME),
52            mempool_download_redundancy: Some(DEFAULT_DOWNLOAD_REDUNDANCY),
53        }
54    }
55}
56
57const fn default_max_moonlight_future_nonce_per_account() -> usize {
58    DEFAULT_MAX_MOONLIGHT_FUTURE_NONCE_PER_ACCOUNT
59}
60
61impl std::fmt::Display for Params {
62    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
63        write!(
64            f,
65            "max_queue_size: {}, max_mempool_txn_count: {}, max_moonlight_future_nonce_per_account: {},
66         idle_interval: {:?}, mempool_expiry: {:?}, mempool_download_redundancy: {:?}",
67            self.max_queue_size,
68            self.max_mempool_txn_count,
69            self.max_moonlight_future_nonce_per_account,
70            self.idle_interval,
71            self.mempool_expiry,
72            self.mempool_download_redundancy
73        )
74    }
75}