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
2 changes: 1 addition & 1 deletion crates/common/src/pbs/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const SUBMIT_BLOCK_PATH: &str = "/blinded_blocks";

pub const HEADER_SLOT_UUID_KEY: &str = "X-MEVBoost-SlotID";
pub const HEADER_VERSION_KEY: &str = "X-CommitBoost-Version";
pub const HEAVER_VERSION_VALUE: &str = "0.1.0";
pub const HEAVER_VERSION_VALUE: &str = env!("CARGO_PKG_VERSION");
pub const HEADER_START_TIME_UNIX_MS: &str = "X-MEVBoost-StartTimeUnixMS";

pub const BUILDER_EVENTS_PATH: &str = "/builder_events";
Expand Down
14 changes: 12 additions & 2 deletions crates/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloy::{
primitives::U256,
rpc::types::beacon::{BlsPublicKey, BlsSignature},
};
use axum::http::HeaderValue;
use blst::min_pk::{PublicKey, Signature};
use rand::{distributions::Alphanumeric, Rng};
use reqwest::header::HeaderMap;
Expand All @@ -16,6 +17,7 @@ use tracing_subscriber::{fmt::Layer, prelude::*, EnvFilter};

use crate::{
config::{default_log_level, RollingDuration, CB_BASE_LOG_PATH},
pbs::HEAVER_VERSION_VALUE,
types::Chain,
};

Expand Down Expand Up @@ -219,9 +221,17 @@ pub fn random_jwt() -> String {
rand::thread_rng().sample_iter(&Alphanumeric).take(32).map(char::from).collect()
}

/// Extracts the user agent from the request headers
pub fn get_user_agent(req_headers: &HeaderMap) -> Option<String> {
/// Returns the user agent from the request headers or an empty string if not
/// present
pub fn get_user_agent(req_headers: &HeaderMap) -> String {
req_headers
.get(reqwest::header::USER_AGENT)
.and_then(|ua| ua.to_str().ok().map(|s| s.to_string()))
.unwrap_or_default()
}

/// Adds the commit boost version to the existing user agent
pub fn get_user_agent_with_version(req_headers: &HeaderMap) -> eyre::Result<HeaderValue> {
let ua = get_user_agent(req_headers);
Ok(HeaderValue::from_str(&format!("commit-boost/{HEAVER_VERSION_VALUE} {}", ua))?)
}
6 changes: 2 additions & 4 deletions crates/pbs/src/mev_boost/get_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cb_common::{
},
signature::verify_signed_builder_message,
types::Chain,
utils::{get_user_agent, ms_into_slot, utcnow_ms},
utils::{get_user_agent_with_version, ms_into_slot, utcnow_ms},
};
use futures::future::join_all;
use reqwest::{header::USER_AGENT, StatusCode};
Expand Down Expand Up @@ -55,9 +55,7 @@ pub async fn get_header<S: BuilderApiState>(
// prepare headers, except for start time which is set in `send_one_get_header`
let mut send_headers = HeaderMap::new();
send_headers.insert(HEADER_SLOT_UUID_KEY, HeaderValue::from_str(&slot_uuid.to_string())?);
if let Some(ua) = get_user_agent(&req_headers) {
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
}
send_headers.insert(USER_AGENT, get_user_agent_with_version(&req_headers)?);

let relays = state.relays();
let mut handles = Vec::with_capacity(relays.len());
Expand Down
6 changes: 2 additions & 4 deletions crates/pbs/src/mev_boost/register_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy::rpc::types::beacon::relay::ValidatorRegistration;
use axum::http::{HeaderMap, HeaderValue};
use cb_common::{
pbs::{RelayClient, HEADER_START_TIME_UNIX_MS},
utils::{get_user_agent, utcnow_ms},
utils::{get_user_agent_with_version, utcnow_ms},
};
use eyre::bail;
use futures::future::join_all;
Expand All @@ -29,9 +29,7 @@ pub async fn register_validator<S: BuilderApiState>(
let mut send_headers = HeaderMap::new();
send_headers
.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from_str(&utcnow_ms().to_string())?);
if let Some(ua) = get_user_agent(&req_headers) {
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
}
send_headers.insert(USER_AGENT, get_user_agent_with_version(&req_headers)?);

let relays = state.relays();
let mut handles = Vec::with_capacity(relays.len());
Expand Down
8 changes: 3 additions & 5 deletions crates/pbs/src/mev_boost/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::{Duration, Instant};

use axum::http::{HeaderMap, HeaderValue};
use cb_common::{pbs::RelayClient, utils::get_user_agent};
use axum::http::HeaderMap;
use cb_common::{pbs::RelayClient, utils::get_user_agent_with_version};
use futures::future::select_ok;
use reqwest::header::USER_AGENT;
use tracing::{debug, error};
Expand All @@ -26,9 +26,7 @@ pub async fn get_status<S: BuilderApiState>(
} else {
// prepare headers
let mut send_headers = HeaderMap::new();
if let Some(ua) = get_user_agent(&req_headers) {
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
}
send_headers.insert(USER_AGENT, get_user_agent_with_version(&req_headers)?);

let relays = state.relays();
let mut handles = Vec::with_capacity(relays.len());
Expand Down
6 changes: 2 additions & 4 deletions crates/pbs/src/mev_boost/submit_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cb_common::{
RelayClient, SignedBlindedBeaconBlock, SubmitBlindedBlockResponse, HEADER_SLOT_UUID_KEY,
HEADER_START_TIME_UNIX_MS,
},
utils::{get_user_agent, utcnow_ms},
utils::{get_user_agent_with_version, utcnow_ms},
};
use futures::future::select_ok;
use reqwest::header::USER_AGENT;
Expand All @@ -31,9 +31,7 @@ pub async fn submit_block<S: BuilderApiState>(
let mut send_headers = HeaderMap::new();
send_headers.insert(HEADER_SLOT_UUID_KEY, HeaderValue::from_str(&slot_uuid.to_string())?);
send_headers.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from(utcnow_ms()));
if let Some(ua) = get_user_agent(&req_headers) {
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
}
send_headers.insert(USER_AGENT, get_user_agent_with_version(&req_headers)?);

let relays = state.relays();
let mut handles = Vec::with_capacity(relays.len());
Expand Down
2 changes: 1 addition & 1 deletion crates/pbs/src/routes/get_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn handle_get_header<S: BuilderApiState, T: BuilderApi<S>>(
let ua = get_user_agent(&req_headers);
let ms_into_slot = ms_into_slot(params.slot, state.config.chain);

info!(?ua, parent_hash=%params.parent_hash, validator_pubkey=%params.pubkey, ms_into_slot);
info!(ua, parent_hash=%params.parent_hash, validator_pubkey=%params.pubkey, ms_into_slot);

match T::get_header(params, req_headers, state.clone()).await {
Ok(res) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/pbs/src/routes/register_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn handle_register_validator<S: BuilderApiState, T: BuilderApi<S>>(

let ua = get_user_agent(&req_headers);

info!(?ua, num_registrations = registrations.len());
info!(ua, num_registrations = registrations.len());

if let Err(err) = T::register_validator(registrations, req_headers, state.clone()).await {
state.publish_event(BuilderEvent::RegisterValidatorResponse);
Expand Down
2 changes: 1 addition & 1 deletion crates/pbs/src/routes/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn handle_get_status<S: BuilderApiState, T: BuilderApi<S>>(

let ua = get_user_agent(&req_headers);

info!(?ua, relay_check = state.config.pbs_config.relay_check);
info!(ua, relay_check = state.config.pbs_config.relay_check);

match T::get_status(req_headers, state.clone()).await {
Ok(_) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/pbs/src/routes/submit_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn handle_submit_block<S: BuilderApiState, T: BuilderApi<S>>(
let ua = get_user_agent(&req_headers);
let (curr_slot, slot_uuid) = state.get_slot_and_uuid();

info!(?ua, %slot_uuid, ms_into_slot=now.saturating_sub(slot_start_ms), %block_hash);
info!(ua, %slot_uuid, ms_into_slot=now.saturating_sub(slot_start_ms), %block_hash);

if curr_slot != signed_blinded_block.message.slot {
warn!(expected = curr_slot, got = slot, "blinded beacon slot mismatch")
Expand Down