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

[Merged by Bors] - Add finalized to HTTP API responses #3753

Closed
wants to merge 28 commits into from

Conversation

danielrachi1
Copy link
Contributor

@danielrachi1 danielrachi1 commented Nov 26, 2022

Issue Addressed

#3708

Proposed Changes

  • Add is_finalized_block method to BeaconChain in beacon_node/beacon_chain/src/beacon_chain.rs.
  • Add is_finalized_state method to BeaconChain in beacon_node/beacon_chain/src/beacon_chain.rs.
  • Add fork_and_execution_optimistic_and_finalized in beacon_node/http_api/src/state_id.rs.
  • Add ExecutionOptimisticFinalizedForkVersionedResponse type in consensus/types/src/fork_versioned_response.rs.
  • Add execution_optimistic_finalized_fork_versioned_responsefunction in beacon_node/http_api/src/version.rs.
  • Add ExecutionOptimisticFinalizedResponse type in common/eth2/src/types.rs.
  • Add add_execution_optimistic_finalized method in common/eth2/src/types.rs.
  • Update API response methods to include finalized.
  • Remove execution_optimistic_fork_versioned_response

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

This is great, thanks for digging into it!

You're definitely on the right track, I just left a few pointers about how to progress from here

beacon_node/http_api/src/lib.rs Outdated Show resolved Hide resolved
beacon_node/http_api/src/block_id.rs Outdated Show resolved Hide resolved
common/eth2/src/types.rs Outdated Show resolved Hide resolved
@danielrachi1
Copy link
Contributor Author

danielrachi1 commented Dec 4, 2022

I think that's all :)

Some things to settle before it's... finalized:

  • I don't know how I should do the error handling for the two functions I added (is_finalized_block and is_finalized_state). I don't see how they could fail / when I should return an error. So, any help here would be great. (Maybe just unwrap_or(false) ?)
  • execution_optimistic_fork_versioned_response is no longer used. So, I'll delete it in my next commit. (I wanted to mention this explicitly, just in case.)
  • I haven't added any tests. I think I should read the existing tests on beacon_node/http_api/tests/ and modify them so they check if finalized is being returned with the right value. Is this the right way to go?

@michaelsproul
Copy link
Member

Sorry I didn't get back to you about this!

Your approach to error handling looks good at a quick glance and I agree we don't need execution_optimistic_fork_versioned_response if it's unused.

I'll try to give this a more thorough review on Monday & help with writing tests if you need help

@michaelsproul michaelsproul added work-in-progress PR is a work-in-progress HTTP-API labels Dec 16, 2022
@danielrachi1 danielrachi1 marked this pull request as ready for review December 18, 2022 23:14
@macladson macladson added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Jan 8, 2023
Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

This is looking really nice on the whole, I've just made a few suggestions which I hope will decrease the impact on performance.

In general my suggestions try to avoid disk I/O and repetition. Disk I/O, particularly loading full states, is a major source of slowness.

It would also be really cool to do some real-world benchmarks of nodes before and after this change is applied. We could write a utility into lcli which uses the API wrappers from eth2 to make different calls against a live node, and record how long they take. I'd be happy to work on this as it would also be useful for testing other API changes and optimisations.

beacon_node/http_api/src/lib.rs Outdated Show resolved Hide resolved
beacon_node/http_api/src/lib.rs Outdated Show resolved Hide resolved
beacon_node/http_api/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@michaelsproul michaelsproul 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

There are a few merge conflicts to fix up but once they're resolved I'll give it another look and we can merge.

Most of the conflicts will be from #4068, which changed all the HTTP handlers to return warp::reply::Response. Sprinkling a few into_response() calls in a couple of places might be all we need. The blocking_json_task already takes care of returning a Response, so any calls using that should be OK.

@michaelsproul michaelsproul added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Mar 14, 2023
@danielrachi1
Copy link
Contributor Author

Unless I missed something, it seems like the conflicts were quite simple. Just some use statements that needed to be updated.

@michaelsproul michaelsproul added ready-for-review The code is ready for review v4.1.0 Post-Capella minor release and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Mar 17, 2023
@michaelsproul
Copy link
Member

Thanks @danielrachi, seeing as this is quite a major change and isn't essential for Capella I'm nominating it for inclusion in v4.1.0, which should be released in a few weeks.

- Remove unnecessary tuple nesting like `((data, finalized), optimistic)`
- Return `finalized` from `BlockId` functions to avoid repeated block loads from disk
- Add `finalized` status to new rewards APIs added after this PR was opened
@michaelsproul
Copy link
Member

@danielrachi I pushed some minor changes in 5e2be5f that I thought of while reviewing. I'll deploy this PR on some of our nodes, and then I think it's good to merge

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Mar 30, 2023
Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

This has been:

  • Manually reviewed
  • Benchmarked
  • Deployed on Goerli

We're good to go

@michaelsproul
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Mar 30, 2023
## Issue Addressed

#3708 

## Proposed Changes
- Add `is_finalized_block` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `is_finalized_state` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `fork_and_execution_optimistic_and_finalized` in `beacon_node/http_api/src/state_id.rs`.
- Add `ExecutionOptimisticFinalizedForkVersionedResponse` type in `consensus/types/src/fork_versioned_response.rs`.
- Add `execution_optimistic_finalized_fork_versioned_response`function in  `beacon_node/http_api/src/version.rs`.
- Add `ExecutionOptimisticFinalizedResponse` type in `common/eth2/src/types.rs`.
- Add `add_execution_optimistic_finalized` method in  `common/eth2/src/types.rs`.
- Update API response methods to include finalized.
- Remove `execution_optimistic_fork_versioned_response`

Co-authored-by: Michael Sproul <michael@sigmaprime.io>
@michaelsproul
Copy link
Member

Will batch this actually

bors r-
bors r+

@bors
Copy link

bors bot commented Mar 30, 2023

Canceled.

bors bot pushed a commit that referenced this pull request Mar 30, 2023
## Issue Addressed

#3708 

## Proposed Changes
- Add `is_finalized_block` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `is_finalized_state` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `fork_and_execution_optimistic_and_finalized` in `beacon_node/http_api/src/state_id.rs`.
- Add `ExecutionOptimisticFinalizedForkVersionedResponse` type in `consensus/types/src/fork_versioned_response.rs`.
- Add `execution_optimistic_finalized_fork_versioned_response`function in  `beacon_node/http_api/src/version.rs`.
- Add `ExecutionOptimisticFinalizedResponse` type in `common/eth2/src/types.rs`.
- Add `add_execution_optimistic_finalized` method in  `common/eth2/src/types.rs`.
- Update API response methods to include finalized.
- Remove `execution_optimistic_fork_versioned_response`

Co-authored-by: Michael Sproul <michael@sigmaprime.io>
@bors bors bot changed the title Add finalized to HTTP API responses [Merged by Bors] - Add finalized to HTTP API responses Mar 30, 2023
@bors bors bot closed this Mar 30, 2023
@paulhauner paulhauner added the backwards-incompat Backwards-incompatible API change label Apr 13, 2023
ghost pushed a commit to oone-world/lighthouse that referenced this pull request Jul 13, 2023
## Issue Addressed

sigp#3708 

## Proposed Changes
- Add `is_finalized_block` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `is_finalized_state` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `fork_and_execution_optimistic_and_finalized` in `beacon_node/http_api/src/state_id.rs`.
- Add `ExecutionOptimisticFinalizedForkVersionedResponse` type in `consensus/types/src/fork_versioned_response.rs`.
- Add `execution_optimistic_finalized_fork_versioned_response`function in  `beacon_node/http_api/src/version.rs`.
- Add `ExecutionOptimisticFinalizedResponse` type in `common/eth2/src/types.rs`.
- Add `add_execution_optimistic_finalized` method in  `common/eth2/src/types.rs`.
- Update API response methods to include finalized.
- Remove `execution_optimistic_fork_versioned_response`

Co-authored-by: Michael Sproul <michael@sigmaprime.io>
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
- Add `is_finalized_block` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `is_finalized_state` method to `BeaconChain` in `beacon_node/beacon_chain/src/beacon_chain.rs`.
- Add `fork_and_execution_optimistic_and_finalized` in `beacon_node/http_api/src/state_id.rs`.
- Add `ExecutionOptimisticFinalizedForkVersionedResponse` type in `consensus/types/src/fork_versioned_response.rs`.
- Add `execution_optimistic_finalized_fork_versioned_response`function in  `beacon_node/http_api/src/version.rs`.
- Add `ExecutionOptimisticFinalizedResponse` type in `common/eth2/src/types.rs`.
- Add `add_execution_optimistic_finalized` method in  `common/eth2/src/types.rs`.
- Update API response methods to include finalized.
- Remove `execution_optimistic_fork_versioned_response`

Co-authored-by: Michael Sproul <michael@sigmaprime.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-incompat Backwards-incompatible API change HTTP-API ready-for-merge This PR is ready to merge. v4.1.0 Post-Capella minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants