Skip to content

Commit

Permalink
Merge pull request #61 from gattaca-com/ltitanb/logs
Browse files Browse the repository at this point in the history
chore: builder api logs
  • Loading branch information
0w3n-d authored Dec 6, 2024
2 parents 17fb43b + 4bcbbb2 commit 89cb716
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 470 deletions.
584 changes: 190 additions & 394 deletions crates/api/src/builder/api.rs

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions crates/api/src/builder/simulator/mock_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use async_trait::async_trait;
use tokio::sync::mpsc::Sender;

use helix_common::{simulator::BlockSimError, BuilderInfo};
use uuid::Uuid;

use crate::builder::{traits::BlockSimulator, BlockSimRequest, DbInfo};

Expand All @@ -23,7 +22,6 @@ impl BlockSimulator for MockSimulator {
_builder_info: &BuilderInfo,
_is_top_bid: bool,
_sim_result_saver_sender: Sender<DbInfo>,
_request_id: Uuid,
) -> Result<bool, BlockSimError> {
Ok(true)
}
Expand Down
6 changes: 1 addition & 5 deletions crates/api/src/builder/simulator/multi_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::sync::{
Arc,
};
use tokio::sync::mpsc::Sender;
use uuid::Uuid;

use crate::builder::DbInfo;

Expand Down Expand Up @@ -35,7 +34,6 @@ impl<B: BlockSimulator + Send + Sync> BlockSimulator for MultiSimulator<B> {
builder_info: &BuilderInfo,
is_top_bid: bool,
sim_result_saver_sender: Sender<DbInfo>,
request_id: Uuid,
) -> Result<bool, BlockSimError> {
// Load balancing: round-robin selection
let index = self
Expand All @@ -48,8 +46,6 @@ impl<B: BlockSimulator + Send + Sync> BlockSimulator for MultiSimulator<B> {
let simulator = &self.simulators[index];

// Process the request with the selected simulator
simulator
.process_request(request, builder_info, is_top_bid, sim_result_saver_sender, request_id)
.await
simulator.process_request(request, builder_info, is_top_bid, sim_result_saver_sender).await
}
}
42 changes: 16 additions & 26 deletions crates/api/src/builder/simulator/optimistic_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use async_trait::async_trait;
use ethereum_consensus::primitives::{BlsPublicKey, Hash32};
use reqwest::Client;
use tokio::sync::{mpsc::Sender, RwLock};
use tracing::{debug, error, warn};
use uuid::Uuid;
use tracing::{debug, error, warn, Instrument};

use helix_common::{metrics::SimulatorMetrics, simulator::BlockSimError, BuilderInfo};
use helix_database::DatabaseService;
Expand Down Expand Up @@ -58,22 +57,14 @@ impl<A: Auctioneer + 'static, DB: DatabaseService + 'static> OptimisticSimulator
is_top_bid: bool,
sim_result_saver_sender: Sender<DbInfo>,
builder_info: BuilderInfo,
request_id: Uuid,
) -> Result<(), BlockSimError> {
if let Err(err) = self
.simulator
.process_request(
request.clone(),
&builder_info,
is_top_bid,
sim_result_saver_sender,
request_id,
)
.process_request(request.clone(), &builder_info, is_top_bid, sim_result_saver_sender)
.await
{
if builder_info.is_optimistic {
warn!(
request_id=%request_id,
builder=%request.message.builder_public_key,
block_hash=%request.execution_payload.block_hash(),
err=%err,
Expand Down Expand Up @@ -156,37 +147,37 @@ impl<A: Auctioneer, DB: DatabaseService> BlockSimulator for OptimisticSimulator<
builder_info: &BuilderInfo,
is_top_bid: bool,
sim_result_saver_sender: Sender<DbInfo>,
request_id: Uuid,
) -> Result<bool, BlockSimError> {
if self.should_process_optimistically(&request, builder_info).await {
SimulatorMetrics::sim_count(true);

debug!(
request_id=%request_id,
block_hash=%request.execution_payload.block_hash(),
"optimistically processing request"
);

let cloned_self = self.clone_for_async();
let builder_info = builder_info.clone();
tokio::spawn(async move {
cloned_self
.handle_simulation(
request,
is_top_bid,
sim_result_saver_sender,
builder_info,
request_id,
)
.await
});
tokio::spawn(
async move {
cloned_self
.handle_simulation(
request,
is_top_bid,
sim_result_saver_sender,
builder_info,
)
.await
}
.in_current_span(),
);

Ok(true)
} else {
SimulatorMetrics::sim_count(false);

debug!(
request_id=%request_id,

block_hash=?request.execution_payload.block_hash(),
block_parent_hash=?request.execution_payload.parent_hash(),
block_number=%request.execution_payload.block_number(),
Expand All @@ -198,7 +189,6 @@ impl<A: Auctioneer, DB: DatabaseService> BlockSimulator for OptimisticSimulator<
is_top_bid,
sim_result_saver_sender,
builder_info.clone(),
request_id,
)
.await
.map(|_| false)
Expand Down
21 changes: 8 additions & 13 deletions crates/api/src/builder/simulator/optimistic_simulator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod simulator_tests {
use reth_primitives::hex;
use serde_json::json;
use std::sync::{atomic::AtomicBool, Arc};
use uuid::Uuid;

// ++++ HELPERS ++++
fn get_optimistic_simulator(
Expand Down Expand Up @@ -109,9 +108,8 @@ mod simulator_tests {
builder_demoted.clone(),
);

let result = simulator
.process_request(get_sim_req(), &builder_info, true, sim_res_sender, Uuid::new_v4())
.await;
let result =
simulator.process_request(get_sim_req(), &builder_info, true, sim_res_sender).await;

// give the simulator time to process the request
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
Expand Down Expand Up @@ -140,9 +138,8 @@ mod simulator_tests {
builder_demoted.clone(),
);

let result = simulator
.process_request(get_sim_req(), &builder_info, true, sim_res_sender, Uuid::new_v4())
.await;
let result =
simulator.process_request(get_sim_req(), &builder_info, true, sim_res_sender).await;

// give the simulator time to process the request
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
Expand Down Expand Up @@ -171,9 +168,8 @@ mod simulator_tests {
builder_demoted.clone(),
);

let result = simulator
.process_request(get_sim_req(), &builder_info, true, sim_res_sender, Uuid::new_v4())
.await;
let result =
simulator.process_request(get_sim_req(), &builder_info, true, sim_res_sender).await;

// give the simulator time to process the request
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
Expand Down Expand Up @@ -202,9 +198,8 @@ mod simulator_tests {
builder_demoted.clone(),
);

let result = simulator
.process_request(get_sim_req(), &builder_info, true, sim_res_sender, Uuid::new_v4())
.await;
let result =
simulator.process_request(get_sim_req(), &builder_info, true, sim_res_sender).await;

// give the simulator time to process the request
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
Expand Down
7 changes: 2 additions & 5 deletions crates/api/src/builder/simulator/rpc_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use tokio::sync::mpsc::Sender;
use tracing::{debug, error};

use helix_common::simulator::BlockSimError;
use uuid::Uuid;

use crate::builder::{traits::BlockSimulator, BlockSimRequest, DbInfo};

Expand Down Expand Up @@ -94,14 +93,12 @@ impl BlockSimulator for RpcSimulator {
_builder_info: &BuilderInfo,
is_top_bid: bool,
sim_result_saver_sender: Sender<DbInfo>,
request_id: Uuid,
) -> Result<bool, BlockSimError> {
let timer = SimulatorMetrics::timer();

let block_hash = request.execution_payload.block_hash().clone();
debug!(
request_id = %request_id,
block_hash = %block_hash,
%block_hash,
builder_pub_key = %request.message.builder_public_key,
"RpcSimulator::process_request",
);
Expand All @@ -124,7 +121,7 @@ impl BlockSimulator for RpcSimulator {
}
Err(err) => {
timer.stop_and_discard();
error!(request_id = %request_id, err = ?err, "Error sending RPC request");
error!(?err, "Error sending RPC request");
SimulatorMetrics::sim_status(false);
Err(BlockSimError::RpcError(err.to_string()))
}
Expand Down
16 changes: 6 additions & 10 deletions crates/api/src/builder/simulator/simulator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use reqwest::Client;
use reth_primitives::hex;
use serde_json::json;
use std::sync::Arc;
use uuid::Uuid;

// ++++ HELPERS ++++
fn get_simulator(endpoint: &str) -> RpcSimulator {
Expand Down Expand Up @@ -65,9 +64,8 @@ async fn test_process_request_ok() {
let (sim_res_sender, mut sim_res_receiver) = tokio::sync::mpsc::channel(100);
let simulator = get_simulator(&server.url());
let builder_info = BuilderInfo::default();
let result = simulator
.process_request(get_sim_req(), &builder_info, true, sim_res_sender, Uuid::new_v4())
.await;
let result =
simulator.process_request(get_sim_req(), &builder_info, true, sim_res_sender).await;

mock.assert();
assert!(result.is_ok());
Expand Down Expand Up @@ -98,9 +96,8 @@ async fn test_process_request_error() {
let (sim_res_sender, _sim_res_receiver) = tokio::sync::mpsc::channel(100);
let simulator = get_simulator(&server.url());
let builder_info = BuilderInfo::default();
let result = simulator
.process_request(get_sim_req(), &builder_info, true, sim_res_sender, Uuid::new_v4())
.await;
let result =
simulator.process_request(get_sim_req(), &builder_info, true, sim_res_sender).await;

mock.assert();
assert!(result.is_err());
Expand Down Expand Up @@ -130,9 +127,8 @@ async fn test_process_request_validation_failed() {
let (sim_res_sender, _sim_res_receiver) = tokio::sync::mpsc::channel(100);
let simulator = get_simulator(&server.url());
let builder_info = BuilderInfo::default();
let result = simulator
.process_request(get_sim_req(), &builder_info, true, sim_res_sender, Uuid::new_v4())
.await;
let result =
simulator.process_request(get_sim_req(), &builder_info, true, sim_res_sender).await;

mock.assert();
assert!(result.is_err());
Expand Down
2 changes: 0 additions & 2 deletions crates/api/src/builder/simulator/traits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use async_trait::async_trait;
use helix_common::{simulator::BlockSimError, BuilderInfo};
use tokio::sync::mpsc::Sender;
use uuid::Uuid;

use crate::builder::{BlockSimRequest, DbInfo};

Expand All @@ -14,6 +13,5 @@ pub trait BlockSimulator: Send + Sync + Clone {
builder_info: &BuilderInfo,
is_top_bid: bool,
sim_result_saver_sender: Sender<DbInfo>,
request_id: Uuid,
) -> Result<bool, BlockSimError>;
}
21 changes: 8 additions & 13 deletions crates/api/src/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,9 @@ async fn test_header_submission_decoding_json_capella() {
load_bytes(current_dir.to_str().expect("Failed to convert path to string"));

let mut header_submission_trace = HeaderSubmissionTrace::default();
let uuid = uuid::Uuid::new_v4();
let request = generate_request(false, false, false, &req_payload_bytes);
let decoded_submission =
decode_header_submission(request, &mut header_submission_trace, &uuid).await.unwrap();
decode_header_submission(request, &mut header_submission_trace).await.unwrap();

assert_eq!(decoded_submission.0.slot(), 5552306);
assert!(matches!(
Expand Down Expand Up @@ -505,10 +504,10 @@ async fn test_header_submission_decoding_ssz_capella() {
load_bytes(current_dir.to_str().expect("Failed to convert path to string"));

let mut header_submission_trace = HeaderSubmissionTrace::default();
let uuid = uuid::Uuid::new_v4();

let request = generate_request(false, false, true, &req_payload_bytes);
let decoded_submission =
decode_header_submission(request, &mut header_submission_trace, &uuid).await.unwrap();
decode_header_submission(request, &mut header_submission_trace).await.unwrap();

assert!(matches!(decoded_submission.0, SignedHeaderSubmission::Capella(_)));
assert!(decoded_submission.0.commitments().is_none());
Expand All @@ -529,10 +528,10 @@ async fn test_header_submission_decoding_ssz_deneb() {
load_bytes(current_dir.to_str().expect("Failed to convert path to string"));

let mut header_submission_trace = HeaderSubmissionTrace::default();
let uuid = uuid::Uuid::new_v4();

let request = generate_request(false, false, true, &req_payload_bytes);
let decoded_submission =
decode_header_submission(request, &mut header_submission_trace, &uuid).await.unwrap();
decode_header_submission(request, &mut header_submission_trace).await.unwrap();

assert!(matches!(decoded_submission.0, SignedHeaderSubmission::Deneb(_)));
assert!(decoded_submission.0.commitments().is_some());
Expand All @@ -553,9 +552,8 @@ async fn test_signed_bid_submission_decoding_capella() {
load_bytes(current_dir.to_str().expect("Failed to convert path to string"));

let mut submission_trace = SubmissionTrace::default();
let uuid = uuid::Uuid::new_v4();
let request = generate_request(false, false, false, &req_payload_bytes);
let decoded_submission = decode_payload(request, &mut submission_trace, &uuid).await.unwrap();
let decoded_submission = decode_payload(request, &mut submission_trace).await.unwrap();

assert_eq!(decoded_submission.0.message().slot, 5552306);
assert!(matches!(decoded_submission.0.execution_payload(), ExecutionPayload::Capella(_)));
Expand All @@ -574,9 +572,8 @@ async fn test_signed_bid_submission_decoding_capella_gzip() {
load_bytes(current_dir.to_str().expect("Failed to convert path to string"));

let mut submission_trace = SubmissionTrace::default();
let uuid = uuid::Uuid::new_v4();
let request = generate_request(false, true, false, &req_payload_bytes);
let decoded_submission = decode_payload(request, &mut submission_trace, &uuid).await.unwrap();
let decoded_submission = decode_payload(request, &mut submission_trace).await.unwrap();

assert_eq!(decoded_submission.0.message().slot, 5552306);
assert!(matches!(decoded_submission.0.execution_payload(), ExecutionPayload::Capella(_)));
Expand All @@ -595,10 +592,8 @@ async fn test_signed_bid_submission_decoding_deneb() {
load_bytes(current_dir.to_str().expect("Failed to convert path to string"));

let mut submission_trace = SubmissionTrace::default();
let uuid = uuid::Uuid::new_v4();
let request = generate_request(false, false, false, &req_payload_bytes);
let (decoded_submission, _) =
decode_payload(request, &mut submission_trace, &uuid).await.unwrap();
let (decoded_submission, _) = decode_payload(request, &mut submission_trace).await.unwrap();

assert_eq!(decoded_submission.message().slot, 5552306);
assert!(matches!(decoded_submission.execution_payload(), ExecutionPayload::Deneb(_)));
Expand Down

0 comments on commit 89cb716

Please sign in to comment.