Skip to content
Merged
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
10 changes: 5 additions & 5 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ validator_pubkeys = [
loader = "./mux_keys.example.json"
timeout_get_header_ms = 900
late_in_slot_time_ms = 1500
# For each mux, one or more [[pbs_mux.relays]] can be defined, which will be used for the matching validator pubkeys
# Only the relays defined here will be used, and the rest of the relays defined in the main config will be ignored
# Any field defined here will override the default value from the relay config with the same id in [[relays]]
# For each mux, one or more [[mux.relays]] can be defined, which will be used for the matching validator pubkeys
# Only the relays defined here will be used, and the relays defined in the main [[relays]] config will be ignored
# The fields specified here are the same as in [[relays]] (headers, enable_timing_games, target_first_request_ms, frequency_get_header_ms)
[[mux.relays]]
id = "example-relay"
headers = { X-MyCustomHeader = "ADifferentCustomValue" }
id = "mux-relay-1"
url = "http://0xa119589bb33ef52acbb8116832bec2b58fca590fe5c85eac5d3230b44d5bc09fe73ccd21f88eab31d6de16194d17782e@def.xyz"

# Configuration for the Signer Module, only required if any `commit` module is present, or if `pbs.with_signer = true`
# Currently two types of Signer modules are supported (only one can be used at a time):
Expand Down
12 changes: 5 additions & 7 deletions configs/pbs-mux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ port = 18550
timeout_get_header_ms = 950
late_in_slot_time_ms = 2000

# Used for all validators except the ones in the mux
[[relays]]
id = "relay-1"
url = "http://0xa1cec75a3f0661e99299274182938151e8433c61a19222347ea1313d839229cb4ce4e3e5aa2bdeb71c8fcf1b084963c2@abc.xyz"

[[relays]]
id = "relay-2"
url = "http://0xa119589bb33ef52acbb8116832bec2b58fca590fe5c85eac5d3230b44d5bc09fe73ccd21f88eab31d6de16194d17782e@def.xyz"
enable_timing_games = true
target_first_request_ms = 200

[[mux]]
id = "test_mux"
id = "timing-mux"
validator_pubkeys = [
"0x80c7f782b2467c5898c5516a8b6595d75623960b4afc4f71ee07d40985d20e117ba35e7cd352a3e75fb85a8668a3b745",
]
Expand All @@ -28,4 +24,6 @@ late_in_slot_time_ms = 1500

[[mux.relays]]
id = "relay-2"
enable_timing_games = false
url = "http://0xa119589bb33ef52acbb8116832bec2b58fca590fe5c85eac5d3230b44d5bc09fe73ccd21f88eab31d6de16194d17782e@def.xyz"
enable_timing_games = true
target_first_request_ms = 200
63 changes: 5 additions & 58 deletions crates/common/src/config/mux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::{
};

use alloy::rpc::types::beacon::BlsPublicKey;
use eyre::{bail, ensure, eyre, Context};
use eyre::{bail, ensure, Context};
use serde::{Deserialize, Serialize};

use super::{load_optional_env_var, PbsConfig, RelayConfig, MUX_PATH_ENV};
use crate::pbs::{RelayClient, RelayEntry};
use crate::pbs::RelayClient;

#[derive(Debug, Deserialize, Serialize)]
pub struct PbsMuxes {
Expand All @@ -29,7 +29,6 @@ impl PbsMuxes {
pub fn validate_and_fill(
self,
default_pbs: &PbsConfig,
default_relays: &[RelayConfig],
) -> eyre::Result<HashMap<BlsPublicKey, RuntimeMuxConfig>> {
let mut muxes = self.muxes;

Expand Down Expand Up @@ -61,33 +60,8 @@ impl PbsMuxes {
);

let mut relay_clients = Vec::with_capacity(mux.relays.len());
for partial_relay in mux.relays.into_iter() {
// create a new config overriding only the missing fields
let partial_id = partial_relay.id()?;
// assume that there is always a relay defined in the default config. If this
// becomes too much of a burden, we can change this to allow defining relays
// that are exclusively used by a mux
let default_relay = default_relays
.iter()
.find(|r| r.id() == partial_id)
.ok_or_else(|| eyre!("default relay config not found for: {}", partial_id))?;

let full_config = RelayConfig {
id: Some(partial_id.to_string()),
entry: partial_relay.entry.unwrap_or(default_relay.entry.clone()),
headers: partial_relay.headers.or(default_relay.headers.clone()),
enable_timing_games: partial_relay
.enable_timing_games
.unwrap_or(default_relay.enable_timing_games),
target_first_request_ms: partial_relay
.target_first_request_ms
.or(default_relay.target_first_request_ms),
frequency_get_header_ms: partial_relay
.frequency_get_header_ms
.or(default_relay.frequency_get_header_ms),
};

relay_clients.push(RelayClient::new(full_config)?);
for config in mux.relays.into_iter() {
relay_clients.push(RelayClient::new(config)?);
}

let config = PbsConfig {
Expand Down Expand Up @@ -117,7 +91,7 @@ pub struct MuxConfig {
/// Identifier for this mux config
pub id: String,
/// Relays to use for this mux config
pub relays: Vec<PartialRelayConfig>,
pub relays: Vec<RelayConfig>,
/// Which validator pubkeys to match against this mux config
#[serde(default)]
pub validator_pubkeys: Vec<BlsPublicKey>,
Expand All @@ -142,33 +116,6 @@ impl MuxConfig {
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
/// A relay config with all optional fields. See [`RelayConfig`] for the
/// description of the fields.
pub struct PartialRelayConfig {
pub id: Option<String>,
#[serde(rename = "url")]
pub entry: Option<RelayEntry>,
pub headers: Option<HashMap<String, String>>,
pub enable_timing_games: Option<bool>,
pub target_first_request_ms: Option<u64>,
pub frequency_get_header_ms: Option<u64>,
}

impl PartialRelayConfig {
pub fn id(&self) -> eyre::Result<&str> {
match &self.id {
Some(id) => Ok(id.as_str()),
None => {
let entry = self.entry.as_ref().ok_or_else(|| {
eyre!("relays in [[mux]] need to specifify either an `id` or a `url`")
})?;
Ok(entry.id.as_str())
}
}
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum MuxKeysLoader {
Expand Down
10 changes: 3 additions & 7 deletions crates/common/src/config/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ pub fn load_pbs_config() -> Result<PbsModuleConfig> {
SocketAddr::from((config.pbs.pbs_config.host, config.pbs.pbs_config.port))
};

let muxes = config
.muxes
.map(|muxes| muxes.validate_and_fill(&config.pbs.pbs_config, &config.relays))
.transpose()?;
let muxes =
config.muxes.map(|muxes| muxes.validate_and_fill(&config.pbs.pbs_config)).transpose()?;

let relay_clients =
config.relays.into_iter().map(RelayClient::new).collect::<Result<Vec<_>>>()?;
Expand Down Expand Up @@ -234,9 +232,7 @@ pub fn load_pbs_custom_config<T: DeserializeOwned>() -> Result<(PbsModuleConfig,
};

let muxes = match cb_config.muxes {
Some(muxes) => Some(
muxes.validate_and_fill(&cb_config.pbs.static_config.pbs_config, &cb_config.relays)?,
),
Some(muxes) => Some(muxes.validate_and_fill(&cb_config.pbs.static_config.pbs_config)?),
None => None,
};

Expand Down
Loading