feat: provide first-class ssz support on api #6749
Merged
wemeetagain merged 292 commits intounstablefrom Jun 10, 2024
Merged
Conversation
This was referenced Jun 3, 2024
nazarhussain
previously approved these changes
Jun 3, 2024
Review proof routes
Review lightclient routes
Review node routes
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #6749 +/- ##
============================================
+ Coverage 62.19% 62.77% +0.58%
============================================
Files 571 580 +9
Lines 60099 61306 +1207
Branches 1978 2116 +138
============================================
+ Hits 37376 38486 +1110
- Misses 22680 22781 +101
+ Partials 43 39 -4 |
nazarhussain
previously approved these changes
Jun 7, 2024
Member
Author
|
Metrics from feat3 in addition to what's already in #6749 (comment), most notable difference if of course in the REST API latency, especially if we look at it from VC point of view as it includes latency over the wire, and not just serialization / deserialization. Other metrics look good to me as well (no regressions), or even slightly better across the board (lower gc, eventloop lag, etc.) |
nazarhussain
approved these changes
Jun 10, 2024
wemeetagain
approved these changes
Jun 10, 2024
Member
wemeetagain
left a comment
There was a problem hiding this comment.
LGTM
Thanks for doing the hard work of pushing this to completion
Member
|
🎉 This PR is included in v1.20.0 🎉 |
ensi321
pushed a commit
that referenced
this pull request
Feb 18, 2025
**Motivation** Forgot to update this as part of #6749, but adding new endpoints is much simpler / cleaner now and everything is inferred from `Endpoint` type definition when adding a new route, it's not possible to forget updating something as typescript will complain (and also spec tests). So instead of updating this I figured it's best to just remove it, looking at the code is much easier to figure out what do to than having to read some text I would put there, eg. see example #7472. **Description** Remove outdated reasoning of the API definitions comment
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
Initial discussion around this has started in #5128 to provide first-class support for SSZ in both request and response bodies but besides that, there are plenty of other shortcomings in the way we currently define routes and handle server / client responses. In a lot of cases, Lodestar was not following the spec (e.g. not setting all required headers) causing incompatibilities with other clients. The main reason for this is because our API spec tests were incomplete, headers were not checked at all or if we support SSZ on all required routes as per spec, and addressing those shortcomings requires workarounds like overriding handlers on both the client and server.
Description
This PR changes the structure of how routes are defined and makes it trivial to add SSZ support to any route. The only exception are routes with data payloads that cannot be represented as a SSZ type due to lack of JSON mapping, meaning it is not possible to translate the JSON payload into a SSZ-serialized payload.
The second major change is how we handle requests and responses on the server and client. While previously if you would request a state as SSZ from the server, the client would only be able to handle that format and if the server didn't support it, the request would fail. Now, we use content type negotiation between client and server which works based on headers and status codes to allow a more flexible and robust handling of requests and responses.
The third redesign in this PR is related to the API client, it is now possible to provide options like HTTP timeout per request and the response object is much more complete and self-contained, e.g. it's no longer needed to call
ApiError.assert(...)everywhere (more examples below). This refactoring allows for further extensions in the future like a per route strategy for sending requests to fallback nodes and picking responses based on metadata, e.g. pick the most profitable block from all connected beacon nodes.BREAKING CHANGES
While there is are no breaking changes to the validator client and beacon node, the client exported from
@lodestar/apipackage changed significantly, and there are minor other changes to exported types but those are not as relevant for most consumers.These are the most notable changes
Client initialization
before
after
Request with value
before
after (
.value()will assert if request was successful and throw detailed error)Request without value
before
after (response object is self-contained, no utility like
ApiError.assertis required anymore)Passing arguments
before
after (args are passed as object, it is now possible to pass per request options, like timeout)
TODO
Access-Control-Expose-Headers: Eth-Consensus-Versionheader required? Add support for ssz response togetLightClientUpdatesByRange#6841, chore: review lightclient routes #6842@paramfrom method jsdoc to propertyadd option to server to disable JSON responses to avoid potential DoS vector, how to handle routes that do not support SSZ?Add option to server to disable JSON responses #6838Closes #5128
Closes #5244
Closes #5826
Closes #6110
Closes #6564
Closes #6634