Skip to content

Commit

Permalink
Move config to relays
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelBilbao committed Jan 17, 2025
1 parent a8e150d commit ae20add
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 41 deletions.
1 change: 1 addition & 0 deletions benches/pbs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn get_mock_validator(bench: BenchConfig) -> RelayClient {
enable_timing_games: false,
target_first_request_ms: None,
frequency_get_header_ms: None,
validator_registration_batch_size: None,
};

RelayClient::new(config).unwrap()
Expand Down
6 changes: 3 additions & 3 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ extra_validation_enabled = false
# Execution Layer RPC url to use for extra validation
# OPTIONAL
rpc_url = "https://ethereum-holesky-rpc.publicnode.com"
# Maximum number of validators to register in a single request to each relay.
# OPTIONAL, DEFAULT: None (unlimited)
# validator_registration_batch_size = 1000

# The PBS module needs one or more [[relays]] as defined below.
[[relays]]
Expand Down Expand Up @@ -99,6 +96,9 @@ target_first_request_ms = 200
# Frequency in ms to send get_header requests
# OPTIONAL
frequency_get_header_ms = 300
# Maximum number of validators to register in a single request.
# OPTIONAL, DEFAULT: "" (unlimited)
validator_registration_batch_size = ""

# Configuration for the PBS multiplexers, which enable different configs to be used for get header requests, depending on validator pubkey
# Note that:
Expand Down
44 changes: 22 additions & 22 deletions crates/common/src/config/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ pub struct RelayConfig {
pub target_first_request_ms: Option<u64>,
/// Frequency in ms to send get_header requests
pub frequency_get_header_ms: Option<u64>,
/// Maximum number of validators to send to relays in one registration
/// request
#[serde(deserialize_with = "empty_string_as_none")]
pub validator_registration_batch_size: Option<usize>,
}

fn empty_string_as_none<'de, D>(deserializer: D) -> Result<Option<usize>, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum Helper {
Str(String),
Number(usize),
}

match Helper::deserialize(deserializer)? {
Helper::Str(str) if str.is_empty() => Ok(None),
Helper::Number(number) => Ok(Some(number)),
_ => Err(serde::de::Error::custom(format!("Expected empty string or number"))),
}
}

impl RelayConfig {
Expand Down Expand Up @@ -98,28 +120,6 @@ pub struct PbsConfig {
pub extra_validation_enabled: bool,
/// Execution Layer RPC url to use for extra validation
pub rpc_url: Option<Url>,
/// Maximum number of validators to send to relays in one registration
/// request
#[serde(deserialize_with = "empty_string_as_none")]
pub validator_registration_batch_size: Option<usize>,
}

fn empty_string_as_none<'de, D>(deserializer: D) -> Result<Option<usize>, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum Helper {
Str(String),
Number(usize),
}

match Helper::deserialize(deserializer)? {
Helper::Str(str) if str.is_empty() => Ok(None),
Helper::Number(number) => Ok(Some(number)),
_ => Err(serde::de::Error::custom(format!("Expected empty string or number"))),
}
}

impl PbsConfig {
Expand Down
23 changes: 8 additions & 15 deletions crates/pbs/src/mev_boost/register_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,18 @@ pub async fn register_validator<S: BuilderApiState>(
.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from_str(&utcnow_ms().to_string())?);
send_headers.insert(USER_AGENT, get_user_agent_with_version(&req_headers)?);

let validator_batches = registrations
.chunks(
state
.config
.pbs_config
.validator_registration_batch_size
.unwrap_or(registrations.len()),
)
.map(|chunk| chunk.to_vec())
.collect::<Vec<Vec<ValidatorRegistration>>>();

let relays = state.all_relays().to_vec();
let mut handles = Vec::with_capacity(relays.len());
for batch in validator_batches {
for relay in relays.clone() {
for relay in relays.clone() {
for batch in registrations
.chunks(relay.config.validator_registration_batch_size.unwrap_or(registrations.len()))
.map(|chunk| chunk.to_vec())
.collect::<Vec<Vec<ValidatorRegistration>>>()
{
handles.push(tokio::spawn(
send_register_validator_with_timeout(
batch.clone(),
relay,
batch,
relay.clone(),
send_headers.clone(),
state.pbs_config().timeout_register_validator_ms,
)
Expand Down
1 change: 1 addition & 0 deletions tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn generate_mock_relay(port: u16, pubkey: BlsPublicKey) -> Result<RelayClien
enable_timing_games: false,
target_first_request_ms: None,
frequency_get_header_ms: None,
validator_registration_batch_size: None,
};
RelayClient::new(config)
}
1 change: 0 additions & 1 deletion tests/tests/pbs_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ fn get_pbs_static_config(port: u16) -> PbsConfig {
relay_monitors: vec![],
extra_validation_enabled: false,
rpc_url: None,
validator_registration_batch_size: None,
}
}

Expand Down

0 comments on commit ae20add

Please sign in to comment.