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

Capella beacon state #11141

Merged
merged 51 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d56db46
fork
rkapka Jul 29, 2022
657b897
types
rkapka Jul 29, 2022
fffa376
cloners
rkapka Jul 29, 2022
ed6c73a
getters
rkapka Jul 29, 2022
2b8a8da
remove CapellaBlind from fork
rkapka Jul 29, 2022
6d303f6
hasher
rkapka Jul 29, 2022
d21d437
setters
rkapka Jul 29, 2022
f061dab
spec params, config tests
rkapka Jul 29, 2022
00a840b
generate ssz
rkapka Aug 1, 2022
a8c9125
executionPayloadHeaderCapella
rkapka Aug 1, 2022
6790b1c
proto state
rkapka Aug 1, 2022
b1ba747
BeaconStateCapella SSZ
rkapka Aug 1, 2022
0b7cfbd
saving state
rkapka Aug 1, 2022
437c265
configfork
rkapka Aug 1, 2022
c5deedb
BUILD files
rkapka Aug 1, 2022
8af7855
Merge branch 'develop' into capella-state
rkapka Aug 1, 2022
d5e8c25
fix RealPosition
rkapka Aug 1, 2022
f98e90b
Merge branch '__develop' into capella-state
rkapka Aug 1, 2022
8b4b3cf
Merge remote-tracking branch 'origin/capella-state' into capella-state
rkapka Aug 1, 2022
d2aabcf
fix hasher
rkapka Aug 1, 2022
e74ad33
SetLatestExecutionPayloadHeaderCapella
rkapka Aug 1, 2022
e21ab9c
fix error message
rkapka Aug 1, 2022
c96303e
reduce complexity of saveStatesEfficientInternal
rkapka Aug 1, 2022
50ba24b
add latestExecutionPayloadHeaderCapella to minimal state
rkapka Aug 1, 2022
70c74ba
halway done interface
rkapka Aug 2, 2022
525066f
remove withdrawal methods
rkapka Aug 2, 2022
686d14c
merge setters
rkapka Aug 2, 2022
5926230
change signatures for v1 and v2
rkapka Aug 2, 2022
b05ed63
fixing errors pt. 1
rkapka Aug 2, 2022
bfeff5e
paylod_test fixes
rkapka Aug 2, 2022
a995186
fix everything
rkapka Aug 2, 2022
5d84931
remove unused func
rkapka Aug 2, 2022
ad28693
Merge branch '__develop' into capella-state
rkapka Sep 29, 2022
a311c89
fix tests
rkapka Sep 29, 2022
6326523
state_trie_test improvements
rkapka Sep 29, 2022
d7de7c7
in progress...
rkapka Sep 29, 2022
2647b1f
hasher test
rkapka Sep 29, 2022
bcae282
fix configs
rkapka Sep 30, 2022
fb6b1d1
Merge branch '__develop' into capella-state
rkapka Sep 30, 2022
0df2f33
simplify hashing
rkapka Sep 30, 2022
a117e0b
Revert "fix configs"
rkapka Sep 30, 2022
0b00e1e
remove capella from config test
rkapka Sep 30, 2022
1a43b53
Merge branch 'develop' into capella-state
rkapka Sep 30, 2022
5548f0f
unify locking
rkapka Oct 4, 2022
6a49722
Merge branch 'develop' into capella-state
terencechain Oct 4, 2022
54e519c
review
rkapka Oct 4, 2022
ae78e88
hashing
rkapka Oct 5, 2022
2ab4908
Merge branch 'develop' into capella-state
rkapka Oct 5, 2022
872245c
fixes
rkapka Oct 5, 2022
f437cd8
Merge branch 'develop' into capella-state
rauljordan Oct 5, 2022
6266ce2
Merge branch 'develop' into capella-state
rkapka Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the description

ctx, span := trace.StartSpan(ctx, "blockChain.notifyNewPayload")
defer span.End()

Expand Down
15 changes: 5 additions & 10 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v3/monitoring/tracing"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
ethpbv1 "github.com/prysmaticlabs/prysm/v3/proto/eth/v1"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/attestation"
Expand Down Expand Up @@ -278,11 +277,11 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo
return nil
}

func getStateVersionAndPayload(st state.BeaconState) (int, *enginev1.ExecutionPayloadHeader, error) {
func getStateVersionAndPayload(st state.BeaconState) (int, interfaces.ExecutionData, error) {
if st == nil {
return 0, nil, errors.New("nil state")
}
var preStateHeader *enginev1.ExecutionPayloadHeader
var preStateHeader interfaces.ExecutionData
var err error
preStateVersion := st.Version()
switch preStateVersion {
Expand Down Expand Up @@ -340,7 +339,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeac
}
type versionAndHeader struct {
version int
header *enginev1.ExecutionPayloadHeader
header interfaces.ExecutionData
}
preVersionAndHeaders := make([]*versionAndHeader, len(blks))
postVersionAndHeaders := make([]*versionAndHeader, len(blks))
Expand Down Expand Up @@ -607,7 +606,7 @@ func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b
}

// validateMergeTransitionBlock validates the merge transition block.
func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion int, stateHeader *enginev1.ExecutionPayloadHeader, blk interfaces.SignedBeaconBlock) error {
func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion int, stateHeader interfaces.ExecutionData, blk interfaces.SignedBeaconBlock) error {
// Skip validation if block is older than Bellatrix.
if blocks.IsPreBellatrixVersion(blk.Block().Version()) {
return nil
Expand All @@ -634,11 +633,7 @@ func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion

// Skip validation if the block is not a merge transition block.
// To reach here. The payload must be non-empty. If the state header is empty then it's at transition.
wh, err := consensusblocks.WrappedExecutionPayloadHeader(stateHeader)
if err != nil {
return err
}
empty, err := consensusblocks.IsEmptyExecutionData(wh)
empty, err := consensusblocks.IsEmptyExecutionData(stateHeader)
if err != nil {
return err
}
Expand Down
52 changes: 28 additions & 24 deletions beacon-chain/blockchain/process_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,11 @@ func Test_getStateVersionAndPayload(t *testing.T) {
ver, header, err := getStateVersionAndPayload(tt.st)
require.NoError(t, err)
require.Equal(t, tt.version, ver)
require.DeepEqual(t, tt.header, header)
if header != nil {
protoHeader, ok := header.Proto().(*enginev1.ExecutionPayloadHeader)
require.Equal(t, true, ok)
require.DeepEqual(t, tt.header, protoHeader)
}
})
}
}
Expand Down Expand Up @@ -1187,7 +1191,7 @@ func Test_validateMergeTransitionBlock(t *testing.T) {
tests := []struct {
name string
stateVersion int
header *enginev1.ExecutionPayloadHeader
header interfaces.ExecutionData
payload *enginev1.ExecutionPayload
errString string
}{
Expand Down Expand Up @@ -1244,35 +1248,35 @@ func Test_validateMergeTransitionBlock(t *testing.T) {
payload: &enginev1.ExecutionPayload{
ParentHash: aHash[:],
},
header: &enginev1.ExecutionPayloadHeader{
ParentHash: make([]byte, fieldparams.RootLength),
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
StateRoot: make([]byte, fieldparams.RootLength),
ReceiptsRoot: make([]byte, fieldparams.RootLength),
LogsBloom: make([]byte, fieldparams.LogsBloomLength),
PrevRandao: make([]byte, fieldparams.RootLength),
BaseFeePerGas: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
TransactionsRoot: make([]byte, fieldparams.RootLength),
},
header: func() interfaces.ExecutionData {
h, err := consensusblocks.WrappedExecutionPayloadHeader(&enginev1.ExecutionPayloadHeader{
ParentHash: make([]byte, fieldparams.RootLength),
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength),
StateRoot: make([]byte, fieldparams.RootLength),
ReceiptsRoot: make([]byte, fieldparams.RootLength),
LogsBloom: make([]byte, fieldparams.LogsBloomLength),
PrevRandao: make([]byte, fieldparams.RootLength),
BaseFeePerGas: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
TransactionsRoot: make([]byte, fieldparams.RootLength),
})
require.NoError(t, err)
return h
}(),
},
{
name: "state is Bellatrix, non empty payload, non empty header",
stateVersion: 2,
payload: &enginev1.ExecutionPayload{
ParentHash: aHash[:],
},
header: &enginev1.ExecutionPayloadHeader{
BlockNumber: 1,
},
},
{
name: "state is Bellatrix, non empty payload, nil header",
stateVersion: 2,
payload: &enginev1.ExecutionPayload{
ParentHash: aHash[:],
},
errString: "attempted to wrap nil object",
header: func() interfaces.ExecutionData {
h, err := consensusblocks.WrappedExecutionPayloadHeader(&enginev1.ExecutionPayloadHeader{
BlockNumber: 1,
})
require.NoError(t, err)
return h
}(),
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ go_library(
"//encoding/bytesutil:go_default_library",
"//math:go_default_library",
"//network/forks:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/attestation:go_default_library",
"//proto/prysm/v1alpha1/slashings:go_default_library",
Expand Down Expand Up @@ -93,6 +92,7 @@ go_test(
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//container/trie:go_default_library",
"//crypto/bls:go_default_library",
Expand Down
19 changes: 5 additions & 14 deletions beacon-chain/core/blocks/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
"github.com/prysmaticlabs/prysm/v3/time/slots"
)
Expand Down Expand Up @@ -38,11 +37,7 @@ func IsMergeTransitionComplete(st state.BeaconState) (bool, error) {
if err != nil {
return false, err
}
wrappedHeader, err := blocks.WrappedExecutionPayloadHeader(h)
if err != nil {
return false, err
}
isEmpty, err := blocks.IsEmptyExecutionData(wrappedHeader)
isEmpty, err := blocks.IsEmptyExecutionData(h)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -95,12 +90,8 @@ func IsExecutionEnabled(st state.BeaconState, body interfaces.BeaconBlockBody) (

// IsExecutionEnabledUsingHeader returns true if the execution is enabled using post processed payload header and block body.
// This is an optimized version of IsExecutionEnabled where beacon state is not required as an argument.
func IsExecutionEnabledUsingHeader(header *enginev1.ExecutionPayloadHeader, body interfaces.BeaconBlockBody) (bool, error) {
wrappedHeader, err := blocks.WrappedExecutionPayloadHeader(header)
if err != nil {
return false, err
}
isEmpty, err := blocks.IsEmptyExecutionData(wrappedHeader)
func IsExecutionEnabledUsingHeader(header interfaces.ExecutionData, body interfaces.BeaconBlockBody) (bool, error) {
isEmpty, err := blocks.IsEmptyExecutionData(header)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -135,7 +126,7 @@ func ValidatePayloadWhenMergeCompletes(st state.BeaconState, payload interfaces.
if err != nil {
return err
}
if !bytes.Equal(payload.ParentHash(), header.BlockHash) {
if !bytes.Equal(payload.ParentHash(), header.BlockHash()) {
return ErrInvalidPayloadBlockHash
}
return nil
Expand Down Expand Up @@ -236,7 +227,7 @@ func ValidatePayloadHeaderWhenMergeCompletes(st state.BeaconState, header interf
if err != nil {
return err
}
if !bytes.Equal(header.ParentHash(), h.BlockHash) {
if !bytes.Equal(header.ParentHash(), h.BlockHash()) {
return ErrInvalidPayloadBlockHash
}
return nil
Expand Down
Loading