use std::time::Duration;
use crate::{
db::{SettingsStore, setting_keys::MPOOL_CONFIG_KEY},
shim::{address::Address, percent::Percent},
utils::encoding::from_slice_with_fallback,
};
use serde::{Deserialize, Serialize};
const SIZE_LIMIT_LOW: i64 = 20000;
const SIZE_LIMIT_HIGH: i64 = 30000;
const PRUNE_COOLDOWN: Duration = Duration::from_secs(60); const GAS_LIMIT_OVERESTIMATION: f64 = 1.25;
pub const REPLACE_BY_FEE_RATIO_DEFAULT: Percent = Percent(125);
#[derive(Clone, Serialize, Deserialize)]
pub struct MpoolConfig {
pub priority_addrs: Vec<Address>,
pub size_limit_high: i64,
pub size_limit_low: i64,
pub replace_by_fee_ratio: Percent,
pub prune_cooldown: Duration,
pub gas_limit_overestimation: f64,
}
impl Default for MpoolConfig {
fn default() -> Self {
Self {
priority_addrs: vec![],
size_limit_high: SIZE_LIMIT_HIGH,
size_limit_low: SIZE_LIMIT_LOW,
replace_by_fee_ratio: REPLACE_BY_FEE_RATIO_DEFAULT,
prune_cooldown: PRUNE_COOLDOWN,
gas_limit_overestimation: GAS_LIMIT_OVERESTIMATION,
}
}
}
impl MpoolConfig {
pub fn size_limit_low(&self) -> i64 {
self.size_limit_low
}
pub fn priority_addrs(&self) -> &[Address] {
&self.priority_addrs
}
}
impl MpoolConfig {
pub fn load_config<DB: SettingsStore>(store: &DB) -> anyhow::Result<Self> {
match store.read_bin(MPOOL_CONFIG_KEY)? {
Some(v) => Ok(from_slice_with_fallback(&v)?),
None => Ok(Default::default()),
}
}
}