Skip to content

Commit eaa84c1

Browse files
committed
remove request_context entirely, relay info encoded in url already
1 parent fd22805 commit eaa84c1

8 files changed

Lines changed: 22 additions & 73 deletions

File tree

crates/common/src/config/mux.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ impl MuxKeysLoader {
239239
let url = url.as_str();
240240
let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?;
241241
let response = client.get(url).send().await?;
242-
let pubkey_bytes =
243-
safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH, url).await?;
242+
let pubkey_bytes = safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH).await?;
244243
serde_json::from_slice(&pubkey_bytes)
245244
.wrap_err("failed to fetch mux keys from HTTP endpoint")
246245
}
@@ -472,8 +471,7 @@ async fn fetch_ssv_pubkeys_from_public_api(
472471
);
473472
let url = url.join(&route).wrap_err("failed to construct SSV API URL")?;
474473

475-
let response =
476-
request_ssv_pubkeys_from_public_api(url, node_operator_id, http_timeout).await?;
474+
let response = request_ssv_pubkeys_from_public_api(url, http_timeout).await?;
477475
let fetched = response.validators.len();
478476
if expected_total.is_none() && fetched > 0 {
479477
expected_total = Some(response.pagination.total);

crates/common/src/interop/ssv/utils.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ pub async fn request_ssv_pubkeys_from_ssv_node(
2929
})?;
3030

3131
// Parse the response as JSON
32-
let body_bytes =
33-
safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH, &node_operator_id.to_string())
34-
.await?;
32+
let body_bytes = safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH).await?;
3533
serde_json::from_slice::<SSVNodeResponse>(&body_bytes).wrap_err("failed to parse SSV response")
3634
}
3735

3836
pub async fn request_ssv_pubkeys_from_public_api(
3937
url: Url,
40-
node_operator_id: U256,
4138
http_timeout: Duration,
4239
) -> eyre::Result<SSVPublicResponse> {
4340
let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?;
@@ -50,9 +47,7 @@ pub async fn request_ssv_pubkeys_from_public_api(
5047
})?;
5148

5249
// Parse the response as JSON
53-
let body_bytes =
54-
safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH, &node_operator_id.to_string())
55-
.await?;
50+
let body_bytes = safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH).await?;
5651
serde_json::from_slice::<SSVPublicResponse>(&body_bytes)
5752
.wrap_err("failed to parse SSV response")
5853
}

crates/common/src/wire.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,17 @@ pub const CONSENSUS_VERSION_HEADER: &str = "Eth-Consensus-Version";
2424
#[derive(Debug, Error)]
2525
pub enum ResponseReadError {
2626
#[error(
27-
"response size exceeds max size; max: {max}, content_length: {content_length}, request_url: {request_url}, request_context: {request_context}"
27+
"response size exceeds max size; max: {max}, content_length: {content_length}, request_url: {request_url}"
2828
)]
29-
PayloadTooLarge {
30-
max: usize,
31-
content_length: usize,
32-
request_url: String,
33-
request_context: String,
34-
},
29+
PayloadTooLarge { max: usize, content_length: usize, request_url: String },
3530

3631
#[error("error reading response stream: {0}")]
3732
ReqwestError(#[from] reqwest::Error),
3833

3934
#[error(
40-
"request failed with status: {status_code}, request_url: {request_url}, request_context: {request_context}, body: {error_msg}"
35+
"request failed with status: {status_code}, request_url: {request_url}, body: {error_msg}"
4136
)]
42-
NonSuccess { status_code: u16, error_msg: String, request_url: String, request_context: String },
37+
NonSuccess { status_code: u16, error_msg: String, request_url: String },
4338
}
4439

4540
#[cfg(feature = "testing-flags")]
@@ -63,7 +58,6 @@ fn should_ignore_content_length() -> bool {
6358
pub async fn read_chunked_body_with_max(
6459
res: Response,
6560
max_size: usize,
66-
request_id: &str,
6761
request_url: &str,
6862
) -> Result<Vec<u8>, ResponseReadError> {
6963
// Get the content length from the response headers
@@ -87,7 +81,6 @@ pub async fn read_chunked_body_with_max(
8781
max: max_size,
8882
content_length: length as usize,
8983
request_url: request_url.to_string(),
90-
request_context: request_id.to_string(),
9184
});
9285
}
9386

@@ -103,7 +96,6 @@ pub async fn read_chunked_body_with_max(
10396
max: max_size,
10497
content_length: content_length.unwrap_or(0) as usize,
10598
request_url: request_url.to_string(),
106-
request_context: request_id.to_string(),
10799
});
108100
}
109101

@@ -118,19 +110,17 @@ pub async fn read_chunked_body_with_max(
118110
pub async fn safe_read_http_response(
119111
response: reqwest::Response,
120112
max_size: usize,
121-
request_id: &str,
122113
) -> Result<Vec<u8>, ResponseReadError> {
123114
let status_code = response.status();
124115
let request_url = response.url().to_string();
125-
let body = read_chunked_body_with_max(response, max_size, request_id, &request_url).await?;
116+
let body = read_chunked_body_with_max(response, max_size, &request_url).await?;
126117
if status_code.is_success() {
127118
Ok(body)
128119
} else {
129120
Err(ResponseReadError::NonSuccess {
130121
status_code: status_code.as_u16(),
131122
error_msg: String::from_utf8_lossy(&body).into_owned(),
132123
request_url: request_url.to_string(),
133-
request_context: request_id.to_string(),
134124
})
135125
}
136126
}

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ async fn send_one_get_header(
351351
let code = res.status();
352352
RELAY_STATUS_CODE.with_label_values(&[code.as_str(), GET_HEADER_ENDPOINT_TAG, &relay.id]).inc();
353353

354-
let response_bytes =
355-
safe_read_http_response(res, MAX_SIZE_GET_HEADER_RESPONSE, relay.id.as_ref()).await?;
354+
let response_bytes = safe_read_http_response(res, MAX_SIZE_GET_HEADER_RESPONSE).await?;
356355
let header_size_bytes = response_bytes.len();
357356
if code == StatusCode::NO_CONTENT {
358357
debug!(

crates/pbs/src/mev_boost/register_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ async fn send_register_validator(
187187
.with_label_values(&[code.as_str(), REGISTER_VALIDATOR_ENDPOINT_TAG, &relay.id])
188188
.inc();
189189

190-
safe_read_http_response(res, MAX_SIZE_DEFAULT, relay.id.as_ref()).await.inspect_err(|e| {
190+
safe_read_http_response(res, MAX_SIZE_DEFAULT).await.inspect_err(|e| {
191191
error!(relay_id = relay.id.as_ref(), retry, %e, "failed registration");
192192
})?;
193193

crates/pbs/src/mev_boost/status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async fn send_relay_check(relay: &RelayClient, headers: HeaderMap) -> Result<(),
7373
let code = res.status();
7474
RELAY_STATUS_CODE.with_label_values(&[code.as_str(), STATUS_ENDPOINT_TAG, &relay.id]).inc();
7575

76-
safe_read_http_response(res, MAX_SIZE_DEFAULT, relay.id.as_ref()).await.inspect_err(|e| {
76+
safe_read_http_response(res, MAX_SIZE_DEFAULT).await.inspect_err(|e| {
7777
error!(relay_id = relay.id.as_ref(), %e, "status failed");
7878
})?;
7979

crates/pbs/src/mev_boost/submit_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async fn send_submit_block(
201201
.with_label_values(&[code.as_str(), SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG, &relay.id])
202202
.inc();
203203

204-
let response_bytes = safe_read_http_response(res, MAX_SIZE_SUBMIT_BLOCK_RESPONSE, relay.id.as_ref())
204+
let response_bytes = safe_read_http_response(res, MAX_SIZE_SUBMIT_BLOCK_RESPONSE)
205205
.await
206206
.inspect_err(|e| {
207207
warn!(relay_id = relay.id.as_ref(), retry, %e, "failed to get payload (this might be ok if other relays have it)");

tests/tests/pbs_mux.rs

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@ async fn test_ssv_public_network_fetch() -> Result<()> {
4141
let url =
4242
Url::parse(&format!("http://localhost:{port}/api/v4/test_chain/validators/in_operator/1"))
4343
.unwrap();
44-
let node_operator_id = U256::from(0);
45-
let response = request_ssv_pubkeys_from_public_api(
46-
url,
47-
node_operator_id,
48-
Duration::from_secs(HTTP_TIMEOUT_SECONDS_DEFAULT),
49-
)
50-
.await?;
44+
let response =
45+
request_ssv_pubkeys_from_public_api(url, Duration::from_secs(HTTP_TIMEOUT_SECONDS_DEFAULT))
46+
.await?;
5147

5248
// Make sure the response is correct
5349
// NOTE: requires that ssv_valid_public.json doesn't change
@@ -82,30 +78,18 @@ async fn test_ssv_network_fetch_big_data() -> Result<()> {
8278
let server_handle =
8379
cb_tests::mock_ssv_public::create_mock_public_ssv_server(port, None).await?;
8480
let url = Url::parse(&format!("http://localhost:{port}/big_data")).unwrap();
85-
let node_operator_id = U256::from(0);
86-
let response = request_ssv_pubkeys_from_public_api(
87-
url.clone(),
88-
node_operator_id,
89-
Duration::from_secs(120),
90-
)
91-
.await;
81+
let response = request_ssv_pubkeys_from_public_api(url.clone(), Duration::from_secs(120)).await;
9282

9383
// The response should fail due to content length being too big
9484
match response {
9585
Ok(_) => {
9686
panic!("Expected an error due to big content length, but got a successful response")
9787
}
9888
Err(e) => match e.downcast_ref::<ResponseReadError>() {
99-
Some(ResponseReadError::PayloadTooLarge {
100-
max,
101-
content_length,
102-
request_url,
103-
request_context,
104-
}) => {
89+
Some(ResponseReadError::PayloadTooLarge { max, content_length, request_url }) => {
10590
assert_eq!(*max, MUXER_HTTP_MAX_LENGTH);
10691
assert!(*content_length > MUXER_HTTP_MAX_LENGTH);
10792
assert_eq!(url.as_str(), request_url.as_str());
108-
assert_eq!(request_context.as_str(), node_operator_id.to_string());
10993
}
11094
_ => panic!("Expected PayloadTooLarge error, got: {}", e),
11195
},
@@ -131,13 +115,8 @@ async fn test_ssv_network_fetch_timeout() -> Result<()> {
131115
let url =
132116
Url::parse(&format!("http://localhost:{port}/api/v4/test_chain/validators/in_operator/1"))
133117
.unwrap();
134-
let node_operator_id = U256::from(0);
135-
let response = request_ssv_pubkeys_from_public_api(
136-
url,
137-
node_operator_id,
138-
Duration::from_secs(TEST_HTTP_TIMEOUT),
139-
)
140-
.await;
118+
let response =
119+
request_ssv_pubkeys_from_public_api(url, Duration::from_secs(TEST_HTTP_TIMEOUT)).await;
141120

142121
// The response should fail due to timeout
143122
assert!(response.is_err(), "Expected timeout error, but got success");
@@ -160,30 +139,18 @@ async fn test_ssv_network_fetch_big_data_without_content_length() -> Result<()>
160139
set_ignore_content_length(true);
161140
let server_handle = create_mock_public_ssv_server(port, None).await?;
162141
let url = Url::parse(&format!("http://localhost:{port}/big_data")).unwrap();
163-
let node_operator_id = U256::from(0);
164-
let response = request_ssv_pubkeys_from_public_api(
165-
url.clone(),
166-
node_operator_id,
167-
Duration::from_secs(120),
168-
)
169-
.await;
142+
let response = request_ssv_pubkeys_from_public_api(url.clone(), Duration::from_secs(120)).await;
170143

171144
// The response should fail due to the body being too big
172145
match response {
173146
Ok(_) => {
174147
panic!("Expected an error due to excessive data, but got a successful response")
175148
}
176149
Err(e) => match e.downcast_ref::<ResponseReadError>() {
177-
Some(ResponseReadError::PayloadTooLarge {
178-
max,
179-
content_length,
180-
request_url,
181-
request_context,
182-
}) => {
150+
Some(ResponseReadError::PayloadTooLarge { max, content_length, request_url }) => {
183151
assert_eq!(*max, MUXER_HTTP_MAX_LENGTH);
184152
assert_eq!(*content_length, 0);
185153
assert_eq!(url.as_str(), request_url.as_str());
186-
assert_eq!(request_context.as_str(), node_operator_id.to_string());
187154
}
188155
_ => panic!("Expected PayloadTooLarge error, got: {}", e),
189156
},

0 commit comments

Comments
 (0)