diff --git a/crates/common/src/constants.rs b/crates/common/src/constants.rs index 721e9e84..44b17e1a 100644 --- a/crates/common/src/constants.rs +++ b/crates/common/src/constants.rs @@ -1,3 +1,4 @@ pub const APPLICATION_BUILDER_DOMAIN: [u8; 4] = [0, 0, 0, 1]; pub const GENESIS_VALIDATORS_ROOT: [u8; 32] = [0; 32]; pub const COMMIT_BOOST_DOMAIN: [u8; 4] = [109, 109, 111, 67]; +pub const COMMIT_BOOST_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/crates/common/src/pbs/constants.rs b/crates/common/src/pbs/constants.rs index e8e0c9e1..0a7a79c4 100644 --- a/crates/common/src/pbs/constants.rs +++ b/crates/common/src/pbs/constants.rs @@ -1,3 +1,5 @@ +use crate::constants::COMMIT_BOOST_VERSION; + pub const BUILDER_API_PATH: &str = "/eth/v1/builder"; pub const GET_HEADER_PATH: &str = "/header/:slot/:parent_hash/:pubkey"; @@ -9,7 +11,7 @@ pub const SUBMIT_BLOCK_PATH: &str = "/blinded_blocks"; pub const HEADER_SLOT_UUID_KEY: &str = "X-MEVBoost-SlotID"; pub const HEADER_VERSION_KEY: &str = "X-CommitBoost-Version"; -pub const HEADER_VERSION_VALUE: &str = env!("CARGO_PKG_VERSION"); +pub const HEADER_VERSION_VALUE: &str = COMMIT_BOOST_VERSION; pub const HEADER_START_TIME_UNIX_MS: &str = "X-MEVBoost-StartTimeUnixMS"; pub const BUILDER_EVENTS_PATH: &str = "/builder_events"; diff --git a/crates/common/src/pbs/error.rs b/crates/common/src/pbs/error.rs index 763bfd62..45922a00 100644 --- a/crates/common/src/pbs/error.rs +++ b/crates/common/src/pbs/error.rs @@ -14,14 +14,14 @@ pub enum PbsError { #[error("reqwest error: {0}")] Reqwest(#[from] reqwest::Error), - #[error("serde decode error: {0}")] - SerdeDecodeError(#[from] serde_json::Error), + #[error("json decode error: {err}, raw: {raw}")] + JsonDecode { err: serde_json::Error, raw: String }, #[error("relay response error. Code: {code}, err: {error_msg}")] RelayResponse { error_msg: String, code: u16 }, - #[error("Response size exceeds 10MB! Got: {payload_size}")] - PayloadTooLarge { payload_size: usize }, + #[error("response size exceeds max size: max: {max} got: {got}")] + PayloadTooLarge { max: usize, got: usize }, #[error("failed validating relay response: {0}")] Validation(#[from] ValidationError), diff --git a/crates/pbs/src/mev_boost/get_header.rs b/crates/pbs/src/mev_boost/get_header.rs index ee5fa339..772f8c5a 100644 --- a/crates/pbs/src/mev_boost/get_header.rs +++ b/crates/pbs/src/mev_boost/get_header.rs @@ -85,7 +85,7 @@ pub async fn get_header( } Ok(_) => {} Err(err) if err.is_timeout() => error!(err = "Timed Out", relay_id), - Err(err) => error!(?err, relay_id), + Err(err) => error!(%err, relay_id), } } @@ -163,7 +163,7 @@ async fn send_timed_get_header( } Err(err) if err.is_timeout() => None, Err(err) => { - error!(?err, "TG: error sending header request"); + error!(%err, "TG: error sending header request"); None } }) @@ -245,7 +245,7 @@ async fn send_one_get_header( let response_bytes = res.bytes().await?; if response_bytes.len() > MAX_SIZE { - return Err(PbsError::PayloadTooLarge { payload_size: response_bytes.len() }); + return Err(PbsError::PayloadTooLarge { max: MAX_SIZE, got: response_bytes.len() }); } if !code.is_success() { @@ -264,7 +264,15 @@ async fn send_one_get_header( return Ok((start_request_time, None)); } - let get_header_response: GetHeaderResponse = serde_json::from_slice(&response_bytes)?; + let get_header_response = match serde_json::from_slice::(&response_bytes) { + Ok(parsed) => parsed, + Err(err) => { + return Err(PbsError::JsonDecode { + err, + raw: String::from_utf8_lossy(&response_bytes).into_owned(), + }); + } + }; debug!( latency = ?request_latency, diff --git a/crates/pbs/src/mev_boost/register_validator.rs b/crates/pbs/src/mev_boost/register_validator.rs index 5fcfc991..88eb463f 100644 --- a/crates/pbs/src/mev_boost/register_validator.rs +++ b/crates/pbs/src/mev_boost/register_validator.rs @@ -93,7 +93,7 @@ async fn send_register_validator( let response_bytes = res.bytes().await?; if response_bytes.len() > MAX_SIZE { - return Err(PbsError::PayloadTooLarge { payload_size: response_bytes.len() }); + return Err(PbsError::PayloadTooLarge { max: MAX_SIZE, got: response_bytes.len() }); } if !code.is_success() { let err = PbsError::RelayResponse { @@ -102,7 +102,7 @@ async fn send_register_validator( }; // error here since we check if any success aboves - error!(?err, "failed registration"); + error!(%err, "failed registration"); return Err(err); }; diff --git a/crates/pbs/src/mev_boost/status.rs b/crates/pbs/src/mev_boost/status.rs index 514ef860..29a268ba 100644 --- a/crates/pbs/src/mev_boost/status.rs +++ b/crates/pbs/src/mev_boost/status.rs @@ -76,7 +76,7 @@ async fn send_relay_check(relay: &RelayClient, headers: HeaderMap) -> Result<(), let response_bytes = res.bytes().await?; if response_bytes.len() > MAX_SIZE { - return Err(PbsError::PayloadTooLarge { payload_size: response_bytes.len() }); + return Err(PbsError::PayloadTooLarge { max: MAX_SIZE, got: response_bytes.len() }); } if !code.is_success() { let err = PbsError::RelayResponse { @@ -84,7 +84,7 @@ async fn send_relay_check(relay: &RelayClient, headers: HeaderMap) -> Result<(), code: code.as_u16(), }; - error!(?err, "status failed"); + error!(%err, "status failed"); return Err(err); }; diff --git a/crates/pbs/src/mev_boost/submit_block.rs b/crates/pbs/src/mev_boost/submit_block.rs index e430ca32..295cc354 100644 --- a/crates/pbs/src/mev_boost/submit_block.rs +++ b/crates/pbs/src/mev_boost/submit_block.rs @@ -97,7 +97,7 @@ async fn send_submit_block( let response_bytes = res.bytes().await?; if response_bytes.len() > MAX_SIZE { - return Err(PbsError::PayloadTooLarge { payload_size: response_bytes.len() }); + return Err(PbsError::PayloadTooLarge { max: MAX_SIZE, got: response_bytes.len() }); } if !code.is_success() { let err = PbsError::RelayResponse { @@ -106,11 +106,20 @@ async fn send_submit_block( }; // we request payload to all relays, but some may have not received it - warn!(?err, "failed to get payload (this might be ok if other relays have it)"); + warn!(%err, "failed to get payload (this might be ok if other relays have it)"); return Err(err); }; - let block_response: SubmitBlindedBlockResponse = serde_json::from_slice(&response_bytes)?; + let block_response = match serde_json::from_slice::(&response_bytes) + { + Ok(parsed) => parsed, + Err(err) => { + return Err(PbsError::JsonDecode { + err, + raw: String::from_utf8_lossy(&response_bytes).into_owned(), + }); + } + }; debug!( latency = ?request_latency, diff --git a/crates/pbs/src/routes/register_validator.rs b/crates/pbs/src/routes/register_validator.rs index b7b8c65a..fd73837b 100644 --- a/crates/pbs/src/routes/register_validator.rs +++ b/crates/pbs/src/routes/register_validator.rs @@ -76,7 +76,7 @@ async fn send_relay_monitor_registrations( { Ok(res) => res, Err(err) => { - error!(?err, "failed monitor registration"); + error!(%err, "failed monitor registration"); return; } }; @@ -89,10 +89,10 @@ async fn send_relay_monitor_registrations( debug!(?code, latency = ?request_latency, "relay monitor registration successful"); } else { let err = String::from_utf8_lossy(&response_bytes); - error!(?code, ?err, "failed monitor registration"); + error!(?code, %err, "failed monitor registration"); } } - Err(err) => error!(?err, "failed to decode monitor response"), + Err(err) => error!(%err, "failed to decode monitor response"), } } diff --git a/crates/pbs/src/routes/submit_block.rs b/crates/pbs/src/routes/submit_block.rs index 033cee85..66e2ed23 100644 --- a/crates/pbs/src/routes/submit_block.rs +++ b/crates/pbs/src/routes/submit_block.rs @@ -63,7 +63,7 @@ pub async fn handle_submit_block>( relays: fault_relays, }); } else { - error!(?err, %block_hash, "CRITICAL: no payload delivered and no relay for block hash. Was getHeader even called?"); + error!(%err, %block_hash, "CRITICAL: no payload delivered and no relay for block hash. Was getHeader even called?"); state.publish_event(BuilderEvent::MissedPayload { block_hash, relays: String::default(), diff --git a/crates/pbs/src/service.rs b/crates/pbs/src/service.rs index af1725fe..7b47a179 100644 --- a/crates/pbs/src/service.rs +++ b/crates/pbs/src/service.rs @@ -1,5 +1,6 @@ use std::net::SocketAddr; +use cb_common::constants::COMMIT_BOOST_VERSION; use cb_metrics::provider::MetricsProvider; use eyre::{Context, Result}; use prometheus::core::Collector; @@ -15,14 +16,12 @@ use crate::{ pub struct PbsService; -// TODO: add ServerMaxHeaderBytes - impl PbsService { pub async fn run>(state: PbsState) -> Result<()> { let address = SocketAddr::from(([0, 0, 0, 0], state.config.pbs_config.port)); let events_subs = state.config.event_publisher.as_ref().map(|e| e.n_subscribers()).unwrap_or_default(); - info!(?address, events_subs, chain =? state.config.chain, "Starting PBS service"); + info!(version = COMMIT_BOOST_VERSION, ?address, events_subs, chain =? state.config.chain, "Starting PBS service"); let app = create_app_router::(state); let listener = TcpListener::bind(address).await.expect("failed tcp binding"); diff --git a/crates/signer/src/service.rs b/crates/signer/src/service.rs index 0f7e432e..754dda92 100644 --- a/crates/signer/src/service.rs +++ b/crates/signer/src/service.rs @@ -19,6 +19,7 @@ use cb_common::{ }, }, config::StartSignerConfig, + constants::COMMIT_BOOST_VERSION, types::{Jwt, ModuleId}, }; use eyre::{Result, WrapErr}; @@ -50,7 +51,7 @@ impl SigningService { let module_ids: Vec = config.jwts.left_values().cloned().map(Into::into).collect(); - info!(modules =? module_ids, port =? config.server_port, "Starting signing service"); + info!(version = COMMIT_BOOST_VERSION, modules =? module_ids, port =? config.server_port, "Starting signing service"); } let mut manager = SigningManager::new(config.chain); @@ -73,7 +74,7 @@ impl SigningService { let listener = TcpListener::bind(address).await.wrap_err("failed tcp binding")?; if let Err(err) = axum::serve(listener, app).await { - error!(?err, "Signing server exited") + error!(%err, "Signing server exited") } Ok(()) } diff --git a/docs/docs/developing/commit-module.md b/docs/docs/developing/commit-module.md index 82b6f616..af47384e 100644 --- a/docs/docs/developing/commit-module.md +++ b/docs/docs/developing/commit-module.md @@ -4,7 +4,7 @@ sidebar_position: 2 # Commit Module -While a module can be written in any language, we currently provide some utils for Rust, with the goal of supporting more generalized APIs and simplify development in languages other than Rust. +While a module can be written in any language, we currently provide some utilities for Rust, with the goal of supporting more generalized APIs and simplify development in languages other than Rust. :::note Commit-Boost is still in alpha development, all APIs are subject to change @@ -25,7 +25,7 @@ use commit_boost::prelude::*; ## Config Your module will likely need a configuration for the Node Operator to customize. This will have to be in the `cb-config.toml` file, in the correct `[[module]]` section. In the module, you can define and load your config as follows. -First define all the parameters needed in a struct: +First, define all the parameters needed in a struct: ```rust #[derive(Debug, Deserialize)] struct ExtraConfig { @@ -109,7 +109,7 @@ You can use the `prometheus` crate to create a custom registry and metrics, for ```rust static ref MY_CUSTOM_REGISTRY: Registry = Registry::new_custom(Some("da_commit".to_string()), None).unwrap(); -static ref SIG_RECEIVED_COUNTER: IntCounter = IntCounter::new("signature_received", "successful signatures requests received").unwrap(); +static ref SIG_RECEIVED_COUNTER: IntCounter = IntCounter::new("signature_received", "successful signature requests received").unwrap(); ``` ### Start Metrics Provider @@ -125,4 +125,4 @@ All that is left is to use the metrics throughout your code: ```rust SIG_RECEIVED_COUNTER.inc(); ``` -These will automatically scraped by the Prometheus service running, and exposed on port `9090`. We plan to allow developers to ship pre-made dashboards together with their modules, to allow Node Operators to have an improved oversight on the modules they are running. \ No newline at end of file +These will be automatically scraped by the Prometheus service running, and exposed on port `9090`. We plan to allow developers to ship pre-made dashboards together with their modules, to allow Node Operators to have an improved oversight on the modules they are running. \ No newline at end of file diff --git a/docs/docs/get_started/running/binary.md b/docs/docs/get_started/running/binary.md index 28a22a6e..b86c8ffa 100644 --- a/docs/docs/get_started/running/binary.md +++ b/docs/docs/get_started/running/binary.md @@ -35,7 +35,7 @@ For loading keys we currently support: - `CB_MODULE_ID`: required, unique id of the module #### Commit modules -- `CB_SIGNER_URL`: requred, url to the signer module server +- `CB_SIGNER_URL`: required, url to the signer module server - `CB_SIGNER_JWT`: required, jwt to use to for signature requests (needs to match what is in `CB_JWTS`) #### Events modules diff --git a/examples/builder_log/src/main.rs b/examples/builder_log/src/main.rs index 96544856..aed6a4ba 100644 --- a/examples/builder_log/src/main.rs +++ b/examples/builder_log/src/main.rs @@ -23,7 +23,7 @@ async fn main() -> eyre::Result<()> { let client = BuilderEventClient::new(config.server_port, LogProcessor); if let Err(err) = client.run().await { - error!(?err, "Service failed"); + error!(%err, "Service failed"); } } Err(err) => { diff --git a/examples/da_commit/src/main.rs b/examples/da_commit/src/main.rs index cc2e2204..88767f00 100644 --- a/examples/da_commit/src/main.rs +++ b/examples/da_commit/src/main.rs @@ -120,7 +120,7 @@ async fn main() -> Result<()> { let service = DaCommitService { config }; if let Err(err) = service.run().await { - error!(?err, "Service failed"); + error!(%err, "Service failed"); } } Err(err) => { diff --git a/tests/src/main.rs b/tests/src/main.rs deleted file mode 100644 index 47e28fa6..00000000 --- a/tests/src/main.rs +++ /dev/null @@ -1,33 +0,0 @@ -#[tokio::main] -async fn main() { - // initialize_tracing_log(); - - // info!("Starting mock validator"); - - // let args = cb_cli::Args::parse(); - - // match args.cmd { - // cb_cli::Command::Init { .. } => { - // unreachable!() - // } - // cb_cli::Command::Start { .. } => { - // unreachable!() - // } - // cb_cli::Command::Start2 { config } => { - // let config = CommitBoostConfig::from_file(&config); - - // let mock_validator = - // MockValidator::new(config.pbs.pbs_config.address); - - // loop { - // if let Err(err) = mock_validator.do_get_status().await { - // error!(?err, "failed to get status") - // } else { - // info!("Get status successful") - // }; - - // sleep(Duration::from_secs(3)).await; - // } - // } - // } -}