Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions crates/common/src/pbs/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub const RELOAD_PATH: &str = "/reload";
pub const HEADER_VERSION_KEY: &str = "X-CommitBoost-Version";
pub const HEADER_VERSION_VALUE: &str = COMMIT_BOOST_VERSION;
pub const HEADER_START_TIME_UNIX_MS: &str = "Date-Milliseconds";
pub const HEADER_TIMEOUT_MS: &str = "X-Timeout-Ms";

pub const BUILDER_EVENTS_PATH: &str = "/builder_events";
pub const DEFAULT_PBS_JWT_KEY: &str = "DEFAULT_PBS";
Expand Down
31 changes: 30 additions & 1 deletion crates/pbs/src/mev_boost/get_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use cb_common::{
pbs::{
error::{PbsError, ValidationError},
GetHeaderParams, GetHeaderResponse, RelayClient, VersionedResponse, EMPTY_TX_ROOT_HASH,
HEADER_START_TIME_UNIX_MS,
HEADER_START_TIME_UNIX_MS, HEADER_TIMEOUT_MS,
},
signature::verify_signed_message,
types::{BlsPublicKey, BlsSignature, Chain},
Expand Down Expand Up @@ -81,6 +81,31 @@ pub async fn get_header<S: BuilderApiState>(
return Ok(None);
}

// Use the minimum of the time left and the user provided timeout header
let max_timeout_ms = match req_headers.get(HEADER_TIMEOUT_MS) {
Some(user_header_value) => match user_header_value.to_str() {
Ok(user_timeout_string) => match user_timeout_string.parse::<u64>() {
Ok(user_timeout) => {
if user_timeout == 0 {
warn!("user-supplied timeout header is 0, using {max_timeout_ms}ms");
max_timeout_ms
} else {
user_timeout.min(max_timeout_ms)
}
}
Err(e) => {
warn!("cannot parse user-supplied timeout header '{user_timeout_string}', using {max_timeout_ms}ms ({e})");
max_timeout_ms
}
},
Err(e) => {
warn!("invalid user-supplied timeout header, using {max_timeout_ms}ms ({e})");
max_timeout_ms
}
},
None => max_timeout_ms,
};

// prepare headers, except for start time which is set in `send_one_get_header`
let mut send_headers = HeaderMap::new();
send_headers.insert(USER_AGENT, get_user_agent_with_version(&req_headers)?);
Expand Down Expand Up @@ -301,6 +326,10 @@ async fn send_one_get_header(
let start_request_time = utcnow_ms();
req_config.headers.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from(start_request_time));

// The timeout header indicating how long a relay has to respond, so they can
// minimize timing games without losing the bid
req_config.headers.insert(HEADER_TIMEOUT_MS, HeaderValue::from(req_config.timeout_ms));

let start_request = Instant::now();
let res = match relay
.client
Expand Down
Loading