-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add expected withdrawals API #12519
Conversation
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.
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() { |
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.
This will panic on networks that are bootstrapped from Capella
var blockRoot [32]byte | ||
copy(blockRoot[:], root) |
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.
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) |
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.
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.
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.
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) { |
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.
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)) |
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.
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() { |
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.
According to the error message this should be a >
saved := params.BeaconConfig().MaxValidatorsPerWithdrawalsSweep | ||
params.BeaconConfig().MaxValidatorsPerWithdrawalsSweep = 16 |
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.
We usually use something like this in tests:
params.SetupTestConfigCleanup(t)
cfg := params.MainnetConfig().Copy()
cfg.ConfigName = "test"
params.OverrideBeaconConfig(cfg)
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.
lgtm, really nice PR. I'm a fan. Thank you!
* 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>
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
MAX_SEED_LOOKAHEAD
. Teku does it this way too but it is open for discussion :)