Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sidecar): import tracing macros in files #184

Merged
merged 1 commit into from
Aug 6, 2024
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
8 changes: 3 additions & 5 deletions bolt-client/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use alloy::{
};
use beacon_api_client::ProposerDuty;
use reqwest::Client;
use tracing::info;
use url::Url;
use BoltRegistryContract::{BoltRegistryContractErrors, BoltRegistryContractInstance, Registrant};

Expand Down Expand Up @@ -87,7 +88,7 @@ impl BoltRegistry {
Ok(Some(token_raw)) => {
next_preconfer_slot = duty.slot;
proposer_rpc = token_raw.metadata.rpc;
tracing::info!(
info!(
"pre-confirmation will be sent for slot {} to validator with index {} at url {}",
duty.slot,
duty.validator_index,
Expand All @@ -99,10 +100,7 @@ impl BoltRegistry {
// Handle the case where the result is Ok but contains None.
// You might want to continue to the next iteration, log something, or handle it
// in another way.
tracing::info!(
"No registrant found for validator index {}",
duty.validator_index
);
info!("No registrant found for validator index {}", duty.validator_index);
continue;
}
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion bolt-kurtosis-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Opts {
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
tracing::info!("starting bolt-spammer");
info!("starting bolt-spammer");

let opts = Opts::parse();

Expand Down
39 changes: 20 additions & 19 deletions bolt-sidecar/src/api/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use serde::Deserialize;
use std::{sync::Arc, time::Duration};
use thiserror::Error;
use tokio::net::TcpListener;
use tracing::{debug, error, info, warn};

use super::spec::{
BuilderApiError, ConstraintsApi, GET_HEADER_PATH, GET_PAYLOAD_PATH, REGISTER_VALIDATORS_PATH,
Expand Down Expand Up @@ -64,18 +65,18 @@ where
/// Gets the status. Just forwards the request to mev-boost and returns the status.
pub async fn status(State(server): State<Arc<BuilderProxyServer<T, P>>>) -> StatusCode {
let start = std::time::Instant::now();
tracing::debug!("Received status request");
debug!("Received status request");

let status = match server.proxy_target.status().await {
Ok(status) => status,
Err(error) => {
tracing::error!(%error, "Failed to get status from mev-boost");
error!(%error, "Failed to get status from mev-boost");
StatusCode::INTERNAL_SERVER_ERROR
}
};

let elapsed = start.elapsed();
tracing::debug!(?elapsed, "Returning status: {:?}", status);
debug!(?elapsed, "Returning status: {:?}", status);

status
}
Expand All @@ -89,12 +90,12 @@ where
Json(registrations): Json<Vec<SignedValidatorRegistration>>,
) -> Result<StatusCode, BuilderApiError> {
let start = std::time::Instant::now();
tracing::debug!("Received register validators request");
debug!("Received register validators request");

let response = server.proxy_target.register_validators(registrations).await;

let elapsed = start.elapsed();
tracing::debug!(?elapsed, "Returning response: {:?}", response);
debug!(?elapsed, "Returning response: {:?}", response);

response.map(|_| StatusCode::OK)
}
Expand All @@ -110,7 +111,7 @@ where
) -> Result<Json<VersionedValue<SignedBuilderBid>>, BuilderApiError> {
let start = std::time::Instant::now();

tracing::debug!("Received get_header request");
debug!("Received get_header request");
let slot = params.slot;

let err = match tokio::time::timeout(
Expand All @@ -128,27 +129,27 @@ where
let mut local_payload = server.local_payload.lock();
*local_payload = None;

tracing::debug!(elapsed = ?start.elapsed(), "Returning signed builder bid");
debug!(elapsed = ?start.elapsed(), "Returning signed builder bid");
return Ok(Json(header));
}
},
Err(err) => BuilderApiError::Timeout(err),
};

// On ANY error, we fall back to locally built block
tracing::warn!(slot, elapsed = ?start.elapsed(), err = ?err, "Proxy error, fetching local payload instead");
warn!(slot, elapsed = ?start.elapsed(), err = ?err, "Proxy error, fetching local payload instead");

let Some(payload_and_bid) = server.payload_fetcher.fetch_payload(slot).await else {
// TODO: handle failure? In this case, we don't have a fallback block
// which means we haven't made any commitments. This means the EL should
// fallback to local block building.
tracing::debug!("No local payload with commitments produced for slot {slot}");
debug!("No local payload with commitments produced for slot {slot}");
return Err(BuilderApiError::FailedToFetchLocalPayload(slot));
};

let hash = payload_and_bid.bid.message.header.block_hash.clone();
let number = payload_and_bid.bid.message.header.block_number;
tracing::info!(elapsed = ?start.elapsed(), %hash, "Fetched local payload for slot {slot}");
info!(elapsed = ?start.elapsed(), %hash, "Fetched local payload for slot {slot}");

{
// Since we've signed a local header, set the payload for
Expand All @@ -163,7 +164,7 @@ where
meta: Default::default(),
};

tracing::info!(elapsed = ?start.elapsed(), %hash, number, ?versioned_bid, "Returning locally built header");
info!(elapsed = ?start.elapsed(), %hash, number, ?versioned_bid, "Returning locally built header");
Ok(Json(versioned_bid))
}

Expand All @@ -172,18 +173,18 @@ where
req: Request<Body>,
) -> Result<Json<GetPayloadResponse>, BuilderApiError> {
let start = std::time::Instant::now();
tracing::debug!("Received get_payload request");
debug!("Received get_payload request");

let body_bytes =
body::to_bytes(req.into_body(), MAX_BLINDED_BLOCK_LENGTH).await.map_err(|e| {
tracing::error!(error = %e, "Failed to read request body");
error!(error = %e, "Failed to read request body");
e
})?;

// Convert to signed blinded beacon block
let signed_blinded_block = serde_json::from_slice::<SignedBlindedBeaconBlock>(&body_bytes)
.map_err(|e| {
tracing::error!(error = %e, "Failed to parse signed blinded block");
error!(error = %e, "Failed to parse signed blinded block");
e
})?;

Expand All @@ -192,7 +193,7 @@ where
if let Some(local_payload) = server.local_payload.lock().take() {
check_locally_built_payload_integrity(&signed_blinded_block, &local_payload)?;

tracing::debug!("Valid local block found, returning: {local_payload:?}");
debug!("Valid local block found, returning: {local_payload:?}");
return Ok(Json(local_payload));
}

Expand All @@ -205,11 +206,11 @@ where
.await
.map(Json)
.map_err(|e| {
tracing::error!(elapsed = ?start.elapsed(), error = %e, "Failed to get payload from mev-boost");
error!(elapsed = ?start.elapsed(), error = %e, "Failed to get payload from mev-boost");
e
})?;

tracing::debug!(elapsed = ?start.elapsed(), "Returning payload");
debug!(elapsed = ?start.elapsed(), "Returning payload");

Ok(payload)
}
Expand All @@ -232,7 +233,7 @@ pub async fn start_builder_proxy_server<P>(
where
P: PayloadFetcher + Send + Sync + 'static,
{
tracing::info!(
info!(
port = config.server_port,
target = config.mevboost_url.to_string(),
"Starting builder proxy..."
Expand Down Expand Up @@ -273,7 +274,7 @@ pub enum LocalPayloadIntegrityError {
macro_rules! assert_payload_fields_eq {
($expected:expr, $have:expr, $field_name:ident) => {
if $expected != $have {
tracing::error!(
error!(
field_name = stringify!($field_name),
expected = %$expected,
have = %$have,
Expand Down
18 changes: 9 additions & 9 deletions bolt-sidecar/src/api/commitments/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::{
net::TcpListener,
sync::{mpsc, oneshot},
};
use tracing::error;
use tracing::{debug, error, info, instrument};

use crate::{
common::CARGO_PKG_VERSION,
Expand Down Expand Up @@ -135,13 +135,13 @@ impl CommitmentsApiServer {
let addr = listener.local_addr().expect("Failed to get local address");
self.addr = addr;

tracing::info!("Commitments RPC server bound to {addr}");
info!("Commitments RPC server bound to {addr}");

let signal = self.signal.take().expect("Signal not set");

tokio::spawn(async move {
if let Err(err) = axum::serve(listener, router).with_graceful_shutdown(signal).await {
tracing::error!(?err, "Commitments API Server error");
error!(?err, "Commitments API Server error");
}
});
}
Expand All @@ -152,16 +152,16 @@ impl CommitmentsApiServer {
}

/// Handler function for the root JSON-RPC path.
#[tracing::instrument(skip_all, name = "RPC", fields(method = %payload.method))]
#[instrument(skip_all, name = "RPC", fields(method = %payload.method))]
async fn handle_rpc(
headers: HeaderMap,
State(api): State<Arc<CommitmentsApiInner>>,
WithRejection(Json(payload), _): WithRejection<Json<JsonPayload>, Error>,
) -> Result<Json<JsonResponse>, Error> {
tracing::debug!("Received new request");
debug!("Received new request");

let (signer, signature) = auth_from_headers(&headers).inspect_err(|e| {
tracing::error!("Failed to extract signature from headers: {:?}", e);
error!("Failed to extract signature from headers: {:?}", e);
})?;

match payload.method.as_str() {
Expand Down Expand Up @@ -190,7 +190,7 @@ impl CommitmentsApiServer {
let recovered_signer = signature.recover_address_from_prehash(&digest)?;

if recovered_signer != signer {
tracing::error!(
error!(
?recovered_signer,
?signer,
"Recovered signer does not match the provided signer"
Expand All @@ -202,7 +202,7 @@ impl CommitmentsApiServer {
// Set the request signer
inclusion_request.set_signer(recovered_signer);

tracing::info!(signer = ?recovered_signer, %digest, "New valid inclusion request received");
info!(signer = ?recovered_signer, %digest, "New valid inclusion request received");
let inclusion_commitment = api.request_inclusion(inclusion_request).await?;

// Create the JSON-RPC response
Expand All @@ -215,7 +215,7 @@ impl CommitmentsApiServer {
Ok(Json(response))
}
other => {
tracing::error!("Unknown method: {}", other);
error!("Unknown method: {}", other);
Err(Error::UnknownMethod)
}
}
Expand Down
20 changes: 11 additions & 9 deletions bolt-sidecar/src/builder/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use reth_primitives::{
};
use reth_rpc_layer::{secret_to_bearer_header, JwtSecret};
use serde_json::Value;
use tracing::{debug, info, trace, warn};

use super::{
compat::{to_alloy_execution_payload, to_reth_withdrawal},
Expand Down Expand Up @@ -106,7 +107,7 @@ impl FallbackPayloadBuilder {
) -> Result<SealedBlock, BuilderError> {
// TODO: what if the latest block ends up being reorged out?
let latest_block = self.execution_rpc_client.get_block(None, true).await?;
tracing::debug!(num = ?latest_block.header.number, "got latest block");
debug!(num = ?latest_block.header.number, "got latest block");

let withdrawals = self
.beacon_api_client
Expand All @@ -117,7 +118,7 @@ impl FallbackPayloadBuilder {
.map(to_reth_withdrawal)
.collect::<Vec<_>>();

tracing::debug!(amount = ?withdrawals.len(), "got withdrawals");
debug!(amount = ?withdrawals.len(), "got withdrawals");

// let prev_randao = self
// .beacon_api_client
Expand All @@ -138,18 +139,18 @@ impl FallbackPayloadBuilder {
.unwrap();
let prev_randao = prev_randao.pointer("/data/randao").unwrap().as_str().unwrap();
let prev_randao = B256::from_hex(prev_randao).unwrap();
tracing::debug!("got prev_randao");
debug!("got prev_randao");

let parent_beacon_block_root =
self.beacon_api_client.get_beacon_block_root(BlockId::Head).await?;
tracing::debug!(parent = ?parent_beacon_block_root, "got parent_beacon_block_root");
debug!(parent = ?parent_beacon_block_root, "got parent_beacon_block_root");

let versioned_hashes = transactions
.iter()
.flat_map(|tx| tx.blob_versioned_hashes())
.flatten()
.collect::<Vec<_>>();
tracing::info!(amount = ?versioned_hashes.len(), "got versioned_hashes");
info!(amount = ?versioned_hashes.len(), "got versioned_hashes");

let base_fee = calc_next_block_base_fee(
latest_block.header.gas_used,
Expand Down Expand Up @@ -204,11 +205,11 @@ impl FallbackPayloadBuilder {
.fetch_next_payload_hint(&exec_payload, &versioned_hashes, parent_beacon_block_root)
.await?;

tracing::debug!("engine_hint: {:?}", engine_hint);
debug!("engine_hint: {:?}", engine_hint);

match engine_hint {
EngineApiHint::BlockHash(hash) => {
tracing::warn!("Should not receive block hash hint {:?}", hash);
warn!("Should not receive block hash hint {:?}", hash);
hints.block_hash = Some(hash)
}

Expand Down Expand Up @@ -306,7 +307,7 @@ impl EngineHinter {
}
};

tracing::trace!("raw hint: {:?}", raw_hint);
trace!("raw hint: {:?}", raw_hint);

// Match the hint value to the corresponding header field and return it
if raw_hint.contains("blockhash mismatch") {
Expand Down Expand Up @@ -401,6 +402,7 @@ mod tests {
signers::{k256::ecdsa::SigningKey, local::PrivateKeySigner},
};
use reth_primitives::TransactionSigned;
use tracing::warn;

use crate::{
builder::payload_builder::FallbackPayloadBuilder,
Expand All @@ -412,7 +414,7 @@ mod tests {
let _ = tracing_subscriber::fmt::try_init();

let Some(cfg) = get_test_config().await else {
tracing::warn!("Skipping test: missing test config");
warn!("Skipping test: missing test config");
return Ok(());
};

Expand Down
3 changes: 2 additions & 1 deletion bolt-sidecar/src/builder/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ethereum_consensus::{
deneb::mainnet::{Blob, BlobsBundle},
};
use reth_primitives::TransactionSigned;
use tracing::warn;

use crate::{
common::max_transaction_cost,
Expand Down Expand Up @@ -188,7 +189,7 @@ impl BlockTemplate {

if state.balance < max_total_cost || state.transaction_count > min_nonce {
// Remove invalidated constraints due to balance / nonce of chain state
tracing::warn!(
warn!(
%address,
"Removing invalidated constraints for address"
);
Expand Down
Loading
Loading