-
Notifications
You must be signed in to change notification settings - Fork 26
feat(rpc): add GET /lean/v0/config/spec #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MegaRedHand
wants to merge
6
commits into
main
Choose a base branch
from
feat/lean-api-spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4af7780
feat(rpc): add GET /lean/v0/config/spec
MegaRedHand 7221691
fix(rpc): address review feedback on config/spec (test assertion, sta…
MegaRedHand f131350
Merge remote-tracking branch 'origin/main' into feat/lean-api-spec
MegaRedHand e540428
docs(rpc): document GET /lean/v0/config/spec
MegaRedHand e71caec
Merge remote-tracking branch 'origin/main' into feat/lean-api-spec
MegaRedHand e08af63
refactor(types): centralize FORK_DIGEST in a shared constants module
MegaRedHand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| //! Protocol constants shared across crates. | ||
|
|
||
| /// Fork digest embedded in every gossipsub topic string, as lowercase hex | ||
| /// without a `0x` prefix. | ||
| /// | ||
| /// The [leanSpec](https://github.com/leanEthereum/leanSpec/pull/622) | ||
| /// currently mandates a dummy value shared across all clients; this will | ||
| /// eventually be derived from the fork version and genesis validators root. | ||
| // TODO: derive dynamically once the spec defines fork identification. | ||
| pub const FORK_DIGEST: &str = "12345678"; |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| use axum::{Router, response::IntoResponse, routing::get}; | ||
| use ethlambda_blockchain::{INTERVALS_PER_SLOT, MILLISECONDS_PER_INTERVAL, MILLISECONDS_PER_SLOT}; | ||
| use ethlambda_storage::Store; | ||
| use ethlambda_types::{constants::FORK_DIGEST, state::HISTORICAL_ROOTS_LIMIT}; | ||
| use serde::Serialize; | ||
|
|
||
| use crate::json_response; | ||
|
|
||
| #[derive(Serialize)] | ||
| struct SpecResponse { | ||
| #[serde(rename = "MILLISECONDS_PER_SLOT")] | ||
| ms_per_slot: u64, | ||
| #[serde(rename = "INTERVALS_PER_SLOT")] | ||
| intervals_per_slot: u64, | ||
| #[serde(rename = "MILLISECONDS_PER_INTERVAL")] | ||
| ms_per_interval: u64, | ||
| #[serde(rename = "HISTORICAL_ROOTS_LIMIT")] | ||
| historical_roots_limit: u64, | ||
| #[serde(rename = "FORK_DIGEST")] | ||
| fork_digest: &'static str, | ||
| } | ||
|
|
||
| async fn get_spec() -> impl IntoResponse { | ||
| json_response(SpecResponse { | ||
| ms_per_slot: MILLISECONDS_PER_SLOT, | ||
| intervals_per_slot: INTERVALS_PER_SLOT, | ||
| ms_per_interval: MILLISECONDS_PER_INTERVAL, | ||
| historical_roots_limit: HISTORICAL_ROOTS_LIMIT as u64, | ||
| fork_digest: FORK_DIGEST, | ||
| }) | ||
| } | ||
|
|
||
| pub(crate) fn routes() -> Router<Store> { | ||
| Router::new().route("/lean/v0/config/spec", get(get_spec)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::FORK_DIGEST; | ||
| use crate::test_utils::create_test_state; | ||
| use axum::{ | ||
| body::Body, | ||
| http::{Request, StatusCode}, | ||
| }; | ||
| use ethlambda_blockchain::{ | ||
| INTERVALS_PER_SLOT, MILLISECONDS_PER_INTERVAL, MILLISECONDS_PER_SLOT, | ||
| }; | ||
| use ethlambda_storage::{Store, backend::InMemoryBackend}; | ||
| use ethlambda_types::state::HISTORICAL_ROOTS_LIMIT; | ||
| use http_body_util::BodyExt; | ||
| use std::sync::Arc; | ||
| use tower::ServiceExt; | ||
|
|
||
| #[tokio::test] | ||
| async fn spec_returns_lean_constants() { | ||
| let store = Store::from_anchor_state(Arc::new(InMemoryBackend::new()), create_test_state()); | ||
| let app = crate::build_api_router(store); | ||
| let resp = app | ||
| .oneshot( | ||
| Request::builder() | ||
| .uri("/lean/v0/config/spec") | ||
| .body(Body::empty()) | ||
| .unwrap(), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(resp.status(), StatusCode::OK); | ||
| let body = resp.into_body().collect().await.unwrap().to_bytes(); | ||
| let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); | ||
| assert_eq!(json["MILLISECONDS_PER_SLOT"], MILLISECONDS_PER_SLOT); | ||
| assert_eq!(json["INTERVALS_PER_SLOT"], INTERVALS_PER_SLOT); | ||
| assert_eq!(json["MILLISECONDS_PER_INTERVAL"], MILLISECONDS_PER_INTERVAL); | ||
| assert_eq!( | ||
| json["HISTORICAL_ROOTS_LIMIT"], | ||
| HISTORICAL_ROOTS_LIMIT as u64 | ||
| ); | ||
| assert_eq!(json["FORK_DIGEST"], FORK_DIGEST); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.