Skip to content

Commit 14d00f8

Browse files
authored
fix: correctly handle null params (#16)
JSON-RPC can come in with params == `null`. this PR makes `rproxy` to correctly handle that
2 parents 010466d + 3e7c8e9 commit 14d00f8

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rproxy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rproxy"
3-
version = "0.0.7"
3+
version = "0.0.8"
44
edition = "2024"
55
default-run = "rproxy"
66

crates/rproxy/src/jrpc/jrpc_request.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ const JRPC_METHOD_FCUV2_WITH_PAYLOAD: Cow<'static, str> =
1212
const JRPC_METHOD_FCUV3_WITH_PAYLOAD: Cow<'static, str> =
1313
Cow::Borrowed("engine_forkchoiceUpdatedV3_withPayload");
1414

15+
const EMPTY_PARAMS: &Vec<serde_json::Value> = &Vec::new();
16+
1517
pub(crate) struct JrpcRequestMeta {
1618
id: Id,
1719

1820
method: Cow<'static, str>,
1921
method_enriched: Cow<'static, str>,
2022

21-
params: Vec<serde_json::Value>,
23+
params: serde_json::Value,
2224
}
2325

2426
impl JrpcRequestMeta {
@@ -39,7 +41,7 @@ impl JrpcRequestMeta {
3941

4042
#[inline]
4143
pub(crate) fn params(&self) -> &Vec<serde_json::Value> {
42-
&self.params
44+
self.params.as_array().unwrap_or(EMPTY_PARAMS)
4345
}
4446
}
4547

@@ -52,15 +54,17 @@ impl<'a> Deserialize<'a> for JrpcRequestMeta {
5254
struct JrpcRequestMetaWire {
5355
id: Id,
5456
method: Cow<'static, str>,
55-
params: Vec<serde_json::Value>,
57+
params: serde_json::Value,
5658
}
5759

5860
let wire = JrpcRequestMetaWire::deserialize(deserializer)?;
5961

6062
let mut params_count = 0;
61-
for param in wire.params.iter() {
62-
if !param.is_null() {
63-
params_count += 1;
63+
if let Some(params) = wire.params.as_array() {
64+
for param in params.iter() {
65+
if !param.is_null() {
66+
params_count += 1;
67+
}
6468
}
6569
}
6670

crates/rproxy/src/server/proxy/http/proxy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ where
455455
request_id = %req_id,
456456
connection_id = %conn_id,
457457
worker_id = %this.id,
458+
http_request = if this.shared.config().log_proxied_responses() { str::from_utf8(&decompressed_body).unwrap_or_default() } else { "" },
458459
error = ?err,
459460
"Failed to parse json-rpc request",
460461
);
@@ -619,6 +620,7 @@ where
619620
request_id = %clnt_req.info.req_id,
620621
connection_id = %clnt_req.info.conn_id,
621622
worker_id = %worker_id,
623+
http_request = if inner.config().log_proxied_responses() { str::from_utf8(&clnt_req.decompressed_body).unwrap_or_default() } else { "" },
622624
error = ?err,
623625
"Failed to parse json-rpc request",
624626
);

0 commit comments

Comments
 (0)