-
Notifications
You must be signed in to change notification settings - Fork 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
Capella beacon state #11141
Capella beacon state #11141
Conversation
fieldRoots[nativetypes.LatestExecutionPayloadHeaderCapella.RealPosition()] = executionPayloadRoot[:] | ||
|
||
// Withdrawal queue root. | ||
withdrawalQueueRoot := []byte("stub") |
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 left an exercise for you @potuz - complete the stub
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.
These are hashed as normal SSZ lists of Withdrawal
objects, doesn't fastssz already cover this?
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.
discussed offline, we can reuse Nishant's vectorized merkleizer
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.
Do we intend to fix this ? Or is this meant to be in a follow up PR. i rather not have our hashing incomplete like this if we are adding in the whole state.
consensus-types/blocks/execution.go
Outdated
BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas()), | ||
BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash()), | ||
TransactionsRoot: txRoot[:], | ||
WithdrawalsRoot: []byte("stub"), |
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 one for @potuz
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.
Same here this is the usual list.HTR
from the withdrawal list in the execution payload.
@@ -294,6 +294,28 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl | |||
if err := valIdxBkt.Put(rt[:], validatorKeys[i]); err != nil { | |||
return err | |||
} | |||
case *ethpb.BeaconStateCapella: |
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 case switch is a good candidate for simplification using generics since all cases are the same function based on pbState.
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.
Yes, this was my impression too. But I didn't want to refactor existing code in this PR.
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.
There isn't even a need for generics if we can just pass in fastssz.Marshaler as an interface (beacon state satisfies this)
@@ -19,11 +21,20 @@ func (b *BeaconState) LatestExecutionPayloadHeader() (*enginev1.ExecutionPayload | |||
b.lock.RLock() | |||
defer b.lock.RUnlock() | |||
|
|||
return b.latestExecutionPayloadHeaderVal(), nil | |||
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 think in general and considering future forks, the best approach for all these switches is the opposite order
if version >= Capella { do something }
else if version >= Bellatrix { do something }
else { not supported }
The first one is hit more often.
case nativetypes.LatestExecutionPayloadHeaderCapella: | ||
return b.latestExecutionPayloadHeaderCapella.HashTreeRoot() | ||
case nativetypes.WithdrawalQueue: | ||
return [32]byte{}, errors.New("not implemented") |
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.
and one more @potuz
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.
Same as above, why doesn't fastssz already cover this give it's a list?
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.
its not hard to do custom hashing for this too.
920fc31
to
0df2f33
Compare
@@ -85,6 +85,10 @@ type WriteOnlyBeaconState interface { | |||
UpdateSlashingsAtIndex(idx, val uint64) error | |||
AppendHistoricalRoots(root [32]byte) error | |||
SetLatestExecutionPayloadHeader(payload interfaces.ExecutionData) error | |||
SetWithdrawalQueue(val []*enginev1.Withdrawal) 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.
Not really related to your PR, but why is the withdrawal object in our engine namespace ? Seems like the wrong place for it
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.
See discussion starting in https://discord.com/channels/476244492043812875/998988600530194583/1001913104512335882
fieldRoots[nativetypes.LatestExecutionPayloadHeaderCapella.RealPosition()] = executionPayloadRoot[:] | ||
|
||
// Withdrawal queue root. | ||
withdrawalQueueRoot := []byte("stub") |
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.
Do we intend to fix this ? Or is this meant to be in a follow up PR. i rather not have our hashing incomplete like this if we are adding in the whole state.
@@ -14,14 +14,20 @@ func (b *BeaconState) SetLatestExecutionPayloadHeader(val interfaces.ExecutionDa | |||
b.lock.Lock() | |||
defer b.lock.Unlock() | |||
|
|||
if b.version == version.Phase0 || b.version == version.Altair { | |||
if b.version < version.Bellatrix { | |||
return errNotSupported("SetLatestExecutionPayloadHeader", b.version) | |||
} | |||
header, ok := val.Proto().(*enginev1.ExecutionPayloadHeader) |
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.
can we use a switch statement here rather than multiple type assertions. Would make the code cleaner to read
case version.Altair: | ||
dst.sharedFieldReferences = make(map[nativetypes.FieldIndex]*stateutil.Reference, 11) | ||
case version.Bellatrix: | ||
case version.Altair, version.Bellatrix, version.Capella: |
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 isnt correct, altair, bellatrix and capella have different sizes.
case nativetypes.LatestExecutionPayloadHeaderCapella: | ||
return b.latestExecutionPayloadHeaderCapella.HashTreeRoot() | ||
case nativetypes.WithdrawalQueue: | ||
return [32]byte{}, errors.New("not implemented") |
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.
its not hard to do custom hashing for this too.
@@ -183,7 +183,7 @@ func (s *Service) getPayloadHash(ctx context.Context, root []byte) ([32]byte, er | |||
// notifyForkchoiceUpdate signals execution engine on a new payload. | |||
// It returns true if the EL has returned VALID for the block | |||
func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int, | |||
postStateHeader *enginev1.ExecutionPayloadHeader, blk interfaces.SignedBeaconBlock) (bool, error) { | |||
postStateHeader interfaces.ExecutionData, blk interfaces.SignedBeaconBlock) (bool, 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.
What's the reason for changing *enginev1.ExecutionPayloadHeader
to interfaces.ExecutionData
. First glance, it seems unrelated to the PR title. Can you please explain it or even better cover that in the description?
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 updated the description
b.lock.RLock() | ||
defer b.lock.RUnlock() |
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.
Should we move these read locks before the version check? Currently, it's not consistent with SetWithdrawalQueue
and the setter method
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 made everything consistent
Let's get one more approve before merge plz |
What type of PR is this?
Feature
What does this PR do? Why is it needed?
Adds in Capella state, including new:
This PR introduces the
ExecutionData
interface, which is a common abstraction overexecutionPayload
,executionPayloadCapella
,executionPayloadHeader
andexecutionPayloadHeaderCapella
. The reason for it is to avoid duplication in functions such as this:Here
postStateHeader
is of typeExecutionData
, which means a single function can handle both possible underlying header types.Which issues(s) does this PR fix?
Part of #11077