Configure Gas Price Oracle with CLI arguments (#2664)

Co-authored-by: Aditya Pandey <aditya.p@Aditya-P.local>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Aditya Pandey
2023-05-15 15:16:05 +05:30
committed by GitHub
parent 599a5757d1
commit c190d0e69b
6 changed files with 114 additions and 7 deletions

View File

@@ -46,3 +46,11 @@ impl Default for EthConfig {
}
}
}
impl EthConfig {
/// Configures the gas price oracle settings
pub fn with_gpo_config(mut self, gas_oracle_config: GasPriceOracleConfig) -> Self {
self.gas_oracle = gas_oracle_config;
self
}
}

View File

@@ -349,6 +349,10 @@ impl RpcModuleConfig {
pub fn builder() -> RpcModuleConfigBuilder {
RpcModuleConfigBuilder::default()
}
/// Returns a new RPC module config given the eth namespace config
pub fn new(eth: EthConfig) -> Self {
Self { eth }
}
}
/// Configures [RpcModuleConfig]

View File

@@ -59,6 +59,26 @@ impl Default for GasPriceOracleConfig {
}
}
impl GasPriceOracleConfig {
/// Creating a new gpo config with blocks, ignoreprice, maxprice and percentile
pub fn new(
blocks: Option<u32>,
ignore_price: Option<u64>,
max_price: Option<u64>,
percentile: Option<u32>,
) -> Self {
Self {
blocks: blocks.unwrap_or(20),
percentile: percentile.unwrap_or(60),
max_header_history: 1024,
max_block_history: 1024,
default: None,
max_price: max_price.map(U256::from).or(Some(DEFAULT_MAX_PRICE)),
ignore_price: ignore_price.map(U256::from).or(Some(DEFAULT_IGNORE_PRICE)),
}
}
}
/// Calculates a gas price depending on recent blocks.
#[derive(Debug)]
pub struct GasPriceOracle<Client> {