Repository navigation
feat(validator): accept a JSON produceBlockV3 answer - #862
MegaRedHand wants to merge 5 commits into
Conversation
ethereum-package's blobber rewrites Accept to application/json on produceBlockV3 and relays the node's answer unchanged, so a validator client that took SSZ alone lost every proposal behind it. produceBlockV3 now asks for application/octet-stream;q=1.0,application/json;q=0.9 and dispatches on Content-Type. SSZ goes down the existing path. JSON is decoded into the same ProducedBlock through the containers' serde support in ethlambda-types: the fork from the body's version (falling back on Eth-Consensus-Version), blindedness from execution_payload_blinded (falling back on Eth-Execution-Payload-Blinded), a disagreement between body and header refused. produceBlockV4 and the payload envelope stay SSZ-only.
|
/review |
AI security review: 0 finding(s) to checkReviewed by Opus, GPT, Kimi, GLM, DeepSeek. No findings to check. Leads from a script (not checked): 1Found without a model, from the lines this PR adds. Some can be wrong, e.g. a path created at runtime or a name used through reflection.
Cost of this review: ~$1.93 of a $30 budget (estimated from token counts). |
| "Blinded", | ||
| )?; | ||
| let bytes = Self::answer_bytes(url, response).await?; | ||
| let answer: ProduceBlockV3Response = serde_json::from_slice(&bytes) |
There was a problem hiding this comment.
Real blobber drops the node's status code. In validator_proxy/proxy.go (v1.1.0, proxyHandler, lines 143-185) it copies the upstream headers and then io.Copys the body, but never calls w.WriteHeader(proxyRes.StatusCode), so Go answers 200. Any produceBlockV3 failure behind it (503 while syncing, 400, 500) therefore reaches this client as 200 application/json with a body like {"code":503,"message":"..."}, and lands here as Error::Decode("produceBlockV3 JSON answer: missing field data").
Decode is retryable, so failover still moves on, but a syncing node is no longer reported as BeaconNodeSyncing and the error points at a malformed answer instead of the node's own error.
Suggestion: when the body has code/message and no data, map it to what send_for_answer would have returned for that status (503 -> syncing, otherwise the BeaconNode error carrying the message).
| relayed.lock().unwrap().push(content_type); | ||
| } | ||
| let mut response = Response::new(Body::from(answer.bytes().await.unwrap())); | ||
| *response.status_mut() = status; |
There was a problem hiding this comment.
The real proxy.go doesn't do this: it never writes the upstream status, so every relayed answer is a 200 (see the comment on json_block_answer in http.rs). Since the stand-in is documented as modelled on proxy.go, I'd drop the status here as blobber does, and add a case where the node fails produceBlockV3 behind it (for example while syncing), so the 200-with-an-error-body shape is covered.
| /// written by its container's own serde, the one an ethlambda beacon node | ||
| /// serves it with; the proofs and blobs as the hex strings the Beacon API | ||
| /// specifies. | ||
| fn block_contents_at(fork: ForkName) -> (serde_json::Value, Vec<u8>) { |
There was a problem hiding this comment.
Every JSON test builds data with our own serde_json::to_value, and the e2e test in ethlambda-rpc runs against the ethlambda node, so what is tested is ethlambda's JSON round-tripping through ethlambda's serde. Behind blobber in ethereum-package the node may be Lighthouse, Teku, Prysm and so on.
The types crate has some cover (tests/beacon_json.rs checks that no integer is a bare number, and the builder-specs fulu signed_blinded_beacon_block example is vendored), but nothing from another source exercises a full electra/fulu produceBlockV3 answer: the full ExecutionPayload (transactions, withdrawals), execution_requests, and kzg_proofs/blobs.
Could we vendor one real answer (captured from Lighthouse, or the beacon-APIs example) with its SSZ alongside, and assert both decode to the same ProducedBlock and root? That's the property this PR rests on.
blobber's proxyHandler copies the node's headers and body but never its status, so a node failing produceBlockV3 behind it answers 200 with the specification's ErrorMessage in the body. That read as a malformed block answer, and a syncing node stopped being reported as one. A JSON block answer that does not parse and is an ErrorMessage with a 4xx/5xx code is now the error its status would have given (503 is BeaconNodeSyncing). The blobber stand-in in the rpc tests now drops the status on produceBlockV3 the way proxy.go does, with an end-to-end case for a node failing block production behind it. The JSON path is also checked against JSON this repository did not write: builder-specs' fulu blinded block and execution payload bundle examples (the bundle newly vendored), decoded as produceBlockV3 answers and held to their own SSZ.
# Conflicts: # crates/validator/src/beacon_node/http.rs
Closes #861.
Problem
ethereum-package's blobber (marioevz/blobber v1.1.0,
validator_proxy/proxy.go) sits between a validator client and its beacon node. On/eth/v2/validator/blocks/{slot}and/eth/v3/validator/blocks/{slot}it rewrites the request'sAccepttoapplication/json, then relays the node's answer unchanged, headers included.produce_blockasked for SSZ only, andread_sszrefused anything else ("asked for SSZ, node answered with application/json"), so every proposal by an ethlambda validator client behind blobber failed.get_ssz's doc gave the reason: "there is no JSON path for a block".What this does
produceBlockV3takes SSZ or JSON. The request now sendsAccept: application/octet-stream;q=1.0,application/json;q=0.9(the specification's own example) through a newget_block_v3, which dispatches on the answer'sContent-Type:application/octet-stream, or no content type, goes down the existing SSZ path unchanged: the fork fromEth-Consensus-Version, a requiredEth-Execution-Payload-Blinded, thenProducedBlock::from_ssz/from_blinded_ssz.application/json(with or without; charset=...) is read as the beacon-APIs JSON answer:version, falling back onEth-Consensus-Version;execution_payload_blinded, falling back onEth-Execution-Payload-Blinded;InconsistentResponse. This applies to the fork, as the issue asks, and also to blindedness, since either one selects the containerdatais decoded as;JSON
datais decoded into the sameProducedBlockthe SSZ path yields, through newProducedBlock::from_json/from_blinded_json. These share the fork match with the SSZ functions (a privateBodyenum, SSZ bytes or JSON value), so electra and fulu decode, and gloas and the pre-electra forks are refused by name exactly as before. Every check after decoding still runs: a blinded block while builder proposals are off is refused, andvalidate_produced_blockchecks the slot and proposer.No parallel types. The block containers (
electra::BeaconBlock,builder::BlindedBeaconBlock,KzgProof) already derive serde inethlambda-types, and the beacon node serves its ownproduceBlockV3JSON with them. The only addition isDeserializeon the validator'sBlockContentsandFuluBlockContents, with the same field attributes the node'sFuluBlockContentsuses (serde_helpers::seqfor the proofs,ssz_hex_seqfor the blobs). The root is still taken from the typed container, never from a hand-written mapping.execution_payload_valueandconsensus_block_valueare not read, because the SSZ path does not read their headers either: the node, not this client, weighs one payload against another.What stays SSZ-only.
produceBlockV4(gloas,post_json_for_ssz), which blobber does not intercept.get_ssz).Docs. I rewrote every place that said block production is SSZ-only:
get_sszandpost_json_for_ssz;block_contentsmodule doc;BeaconNodeApi::produce_block;dto.rs;Cargo.toml;docs/cli.md.Tests
Validator unit tests (
beacon_node/http.rs, on the existingservedouble):produceBlockV3sends the newAccept;produceBlockV4still sendsapplication/octet-streamalone.ProducedBlockas its SSZ, root included, at electra and fulu. The block indatais written by the containers' own serde.versionandexecution_payload_blindedfalls back on the headers.End to end (
ethlambda-rpc'svalidator_client_tests), against the real beacon router behind a blobber stand-in modelled onproxy.go: it rewritesAccepttoapplication/jsononproduceBlockV3and relays the answer and its headers unchanged.Both suites compile under
make lint. I have not run them; CI runs the tests. The blobber stand-in is written fromproxy.go, not the real binary, so a kurtosis run withblobber_enabledand an ethlambda validator client is still the real end-to-end check. Once this is in:unstable, ethereum-package's guard against that combination (add-ethlambda) can go.