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

Add expected withdrawals API #12519

Merged

Conversation

tanhengyeow
Copy link
Contributor

What type of PR is this?

Feature

What does this PR do? Why is it needed?

This PR adds a withdrawal endpoint to fetch withdrawals from a parent state. The corresponding PR for the beacon API specs can be found here.

Which issues(s) does this PR fix?

Fixes #12261

Other notes for review

  • This PR implements the API without using gRPC, similar to the rewards server.
  • Upper bound for proposal slot is 4 epochs after the epoch of the current state, which corresponds to MAX_SEED_LOOKAHEAD. Teku does it this way too but it is open for discussion :)

@tanhengyeow tanhengyeow requested a review from a team as a code owner June 13, 2023 07:52
@tanhengyeow tanhengyeow requested review from saolyn, potuz and rkapka June 13, 2023 07:52
Copy link
Contributor

@potuz potuz left a comment

Choose a reason for hiding this comment

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

Just a couple of comments, thanks for the PR, it's well scoped, well written, easy to follow and a complete work. Looking forward to reading more like this!

}
lookAheadLimit := uint64(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().MaxSeedLookahead)))
// SafeSub not needed as we have checked that proposal slot cannot be lesser than Capella start epoch
if proposalSlot.Sub(lookAheadLimit) >= st.Slot() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will panic on networks that are bootstrapped from Capella

Comment on lines 86 to 87
var blockRoot [32]byte
copy(blockRoot[:], root)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can cast now [32]byte(root)

copy(blockRoot[:], root)
isFinalized := s.FinalizationFetcher.IsFinalized(r.Context(), blockRoot)
// Advance state forward to proposal slot
st, err = transition.ProcessSlots(r.Context(), st, proposalSlot)
Copy link
Contributor

Choose a reason for hiding this comment

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

What' s the expected usage of this endpoint? It may be useful to expose the NSC to the RPC methods, although lock contention may be an issue. Better to ping me on Discord to have this discussion there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The endpoint is targeted at external block builders. Quoting from this issue:
With this API, withdrawals in the payload of externally built blocks can be compared with the expected withdrawals to ensure that the two match.

"strconv"
)

func (s *Server) ExpectedWithdrawals(w http.ResponseWriter, r *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the description from the spec in the form of a comment:

Get the withdrawals computed from the specified state, that will be included in the block
that gets built on the specified state.

}
st, err := s.Stater.State(r.Context(), []byte(stateId))
if err != nil {
network.WriteError(w, handleWrapError(err, "could not retrieve state_id", http.StatusNotFound))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
network.WriteError(w, handleWrapError(err, "could not retrieve state_id", http.StatusNotFound))
network.WriteError(w, handleWrapError(err, "could not retrieve state", http.StatusNotFound))

}
lookAheadLimit := uint64(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().MaxSeedLookahead)))
// SafeSub not needed as we have checked that proposal slot cannot be lesser than Capella start epoch
if proposalSlot.Sub(lookAheadLimit) >= st.Slot() {
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the error message this should be a >

Comment on lines 117 to 118
saved := params.BeaconConfig().MaxValidatorsPerWithdrawalsSweep
params.BeaconConfig().MaxValidatorsPerWithdrawalsSweep = 16
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually use something like this in tests:

params.SetupTestConfigCleanup(t)
cfg := params.MainnetConfig().Copy()
cfg.ConfigName = "test"
params.OverrideBeaconConfig(cfg)

Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

lgtm, really nice PR. I'm a fan. Thank you!

@prylabs-bulldozer prylabs-bulldozer bot merged commit c018981 into prysmaticlabs:develop Jun 21, 2023
james-prysm added a commit that referenced this pull request Jun 27, 2023
* add structs for expected-withdrawals-api

* add server handler

* add tests

* add bazel file

* register api in service

* remove get prefix for endpoint

* fix review comments

* Update beacon-chain/rpc/eth/builder/handlers.go

* use goimports sorting type

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
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.

Fetch withdrawals from a parent state
5 participants