Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBS Module Mux #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions crates/cli/src/docker_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand All @@ -290,16 +290,15 @@ 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,
environment: Environment::KvPair(pbs_envs),
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()),
retries: 3,
Expand Down
12 changes: 7 additions & 5 deletions crates/common/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -27,7 +27,7 @@ pub use utils::*;
pub struct CommitBoostConfig {
pub chain: Chain,
pub relays: Vec<RelayConfig>,
pub pbs: StaticPbsConfig,
pub pbs_modules: Vec<StaticPbsConfig>,
#[serde(flatten)]
pub muxes: Option<PbsMuxes>,
pub modules: Option<Vec<StaticModuleConfig>>,
Expand All @@ -39,7 +39,9 @@ pub struct CommitBoostConfig {
impl CommitBoostConfig {
/// Validate config
pub async fn validate(&self) -> Result<()> {
self.pbs.pbs_config.validate(self.chain).await?;
ensure!(!self.pbs_modules.is_empty(), "must define at least one pbs_module");

self.pbs_modules[0].pbs_config.validate(self.chain).await?;
Ok(())
}

Expand Down Expand Up @@ -74,7 +76,7 @@ impl CommitBoostConfig {
let config = CommitBoostConfig {
chain,
relays: helper_config.relays,
pbs: helper_config.pbs,
pbs_modules: helper_config.pbs,
muxes: helper_config.muxes,
modules: helper_config.modules,
signer: helper_config.signer,
Expand Down Expand Up @@ -111,7 +113,7 @@ struct ChainConfig {
struct HelperConfig {
chain: ChainLoader,
relays: Vec<RelayConfig>,
pbs: StaticPbsConfig,
pbs: Vec<StaticPbsConfig>,
#[serde(flatten)]
muxes: Option<PbsMuxes>,
modules: Option<Vec<StaticModuleConfig>>,
Expand Down
14 changes: 13 additions & 1 deletion crates/common/src/config/mux.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub use crate::config::module::{StaticModuleConfig};

use std::{
collections::{HashMap, HashSet},
path::{Path, PathBuf},
Expand Down Expand Up @@ -41,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?;
Expand Down Expand Up @@ -72,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"
);

Expand All @@ -80,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
Expand Down Expand Up @@ -108,6 +117,8 @@ pub struct MuxConfig {
pub id: String,
/// Relays to use for this mux config
pub relays: Vec<RelayConfig>,
/// PBS Modules to use for this mux config
pub pbs_modules: Vec<StaticModuleConfig>,
/// Which validator pubkeys to match against this mux config
#[serde(default)]
pub validator_pubkeys: Vec<BlsPublicKey>,
Expand All @@ -121,6 +132,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 =
Expand Down
17 changes: 10 additions & 7 deletions crates/common/src/config/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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::{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -198,12 +201,12 @@ pub async fn load_pbs_config() -> Result<PbsModuleConfig> {
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,
Expand Down Expand Up @@ -235,7 +238,7 @@ pub async fn load_pbs_config() -> Result<PbsModuleConfig> {
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,
Expand Down
Loading