fix(node-api): return 404 for unknown state_id roots#3142
Open
NikhilSharmaWe wants to merge 2 commits into
Open
fix(node-api): return 404 for unknown state_id roots#3142NikhilSharmaWe wants to merge 2 commits into
NikhilSharmaWe wants to merge 2 commits into
Conversation
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Beacon API /eth/v1/beacon/states/{state_id}/* endpoints returning HTTP 500 for valid-but-unknown state_id roots by ensuring the mapping layer wraps “unknown state root” lookup failures with the handlers/types.ErrNotFound sentinel so the response middleware correctly maps them to HTTP 404. It explicitly preserves block.ErrBlockStoreNotEnabled as a non-404 configuration/runtime error.
Changes:
- Wrap
GetSlotByStateRootlookup failures withhandlers/types.ErrNotFound(exceptblock.ErrBlockStoreNotEnabled) to produce spec-defined 404s. - Add unit tests covering unknown state roots, block store disabled, and existing resolution paths (
head/slot).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| node-api/handlers/utils/mappings.go | Wrap state-root lookup errors with types.ErrNotFound while passing through ErrBlockStoreNotEnabled. |
| node-api/handlers/utils/mappings_test.go | Adds coverage for state ID resolution paths and error classification. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+102
to
+107
| for _, target := range tc.errIs { | ||
| require.ErrorIs(t, err, target) | ||
| } | ||
| for _, target := range tc.errNot { | ||
| require.NotErrorIs(t, err, target) | ||
| } |
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
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.
Summary
When a client queries a Beacon API endpoint with a valid hex
state_idthat is not indexed on the node (e.g.GET /eth/v1/beacon/states/0x<unknown-root>/validators),StateIDToHeightreturned an error that was not wrapped withtypes.ErrNotFound. Middleware therefore mapped the response to HTTP 500 instead of the spec-defined HTTP 404 ("State not found").This change wraps state root lookup failures with
types.ErrNotFoundat the mapping layer, fixing all/states/{state_id}/*endpoints in one place. The underlying storage error (including the state root) is preserved in the error chain, consistent with howGetBlockHeadershandles unknown parent block roots.block.ErrBlockStoreNotEnabledis passed through unchanged, since that indicates a server configuration issue rather than a missing state.Changes
node-api/handlers/utils/mappings.go: wrapGetSlotByStateRootfailures withtypes.ErrNotFound; excludeErrBlockStoreNotEnablednode-api/handlers/utils/mappings_test.go: unit tests for unknown state root, block store disabled, and existing resolution pathsTest plan
go test ./node-api/handlers/utils/... -count=1Follow-up
BlockIDToHeighthas the same class of issue for unknownblock_idroots (GetBlockHeaderByID,GetBlobSidecars). Happy to follow up in a separate PR if this direction looks good.