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

@ -0,0 +1,49 @@
use clap::Args;
/// Parameters to configure Gas Price Oracle
#[derive(Debug, Args, PartialEq, Eq, Default)]
#[command(next_help_heading = "GAS PRICE ORACLE")]
pub struct GasPriceOracleArgs {
/// Number of recent blocks to check for gas price
#[arg(long = "gpo.blocks", default_value = "20")]
pub blocks: Option<u32>,
/// Gas Price below which gpo will ignore transactions
#[arg(long = "gpo.ignoreprice", default_value = "2")]
pub ignore_price: Option<u64>,
/// Maximum transaction priority fee(or gasprice before London Fork) to be recommended by gpo
#[arg(long = "gpo.maxprice", default_value = "500000000000")]
pub max_price: Option<u64>,
/// The percentile of gas prices to use for the estimate
#[arg(long = "gpo.percentile", default_value = "60")]
pub percentile: Option<u32>,
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
/// A helper type to parse Args more easily
#[derive(Parser)]
struct CommandParser<T: Args> {
#[clap(flatten)]
args: T,
}
#[test]
fn test_parse_gpo_args() {
let args = CommandParser::<GasPriceOracleArgs>::parse_from(["reth"]).args;
assert_eq!(
args,
GasPriceOracleArgs {
blocks: Some(20),
ignore_price: Some(2),
max_price: Some(500000000000),
percentile: Some(60),
}
);
}
}

View File

@ -22,3 +22,6 @@ pub use payload_build_args::PayloadBuilderArgs;
/// Stage related arguments
mod stage_args;
pub use stage_args::StageEnum;
mod gas_price_oracle_args;
pub use gas_price_oracle_args::GasPriceOracleArgs;

View File

@ -1,5 +1,6 @@
//! clap [Args](clap::Args) for RPC related arguments.
use crate::args::GasPriceOracleArgs;
use clap::{
builder::{PossibleValue, TypedValueParser},
Arg, Args, Command,
@ -10,13 +11,13 @@ use reth_provider::{
BlockProviderIdExt, CanonStateSubscriptions, EvmEnvProvider, HeaderProvider,
StateProviderFactory,
};
use reth_rpc::{JwtError, JwtSecret};
use reth_rpc::{eth::gas_oracle::GasPriceOracleConfig, JwtError, JwtSecret};
use reth_rpc_builder::{
auth::{AuthServerConfig, AuthServerHandle},
constants,
error::RpcError,
IpcServerBuilder, RethRpcModule, RpcModuleBuilder, RpcModuleSelection, RpcServerConfig,
RpcServerHandle, ServerBuilder, TransportRpcModuleConfig,
EthConfig, IpcServerBuilder, RethRpcModule, RpcModuleBuilder, RpcModuleConfig,
RpcModuleSelection, RpcServerConfig, RpcServerHandle, ServerBuilder, TransportRpcModuleConfig,
};
use reth_rpc_engine_api::{EngineApi, EngineApiServer};
use reth_tasks::TaskSpawner;
@ -38,8 +39,8 @@ pub(crate) const RPC_DEFAULT_MAX_RESPONSE_SIZE_MB: u32 = 25;
pub(crate) const RPC_DEFAULT_MAX_CONNECTIONS: u32 = 100;
/// Parameters for configuring the rpc more granularity via CLI
#[derive(Debug, Args, PartialEq, Default)]
#[command(next_help_heading = "Rpc")]
#[derive(Debug, Args, PartialEq, Eq, Default)]
#[command(next_help_heading = "RPC")]
pub struct RpcServerArgs {
/// Enable the HTTP-RPC server
#[arg(long)]
@ -116,6 +117,10 @@ pub struct RpcServerArgs {
/// Maximum number of RPC server connections.
#[arg(long, value_name = "COUNT", default_value_t = RPC_DEFAULT_MAX_CONNECTIONS)]
pub rpc_max_connections: u32,
/// Gas price oracle configuration.
#[clap(flatten)]
pub gas_price_oracle: GasPriceOracleArgs,
}
impl RpcServerArgs {
@ -129,6 +134,21 @@ impl RpcServerArgs {
self.rpc_max_response_size * 1024 * 1024
}
/// Extracts the gas price oracle config from the args.
pub fn gas_price_oracle_config(&self) -> GasPriceOracleConfig {
GasPriceOracleConfig::new(
self.gas_price_oracle.blocks,
self.gas_price_oracle.ignore_price,
self.gas_price_oracle.max_price,
self.gas_price_oracle.percentile,
)
}
/// Extracts the [EthConfig] from the args.
pub fn eth_config(&self) -> EthConfig {
EthConfig::default().with_gpo_config(self.gas_price_oracle_config())
}
/// The execution layer and consensus layer clients SHOULD accept a configuration parameter:
/// jwt-secret, which designates a file containing the hex-encoded 256 bit secret key to be used
/// for verifying/generating JWT tokens.
@ -293,8 +313,12 @@ impl RpcServerArgs {
}
/// Creates the [TransportRpcModuleConfig] from cli args.
///
/// This sets all the api modules, and configures additional settings like gas price oracle
/// settings in the [TransportRpcModuleConfig].
fn transport_rpc_module_config(&self) -> TransportRpcModuleConfig {
let mut config = TransportRpcModuleConfig::default();
let mut config = TransportRpcModuleConfig::default()
.with_config(RpcModuleConfig::new(self.eth_config()));
let rpc_modules =
RpcModuleSelection::Selection(vec![RethRpcModule::Admin, RethRpcModule::Eth]);
if self.http {
@ -304,7 +328,6 @@ impl RpcServerArgs {
if self.ws {
config = config.with_ws(self.ws_api.as_ref().unwrap_or(&rpc_modules).clone());
}
config
}