Repository navigation
feat(rpc): serve states/{id}/fork, config/deposit_contract and validator/duties/sync #642
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
pablodeymo
wants to merge
1
commit into
beacon-chain-integration
from
feat/beacon-api-missing-endpoints
+375
−8
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ use crate::{ | |
| pub(crate) fn routes() -> Router<Store> { | ||
| Router::new() | ||
| .route("/eth/v2/debug/beacon/states/{state_id}", get(get_state)) | ||
| .route("/eth/v1/beacon/states/{state_id}/fork", get(get_fork)) | ||
| .route( | ||
| "/eth/v1/beacon/states/{state_id}/finality_checkpoints", | ||
| get(get_finality_checkpoints), | ||
|
|
@@ -100,6 +101,20 @@ async fn get_state( | |
| with_consensus_version(response, fork) | ||
| } | ||
|
|
||
| /// `GET /eth/v1/beacon/states/{state_id}/fork`: the `Fork` the state carries, | ||
| /// which is what a validator client builds its signing domains from. | ||
| async fn get_fork(Path(state_id): Path<String>, State(store): State<Store>) -> Response { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the load, error and |
||
| let (root, state) = match load(&store, &state_id) { | ||
| Ok(found) => found, | ||
| Err(err) => return err.into_response(), | ||
| }; | ||
| crate::json_response(serde_json::json!({ | ||
| "execution_optimistic": store.is_beacon_optimistic(root), | ||
| "finalized": is_finalized(&store, state.slot()), | ||
| "data": state.fork(), | ||
| })) | ||
| } | ||
|
|
||
| async fn get_finality_checkpoints( | ||
| Path(state_id): Path<String>, | ||
| State(store): State<Store>, | ||
|
|
@@ -439,6 +454,44 @@ mod tests { | |
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn the_fork_is_the_one_the_state_carries() { | ||
| let fixture = beacon_fixture(ANCHOR_SLOT); | ||
| let head_state = fixture | ||
| .store | ||
| .get_state(&fixture.head_root) | ||
| .unwrap() | ||
| .unwrap(); | ||
| let expected = serde_json::to_value(head_state.fork()).unwrap(); | ||
|
|
||
| let response = get("/eth/v1/beacon/states/head/fork", None).await; | ||
| assert_eq!(response.status(), StatusCode::OK); | ||
| let json = body_json(response).await; | ||
| assert_eq!(json["data"], expected); | ||
| assert!( | ||
| json["data"]["epoch"].is_string(), | ||
| "the epoch must be quoted" | ||
| ); | ||
| assert!(json["execution_optimistic"].is_boolean()); | ||
| assert!(json["finalized"].is_boolean()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn the_finalized_states_fork_is_marked_finalized() { | ||
| let response = get("/eth/v1/beacon/states/finalized/fork", None).await; | ||
| assert_eq!(response.status(), StatusCode::OK); | ||
| assert_eq!(body_json(response).await["finalized"], true); | ||
| } | ||
|
|
||
| /// The same refusal every other state endpoint gives: state roots are not | ||
| /// indexed, so a `0x` id is a 404 rather than a guess. | ||
| #[tokio::test] | ||
| async fn a_fork_by_state_root_is_a_404() { | ||
| let root = format!("0x{}", "ab".repeat(32)); | ||
| let response = get(&format!("/eth/v1/beacon/states/{root}/fork"), None).await; | ||
| assert_eq!(response.status(), StatusCode::NOT_FOUND); | ||
| } | ||
|
|
||
| mod validators { | ||
| use super::*; | ||
| use crate::test_utils::beacon_store_at; | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
hex_string(config.deposit_contract_address), defined further down in this file, does the same thing.