Skip to content
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

fix: get_block_by_number endpoint #310

Merged
merged 3 commits into from
Aug 29, 2024
Merged

Conversation

avilagaston9
Copy link
Contributor

Motivation

The get-finalized and get-safe endpoints were returning null values because we weren't handling the forkchoice updates from the engine.

Description

This PR adds a minimal implementation to store forkchoice updates and pass the tests. Additionally, it takes the opportunity to implement a refactor.

  • Moves core/types/engine/payload.rs to rpc/types/payload.rs.
  • Creates rpc/engine/payload.rs and rpc/engine/fork_choice.rs to modularize rpc/engine/mod.rs.
  • Adds a minimal implementation of forkchoice_updated_v3().
  • Fixeseth_getBlockByNumber.

Observations

This PR doesn't implement the engine_forkchoiceUpdatedV3 endpoint, It only stores the minimal data needed to pass eth_getBlockByNumber.

Closes #270

@avilagaston9 avilagaston9 marked this pull request as ready for review August 27, 2024 14:07
@avilagaston9 avilagaston9 requested a review from a team as a code owner August 27, 2024 14:07
Copy link
Contributor

@vicentevieytes vicentevieytes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

let request = ForkChoiceUpdatedV3::parse(&req.params).ok_or(RpcErr::BadParams)?;
Ok(
serde_json::to_value(fork_choice::forkchoice_updated_v3(request, storage)?)
.unwrap(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we return an error instead of unwrapping here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally!

"engine_newPayloadV3" => {
let request = NewPayloadV3Request::parse(&req.params).ok_or(RpcErr::BadParams)?;
Ok(serde_json::to_value(engine::new_payload_v3(request, storage)?).unwrap())
Ok(serde_json::to_value(payload::new_payload_v3(request, storage)?).unwrap())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we return an error instead of unwrapping here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

let safe = storage.get_block_number(request.fork_choice_state.safe_block_hash);
let finalized = storage.get_block_number(request.fork_choice_state.finalized_block_hash);

// Check if we already have the blocks stored.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this check, you might get multiple updates that have the same safe/finalized block. You don't need to return an error here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, in this step I'm actually checking that we have those blocks stored beforehand, rather than if we have already marked them as safe/finalized. But maybe I didn't fully understand what you meant.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, my bad then.

@avilagaston9 avilagaston9 added this pull request to the merge queue Aug 29, 2024
Merged via the queue into main with commit bb2835f Aug 29, 2024
5 checks passed
@avilagaston9 avilagaston9 deleted the engine-forkchoice-updated branch August 29, 2024 13:01
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this pull request Oct 16, 2024
**Motivation**

The `get-finalized` and `get-safe` endpoints were returning null values
because we weren't handling the forkchoice updates from the engine.

**Description**

This PR adds a minimal implementation to store forkchoice updates and
pass the tests. Additionally, it takes the opportunity to implement a
refactor.

- Moves `core/types/engine/payload.rs` to `rpc/types/payload.rs`.
- Creates `rpc/engine/payload.rs` and `rpc/engine/fork_choice.rs` to
modularize `rpc/engine/mod.rs`.
- Adds a minimal implementation of `forkchoice_updated_v3()`.
- Fixes`eth_getBlockByNumber`.

**Observations**

This PR doesn't implement the `engine_forkchoiceUpdatedV3` endpoint, It
only stores the minimal data needed to pass `eth_getBlockByNumber`.

Closes lambdaclass#270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hive Testing: eth_getBlockByNumber
4 participants