-
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
Electra: BeaconState implementation #13919
Conversation
67ba5d7
to
f667110
Compare
4626076
to
a41da61
Compare
063f077
to
e980f86
Compare
00b695f
to
6fd2121
Compare
b597662
to
477c9cb
Compare
3f4df33
to
4950d24
Compare
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.
Left some commentary from self review. This PR is ready to review and is very large so it will need more than 1 approval.
undo := util.HackDenebMaxuint(t) | ||
defer undo() |
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 was renamed to HackElectraMaxuint and serves the same purpose. It's no longer needed in this particular test.
|
||
// hasETH1WithdrawalCredential returns whether the validator has an ETH1 | ||
// Withdrawal prefix. It assumes that the caller has a lock on the state | ||
func hasETH1WithdrawalCredential(val *ethpb.Validator) bool { |
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.
Moved these to helpers library
require.Equal(t, false, hasETH1WithdrawalCredential(v)) | ||
} | ||
func TestExpectedWithdrawals(t *testing.T) { | ||
for _, stateVersion := range []int{version.Capella, version.Deneb, version.Electra} { |
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.
I refactored TestExpectedWIthdrawals_$FORK to be a more table driven style instead of a copy and paste with the version changed.
}) | ||
} | ||
|
||
t.Run("electra all pending partial withdrawals", func(t *testing.T) { |
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 test load a ssz test from the spec tests repo as a fully hydrated example rather than hand crafting test data.
// This case is copied from spectest mainnet/electra/operations/voluntary_exit/pyspec_tests/exit_existing_churn_and_churn_limit_balance/pre.ssz_snappy | ||
// and that case was retrieved from the consensus-spec-tests repository at tag v1.5.0-alpha.1. | ||
// The spec tests shows that the exit epoch is 262 for validator 0 performing a voluntary exit. | ||
serializedBytes, err := util.BazelFileBytes("testdata/electra_exit_0.ssz_snappy") |
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.
Another spec test example test data. Helped me find an off by one bug 😅
@@ -21,6 +23,9 @@ func (b *BeaconState) SetLatestExecutionPayloadHeader(val interfaces.ExecutionDa | |||
|
|||
switch header := val.Proto().(type) { | |||
case *enginev1.ExecutionPayload: | |||
if b.version != version.Bellatrix { |
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.
I found it odd and bad that we could have a beacon state that accepted the wrong type of execution payload, so I added that verification for each case and the appropriate test.
) | ||
|
||
// SliceRoot computes the root of a slice of hashable objects. | ||
func SliceRoot[T ssz.Hashable](slice []T, limit uint64) ([32]byte, error) { |
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 is the same logic exactly from beacon-chain/state/stateutil/historical_summaries_root.go, but parameterized / generic version
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.
nice
func Merkleize(leaves [][]byte) [][][]byte { | ||
hashFunc := hash.CustomSHA256Hasher() | ||
layers := make([][][]byte, ssz.Depth(uint64(len(leaves)))+1) | ||
for len(leaves) != 32 { | ||
for len(leaves)%32 != 0 { |
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 was a bug where we would allocate infinite memory if the beacon state had more than 32 fields. Wow!
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.
bug of the week
Update the electra withdrawal example with a ssz state containing pending partial withdrawals
…n ActiveBalanceAtIndex
00d1f54
to
67dd466
Compare
All of @rkapka feedback is addressed. This PR is ready for another round of reviews |
Rebased onto develop and broken by #13948. Trying to figure how how to fix most effectively. |
Build is fixed as of 4ff0357 |
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.
Fantastic work!
s.validators[i] = val | ||
} | ||
expected, err := s.ExpectedWithdrawals() | ||
serializedSSZ, err := snappy.Decode(nil /* dst */, serializedBytes) |
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 could be a nice general test helper (get example state for fork).
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.
If someone finds that useful, I would be happy to help move this to some shared method. I thought this was a rather specific example that I crawled the spectests repo to find.
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.
Didn't mean that as feedback to move it btw, fine where it is.
) | ||
|
||
// SliceRoot computes the root of a slice of hashable objects. | ||
func SliceRoot[T ssz.Hashable](slice []T, limit uint64) ([32]byte, error) { |
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.
nice
* Electra: Beacon State * Electra: Beacon state fixes from PR 13919 * Add missing tests - part 1 * Split eip_7251_root.go into different files and reuse/share code with historical state summaries root. It's identical! * Add missing tests - part 2 * deposit receipts start index getters and setters (#13947) * adding in getters and setters for deposit receipts start index * adding tests * gaz * Add missing tests - part 3 of 3 Update the electra withdrawal example with a ssz state containing pending partial withdrawals * add tests for beacon-chain/state/state-native/getters_balance_deposits.go * Add electra field to testing/util/block.go execution payload * godoc commentary on public methods * Fix failing test * Add balances index out of bounds check and relevant tests. * Revert switch case electra * Instead of copying spectest data into testdata, use the spectest dependency * Deepsource fixes * Address @rkapka PR feedback * s/MaxPendingPartialsPerWithdrawalSweep/MaxPendingPartialsPerWithdrawalsSweep/ * Use multivalue slice compatible accessors for validator and balance in ActiveBalanceAtIndex * More @rkapka feedback. What a great reviewer! * More tests for branching logic in ExitEpochAndUpdateChurn * fix build --------- 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?
Required for Electra.
Which issues(s) does this PR fix?
The beacon state is blocking progress on most electra PRs. #13903 #13898 #13893 #13911 #13888
Other notes for review
We might want to split this into smaller PRs. I split up the changes into logical commits that could be their on PRs, in order.Merge the following PRs before this can be made ready for review: