Add SSZ response support for validators and validator_balances endpoints#601
Open
Zyra-V21 wants to merge 1 commit into
Open
Add SSZ response support for validators and validator_balances endpoints#601Zyra-V21 wants to merge 1 commit into
Zyra-V21 wants to merge 1 commit into
Conversation
Adds `application/octet-stream` (SSZ) response type to:
- `GET /eth/v1/beacon/states/{state_id}/validators`
- `POST /eth/v1/beacon/states/{state_id}/validators`
- `GET /eth/v1/beacon/states/{state_id}/validators/{validator_id}`
- `GET /eth/v1/beacon/states/{state_id}/validator_balances`
- `POST /eth/v1/beacon/states/{state_id}/validator_balances`
The validators response uses the SSZ container
`{ index: uint64, balance: uint64, status: byte, validator: Validator }`,
where `status` is encoded as a single `byte` per the table now documented in
the `ValidatorStatus` schema. Mapping follows the proposal in
ethereum#333 (0x01..0x09, with 0x00 reserved for unknown).
Adds 406 responses for unsupported `Accept` media types and a CHANGES.md
entry under the development version.
Closes ethereum#333.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The
/eth/v1/beacon/states/{state_id}/validatorsendpoint currently returns JSON only. On mainnet today this is roughly 1 GB per state for the full validator set, while the equivalent SSZ payload is around an order of magnitude smaller and trivially cheaper to serialize and parse on both sides. The same applies tovalidator_balances(around 85 MB JSON per state).For analytics and indexing tooling that snapshots validators frequently — for example Migalabs' goteth and similar consensus-layer indexers — JSON parsing and beacon-node CPU time during state snapshots are a real bottleneck. Exposing SSZ on these endpoints reduces both ends of the cost.
This proposal does not introduce a new design: it implements the agreement reached in the discussion of #333 (which has been open and unactioned since 2023).
Scope
Adds
application/octet-stream(SSZ) response support to:GET /eth/v1/beacon/states/{state_id}/validatorsPOST /eth/v1/beacon/states/{state_id}/validatorsGET /eth/v1/beacon/states/{state_id}/validators/{validator_id}GET /eth/v1/beacon/states/{state_id}/validator_balancesPOST /eth/v1/beacon/states/{state_id}/validator_balancesEach affected endpoint also gains a
406 Not Acceptableresponse, matching the pattern used by other SSZ-enabled endpoints in the spec (debug/state.v2,pending_partial_withdrawals,validator_identities, etc.).Validator status encoding
ValidatorResponseis wire-encoded as the SSZ container:Validatoris the consensus-spec object.statusis a singlebyte. The byte mapping is documented in theValidatorStatusschema and is the one proposed by @mcdee in #333:0x000x010x020x030x040x050x060x070x080x09byteis used rather thanuint8per the discussion in #333 (cc @arnetheduck, @michaelsproul) to avoid implying the status is a numeric value with arithmetic semantics.ValidatorBalanceResponseSSZ encoding is the simpler{ index: uint64, balance: uint64 }container; no new type definitions are required.What this PR does not change
application/octet-streamcontinue to receive the same JSON they get today.ValidatorStatusJSON enum (active_ongoing, etc.) remains the canonical string form. The byte mapping is only relevant on the SSZ wire.Lint
redocly lint beacon-node-oapi.yamlreports the same baseline of pre-existing warnings/errors before and after this patch (84 errors, 15 warnings, all unrelated to the touched files). No new lint findings are introduced.Background and credits
The endpoint design, the choice of
byteoveruint8, and the status mapping all come from the discussion in #333. This PR is the implementation of that agreement; the credit for the design belongs to:bytevsuint8clarification.Validatorobject.validator_balanceswas added because it shares the same indexer use case and avoids leaving an obviously asymmetric gap.Related prior art that did not result in a merged spec change:
validatorsandvalidator_balances#367 added POST variants for these endpoints but kept JSON-only responses; the SSZ side was left open.Closes #333.