Add GET /lean/v0/fork_choice JSON endpoint to leanSpec#418
Merged
tcoratger merged 3 commits intoleanEthereum:mainfrom Feb 25, 2026
Merged
Add GET /lean/v0/fork_choice JSON endpoint to leanSpec#418tcoratger merged 3 commits intoleanEthereum:mainfrom
GET /lean/v0/fork_choice JSON endpoint to leanSpec#418tcoratger merged 3 commits intoleanEthereum:mainfrom
Conversation
…e endpoint already available in ethlambdas Rust implementation.
tcoratger
approved these changes
Feb 25, 2026
Collaborator
tcoratger
left a comment
There was a problem hiding this comment.
Just left a minor comment for testing, otherwise, looks good to me.
Comment on lines
107
to
125
| class TestForkChoiceEndpoint: | ||
| """Tests for the /lean/v0/fork_choice endpoint error handling.""" | ||
|
|
||
| async def test_returns_503_when_store_not_initialized(self) -> None: | ||
| """Endpoint returns 503 Service Unavailable when store is not set.""" | ||
| config = ApiServerConfig(port=15058) | ||
| server = ApiServer(config=config) | ||
|
|
||
| await server.start() | ||
|
|
||
| try: | ||
| async with httpx.AsyncClient() as client: | ||
| response = await client.get("http://127.0.0.1:15058/lean/v0/fork_choice") | ||
|
|
||
| assert response.status_code == 503 | ||
|
|
||
| finally: | ||
| server.stop() | ||
| await asyncio.sleep(0.1) |
Collaborator
There was a problem hiding this comment.
Can't we have a test with a 200 OK code as well to test the validity?
Addresses review feedback requesting a test that validates the endpoint returns correct fork choice data when the store is initialized.
from_validator_indices expects ValidatorIndices (SSZModel with .data), not a plain list. This caused an AttributeError in CI.
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.
🗒️ Description
Add
GET /lean/v0/fork_choiceJSON endpoint to leanSpec, matching the endpoint already available in ethlambda's Rust implementation.The endpoint returns a snapshot of the fork choice tree:
Changes
New
compute_block_weightsmethod on Store (store.py): extracts the weight computation loop from_compute_lmd_ghost_headinto a public method. Walks backward from each validator's latest head vote, accumulating weight per block above the finalized slot.New endpoint handler (
endpoints/fork_choice.py): follows the same pattern ascheckpoints.py. Returns 503 when the store is not initialized.Route registration (
routes.py,endpoints/__init__.py): wires up/lean/v0/fork_choice.Tests:
test_server.py: 503 test for the new endpoint (port 15058)test_compute_block_weights.py: genesis-only (empty weights), linear chain (upward accumulation), and multiple attestations (weight stacking)🔗 Related Issues or PRs
N/A
✅ Checklist
toxchecks to avoid unnecessary CI fails:uvx tox