1
- use std:: { sync:: Arc , time:: Duration } ;
1
+ use std:: { ops :: Mul , sync:: Arc , time:: Duration } ;
2
2
3
3
use alloy:: {
4
- primitives:: { B256 , U256 } ,
4
+ primitives:: { utils :: format_ether , B256 , U256 } ,
5
5
rpc:: types:: beacon:: BlsPublicKey ,
6
6
} ;
7
7
use axum:: http:: { HeaderMap , HeaderValue } ;
@@ -10,7 +10,7 @@ use cb_common::{
10
10
pbs:: { RelayEntry , HEADER_SLOT_UUID_KEY , HEADER_START_TIME_UNIX_MS } ,
11
11
signature:: verify_signed_builder_message,
12
12
types:: Chain ,
13
- utils:: { get_user_agent, utcnow_ms, wei_to_eth } ,
13
+ utils:: { get_user_agent, utcnow_ms} ,
14
14
} ;
15
15
use futures:: future:: join_all;
16
16
use reqwest:: { header:: USER_AGENT , StatusCode } ;
@@ -36,12 +36,11 @@ pub async fn get_header<S: BuilderApiState>(
36
36
let slot_uuid = state. get_or_update_slot_uuid ( slot) ;
37
37
38
38
// prepare headers
39
- let ua = get_user_agent ( & req_headers) ;
40
39
let mut send_headers = HeaderMap :: new ( ) ;
41
40
send_headers. insert ( HEADER_SLOT_UUID_KEY , HeaderValue :: from_str ( & slot_uuid. to_string ( ) ) ?) ;
42
41
send_headers
43
42
. 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 ) {
45
44
send_headers. insert ( USER_AGENT , HeaderValue :: from_str ( & ua) ?) ;
46
45
}
47
46
@@ -75,6 +74,7 @@ pub async fn get_header<S: BuilderApiState>(
75
74
Ok ( state. add_bids ( slot, relay_bids) )
76
75
}
77
76
77
+ #[ tracing:: instrument( skip_all, name = "handler" , fields( relay_id = relay. id) ) ]
78
78
async fn send_get_header (
79
79
headers : HeaderMap ,
80
80
slot : u64 ,
@@ -95,35 +95,39 @@ async fn send_get_header(
95
95
. headers ( headers)
96
96
. send ( )
97
97
. await ?;
98
- timer. observe_duration ( ) ;
98
+ let latency_ms = timer. stop_and_record ( ) . mul ( 1000.0 ) . ceil ( ) as u64 ;
99
99
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 ( ) ;
104
102
105
103
let response_bytes = res. bytes ( ) . await ?;
106
- if !status . is_success ( ) {
104
+ if !code . is_success ( ) {
107
105
return Err ( PbsError :: RelayResponse {
108
106
error_msg : String :: from_utf8_lossy ( & response_bytes) . into_owned ( ) ,
109
- code : status . as_u16 ( ) ,
107
+ code : code . as_u16 ( ) ,
110
108
} ) ;
111
109
} ;
112
110
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
+ ) ;
122
118
return Ok ( None )
123
119
}
124
120
125
121
let get_header_response: GetHeaderReponse = serde_json:: from_slice ( & response_bytes) ?;
126
122
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
+
127
131
validate_header (
128
132
& get_header_response. data ,
129
133
chain,
@@ -146,12 +150,9 @@ fn validate_header(
146
150
) -> Result < ( ) , ValidationError > {
147
151
let block_hash = signed_header. message . header . block_hash ;
148
152
let relay_pubkey = signed_header. message . pubkey ;
149
- let block_number = signed_header. message . header . block_number ;
150
153
let tx_root = signed_header. message . header . transactions_root ;
151
154
let value = signed_header. message . value ( ) ;
152
155
153
- debug ! ( block_number, %block_hash, %tx_root, value_eth=wei_to_eth( & value) , "received relay bid" ) ;
154
-
155
156
if block_hash == B256 :: ZERO {
156
157
return Err ( ValidationError :: EmptyBlockhash )
157
158
}
0 commit comments