Skip to content

Commit 7f5eca2

Browse files
committed
improve PBS logs
1 parent 2b77e8e commit 7f5eca2

File tree

9 files changed

+111
-103
lines changed

9 files changed

+111
-103
lines changed

crates/common/src/utils.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ pub fn initialize_tracing_log() {
108108
Level::INFO
109109
};
110110

111-
tracing_subscriber::fmt()
112-
.compact()
113-
.with_max_level(level)
114-
.with_target(true)
115-
.with_file(true)
116-
.init();
111+
tracing_subscriber::fmt().compact().with_max_level(level).with_target(true).init();
117112
}
118113

119114
pub fn print_logo() {

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::{sync::Arc, time::Duration};
1+
use std::{ops::Mul, sync::Arc, time::Duration};
22

33
use alloy::{
4-
primitives::{B256, U256},
4+
primitives::{utils::format_ether, B256, U256},
55
rpc::types::beacon::BlsPublicKey,
66
};
77
use axum::http::{HeaderMap, HeaderValue};
@@ -10,7 +10,7 @@ use cb_common::{
1010
pbs::{RelayEntry, HEADER_SLOT_UUID_KEY, HEADER_START_TIME_UNIX_MS},
1111
signature::verify_signed_builder_message,
1212
types::Chain,
13-
utils::{get_user_agent, utcnow_ms, wei_to_eth},
13+
utils::{get_user_agent, utcnow_ms},
1414
};
1515
use futures::future::join_all;
1616
use reqwest::{header::USER_AGENT, StatusCode};
@@ -36,12 +36,11 @@ pub async fn get_header<S: BuilderApiState>(
3636
let slot_uuid = state.get_or_update_slot_uuid(slot);
3737

3838
// prepare headers
39-
let ua = get_user_agent(&req_headers);
4039
let mut send_headers = HeaderMap::new();
4140
send_headers.insert(HEADER_SLOT_UUID_KEY, HeaderValue::from_str(&slot_uuid.to_string())?);
4241
send_headers
4342
.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from_str(&utcnow_ms().to_string())?);
44-
if let Some(ua) = ua {
43+
if let Some(ua) = get_user_agent(&req_headers) {
4544
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
4645
}
4746

@@ -75,6 +74,7 @@ pub async fn get_header<S: BuilderApiState>(
7574
Ok(state.add_bids(slot, relay_bids))
7675
}
7776

77+
#[tracing::instrument(skip_all, name = "handler", fields(relay_id = relay.id))]
7878
async fn send_get_header(
7979
headers: HeaderMap,
8080
slot: u64,
@@ -95,35 +95,39 @@ async fn send_get_header(
9595
.headers(headers)
9696
.send()
9797
.await?;
98-
timer.observe_duration();
98+
let latency_ms = timer.stop_and_record().mul(1000.0).ceil() as u64;
9999

100-
let status = res.status();
101-
RELAY_STATUS_CODE
102-
.with_label_values(&[status.as_str(), GET_HEADER_ENDPOINT_TAG, &relay.id])
103-
.inc();
100+
let code = res.status();
101+
RELAY_STATUS_CODE.with_label_values(&[code.as_str(), GET_HEADER_ENDPOINT_TAG, &relay.id]).inc();
104102

105103
let response_bytes = res.bytes().await?;
106-
if !status.is_success() {
104+
if !code.is_success() {
107105
return Err(PbsError::RelayResponse {
108106
error_msg: String::from_utf8_lossy(&response_bytes).into_owned(),
109-
code: status.as_u16(),
107+
code: code.as_u16(),
110108
});
111109
};
112110

113-
debug!(
114-
method = "get_header",
115-
relay = relay.id,
116-
code = status.as_u16(),
117-
response = ?response_bytes,
118-
"received response"
119-
);
120-
121-
if status == StatusCode::NO_CONTENT {
111+
if code == StatusCode::NO_CONTENT {
112+
debug!(
113+
?code,
114+
latency_ms,
115+
response = ?response_bytes,
116+
"no header from relay"
117+
);
122118
return Ok(None)
123119
}
124120

125121
let get_header_response: GetHeaderReponse = serde_json::from_slice(&response_bytes)?;
126122

123+
debug!(
124+
?code,
125+
latency_ms,
126+
block_hash = %get_header_response.block_hash(),
127+
value_eth = format_ether(get_header_response.value()),
128+
"received new header"
129+
);
130+
127131
validate_header(
128132
&get_header_response.data,
129133
chain,
@@ -146,12 +150,9 @@ fn validate_header(
146150
) -> Result<(), ValidationError> {
147151
let block_hash = signed_header.message.header.block_hash;
148152
let relay_pubkey = signed_header.message.pubkey;
149-
let block_number = signed_header.message.header.block_number;
150153
let tx_root = signed_header.message.header.transactions_root;
151154
let value = signed_header.message.value();
152155

153-
debug!(block_number, %block_hash, %tx_root, value_eth=wei_to_eth(&value), "received relay bid");
154-
155156
if block_hash == B256::ZERO {
156157
return Err(ValidationError::EmptyBlockhash)
157158
}

crates/pbs/src/mev_boost/register_validator.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use std::time::Duration;
1+
use std::{ops::Mul, time::Duration};
22

33
use alloy::rpc::types::beacon::relay::ValidatorRegistration;
44
use axum::http::{HeaderMap, HeaderValue};
55
use cb_common::{
66
pbs::{RelayEntry, HEADER_START_TIME_UNIX_MS},
77
utils::{get_user_agent, utcnow_ms},
88
};
9+
use eyre::bail;
910
use futures::future::join_all;
1011
use reqwest::header::USER_AGENT;
11-
use tracing::error;
12+
use tracing::{debug, error};
1213

1314
use crate::{
1415
constants::REGISTER_VALIDATOR_ENDPOINT_TAG,
@@ -25,11 +26,10 @@ pub async fn register_validator<S: BuilderApiState>(
2526
state: PbsState<S>,
2627
) -> eyre::Result<()> {
2728
// prepare headers
28-
let ua = get_user_agent(&req_headers);
2929
let mut send_headers = HeaderMap::new();
3030
send_headers
3131
.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from_str(&utcnow_ms().to_string())?);
32-
if let Some(ua) = ua {
32+
if let Some(ua) = get_user_agent(&req_headers) {
3333
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
3434
}
3535

@@ -50,10 +50,11 @@ pub async fn register_validator<S: BuilderApiState>(
5050
if results.iter().any(|res| res.is_ok()) {
5151
Ok(())
5252
} else {
53-
Err(eyre::eyre!("No relay passed register_validator successfully"))
53+
bail!("No relay passed register_validator successfully")
5454
}
5555
}
5656

57+
#[tracing::instrument(skip_all, name = "handler", fields(relay_id = relay.id))]
5758
async fn send_register_validator(
5859
headers: HeaderMap,
5960
relay: RelayEntry,
@@ -73,27 +74,26 @@ async fn send_register_validator(
7374
.json(&registrations)
7475
.send()
7576
.await?;
76-
timer.observe_duration();
77+
let latency_ms = timer.stop_and_record().mul(1000.0).ceil() as u64;
7778

78-
// TODO: send to relay monitor
79-
80-
let status = res.status();
79+
let code = res.status();
8180
RELAY_STATUS_CODE
82-
.with_label_values(&[status.as_str(), REGISTER_VALIDATOR_ENDPOINT_TAG, &relay.id])
81+
.with_label_values(&[code.as_str(), REGISTER_VALIDATOR_ENDPOINT_TAG, &relay.id])
8382
.inc();
8483

8584
let response_bytes = res.bytes().await?;
86-
if !status.is_success() {
85+
if !code.is_success() {
8786
let err = PbsError::RelayResponse {
8887
error_msg: String::from_utf8_lossy(&response_bytes).into_owned(),
89-
code: status.as_u16(),
88+
code: code.as_u16(),
9089
};
9190

9291
// error here since we check if any success aboves
93-
error!(?err, relay_id = relay.id, event = "register_validator");
94-
92+
error!(?err, "failed registration");
9593
return Err(err);
9694
};
9795

96+
debug!(?code, latency_ms, "registration successful");
97+
9898
Ok(())
9999
}

crates/pbs/src/mev_boost/status.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::time::Duration;
1+
use std::{ops::Mul, time::Duration};
22

33
use axum::http::{HeaderMap, HeaderValue};
44
use cb_common::{pbs::RelayEntry, utils::get_user_agent};
55
use futures::future::select_ok;
66
use reqwest::header::USER_AGENT;
7+
use tracing::{debug, error};
78

89
use crate::{
910
constants::STATUS_ENDPOINT_TAG,
@@ -24,9 +25,8 @@ pub async fn get_status<S: BuilderApiState>(
2425
Ok(())
2526
} else {
2627
// prepare headers
27-
let ua = get_user_agent(&req_headers);
2828
let mut send_headers = HeaderMap::new();
29-
if let Some(ua) = ua {
29+
if let Some(ua) = get_user_agent(&req_headers) {
3030
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
3131
}
3232

@@ -49,6 +49,7 @@ pub async fn get_status<S: BuilderApiState>(
4949
}
5050
}
5151

52+
#[tracing::instrument(skip_all, name = "handler", fields(relay_id = relay.id))]
5253
async fn send_relay_check(
5354
headers: HeaderMap,
5455
relay: RelayEntry,
@@ -58,18 +59,23 @@ async fn send_relay_check(
5859

5960
let timer = RELAY_LATENCY.with_label_values(&[STATUS_ENDPOINT_TAG, &relay.id]).start_timer();
6061
let res = client.get(url).timeout(Duration::from_secs(30)).headers(headers).send().await?;
61-
timer.observe_duration();
62+
let latency_ms = timer.stop_and_record().mul(1000.0).ceil() as u64;
6263

63-
let status = res.status();
64-
RELAY_STATUS_CODE.with_label_values(&[status.as_str(), STATUS_ENDPOINT_TAG, &relay.id]).inc();
64+
let code = res.status();
65+
RELAY_STATUS_CODE.with_label_values(&[code.as_str(), STATUS_ENDPOINT_TAG, &relay.id]).inc();
6566

6667
let response_bytes = res.bytes().await?;
67-
if !status.is_success() {
68-
return Err(PbsError::RelayResponse {
68+
if !code.is_success() {
69+
let err = PbsError::RelayResponse {
6970
error_msg: String::from_utf8_lossy(&response_bytes).into_owned(),
70-
code: status.as_u16(),
71-
})
71+
code: code.as_u16(),
72+
};
73+
74+
error!(?err, "status failed");
75+
return Err(err)
7276
};
7377

78+
debug!(?code, latency_ms, "status passed");
79+
7480
Ok(())
7581
}

crates/pbs/src/mev_boost/submit_block.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{sync::Arc, time::Duration};
1+
use std::{ops::Mul, sync::Arc, time::Duration};
22

33
use axum::http::{HeaderMap, HeaderValue};
44
use cb_common::{
@@ -8,7 +8,7 @@ use cb_common::{
88
};
99
use futures::future::select_ok;
1010
use reqwest::header::USER_AGENT;
11-
use tracing::warn;
11+
use tracing::{debug, error};
1212

1313
use crate::{
1414
constants::SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG,
@@ -24,24 +24,14 @@ pub async fn submit_block<S: BuilderApiState>(
2424
req_headers: HeaderMap,
2525
state: PbsState<S>,
2626
) -> eyre::Result<SubmitBlindedBlockResponse> {
27-
let (slot, slot_uuid) = state.get_slot_and_uuid();
28-
let mut send_headers = HeaderMap::new();
29-
30-
if slot != signed_blinded_block.message.slot {
31-
warn!(
32-
expected = slot,
33-
got = signed_blinded_block.message.slot,
34-
"blinded beacon slot mismatch"
35-
);
36-
} else {
37-
send_headers.insert(HEADER_SLOT_UUID_KEY, HeaderValue::from_str(&slot_uuid.to_string())?);
38-
}
27+
let (_, slot_uuid) = state.get_slot_and_uuid();
3928

4029
// prepare headers
41-
let ua = get_user_agent(&req_headers);
30+
let mut send_headers = HeaderMap::new();
31+
send_headers.insert(HEADER_SLOT_UUID_KEY, HeaderValue::from_str(&slot_uuid.to_string())?);
4232
send_headers
4333
.insert(HEADER_START_TIME_UNIX_MS, HeaderValue::from_str(&utcnow_ms().to_string())?);
44-
if let Some(ua) = ua {
34+
if let Some(ua) = get_user_agent(&req_headers) {
4535
send_headers.insert(USER_AGENT, HeaderValue::from_str(&ua)?);
4636
}
4737

@@ -66,6 +56,7 @@ pub async fn submit_block<S: BuilderApiState>(
6656

6757
// submits blinded signed block and expects the execution payload + blobs bundle
6858
// back
59+
#[tracing::instrument(skip_all, name = "handler", fields(relay_id = relay.id))]
6960
async fn send_submit_block(
7061
headers: HeaderMap,
7162
relay: RelayEntry,
@@ -85,23 +76,33 @@ async fn send_submit_block(
8576
.json(&signed_blinded_block)
8677
.send()
8778
.await?;
88-
timer.observe_duration();
79+
let latency_ms = timer.stop_and_record().mul(1000.0).ceil() as u64;
8980

90-
let status = res.status();
81+
let code = res.status();
9182
RELAY_STATUS_CODE
92-
.with_label_values(&[status.as_str(), SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG, &relay.id])
83+
.with_label_values(&[code.as_str(), SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG, &relay.id])
9384
.inc();
9485

9586
let response_bytes = res.bytes().await?;
96-
if !status.is_success() {
97-
return Err(PbsError::RelayResponse {
87+
if !code.is_success() {
88+
let err = PbsError::RelayResponse {
9889
error_msg: String::from_utf8_lossy(&response_bytes).into_owned(),
99-
code: status.as_u16(),
100-
})
90+
code: code.as_u16(),
91+
};
92+
93+
error!(?err, "failed submit block");
94+
return Err(err)
10195
};
10296

10397
let block_response: SubmitBlindedBlockResponse = serde_json::from_slice(&response_bytes)?;
10498

99+
debug!(
100+
?code,
101+
latency_ms,
102+
block_hash = %block_response.block_hash(),
103+
"received unblinded block"
104+
);
105+
105106
if signed_blinded_block.block_hash() != block_response.block_hash() {
106107
return Err(PbsError::Validation(ValidationError::BlockHashMismatch {
107108
expected: signed_blinded_block.block_hash(),

0 commit comments

Comments
 (0)