diff --git a/Cargo.lock b/Cargo.lock index c8c380e0..b7f8f8e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4189,7 +4189,7 @@ dependencies = [ "reth-primitives", "serde", "tokio", - "toml 0.5.11", + "toml 0.8.2", "tracing", "tracing-subscriber", ] @@ -7829,7 +7829,19 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.19.15", +] + +[[package]] +name = "toml" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.20.2", ] [[package]] @@ -7854,6 +7866,19 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.0.2", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" diff --git a/bin/mev/Cargo.toml b/bin/mev/Cargo.toml index 9a8543eb..ab356024 100644 --- a/bin/mev/Cargo.toml +++ b/bin/mev/Cargo.toml @@ -17,7 +17,7 @@ mev-build-rs = { path = "../../mev-build-rs" } mev-rs = { path = "../../mev-rs" } serde = { version = "1.0", features = ["derive"] } -toml = "0.5.9" +toml = "0.8.2" clap = { version = "4.1.4", features = ["derive", "env"] } anyhow = "1.0.57" diff --git a/bin/mev/src/cmd/boost.rs b/bin/mev/src/cmd/boost.rs index 290306ee..afb99b04 100644 --- a/bin/mev/src/cmd/boost.rs +++ b/bin/mev/src/cmd/boost.rs @@ -1,7 +1,7 @@ use crate::cmd::config::Config; use anyhow::{anyhow, Result}; use clap::Args; -use ethereum_consensus::networks::Network; +use tracing::info; use mev_boost_rs::Service; #[derive(Debug, Args)] @@ -12,14 +12,16 @@ pub struct Command { } impl Command { - pub async fn execute(&self, network: Network) -> Result<()> { + pub async fn execute(self) -> Result<()> { let config_file = &self.config_file; let config = Config::from_toml_file(config_file)?; - if let Some(mut config) = config.boost { - config.network = network; - Ok(Service::from(config).spawn(None)?.await?) + let network = config.network; + info!("configured for {network}"); + + if let Some(config) = config.boost { + Ok(Service::from(network, config).spawn(None)?.await?) } else { Err(anyhow!("missing boost config from file provided")) } diff --git a/bin/mev/src/cmd/build/mod.rs b/bin/mev/src/cmd/build/mod.rs index e4c62548..ebff4ed5 100644 --- a/bin/mev/src/cmd/build/mod.rs +++ b/bin/mev/src/cmd/build/mod.rs @@ -2,7 +2,6 @@ mod reth_ext; use anyhow::Result; use clap::Args; -use ethereum_consensus::networks::Network; use reth_ext::{launch_reth_with, RethNodeExt}; #[derive(Debug, Args)] @@ -13,8 +12,8 @@ pub struct Command { } impl Command { - pub async fn execute(&self, network: Network) -> Result<()> { - let ext = RethNodeExt { config_file: self.config_file.clone(), network, config: None }; + pub async fn execute(self) -> Result<()> { + let ext = RethNodeExt { config_file: self.config_file.clone(), network: None, config: None }; launch_reth_with(ext).await; Ok(()) } diff --git a/bin/mev/src/cmd/build/reth_ext.rs b/bin/mev/src/cmd/build/reth_ext.rs index 1a47721d..de3e2b01 100644 --- a/bin/mev/src/cmd/build/reth_ext.rs +++ b/bin/mev/src/cmd/build/reth_ext.rs @@ -5,6 +5,7 @@ use ethereum_consensus::{ state_transition::Context, }; use mev_build_rs::reth_builder::{Config as BuildConfig, DeadlineBidder, Service}; +use tracing::warn; use reth::{ cli::ext::{RethCliExt, RethNodeCommandConfig}, node::NodeCommand, @@ -25,7 +26,7 @@ pub struct RethNodeExt { #[clap(skip)] pub config_file: String, #[clap(skip)] - pub network: Network, + pub network: Option, #[clap(skip)] pub config: Option, } @@ -34,6 +35,7 @@ impl RethNodeExt { pub fn get_build_config(&mut self) -> BuildConfig { self.config.take().unwrap_or_else(|| { let config = Config::from_toml_file(&self.config_file).unwrap(); + self.network = Some(config.network); let config = config.build.unwrap(); self.config = Some(config.clone()); config @@ -61,7 +63,7 @@ impl RethNodeCommandConfig for RethNodeExt { Tasks: reth::tasks::TaskSpawner + Clone + Unpin + 'static, { let build_config = self.get_build_config(); - let network = &self.network; + let network = self.network.as_ref().unwrap(); let context = Arc::new(Context::try_from(network)?); let clock = context.clock().unwrap_or_else(|| { let genesis_time = networks::typical_genesis_time(&context); @@ -110,7 +112,8 @@ pub(crate) async fn launch_reth_with(mut ext: RethNodeExt) { let config = ext.get_build_config(); - let network_name = format!("{0}", ext.network); + let network = ext.network.as_ref().unwrap(); + let network_name = format!("{network}"); let mut params = vec!["".into(), "--chain".into(), network_name.to_string(), "--http".into()]; if let Some(path) = config.jwt_secret_path { @@ -122,6 +125,6 @@ pub(crate) async fn launch_reth_with(mut ext: RethNodeExt) { // NOTE: shim to pass in config node.ext = ext; if let Err(err) = node.execute(ctx).await { - tracing::warn!("{err:?}"); + warn!("{err:?}"); } } diff --git a/bin/mev/src/cmd/config.rs b/bin/mev/src/cmd/config.rs index 3d702065..3a5fd88d 100644 --- a/bin/mev/src/cmd/config.rs +++ b/bin/mev/src/cmd/config.rs @@ -6,9 +6,11 @@ use mev_build_rs::reth_builder::Config as BuildConfig; use mev_relay_rs::Config as RelayConfig; use serde::Deserialize; use std::{fmt, path::Path}; +use tracing::info; #[derive(Debug, Deserialize)] pub struct Config { + pub network: Network, pub boost: Option, #[serde(rename = "builder")] pub build: Option, @@ -19,10 +21,10 @@ impl Config { pub fn from_toml_file + fmt::Display + Clone>(path: P) -> Result { tracing::info!("loading config from `{path}`..."); - let config_data = std::fs::read(path.as_ref()) + let config_data = std::fs::read_to_string(path.as_ref()) .with_context(|| format!("could not read config from `{path}`"))?; - toml::from_slice(&config_data).context("could not parse TOML") + toml::from_str(&config_data).context("could not parse TOML") } } @@ -34,12 +36,11 @@ pub struct Command { } impl Command { - pub async fn execute(&self, network: Network) -> Result<()> { - let config_file = &self.config_file; + pub async fn execute(self) -> Result<()> { + let config_file = self.config_file; let config = Config::from_toml_file(config_file)?; - - tracing::info!("configured for network `{}` with configuration {:#?}", network, config); + info!("{config:#?}"); Ok(()) } diff --git a/bin/mev/src/cmd/relay.rs b/bin/mev/src/cmd/relay.rs index 818a6ca5..4fcdb41b 100644 --- a/bin/mev/src/cmd/relay.rs +++ b/bin/mev/src/cmd/relay.rs @@ -1,8 +1,8 @@ use crate::cmd::config::Config; use anyhow::{anyhow, Result}; use clap::{Args, Subcommand}; -use ethereum_consensus::networks::Network; use mev_relay_rs::Service; +use tracing::info; #[derive(Debug, Args)] #[clap(about = "🏗 connecting builders to proposers", subcommand_negates_reqs = true)] @@ -20,7 +20,7 @@ pub enum Commands { } impl Command { - pub async fn execute(&self, network: Network) -> Result<()> { + pub async fn execute(self) -> Result<()> { let (config_file, _mock) = if let Some(subcommand) = self.command.as_ref() { match subcommand { Commands::Mock { config_file } => (config_file, true), @@ -31,9 +31,11 @@ impl Command { let config = Config::from_toml_file(config_file)?; - if let Some(mut config) = config.relay { - config.network = network; - let service = Service::from(config).spawn(None).await?; + let network = config.network; + info!("configured for {network}"); + + if let Some(config) = config.relay { + let service = Service::from(network, config).spawn(None).await?; Ok(service.await?) } else { Err(anyhow!("missing relay config from file provided")) diff --git a/bin/mev/src/main.rs b/bin/mev/src/main.rs index 72ae02e3..80b70c13 100644 --- a/bin/mev/src/main.rs +++ b/bin/mev/src/main.rs @@ -1,42 +1,14 @@ mod cmd; use anyhow::Result; -use clap::{ArgGroup, Parser, Subcommand}; -use ethereum_consensus::networks::Network; +use clap::{Parser, Subcommand}; use std::future::Future; use tokio::signal; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; -#[derive(Default, Debug, Clone, clap::ValueEnum)] -pub enum NetworkArg { - #[default] - Mainnet, - Sepolia, - Goerli, - Holesky, -} - -// NOTE: define this mapping so only this crate needs the `clap` dependency while still being able -// to use the `clap::ValueEnum` machinery -impl From for Network { - fn from(arg: NetworkArg) -> Self { - match arg { - NetworkArg::Mainnet => Self::Mainnet, - NetworkArg::Sepolia => Self::Sepolia, - NetworkArg::Goerli => Self::Goerli, - NetworkArg::Holesky => Self::Holesky, - } - } -} - #[derive(Debug, Parser)] #[clap(author, version, about = "utilities for block space", long_about = None)] -#[clap(group(ArgGroup::new("network-config").args(&["network", "network_config"])))] struct Cli { - #[clap(long, value_enum, value_name = "NETWORK")] - network: Option, - #[clap(long, value_name = "FILE")] - network_config: Option, #[clap(subcommand)] command: Commands, } @@ -72,25 +44,12 @@ async fn run_task_until_signal(task: impl Future>) -> Result async fn main() -> Result<()> { let cli = Cli::parse(); - let network = if let Some(network) = cli.network { - network.into() - } else if let Some(network_config) = cli.network_config { - // use custom config if provided - Network::Custom(network_config) - } else { - // default to `mainnet` if no network configuration is provided - let network = NetworkArg::Mainnet; - network.into() - }; - setup_logging(); - tracing::info!("configured for {network}"); - match cli.command { - Commands::Boost(cmd) => run_task_until_signal(cmd.execute(network)).await, - Commands::Build(cmd) => run_task_until_signal(cmd.execute(network)).await, - Commands::Relay(cmd) => run_task_until_signal(cmd.execute(network)).await, - Commands::Config(cmd) => run_task_until_signal(cmd.execute(network)).await, + Commands::Boost(cmd) => run_task_until_signal(cmd.execute()).await, + Commands::Build(cmd) => run_task_until_signal(cmd.execute()).await, + Commands::Relay(cmd) => run_task_until_signal(cmd.execute()).await, + Commands::Config(cmd) => run_task_until_signal(cmd.execute()).await, } } diff --git a/example.config.toml b/example.config.toml index d1e26f86..39a58b9f 100644 --- a/example.config.toml +++ b/example.config.toml @@ -1,3 +1,5 @@ +network = "holesky" + [boost] host = "0.0.0.0" port = 18550 diff --git a/mev-boost-rs/src/service.rs b/mev-boost-rs/src/service.rs index e8947dfa..930be59f 100644 --- a/mev-boost-rs/src/service.rs +++ b/mev-boost-rs/src/service.rs @@ -20,18 +20,11 @@ pub struct Config { pub host: Ipv4Addr, pub port: u16, pub relays: Vec, - #[serde(default)] - pub network: Network, } impl Default for Config { fn default() -> Self { - Self { - host: Ipv4Addr::UNSPECIFIED, - port: 18550, - relays: vec![], - network: Network::default(), - } + Self { host: Ipv4Addr::UNSPECIFIED, port: 18550, relays: vec![] } } } @@ -58,10 +51,10 @@ pub struct Service { } impl Service { - pub fn from(config: Config) -> Self { + pub fn from(network: Network, config: Config) -> Self { let relays = parse_relay_endpoints(&config.relays); - Self { host: config.host, port: config.port, relays, network: config.network } + Self { host: config.host, port: config.port, relays, network } } /// Spawns a new [`RelayMux`] and [`BlindedBlockProviderServer`] task diff --git a/mev-boost-rs/tests/integration.rs b/mev-boost-rs/tests/integration.rs index 30eaf76b..c6ebb95d 100644 --- a/mev-boost-rs/tests/integration.rs +++ b/mev-boost-rs/tests/integration.rs @@ -6,6 +6,7 @@ use ethereum_consensus::{ builder::{SignedValidatorRegistration, ValidatorRegistration}, capella::mainnet as capella, crypto::SecretKey, + networks::Network, phase0::mainnet::{compute_domain, Validator}, primitives::{DomainType, ExecutionAddress, Hash32, Root}, signing::sign_with_domain, @@ -96,7 +97,8 @@ async fn test_end_to_end() { config.relays.push(format!("http://{relay_public_key}@127.0.0.1:{port}")); let mux_port = config.port; - let service = Service::from(config); + let network = Network::Sepolia; + let service = Service::from(network, config); service.spawn(Some(context.clone())).unwrap(); let beacon_node = RelayClient::new(ApiClient::new( diff --git a/mev-relay-rs/src/service.rs b/mev-relay-rs/src/service.rs index b4ad6bf3..915c58d0 100644 --- a/mev-relay-rs/src/service.rs +++ b/mev-relay-rs/src/service.rs @@ -17,8 +17,6 @@ pub struct Config { pub host: Ipv4Addr, pub port: u16, pub beacon_node_url: String, - #[serde(default)] - pub network: Network, pub secret_key: SecretKey, } @@ -28,7 +26,6 @@ impl Default for Config { host: Ipv4Addr::LOCALHOST, port: 28545, beacon_node_url: "http://127.0.0.1:5052".into(), - network: Default::default(), secret_key: Default::default(), } } @@ -43,14 +40,14 @@ pub struct Service { } impl Service { - pub fn from(config: Config) -> Self { + pub fn from(network: Network, config: Config) -> Self { let endpoint: Url = config.beacon_node_url.parse().unwrap(); let beacon_node = Client::new(endpoint); Self { host: config.host, port: config.port, beacon_node, - network: config.network, + network: network, secret_key: config.secret_key, } }