Skip to content

Commit

Permalink
body too large warn
Browse files Browse the repository at this point in the history
  • Loading branch information
fbrv committed Sep 30, 2024
1 parent d8577de commit 2abde7c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
3 changes: 3 additions & 0 deletions crates/common/src/pbs/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions crates/pbs/src/mev_boost/get_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions crates/pbs/src/mev_boost/register_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(&registrations)
Expand Down Expand Up @@ -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(),
Expand Down
13 changes: 10 additions & 3 deletions crates/pbs/src/mev_boost/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()
Expand All @@ -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(),
Expand Down
11 changes: 9 additions & 2 deletions crates/pbs/src/mev_boost/submit_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 2abde7c

Please sign in to comment.