Skip to content

Commit fd22805

Browse files
committed
rename request_id -> request_context
pass node_operator_id for mux usage of safe_read_http_response
1 parent 4664fdd commit fd22805

4 files changed

Lines changed: 53 additions & 25 deletions

File tree

crates/common/src/config/mux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ async fn fetch_ssv_pubkeys_from_public_api(
472472
);
473473
let url = url.join(&route).wrap_err("failed to construct SSV API URL")?;
474474

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

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub async fn request_ssv_pubkeys_from_ssv_node(
1616
node_operator_id: U256,
1717
http_timeout: Duration,
1818
) -> eyre::Result<SSVNodeResponse> {
19-
let url = url.as_str();
2019
let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?;
2120
let body = json!({
2221
"operators": [node_operator_id]
@@ -30,15 +29,17 @@ pub async fn request_ssv_pubkeys_from_ssv_node(
3029
})?;
3130

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

3738
pub async fn request_ssv_pubkeys_from_public_api(
3839
url: Url,
40+
node_operator_id: U256,
3941
http_timeout: Duration,
4042
) -> eyre::Result<SSVPublicResponse> {
41-
let url = url.as_str();
4243
let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?;
4344
let response = client.get(url).send().await.map_err(|e| {
4445
if e.is_timeout() {
@@ -49,7 +50,9 @@ pub async fn request_ssv_pubkeys_from_public_api(
4950
})?;
5051

5152
// Parse the response as JSON
52-
let body_bytes = safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH, url).await?;
53+
let body_bytes =
54+
safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH, &node_operator_id.to_string())
55+
.await?;
5356
serde_json::from_slice::<SSVPublicResponse>(&body_bytes)
5457
.wrap_err("failed to parse SSV response")
5558
}

crates/common/src/wire.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@ 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_id: {request_id}"
27+
"response size exceeds max size; max: {max}, content_length: {content_length}, request_url: {request_url}, request_context: {request_context}"
2828
)]
29-
PayloadTooLarge { max: usize, content_length: usize, request_url: String, request_id: String },
29+
PayloadTooLarge {
30+
max: usize,
31+
content_length: usize,
32+
request_url: String,
33+
request_context: String,
34+
},
3035

3136
#[error("error reading response stream: {0}")]
3237
ReqwestError(#[from] reqwest::Error),
3338

3439
#[error(
35-
"request failed with status: {status_code}, request_url: {request_url}, request_id: {request_id}, body: {error_msg}"
40+
"request failed with status: {status_code}, request_url: {request_url}, request_context: {request_context}, body: {error_msg}"
3641
)]
37-
NonSuccess { status_code: u16, error_msg: String, request_url: String, request_id: String },
42+
NonSuccess { status_code: u16, error_msg: String, request_url: String, request_context: String },
3843
}
3944

4045
#[cfg(feature = "testing-flags")]
@@ -82,7 +87,7 @@ pub async fn read_chunked_body_with_max(
8287
max: max_size,
8388
content_length: length as usize,
8489
request_url: request_url.to_string(),
85-
request_id: request_id.to_string(),
90+
request_context: request_id.to_string(),
8691
});
8792
}
8893

@@ -98,7 +103,7 @@ pub async fn read_chunked_body_with_max(
98103
max: max_size,
99104
content_length: content_length.unwrap_or(0) as usize,
100105
request_url: request_url.to_string(),
101-
request_id: request_id.to_string(),
106+
request_context: request_id.to_string(),
102107
});
103108
}
104109

@@ -125,7 +130,7 @@ pub async fn safe_read_http_response(
125130
status_code: status_code.as_u16(),
126131
error_msg: String::from_utf8_lossy(&body).into_owned(),
127132
request_url: request_url.to_string(),
128-
request_id: request_id.to_string(),
133+
request_context: request_id.to_string(),
129134
})
130135
}
131136
}

tests/tests/pbs_mux.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ 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 response =
45-
request_ssv_pubkeys_from_public_api(url, Duration::from_secs(HTTP_TIMEOUT_SECONDS_DEFAULT))
46-
.await?;
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?;
4751

4852
// Make sure the response is correct
4953
// NOTE: requires that ssv_valid_public.json doesn't change
@@ -78,7 +82,13 @@ async fn test_ssv_network_fetch_big_data() -> Result<()> {
7882
let server_handle =
7983
cb_tests::mock_ssv_public::create_mock_public_ssv_server(port, None).await?;
8084
let url = Url::parse(&format!("http://localhost:{port}/big_data")).unwrap();
81-
let response = request_ssv_pubkeys_from_public_api(url.clone(), Duration::from_secs(120)).await;
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;
8292

8393
// The response should fail due to content length being too big
8494
match response {
@@ -90,13 +100,12 @@ async fn test_ssv_network_fetch_big_data() -> Result<()> {
90100
max,
91101
content_length,
92102
request_url,
93-
request_id,
103+
request_context,
94104
}) => {
95105
assert_eq!(*max, MUXER_HTTP_MAX_LENGTH);
96106
assert!(*content_length > MUXER_HTTP_MAX_LENGTH);
97107
assert_eq!(url.as_str(), request_url.as_str());
98-
// url used as request id
99-
assert_eq!(request_id.as_str(), request_url.as_str());
108+
assert_eq!(request_context.as_str(), node_operator_id.to_string());
100109
}
101110
_ => panic!("Expected PayloadTooLarge error, got: {}", e),
102111
},
@@ -122,8 +131,13 @@ async fn test_ssv_network_fetch_timeout() -> Result<()> {
122131
let url =
123132
Url::parse(&format!("http://localhost:{port}/api/v4/test_chain/validators/in_operator/1"))
124133
.unwrap();
125-
let response =
126-
request_ssv_pubkeys_from_public_api(url, Duration::from_secs(TEST_HTTP_TIMEOUT)).await;
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;
127141

128142
// The response should fail due to timeout
129143
assert!(response.is_err(), "Expected timeout error, but got success");
@@ -146,7 +160,13 @@ async fn test_ssv_network_fetch_big_data_without_content_length() -> Result<()>
146160
set_ignore_content_length(true);
147161
let server_handle = create_mock_public_ssv_server(port, None).await?;
148162
let url = Url::parse(&format!("http://localhost:{port}/big_data")).unwrap();
149-
let response = request_ssv_pubkeys_from_public_api(url.clone(), Duration::from_secs(120)).await;
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;
150170

151171
// The response should fail due to the body being too big
152172
match response {
@@ -158,13 +178,12 @@ async fn test_ssv_network_fetch_big_data_without_content_length() -> Result<()>
158178
max,
159179
content_length,
160180
request_url,
161-
request_id,
181+
request_context,
162182
}) => {
163183
assert_eq!(*max, MUXER_HTTP_MAX_LENGTH);
164184
assert_eq!(*content_length, 0);
165185
assert_eq!(url.as_str(), request_url.as_str());
166-
// url used as request id
167-
assert_eq!(request_id.as_str(), request_url.as_str());
186+
assert_eq!(request_context.as_str(), node_operator_id.to_string());
168187
}
169188
_ => panic!("Expected PayloadTooLarge error, got: {}", e),
170189
},

0 commit comments

Comments
 (0)