From d3b8eaa27df94fd7ee8eb92eb127add9c779bfa5 Mon Sep 17 00:00:00 2001 From: irfanshaik Date: Sun, 19 Jan 2025 13:19:20 -0500 Subject: [PATCH 1/4] pbs_modules --- crates/cli/src/docker_init.rs | 14 +++++++------- crates/common/src/config/mod.rs | 6 +++--- crates/common/src/config/mux.rs | 5 +++++ crates/common/src/config/pbs.rs | 6 +++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/cli/src/docker_init.rs b/crates/cli/src/docker_init.rs index 5d25736..98acdae 100644 --- a/crates/cli/src/docker_init.rs +++ b/crates/cli/src/docker_init.rs @@ -88,7 +88,7 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu let mut warnings = Vec::new(); - let mut needs_signer_module = cb_config.pbs.with_signer; + let mut needs_signer_module = cb_config.pbs_modules[0].with_signer; // setup modules if let Some(modules_config) = cb_config.modules { @@ -267,13 +267,13 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu // ports let host_endpoint = - SocketAddr::from((cb_config.pbs.pbs_config.host, cb_config.pbs.pbs_config.port)); - let ports = Ports::Short(vec![format!("{}:{}", host_endpoint, cb_config.pbs.pbs_config.port)]); - warnings.push(format!("pbs has an exported port on {}", cb_config.pbs.pbs_config.port)); + SocketAddr::from((cb_config.pbs_modules[0].pbs_config.host, cb_config.pbs_modules[0].pbs_config.port)); + let ports = Ports::Short(vec![format!("{}:{}", host_endpoint, cb_config.pbs_modules[0].pbs_config.port)]); + warnings.push(format!("pbs has an exported port on {}", cb_config.pbs_modules[0].pbs_config.port)); // inside the container expose on 0.0.0.0 let container_endpoint = - SocketAddr::from((Ipv4Addr::UNSPECIFIED, cb_config.pbs.pbs_config.port)); + SocketAddr::from((Ipv4Addr::UNSPECIFIED, cb_config.pbs_modules[0].pbs_config.port)); let (key, val) = get_env_val(PBS_ENDPOINT_ENV, &container_endpoint.to_string()); pbs_envs.insert(key, val); @@ -290,7 +290,7 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu let pbs_service = Service { container_name: Some("cb_pbs".to_owned()), - image: Some(cb_config.pbs.docker_image), + image: Some(cb_config.pbs_modules[0].docker_image.clone()), ports, networks: pbs_networs, volumes: pbs_volumes, @@ -298,7 +298,7 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu healthcheck: Some(Healthcheck { test: Some(HealthcheckTest::Single(format!( "curl -f http://localhost:{}{}{}", - cb_config.pbs.pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH + cb_config.pbs_modules[0].pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH ))), interval: Some("30s".into()), timeout: Some("5s".into()), diff --git a/crates/common/src/config/mod.rs b/crates/common/src/config/mod.rs index b097d02..82ebc4a 100644 --- a/crates/common/src/config/mod.rs +++ b/crates/common/src/config/mod.rs @@ -27,7 +27,7 @@ pub use utils::*; pub struct CommitBoostConfig { pub chain: Chain, pub relays: Vec, - pub pbs: StaticPbsConfig, + pub pbs_modules: Vec, #[serde(flatten)] pub muxes: Option, pub modules: Option>, @@ -39,7 +39,7 @@ pub struct CommitBoostConfig { impl CommitBoostConfig { /// Validate config pub async fn validate(&self) -> Result<()> { - self.pbs.pbs_config.validate(self.chain).await?; + self.pbs_modules[0].pbs_config.validate(self.chain).await?; Ok(()) } @@ -74,7 +74,7 @@ impl CommitBoostConfig { let config = CommitBoostConfig { chain, relays: helper_config.relays, - pbs: helper_config.pbs, + pbs_modules: vec![helper_config.pbs], muxes: helper_config.muxes, modules: helper_config.modules, signer: helper_config.signer, diff --git a/crates/common/src/config/mux.rs b/crates/common/src/config/mux.rs index 32ff8e9..4b3a1fb 100644 --- a/crates/common/src/config/mux.rs +++ b/crates/common/src/config/mux.rs @@ -1,3 +1,5 @@ +pub use crate::config::module::{StaticModuleConfig}; + use std::{ collections::{HashMap, HashSet}, path::{Path, PathBuf}, @@ -108,6 +110,8 @@ pub struct MuxConfig { pub id: String, /// Relays to use for this mux config pub relays: Vec, + /// PBS Modules to use for this mux config + pub modules: Vec, /// Which validator pubkeys to match against this mux config #[serde(default)] pub validator_pubkeys: Vec, @@ -121,6 +125,7 @@ impl MuxConfig { /// Returns the env, actual path, and internal path to use for the file /// loader pub fn loader_env(&self) -> Option<(String, String, String)> { + self.loader.as_ref().and_then(|loader| match loader { MuxKeysLoader::File(path_buf) => { let path = diff --git a/crates/common/src/config/pbs.rs b/crates/common/src/config/pbs.rs index 5e42b6c..08ca48d 100644 --- a/crates/common/src/config/pbs.rs +++ b/crates/common/src/config/pbs.rs @@ -198,12 +198,12 @@ pub async fn load_pbs_config() -> Result { let endpoint = if let Some(endpoint) = load_optional_env_var(PBS_ENDPOINT_ENV) { endpoint.parse()? } else { - SocketAddr::from((config.pbs.pbs_config.host, config.pbs.pbs_config.port)) + SocketAddr::from((config.pbs_modules[0].pbs_config.host, config.pbs_modules[0].pbs_config.port)) }; let muxes = match config.muxes { Some(muxes) => { - let mux_configs = muxes.validate_and_fill(config.chain, &config.pbs.pbs_config).await?; + let mux_configs = muxes.validate_and_fill(config.chain, &config.pbs_modules[0].pbs_config).await?; Some(mux_configs) } None => None, @@ -235,7 +235,7 @@ pub async fn load_pbs_config() -> Result { Ok(PbsModuleConfig { chain: config.chain, endpoint, - pbs_config: Arc::new(config.pbs.pbs_config), + pbs_config: Arc::new(config.pbs_modules[0].pbs_config.clone()), relays: relay_clients, all_relays, signer_client: None, From 2b8e701da26a735af70f9653479c2c8150f97b4a Mon Sep 17 00:00:00 2001 From: irfanshaik Date: Sun, 19 Jan 2025 13:23:52 -0500 Subject: [PATCH 2/4] ensure at least one pbs moduel is defined --- crates/common/src/config/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/common/src/config/mod.rs b/crates/common/src/config/mod.rs index 82ebc4a..3663bde 100644 --- a/crates/common/src/config/mod.rs +++ b/crates/common/src/config/mod.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use eyre::Result; +use eyre::{ensure, Result}; use serde::{Deserialize, Serialize}; use crate::types::{load_chain_from_file, Chain, ChainLoader, ForkVersion}; @@ -39,6 +39,8 @@ pub struct CommitBoostConfig { impl CommitBoostConfig { /// Validate config pub async fn validate(&self) -> Result<()> { + ensure!(!self.pbs_modules.is_empty(), "must define at least one pbs_module"); + self.pbs_modules[0].pbs_config.validate(self.chain).await?; Ok(()) } From a4d6a5c426e5fb9da2da2db3ead612587ad478a6 Mon Sep 17 00:00:00 2001 From: irfanshaik Date: Sun, 19 Jan 2025 13:39:09 -0500 Subject: [PATCH 3/4] in progress --- crates/common/src/config/mod.rs | 4 ++-- crates/common/src/config/mux.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/common/src/config/mod.rs b/crates/common/src/config/mod.rs index 3663bde..1aa098c 100644 --- a/crates/common/src/config/mod.rs +++ b/crates/common/src/config/mod.rs @@ -76,7 +76,7 @@ impl CommitBoostConfig { let config = CommitBoostConfig { chain, relays: helper_config.relays, - pbs_modules: vec![helper_config.pbs], + pbs_modules: helper_config.pbs, muxes: helper_config.muxes, modules: helper_config.modules, signer: helper_config.signer, @@ -113,7 +113,7 @@ struct ChainConfig { struct HelperConfig { chain: ChainLoader, relays: Vec, - pbs: StaticPbsConfig, + pbs: Vec, #[serde(flatten)] muxes: Option, modules: Option>, diff --git a/crates/common/src/config/mux.rs b/crates/common/src/config/mux.rs index 4b3a1fb..af4b81c 100644 --- a/crates/common/src/config/mux.rs +++ b/crates/common/src/config/mux.rs @@ -111,7 +111,7 @@ pub struct MuxConfig { /// Relays to use for this mux config pub relays: Vec, /// PBS Modules to use for this mux config - pub modules: Vec, + pub pbs_modules: Vec, /// Which validator pubkeys to match against this mux config #[serde(default)] pub validator_pubkeys: Vec, From 775ed82656101fdefccd9eee6c68eb9055379e91 Mon Sep 17 00:00:00 2001 From: Rachit2323 Date: Mon, 20 Jan 2025 16:42:52 +0530 Subject: [PATCH 4/4] changes updated --- crates/cli/src/docker_init.rs | 3 +-- crates/common/src/config/mux.rs | 9 ++++++++- crates/common/src/config/pbs.rs | 11 +++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/cli/src/docker_init.rs b/crates/cli/src/docker_init.rs index 98acdae..ad9f98f 100644 --- a/crates/cli/src/docker_init.rs +++ b/crates/cli/src/docker_init.rs @@ -298,8 +298,7 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu healthcheck: Some(Healthcheck { test: Some(HealthcheckTest::Single(format!( "curl -f http://localhost:{}{}{}", - cb_config.pbs_modules[0].pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH - ))), + cb_config.pbs_modules[0].pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH ))), interval: Some("30s".into()), timeout: Some("5s".into()), retries: 3, diff --git a/crates/common/src/config/mux.rs b/crates/common/src/config/mux.rs index af4b81c..62f56e2 100644 --- a/crates/common/src/config/mux.rs +++ b/crates/common/src/config/mux.rs @@ -43,7 +43,7 @@ impl PbsMuxes { let mut muxes = self.muxes; for mux in muxes.iter_mut() { - ensure!(!mux.relays.is_empty(), "mux config {} must have at least one relay", mux.id); + ensure!(!mux.pbs_modules.is_empty(), "mux config {} must have at least one pbs module", mux.id); if let Some(loader) = &mux.loader { let extra_keys = loader.load(&mux.id, chain, default_pbs.rpc_url.clone()).await?; @@ -74,6 +74,7 @@ impl PbsMuxes { id = mux.id, keys = mux.validator_pubkeys.len(), relays = mux.relays.len(), + pbs_modules = mux.pbs_modules.len(), "using mux" ); @@ -82,6 +83,12 @@ impl PbsMuxes { relay_clients.push(RelayClient::new(config)?); } + let mut pbs_configs = Vec::with_capacity(mux.pbs_modules.len()); + + for config in mux.pbs_modules.into_iter() { + pbs_configs.push(PbsConfig::new(config)); + } + let config = PbsConfig { timeout_get_header_ms: mux .timeout_get_header_ms diff --git a/crates/common/src/config/pbs.rs b/crates/common/src/config/pbs.rs index 08ca48d..f961335 100644 --- a/crates/common/src/config/pbs.rs +++ b/crates/common/src/config/pbs.rs @@ -6,6 +6,8 @@ use std::{ sync::Arc, }; +use super::{constants::PBS_IMAGE_DEFAULT, load_optional_env_var, CommitBoostConfig, RuntimeMuxConfig, StaticModuleConfig, PBS_ENDPOINT_ENV}; + use alloy::{ primitives::{utils::format_ether, U256}, providers::{Provider, ProviderBuilder}, @@ -15,10 +17,7 @@ use eyre::{ensure, Result}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use url::Url; -use super::{ - constants::PBS_IMAGE_DEFAULT, load_optional_env_var, CommitBoostConfig, RuntimeMuxConfig, - PBS_ENDPOINT_ENV, -}; + use crate::{ commit::client::SignerClient, config::{ @@ -101,6 +100,10 @@ pub struct PbsConfig { } impl PbsConfig { + + pub(crate) fn new(p0: StaticModuleConfig) -> PbsConfig { + todo!() + } /// Validate PBS config parameters pub async fn validate(&self, chain: Chain) -> Result<()> { // timeouts must be positive