Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions cb-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chain = "Holesky"

[pbs]
port = 18550

[[relays]]
url = "https://0xaa58208899c6105603b74396734a6263cc7d947f444f396a90f7b7d3e65d102aec7e5e5291b27e08d02c50a050825c2f@holesky.titanrelay.xyz"
2 changes: 2 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ tracing-subscriber.workspace = true

tree_hash.workspace = true
eyre.workspace = true

url.workspace = true
26 changes: 26 additions & 0 deletions tests/data/configs/pbs.happy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
chain = "Holesky"

[pbs]
docker_image = "ghcr.io/commit-boost/pbs:latest"
with_signer = false
host = "127.0.0.1"
port = 18550
relay_check = true
wait_all_registrations = true
timeout_get_header_ms = 950
timeout_get_payload_ms = 4000
timeout_register_validator_ms = 3000
skip_sigverify = false
min_bid_eth = 0.5
relay_monitors = []
late_in_slot_time_ms = 2000
extra_validation_enabled = false
rpc_url = "https://ethereum-holesky-rpc.publicnode.com"

[[relays]]
id = "example-relay"
url = "http://0xa1cec75a3f0661e99299274182938151e8433c61a19222347ea1313d839229cb4ce4e3e5aa2bdeb71c8fcf1b084963c2@abc.xyz"
headers = { X-MyCustomHeader = "MyCustomHeader" }
enable_timing_games = false
target_first_request_ms = 200
frequency_get_header_ms = 300
19 changes: 10 additions & 9 deletions tests/src/mock_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ impl MockRelayState {
pub fn received_submit_block(&self) -> u64 {
self.received_submit_block.load(Ordering::Relaxed)
}
pub fn large_body(&self) -> bool {
self.large_body
}
}

impl MockRelayState {
Expand Down Expand Up @@ -108,7 +111,7 @@ async fn handle_get_header(

let object_root = response.data.message.tree_hash_root().0;
response.data.signature = sign_builder_root(state.chain, &state.signer, object_root);
(StatusCode::OK, axum::Json(response)).into_response()
(StatusCode::OK, Json(response)).into_response()
}

async fn handle_get_status(State(state): State<Arc<MockRelayState>>) -> impl IntoResponse {
Expand All @@ -125,14 +128,12 @@ async fn handle_register_validator(
StatusCode::OK
}

async fn handle_submit_block(State(state): State<Arc<MockRelayState>>) -> impl IntoResponse {
async fn handle_submit_block(State(state): State<Arc<MockRelayState>>) -> Response {
state.received_submit_block.fetch_add(1, Ordering::Relaxed);

let response = if state.large_body {
vec![1u8; 1 + MAX_SIZE_SUBMIT_BLOCK]
if state.large_body() {
(StatusCode::OK, Json(vec![1u8; 1 + MAX_SIZE_SUBMIT_BLOCK])).into_response()
} else {
serde_json::to_vec(&SubmitBlindedBlockResponse::default()).unwrap()
};

(StatusCode::OK, Json(response)).into_response()
let response = SubmitBlindedBlockResponse::default();
(StatusCode::OK, Json(response)).into_response()
}
}
52 changes: 20 additions & 32 deletions tests/src/mock_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,55 @@ use alloy::{
primitives::B256,
rpc::types::beacon::{relay::ValidatorRegistration, BlsPublicKey},
};
use cb_common::pbs::{GetHeaderResponse, RelayClient, SignedBlindedBeaconBlock};
use reqwest::Error;
use cb_common::pbs::{RelayClient, SignedBlindedBeaconBlock};
use reqwest::Response;

use crate::utils::generate_mock_relay;

pub struct MockValidator {
comm_boost: RelayClient,
pub comm_boost: RelayClient,
}

impl MockValidator {
pub fn new(port: u16) -> eyre::Result<Self> {
Ok(Self { comm_boost: generate_mock_relay(port, BlsPublicKey::default())? })
}

pub async fn do_get_header(&self, pubkey: Option<BlsPublicKey>) -> Result<(), Error> {
let url = self
.comm_boost
.get_header_url(0, B256::ZERO, pubkey.unwrap_or(BlsPublicKey::ZERO))
.unwrap();
let res = self.comm_boost.client.get(url).send().await?.bytes().await?;
assert!(serde_json::from_slice::<GetHeaderResponse>(&res).is_ok());

Ok(())
pub async fn do_get_header(&self, pubkey: Option<BlsPublicKey>) -> eyre::Result<Response> {
let url = self.comm_boost.get_header_url(0, B256::ZERO, pubkey.unwrap_or_default())?;
Ok(self.comm_boost.client.get(url).send().await?)
}

pub async fn do_get_status(&self) -> Result<(), Error> {
let url = self.comm_boost.get_status_url().unwrap();
let _res = self.comm_boost.client.get(url).send().await?;
// assert!(res.status().is_success());

Ok(())
pub async fn do_get_status(&self) -> eyre::Result<Response> {
let url = self.comm_boost.get_status_url()?;
Ok(self.comm_boost.client.get(url).send().await?)
}

pub async fn do_register_validator(&self) -> Result<(), Error> {
pub async fn do_register_validator(&self) -> eyre::Result<Response> {
self.do_register_custom_validators(vec![]).await
}

pub async fn do_register_custom_validators(
&self,
registrations: Vec<ValidatorRegistration>,
) -> Result<(), Error> {
) -> eyre::Result<Response> {
let url = self.comm_boost.register_validator_url().unwrap();

self.comm_boost.client.post(url).json(&registrations).send().await?.error_for_status()?;

Ok(())
Ok(self.comm_boost.client.post(url).json(&registrations).send().await?)
}

pub async fn do_submit_block(&self) -> Result<(), Error> {
pub async fn do_submit_block(
&self,
signed_blinded_block: Option<SignedBlindedBeaconBlock>,
) -> eyre::Result<Response> {
let url = self.comm_boost.submit_block_url().unwrap();

let signed_blinded_block = SignedBlindedBeaconBlock::default();

self.comm_boost
Ok(self
.comm_boost
.client
.post(url)
.json(&signed_blinded_block)
.json(&signed_blinded_block.unwrap_or_default())
.send()
.await?
.error_for_status()?;

Ok(())
.await?)
}
}
45 changes: 42 additions & 3 deletions tests/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::sync::Once;
use std::{
net::{Ipv4Addr, SocketAddr},
sync::{Arc, Once},
};

use alloy::rpc::types::beacon::BlsPublicKey;
use alloy::{primitives::U256, rpc::types::beacon::BlsPublicKey};
use cb_common::{
config::RelayConfig,
config::{PbsConfig, PbsModuleConfig, RelayConfig},
pbs::{RelayClient, RelayEntry},
types::Chain,
};
use eyre::Result;

Expand Down Expand Up @@ -51,3 +55,38 @@ pub fn generate_mock_relay_with_batch_size(
};
RelayClient::new(config)
}

pub fn get_pbs_static_config(port: u16) -> PbsConfig {
PbsConfig {
host: Ipv4Addr::UNSPECIFIED,
port,
wait_all_registrations: true,
relay_check: true,
timeout_get_header_ms: u64::MAX,
timeout_get_payload_ms: u64::MAX,
timeout_register_validator_ms: u64::MAX,
skip_sigverify: false,
min_bid_wei: U256::ZERO,
late_in_slot_time_ms: u64::MAX,
relay_monitors: vec![],
extra_validation_enabled: false,
rpc_url: None,
}
}

pub fn to_pbs_config(
chain: Chain,
pbs_config: PbsConfig,
relays: Vec<RelayClient>,
) -> PbsModuleConfig {
PbsModuleConfig {
chain,
endpoint: SocketAddr::new(pbs_config.host.into(), pbs_config.port),
pbs_config: Arc::new(pbs_config),
signer_client: None,
event_publisher: None,
all_relays: relays.clone(),
relays,
muxes: None,
}
}
Loading
Loading