Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
edition = "2024"
rust-version = "1.91"
version = "0.9.6"
version = "0.10.0-rc2"

[workspace.dependencies]
aes = "0.8"
Expand Down
29 changes: 28 additions & 1 deletion crates/common/src/interop/ssv/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ pub async fn request_ssv_pubkeys_from_ssv_node(
http_timeout: Duration,
) -> eyre::Result<SSVNodeResponse> {
let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?;
// The SSV node API expects operator IDs as numeric (uint64) values. Serializing
// the U256 directly emits a JSON string, which the node rejects with a 400,
// so narrow it to a u64 first.
let operator_id = u64::try_from(node_operator_id)
.map_err(|e| eyre::eyre!("SSV node operator ID does not fit in u64: {e}"))?;
let body = json!({
"operators": [node_operator_id]
"operators": [operator_id]
});
let response = client.get(url).json(&body).send().await.map_err(|e| {
if e.is_timeout() {
Expand Down Expand Up @@ -50,3 +55,25 @@ pub async fn request_ssv_pubkeys_from_public_api(
serde_json::from_slice::<SSVPublicResponse>(&body_bytes)
.wrap_err("failed to parse SSV response")
}

#[cfg(test)]
mod tests {
use alloy::primitives::U256;
use serde_json::json;

#[test]
fn ssv_node_request_serializes_operator_as_number() {
let node_operator_id = U256::from(100u64);

// Regression guard: serializing the U256 directly emits a (hex) JSON string,
// which the SSV node rejects ("cannot unmarshal string into ...
// uint64").
let stringy = serde_json::to_string(&json!({ "operators": [node_operator_id] })).unwrap();
assert_eq!(stringy, r#"{"operators":["0x64"]}"#);

// The fix narrows to u64 so the operator ID is emitted as a numeric value.
let operator_id = u64::try_from(node_operator_id).unwrap();
let numeric = serde_json::to_string(&json!({ "operators": [operator_id] })).unwrap();
assert_eq!(numeric, r#"{"operators":[100]}"#);
}
}
Loading