diff --git a/bin/reth/src/args/rpc_server_args.rs b/bin/reth/src/args/rpc_server_args.rs index 3b2c46378..e17d8a1a5 100644 --- a/bin/reth/src/args/rpc_server_args.rs +++ b/bin/reth/src/args/rpc_server_args.rs @@ -166,57 +166,6 @@ pub struct RpcServerArgs { } impl RpcServerArgs { - /// Returns the max request size in bytes. - pub fn rpc_max_request_size_bytes(&self) -> u32 { - self.rpc_max_request_size * 1024 * 1024 - } - - /// Returns the max response size in bytes. - pub fn rpc_max_response_size_bytes(&self) -> u32 { - 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, - ) - } - - /// 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. - /// - /// If such a parameter is given, but the file cannot be read, or does not contain a hex-encoded - /// key of 256 bits, the client SHOULD treat this as an error. - /// - /// If such a parameter is not given, the client SHOULD generate such a token, valid for the - /// duration of the execution, and SHOULD store the hex-encoded secret as a jwt.hex file on - /// the filesystem. This file can then be used to provision the counterpart client. - /// - /// The `default_jwt_path` provided as an argument will be used as the default location for the - /// jwt secret in case the `auth_jwtsecret` argument is not provided. - pub(crate) fn jwt_secret(&self, default_jwt_path: PathBuf) -> Result { - match self.auth_jwtsecret.as_ref() { - Some(fpath) => { - debug!(target: "reth::cli", user_path=?fpath, "Reading JWT auth secret file"); - JwtSecret::from_file(fpath) - } - None => { - if default_jwt_path.exists() { - debug!(target: "reth::cli", ?default_jwt_path, "Reading JWT auth secret file"); - JwtSecret::from_file(&default_jwt_path) - } else { - info!(target: "reth::cli", ?default_jwt_path, "Creating JWT auth secret file"); - JwtSecret::try_create(&default_jwt_path) - } - } - } - } - /// Configures and launches _all_ servers. /// /// Returns the handles for the launched regular RPC server(s) (if any) and the server handle @@ -363,11 +312,44 @@ impl RpcServerArgs { ) .await } +} + +impl RethRpcConfig for RpcServerArgs { + fn rpc_max_request_size_bytes(&self) -> u32 { + self.rpc_max_request_size * 1024 * 1024 + } + + fn rpc_max_response_size_bytes(&self) -> u32 { + self.rpc_max_response_size * 1024 * 1024 + } + + 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, + ) + } + + fn jwt_secret(&self, default_jwt_path: PathBuf) -> Result { + match self.auth_jwtsecret.as_ref() { + Some(fpath) => { + debug!(target: "reth::cli", user_path=?fpath, "Reading JWT auth secret file"); + JwtSecret::from_file(fpath) + } + None => { + if default_jwt_path.exists() { + debug!(target: "reth::cli", ?default_jwt_path, "Reading JWT auth secret file"); + JwtSecret::from_file(&default_jwt_path) + } else { + info!(target: "reth::cli", ?default_jwt_path, "Creating JWT auth secret file"); + JwtSecret::try_create(&default_jwt_path) + } + } + } + } - /// 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() .with_config(RpcModuleConfig::new(self.eth_config())); @@ -395,7 +377,6 @@ impl RpcServerArgs { config } - /// Returns the default server builder for http/ws fn http_ws_server_builder(&self) -> ServerBuilder { ServerBuilder::new() .max_connections(self.rpc_max_connections) @@ -404,7 +385,6 @@ impl RpcServerArgs { .max_subscriptions_per_connection(self.rpc_max_subscriptions_per_connection) } - /// Returns the default ipc server builder fn ipc_server_builder(&self) -> IpcServerBuilder { IpcServerBuilder::default() .max_subscriptions_per_connection(self.rpc_max_subscriptions_per_connection) @@ -413,7 +393,6 @@ impl RpcServerArgs { .max_connections(self.rpc_max_connections) } - /// Creates the [RpcServerConfig] from cli args. fn rpc_server_config(&self) -> RpcServerConfig { let mut config = RpcServerConfig::default(); @@ -439,15 +418,12 @@ impl RpcServerArgs { config } - /// Creates the [AuthServerConfig] from cli args. fn auth_server_config(&self, jwt_secret: JwtSecret) -> Result { let address = SocketAddr::new(self.auth_addr, self.auth_port); Ok(AuthServerConfig::builder(jwt_secret).socket_addr(address).build()) } -} -impl RethRpcConfig for RpcServerArgs { fn is_ipc_enabled(&self) -> bool { // By default IPC is enabled therefor it is enabled if the `ipcdisable` is false. !self.ipcdisable diff --git a/bin/reth/src/cli/config.rs b/bin/reth/src/cli/config.rs index a698b3a5d..b87ed6be0 100644 --- a/bin/reth/src/cli/config.rs +++ b/bin/reth/src/cli/config.rs @@ -2,8 +2,12 @@ use reth_revm::primitives::bytes::BytesMut; use reth_rlp::Encodable; -use reth_rpc_builder::EthConfig; -use std::{borrow::Cow, time::Duration}; +use reth_rpc::{eth::gas_oracle::GasPriceOracleConfig, JwtError, JwtSecret}; +use reth_rpc_builder::{ + auth::AuthServerConfig, error::RpcError, EthConfig, IpcServerBuilder, RpcServerConfig, + ServerBuilder, TransportRpcModuleConfig, +}; +use std::{borrow::Cow, path::PathBuf, time::Duration}; /// A trait that provides configured RPC server. /// @@ -16,7 +20,47 @@ pub trait RethRpcConfig { /// The configured ethereum RPC settings. fn eth_config(&self) -> EthConfig; - // TODO extract more functions from RpcServerArgs + /// Returns the max request size in bytes. + fn rpc_max_request_size_bytes(&self) -> u32; + + /// Returns the max response size in bytes. + fn rpc_max_response_size_bytes(&self) -> u32; + + /// Extracts the gas price oracle config from the args. + fn gas_price_oracle_config(&self) -> GasPriceOracleConfig; + + /// 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; + + /// Returns the default server builder for http/ws + fn http_ws_server_builder(&self) -> ServerBuilder; + + /// Returns the default ipc server builder + fn ipc_server_builder(&self) -> IpcServerBuilder; + + /// Creates the [RpcServerConfig] from cli args. + fn rpc_server_config(&self) -> RpcServerConfig; + + /// Creates the [AuthServerConfig] from cli args. + fn auth_server_config(&self, jwt_secret: JwtSecret) -> Result; + + /// 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. + /// + /// If such a parameter is given, but the file cannot be read, or does not contain a hex-encoded + /// key of 256 bits, the client SHOULD treat this as an error. + /// + /// If such a parameter is not given, the client SHOULD generate such a token, valid for the + /// duration of the execution, and SHOULD store the hex-encoded secret as a jwt.hex file on + /// the filesystem. This file can then be used to provision the counterpart client. + /// + /// The `default_jwt_path` provided as an argument will be used as the default location for the + /// jwt secret in case the `auth_jwtsecret` argument is not provided. + fn jwt_secret(&self, default_jwt_path: PathBuf) -> Result; } /// A trait that provides payload builder settings. diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 36d9c01fd..84e045248 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -8,7 +8,10 @@ use crate::{ DatabaseArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs, RpcServerArgs, TxPoolArgs, }, - cli::ext::{RethCliExt, RethNodeCommandConfig}, + cli::{ + config::RethRpcConfig, + ext::{RethCliExt, RethNodeCommandConfig}, + }, dirs::{DataDirPath, MaybePlatformPath}, init::init_genesis, node::cl_events::ConsensusLayerHealthEvents,