reth_node_core/args/
gas_price_oracle.rsuse alloy_primitives::U256;
use clap::Args;
use reth_rpc_eth_types::GasPriceOracleConfig;
use reth_rpc_server_types::constants::gas_oracle::{
DEFAULT_GAS_PRICE_BLOCKS, DEFAULT_GAS_PRICE_PERCENTILE, DEFAULT_IGNORE_GAS_PRICE,
DEFAULT_MAX_GAS_PRICE,
};
#[derive(Debug, Clone, Copy, Args, PartialEq, Eq)]
#[command(next_help_heading = "Gas Price Oracle")]
pub struct GasPriceOracleArgs {
#[arg(long = "gpo.blocks", default_value_t = DEFAULT_GAS_PRICE_BLOCKS)]
pub blocks: u32,
#[arg(long = "gpo.ignoreprice", default_value_t = DEFAULT_IGNORE_GAS_PRICE.to())]
pub ignore_price: u64,
#[arg(long = "gpo.maxprice", default_value_t = DEFAULT_MAX_GAS_PRICE.to())]
pub max_price: u64,
#[arg(long = "gpo.percentile", default_value_t = DEFAULT_GAS_PRICE_PERCENTILE)]
pub percentile: u32,
}
impl GasPriceOracleArgs {
pub fn gas_price_oracle_config(&self) -> GasPriceOracleConfig {
let Self { blocks, ignore_price, max_price, percentile } = self;
GasPriceOracleConfig {
max_price: Some(U256::from(*max_price)),
ignore_price: Some(U256::from(*ignore_price)),
percentile: *percentile,
blocks: *blocks,
..Default::default()
}
}
}
impl Default for GasPriceOracleArgs {
fn default() -> Self {
Self {
blocks: DEFAULT_GAS_PRICE_BLOCKS,
ignore_price: DEFAULT_IGNORE_GAS_PRICE.to(),
max_price: DEFAULT_MAX_GAS_PRICE.to(),
percentile: DEFAULT_GAS_PRICE_PERCENTILE,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
#[derive(Parser)]
struct CommandParser<T: Args> {
#[command(flatten)]
args: T,
}
#[test]
fn test_parse_gpo_args() {
let args = CommandParser::<GasPriceOracleArgs>::parse_from(["reth"]).args;
assert_eq!(
args,
GasPriceOracleArgs {
blocks: DEFAULT_GAS_PRICE_BLOCKS,
ignore_price: DEFAULT_IGNORE_GAS_PRICE.to(),
max_price: DEFAULT_MAX_GAS_PRICE.to(),
percentile: DEFAULT_GAS_PRICE_PERCENTILE,
}
);
}
#[test]
fn gpo_args_default_sanity_test() {
let default_args = GasPriceOracleArgs::default();
let args = CommandParser::<GasPriceOracleArgs>::parse_from(["reth"]).args;
assert_eq!(args, default_args);
}
}