Skip to content
Open
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
105 changes: 93 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ subtle = "2.5"
tempfile = "3.20.0"
thiserror = "2.0.12"
tokio = { version = "1.37.0", features = ["full"] }
tokio-tungstenite = { version = "0.28.0", default-features = false, features = ["connect", "rustls-tls-webpki-roots"] }
toml = "0.8.13"
tonic = { version = "0.12.3", features = ["channel", "prost", "tls"] }
tonic-build = "0.12.3"
Expand All @@ -93,6 +94,7 @@ typenum = "1.17.0"
unicode-normalization = "0.1.24"
url = { version = "2.5.0", features = ["serde"] }
uuid = { version = "1.8.0", features = ["fast-rng", "serde", "v4"] }
webpki-roots = "1.0"

[patch.crates-io]
blstrs_plus = { git = "https://github.com/Commit-Boost/blstrs" }
5 changes: 2 additions & 3 deletions benches/microbench/src/get_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use cb_common::{pbs::GetHeaderParams, signer::random_secret, types::Chain};
use cb_pbs::{PbsState, get_header};
use cb_tests::{
mock_relay::{MockRelayState, start_mock_relay_service},
utils::{generate_mock_relay, get_pbs_static_config, to_pbs_config},
utils::{generate_mock_relay, get_pbs_config, to_pbs_config},
};
use criterion::{Criterion, black_box, criterion_group, criterion_main};

Expand Down Expand Up @@ -103,8 +103,7 @@ fn bench_get_header(c: &mut Criterion) {
let states: Vec<PbsState> = RELAY_COUNTS
.iter()
.map(|&n| {
let config =
to_pbs_config(CHAIN, get_pbs_static_config(0), relay_clients[..n].to_vec());
let config = to_pbs_config(CHAIN, get_pbs_config(0), relay_clients[..n].to_vec());
PbsState::new(config, PathBuf::new())
})
.collect();
Expand Down
3 changes: 2 additions & 1 deletion benches/pbs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::{Duration, Instant};

use alloy::primitives::B256;
use cb_common::{
config::RelayConfig,
config::{GetHeaderTransport, RelayConfig},
pbs::{GetHeaderResponse, RelayClient, RelayEntry},
types::{BlsPublicKey, BlsSecretKey, Chain},
utils::TestRandomSeed,
Expand Down Expand Up @@ -157,6 +157,7 @@ fn get_mock_validator(bench: BenchConfig) -> RelayClient {
id: None,
headers: None,
get_params: None,
get_header: GetHeaderTransport::Http,
enable_timing_games: false,
target_first_request_ms: None,
frequency_get_header_ms: None,
Expand Down
6 changes: 6 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ headers = { X-MyCustomHeader = "MyCustomValue" }
# GET parameters to add to each request URL for this relay
# OPTIONAL
get_params = { param1 = "value1", param2 = "value2" }
# How to fetch headers from this relay.
Comment thread
ninaiiad marked this conversation as resolved.
# "http" -> one request per get_header, at the relay url above
# "stream" -> websocket stream of bid updates, only for relays that support it. Connects to
# ws(s)://<relay url>/eth/v1/builder/header_stream/{slot}/{parent_hash}/{pubkey}.
# OPTIONAL, DEFAULT: "http"
get_header = "http"
# Whether to enable timing games, as tuned by `target_first_request_ms` and `frequency_get_header_ms`.
# NOTE: if neither `target_first_request_ms` nor `frequency_get_header_ms` is set, this flag has no effect.
#
Expand Down
1 change: 1 addition & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ tree_hash.workspace = true
tree_hash_derive.workspace = true
unicode-normalization.workspace = true
url.workspace = true
uuid.workspace = true
reqwest-eventsource.workspace = true

[dev-dependencies]
Expand Down
11 changes: 11 additions & 0 deletions crates/common/src/config/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ use crate::{
},
};

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum GetHeaderTransport {
#[default]
Http,
Stream,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct RelayConfig {
Expand All @@ -50,6 +58,9 @@ pub struct RelayConfig {
pub headers: Option<HashMap<String, String>>,
/// Optional GET parameters to add to each request
pub get_params: Option<HashMap<String, String>>,
/// How to fetch headers from this relay
#[serde(default)]
pub get_header: GetHeaderTransport,
/// Whether to enable timing games
#[serde(default = "default_bool::<false>")]
pub enable_timing_games: bool,
Expand Down
3 changes: 3 additions & 0 deletions crates/common/src/pbs/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub const BUILDER_V1_API_PATH: &str = "/eth/v1/builder";
pub const BUILDER_V2_API_PATH: &str = "/eth/v2/builder";

pub const GET_HEADER_PATH: &str = "/header/{slot}/{parent_hash}/{pubkey}";

pub const GET_HEADER_STREAM_PATH: &str = "/header_stream";
pub const GET_STATUS_PATH: &str = "/status";
pub const REGISTER_VALIDATOR_PATH: &str = "/validators";
pub const SUBMIT_BLOCK_PATH: &str = "/blinded_blocks";
Expand All @@ -17,6 +19,7 @@ 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 HEADER_API_KEY: &str = "X-Api-Key";
pub const HEADER_CONSENSUS_VERSION: &str = "Eth-Consensus-Version";

pub const DEFAULT_PBS_JWT_KEY: &str = "DEFAULT_PBS";
Expand Down
12 changes: 11 additions & 1 deletion crates/common/src/pbs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,21 @@ pub enum PbsError {

#[error("SSZ error: {0}")]
SszError(#[from] SszValueError),

#[error("websocket error: {0}")]
WebSocket(String),

#[error("websocket timed out")]
WebSocketTimeout,
}

impl PbsError {
pub fn is_timeout(&self) -> bool {
matches!(self, PbsError::Reqwest(err) if err.is_timeout())
match self {
PbsError::Reqwest(err) => err.is_timeout(),
PbsError::WebSocketTimeout => true,
_ => false,
}
}

/// Extract the HTTP status code from relay-originated errors.
Expand Down
Loading
Loading