use std::fmt::Formatter;
use std::time::Duration;
use serde::{Deserialize, Serialize};
pub const DEFAULT_EXPIRY_TIME: Duration = Duration::from_secs(3 * 60 * 60 * 24);
pub const DEFAULT_IDLE_INTERVAL: Duration = Duration::from_secs(60 * 60);
pub const DEFAULT_DOWNLOAD_REDUNDANCY: usize = 5;
pub const DEFAULT_MAX_MOONLIGHT_FUTURE_NONCE_PER_ACCOUNT: usize = 64;
#[derive(Serialize, Deserialize, Copy, Clone)]
pub struct Params {
pub max_queue_size: usize,
pub max_mempool_txn_count: usize,
#[serde(default = "default_max_moonlight_future_nonce_per_account")]
pub max_moonlight_future_nonce_per_account: usize,
#[serde(with = "humantime_serde")]
pub idle_interval: Option<Duration>,
#[serde(with = "humantime_serde")]
pub mempool_expiry: Option<Duration>,
pub mempool_download_redundancy: Option<usize>,
}
impl Default for Params {
fn default() -> Self {
Self {
max_queue_size: 1000,
max_mempool_txn_count: 10_000,
max_moonlight_future_nonce_per_account:
DEFAULT_MAX_MOONLIGHT_FUTURE_NONCE_PER_ACCOUNT,
idle_interval: Some(DEFAULT_IDLE_INTERVAL),
mempool_expiry: Some(DEFAULT_EXPIRY_TIME),
mempool_download_redundancy: Some(DEFAULT_DOWNLOAD_REDUNDANCY),
}
}
}
const fn default_max_moonlight_future_nonce_per_account() -> usize {
DEFAULT_MAX_MOONLIGHT_FUTURE_NONCE_PER_ACCOUNT
}
impl std::fmt::Display for Params {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"max_queue_size: {}, max_mempool_txn_count: {}, max_moonlight_future_nonce_per_account: {},
idle_interval: {:?}, mempool_expiry: {:?}, mempool_download_redundancy: {:?}",
self.max_queue_size,
self.max_mempool_txn_count,
self.max_moonlight_future_nonce_per_account,
self.idle_interval,
self.mempool_expiry,
self.mempool_download_redundancy
)
}
}