diff --git a/crates/common/src/pbs/constants.rs b/crates/common/src/pbs/constants.rs index 5a5437b6..81a19435 100644 --- a/crates/common/src/pbs/constants.rs +++ b/crates/common/src/pbs/constants.rs @@ -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"; diff --git a/crates/common/src/utils.rs b/crates/common/src/utils.rs index aff25860..0966a665 100644 --- a/crates/common/src/utils.rs +++ b/crates/common/src/utils.rs @@ -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; @@ -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, }; @@ -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 { +/// 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 { + let ua = get_user_agent(req_headers); + Ok(HeaderValue::from_str(&format!("commit-boost/{HEAVER_VERSION_VALUE} {}", ua))?) } diff --git a/crates/pbs/src/mev_boost/get_header.rs b/crates/pbs/src/mev_boost/get_header.rs index 54c20414..a1ca1c6a 100644 --- a/crates/pbs/src/mev_boost/get_header.rs +++ b/crates/pbs/src/mev_boost/get_header.rs @@ -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}; @@ -55,9 +55,7 @@ pub async fn get_header( // 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()); diff --git a/crates/pbs/src/mev_boost/register_validator.rs b/crates/pbs/src/mev_boost/register_validator.rs index 7b8c3d93..4cc4b53c 100644 --- a/crates/pbs/src/mev_boost/register_validator.rs +++ b/crates/pbs/src/mev_boost/register_validator.rs @@ -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; @@ -29,9 +29,7 @@ pub async fn register_validator( 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()); diff --git a/crates/pbs/src/mev_boost/status.rs b/crates/pbs/src/mev_boost/status.rs index cd025cbd..42df281f 100644 --- a/crates/pbs/src/mev_boost/status.rs +++ b/crates/pbs/src/mev_boost/status.rs @@ -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}; @@ -26,9 +26,7 @@ pub async fn get_status( } 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()); diff --git a/crates/pbs/src/mev_boost/submit_block.rs b/crates/pbs/src/mev_boost/submit_block.rs index 444d04a1..8f9b81ac 100644 --- a/crates/pbs/src/mev_boost/submit_block.rs +++ b/crates/pbs/src/mev_boost/submit_block.rs @@ -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; @@ -31,9 +31,7 @@ pub async fn submit_block( 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()); diff --git a/crates/pbs/src/routes/get_header.rs b/crates/pbs/src/routes/get_header.rs index 7c61b84b..57d343ae 100644 --- a/crates/pbs/src/routes/get_header.rs +++ b/crates/pbs/src/routes/get_header.rs @@ -32,7 +32,7 @@ pub async fn handle_get_header>( 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) => { diff --git a/crates/pbs/src/routes/register_validator.rs b/crates/pbs/src/routes/register_validator.rs index bcf90dda..098dbe6c 100644 --- a/crates/pbs/src/routes/register_validator.rs +++ b/crates/pbs/src/routes/register_validator.rs @@ -24,7 +24,7 @@ pub async fn handle_register_validator>( 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); diff --git a/crates/pbs/src/routes/status.rs b/crates/pbs/src/routes/status.rs index 4c2031f9..e59a8dbd 100644 --- a/crates/pbs/src/routes/status.rs +++ b/crates/pbs/src/routes/status.rs @@ -21,7 +21,7 @@ pub async fn handle_get_status>( 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(_) => { diff --git a/crates/pbs/src/routes/submit_block.rs b/crates/pbs/src/routes/submit_block.rs index 0515fa9f..e439837f 100644 --- a/crates/pbs/src/routes/submit_block.rs +++ b/crates/pbs/src/routes/submit_block.rs @@ -31,7 +31,7 @@ pub async fn handle_submit_block>( 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")