diff --git a/crates/common/src/pbs/relay.rs b/crates/common/src/pbs/relay.rs index 903277b0..6802890d 100644 --- a/crates/common/src/pbs/relay.rs +++ b/crates/common/src/pbs/relay.rs @@ -15,6 +15,9 @@ use super::{ HEADER_VERSION_KEY, HEADER_VERSION_VALUE, }; use crate::{config::RelayConfig, DEFAULT_REQUEST_TIMEOUT}; + +pub const MAX_SIZE: usize = 10 * 1024 * 1024; + /// A parsed entry of the relay url in the format: scheme://pubkey@host #[derive(Debug, Clone)] pub struct RelayEntry { diff --git a/crates/pbs/src/mev_boost/get_header.rs b/crates/pbs/src/mev_boost/get_header.rs index e98b3e49..aff3ee15 100644 --- a/crates/pbs/src/mev_boost/get_header.rs +++ b/crates/pbs/src/mev_boost/get_header.rs @@ -11,7 +11,7 @@ use cb_common::{ pbs::{ error::{PbsError, ValidationError}, GetHeaderParams, GetHeaderResponse, RelayClient, SignedExecutionPayloadHeader, - EMPTY_TX_ROOT_HASH, HEADER_SLOT_UUID_KEY, HEADER_START_TIME_UNIX_MS, + EMPTY_TX_ROOT_HASH, HEADER_SLOT_UUID_KEY, HEADER_START_TIME_UNIX_MS, MAX_SIZE, }, signature::verify_signed_message, types::Chain, @@ -220,7 +220,7 @@ async fn send_one_get_header( let start_request = Instant::now(); let res = match relay .client - .get(req_config.url) + .get(req_config.url.clone()) .timeout(Duration::from_millis(req_config.timeout_ms)) .headers(req_config.headers) .send() @@ -244,13 +244,20 @@ async fn send_one_get_header( RELAY_STATUS_CODE.with_label_values(&[code.as_str(), GET_HEADER_ENDPOINT_TAG, &relay.id]).inc(); let response_bytes = res.bytes().await?; + if response_bytes.len() > MAX_SIZE { + warn!( + "Warning: Response size exceeds 10MB! URL: {}, Size: {} bytes", + req_config.url, + response_bytes.len() + ); + } + if !code.is_success() { return Err(PbsError::RelayResponse { error_msg: String::from_utf8_lossy(&response_bytes).into_owned(), code: code.as_u16(), }); }; - if code == StatusCode::NO_CONTENT { debug!( ?code, diff --git a/crates/pbs/src/mev_boost/register_validator.rs b/crates/pbs/src/mev_boost/register_validator.rs index d44ca2d3..181acd4a 100644 --- a/crates/pbs/src/mev_boost/register_validator.rs +++ b/crates/pbs/src/mev_boost/register_validator.rs @@ -3,13 +3,13 @@ use std::time::{Duration, Instant}; use alloy::rpc::types::beacon::relay::ValidatorRegistration; use axum::http::{HeaderMap, HeaderValue}; use cb_common::{ - pbs::{error::PbsError, RelayClient, HEADER_START_TIME_UNIX_MS}, + pbs::{error::PbsError, RelayClient, HEADER_START_TIME_UNIX_MS, MAX_SIZE}, utils::{get_user_agent_with_version, utcnow_ms}, }; use eyre::bail; use futures::future::join_all; use reqwest::header::USER_AGENT; -use tracing::{debug, error}; +use tracing::{debug, error, warn}; use crate::{ constants::{REGISTER_VALIDATOR_ENDPOINT_TAG, TIMEOUT_ERROR_CODE_STR}, @@ -62,7 +62,7 @@ async fn send_register_validator( let start_request = Instant::now(); let res = match relay .client - .post(url) + .post(url.clone()) .timeout(Duration::from_millis(timeout_ms)) .headers(headers) .json(®istrations) @@ -92,6 +92,13 @@ async fn send_register_validator( .inc(); let response_bytes = res.bytes().await?; + if response_bytes.len() > MAX_SIZE { + warn!( + "Warning: Response size exceeds 10MB! URL: {}, Size: {} bytes", + url, + response_bytes.len() + ); + } if !code.is_success() { let err = PbsError::RelayResponse { error_msg: String::from_utf8_lossy(&response_bytes).into_owned(), diff --git a/crates/pbs/src/mev_boost/status.rs b/crates/pbs/src/mev_boost/status.rs index 13b29035..7d9eeb4e 100644 --- a/crates/pbs/src/mev_boost/status.rs +++ b/crates/pbs/src/mev_boost/status.rs @@ -2,12 +2,12 @@ use std::time::{Duration, Instant}; use axum::http::HeaderMap; use cb_common::{ - pbs::{error::PbsError, RelayClient}, + pbs::{error::PbsError, RelayClient, MAX_SIZE}, utils::get_user_agent_with_version, }; use futures::future::select_ok; use reqwest::header::USER_AGENT; -use tracing::{debug, error}; +use tracing::{debug, error, warn}; use crate::{ constants::{STATUS_ENDPOINT_TAG, TIMEOUT_ERROR_CODE_STR}, @@ -52,7 +52,7 @@ async fn send_relay_check(relay: &RelayClient, headers: HeaderMap) -> Result<(), let start_request = Instant::now(); let res = match relay .client - .get(url) + .get(url.clone()) .timeout(Duration::from_secs(30)) .headers(headers) .send() @@ -75,6 +75,13 @@ async fn send_relay_check(relay: &RelayClient, headers: HeaderMap) -> Result<(), RELAY_STATUS_CODE.with_label_values(&[code.as_str(), STATUS_ENDPOINT_TAG, &relay.id]).inc(); let response_bytes = res.bytes().await?; + if response_bytes.len() > MAX_SIZE { + warn!( + "Warning: Response size exceeds 10MB! URL: {}, Size: {} bytes", + url, + response_bytes.len() + ); + } if !code.is_success() { let err = PbsError::RelayResponse { error_msg: String::from_utf8_lossy(&response_bytes).into_owned(), diff --git a/crates/pbs/src/mev_boost/submit_block.rs b/crates/pbs/src/mev_boost/submit_block.rs index 9ae83df0..957e5096 100644 --- a/crates/pbs/src/mev_boost/submit_block.rs +++ b/crates/pbs/src/mev_boost/submit_block.rs @@ -5,7 +5,7 @@ use cb_common::{ pbs::{ error::{PbsError, ValidationError}, RelayClient, SignedBlindedBeaconBlock, SubmitBlindedBlockResponse, HEADER_SLOT_UUID_KEY, - HEADER_START_TIME_UNIX_MS, + HEADER_START_TIME_UNIX_MS, MAX_SIZE, }, utils::{get_user_agent_with_version, utcnow_ms}, }; @@ -65,7 +65,7 @@ async fn send_submit_block( let start_request = Instant::now(); let res = match relay .client - .post(url) + .post(url.clone()) .timeout(Duration::from_millis(timeout_ms)) .headers(headers) .json(&signed_blinded_block) @@ -95,6 +95,13 @@ async fn send_submit_block( .inc(); let response_bytes = res.bytes().await?; + if response_bytes.len() > MAX_SIZE { + warn!( + "Warning: Response size exceeds 10MB! URL: {}, Size: {} bytes", + url, + response_bytes.len() + ); + } if !code.is_success() { let err = PbsError::RelayResponse { error_msg: String::from_utf8_lossy(&response_bytes).into_owned(),