Skip to content

Commit

Permalink
Rebase and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Feb 2, 2025
1 parent 3a324d9 commit 723a69b
Show file tree
Hide file tree
Showing 52 changed files with 544 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Test_ReceiveExecutionPayloadEnvelope(t *testing.T) {
require.NoError(t, fcs.UpdateFinalizedCheckpoint(&forkchoicetypes.Checkpoint{Root: service.originBlockRoot}))
post := gs.Copy()
p := &enginev1.ExecutionPayloadEnvelope{
Payload: &enginev1.ExecutionPayloadElectra{
Payload: &enginev1.ExecutionPayloadDeneb{
ParentHash: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Expand All @@ -82,7 +82,10 @@ func Test_ReceiveExecutionPayloadEnvelope(t *testing.T) {
StateRoot: make([]byte, 32),
ExecutionRequests: &enginev1.ExecutionRequests{},
}
e, err := blocks.WrappedROExecutionPayloadEnvelope(p)
sp := &enginev1.SignedExecutionPayloadEnvelope{
Message: p,
}
e, err := blocks.WrappedROSignedExecutionPayloadEnvelope(sp)
require.NoError(t, err)
das := &das.MockAvailabilityStore{}

Expand Down
11 changes: 8 additions & 3 deletions beacon-chain/blockchain/testing/mock_epbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import (
)

// ReceiveExecutionPayloadEnvelope mocks the method in chain service.
func (s *ChainService) ReceiveExecutionPayloadEnvelope(ctx context.Context, env interfaces.ROExecutionPayloadEnvelope, _ das.AvailabilityStore) error {
func (s *ChainService) ReceiveExecutionPayloadEnvelope(ctx context.Context, env interfaces.ROSignedExecutionPayloadEnvelope, _ das.AvailabilityStore) error {
if s.ReceiveBlockMockErr != nil {
return s.ReceiveBlockMockErr
}
if s.State == nil {
return ErrNilState
}
if s.State.Slot() == env.Slot() {
e, err := env.Envelope()
if err != nil {
return err
}

if s.State.Slot() == e.Slot() {
if err := s.State.SetLatestFullSlot(s.State.Slot()); err != nil {
return err
}
}
s.ExecutionPayloadEnvelope = env
s.ExecutionPayloadEnvelope = e
return nil
}
2 changes: 1 addition & 1 deletion beacon-chain/cache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ go_test(
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/primitives:go_default_library",
"//crypto/bls/blst:go_default_library",
"//crypto/bls:go_default_library",
"//crypto/bls/blst:go_default_library",
"//encoding/bytesutil:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/withdrawals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ func TestProcessWithdrawalsEPBS(t *testing.T) {
require.NoError(t, err)
post, err := blocks.ProcessWithdrawals(st, p)
if test.Args.Name == "Parent Node is not full" {
require.IsNil(t, post)
require.DeepEqual(t, post, st)
require.IsNil(t, err)
} else {
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/epbs/execution_payload_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func ValidatePayloadStateTransition(
if err != nil {
return err
}
if err := validateAgainstCommittedBid(committedHeader, envelope); err != nil {
if err := ValidateAgainstCommittedBid(committedHeader, envelope); err != nil {
return err
}
if err := ProcessPayloadStateTransition(ctx, preState, envelope); err != nil {
return err
}
return checkPostStateRoot(ctx, preState, envelope)
return CheckPostStateRoot(ctx, preState, envelope)
}

func ProcessPayloadStateTransition(
Expand Down Expand Up @@ -91,7 +91,7 @@ func UpdateHeaderAndVerify(
return nil
}

func validateAgainstCommittedBid(
func ValidateAgainstCommittedBid(
committedHeader *enginev1.ExecutionPayloadHeaderEPBS,
envelope interfaces.ROExecutionPayloadEnvelope,
) error {
Expand All @@ -109,7 +109,7 @@ func validateAgainstCommittedBid(
return nil
}

func checkPostStateRoot(
func CheckPostStateRoot(
ctx context.Context,
preState state.BeaconState,
envelope interfaces.ROExecutionPayloadEnvelope,
Expand Down
27 changes: 14 additions & 13 deletions beacon-chain/core/epbs/execution_payload_envelope_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package epbs
package epbs_test

import (
"context"
"testing"

"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/epbs"
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
Expand All @@ -30,7 +31,7 @@ func TestProcessPayloadStateTransition(t *testing.T) {
require.NoError(t, err)
require.Equal(t, [32]byte{}, [32]byte(lbh))

require.NoError(t, ProcessPayloadStateTransition(ctx, st, e))
require.NoError(t, epbs.ProcessPayloadStateTransition(ctx, st, e))

lbh, err = st.LatestBlockHash()
require.NoError(t, err)
Expand All @@ -43,7 +44,7 @@ func TestProcessPayloadStateTransition(t *testing.T) {

func Test_validateAgainstHeader(t *testing.T) {
bh := [32]byte{'h'}
payload := &enginev1.ExecutionPayloadElectra{BlockHash: bh[:]}
payload := &enginev1.ExecutionPayloadDeneb{BlockHash: bh[:]}
p := random.ExecutionPayloadEnvelope(t)
p.Payload = payload
e, err := blocks.WrappedROExecutionPayloadEnvelope(p)
Expand All @@ -52,47 +53,47 @@ func Test_validateAgainstHeader(t *testing.T) {
st, err := state_native.InitializeFromProtoUnsafeEpbs(stpb)
require.NoError(t, err)
ctx := context.Background()
require.ErrorContains(t, "invalid nil latest block header", UpdateHeaderAndVerify(ctx, st, e))
require.ErrorContains(t, "invalid nil latest block header", epbs.UpdateHeaderAndVerify(ctx, st, e))

prest, _ := util.DeterministicGenesisStateEpbs(t, 64)
br := [32]byte{'r'}
p.BeaconBlockRoot = br[:]
require.ErrorContains(t, "beacon block root does not match previous header", UpdateHeaderAndVerify(ctx, prest, e))
require.ErrorContains(t, "beacon block root does not match previous header", epbs.UpdateHeaderAndVerify(ctx, prest, e))

header := prest.LatestBlockHeader()
require.NoError(t, err)
headerRoot, err := header.HashTreeRoot()
require.NoError(t, err)
p.BeaconBlockRoot = headerRoot[:]
require.NoError(t, UpdateHeaderAndVerify(ctx, prest, e))
require.NoError(t, epbs.UpdateHeaderAndVerify(ctx, prest, e))
}

func Test_validateAgainstCommittedBid(t *testing.T) {
payload := &enginev1.ExecutionPayloadElectra{}
payload := &enginev1.ExecutionPayloadDeneb{}
p := random.ExecutionPayloadEnvelope(t)
p.Payload = payload
p.BuilderIndex = 1
e, err := blocks.WrappedROExecutionPayloadEnvelope(p)
require.NoError(t, err)
h := &enginev1.ExecutionPayloadHeaderEPBS{}
require.ErrorContains(t, "builder index does not match committed header", validateAgainstCommittedBid(h, e))
require.ErrorContains(t, "builder index does not match committed header", epbs.ValidateAgainstCommittedBid(h, e))

h.BuilderIndex = 1
p.BlobKzgCommitments = make([][]byte, 6)
for i := range p.BlobKzgCommitments {
p.BlobKzgCommitments[i] = make([]byte, 48)
}
h.BlobKzgCommitmentsRoot = make([]byte, 32)
require.ErrorContains(t, "blob KZG commitments root does not match committed header", validateAgainstCommittedBid(h, e))
require.ErrorContains(t, "blob KZG commitments root does not match committed header", epbs.ValidateAgainstCommittedBid(h, e))

root, err := e.BlobKzgCommitmentsRoot()
require.NoError(t, err)
h.BlobKzgCommitmentsRoot = root[:]
require.NoError(t, validateAgainstCommittedBid(h, e))
require.NoError(t, epbs.ValidateAgainstCommittedBid(h, e))
}

func TestCheckPostStateRoot(t *testing.T) {
payload := &enginev1.ExecutionPayloadElectra{}
payload := &enginev1.ExecutionPayloadDeneb{}
p := random.ExecutionPayloadEnvelope(t)
p.Payload = payload
p.BuilderIndex = 1
Expand All @@ -101,9 +102,9 @@ func TestCheckPostStateRoot(t *testing.T) {
ctx := context.Background()
st, _ := util.DeterministicGenesisStateEpbs(t, 64)
p.StateRoot = make([]byte, 32)
require.ErrorContains(t, "state root mismatch", checkPostStateRoot(ctx, st, e))
require.ErrorContains(t, "state root mismatch", epbs.CheckPostStateRoot(ctx, st, e))
root, err := st.HashTreeRoot(ctx)
require.NoError(t, err)
p.StateRoot = root[:]
require.NoError(t, checkPostStateRoot(ctx, st, e))
require.NoError(t, epbs.CheckPostStateRoot(ctx, st, e))
}
3 changes: 1 addition & 2 deletions beacon-chain/core/helpers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ go_library(
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/epbs:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//container/slice:go_default_library",
"//container/trie:go_default_library",
Expand Down Expand Up @@ -57,8 +56,8 @@ go_test(
"attestation_test.go",
"beacon_committee_test.go",
"block_test.go",
"legacy_test.go",
"exports_test.go",
"legacy_test.go",
"payload_attestation_test.go",
"private_access_fuzz_noop_test.go", # keep
"private_access_test.go",
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/db/iface/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ go_library(
"//monitoring/backup:go_default_library",
"//proto/dbval:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/v2:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
],
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/db/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ go_library(
"//monitoring/tracing/trace:go_default_library",
"//proto/dbval:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/v2:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//time:go_default_library",
Expand Down Expand Up @@ -131,8 +130,8 @@ go_test(
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"//testing/util:go_default_library",
"//time/slots:go_default_library",
"//testing/util/random:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
Expand Down
11 changes: 7 additions & 4 deletions beacon-chain/db/kv/blind_payload_envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/prysmaticlabs/prysm/v5/testing/util/random"
)
Expand All @@ -14,10 +15,12 @@ func TestStore_SignedBlindPayloadEnvelope(t *testing.T) {
_, err := db.SignedBlindPayloadEnvelope(ctx, []byte("test"))
require.ErrorIs(t, err, ErrNotFound)

env := random.SignedBlindPayloadEnvelope(t)
err = db.SaveBlindPayloadEnvelope(ctx, env)
env := random.SignedExecutionPayloadEnvelope(t)
e, err := blocks.WrappedROSignedExecutionPayloadEnvelope(env)
require.NoError(t, err)
got, err := db.SignedBlindPayloadEnvelope(ctx, env.Message.BeaconBlockRoot)
err = db.SaveBlindPayloadEnvelope(ctx, e)
require.NoError(t, err)
require.DeepEqual(t, got, env)
got, err := db.SignedBlindPayloadEnvelope(ctx, env.Message.Payload.BlockHash)
require.NoError(t, err)
require.DeepEqual(t, got, env.Blind())
}
3 changes: 2 additions & 1 deletion beacon-chain/db/kv/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ func unmarshalBlock(_ context.Context, enc []byte) (interfaces.ReadOnlySignedBea
rawBlock = &ethpb.SignedBlindedBeaconBlockFulu{}
if err := rawBlock.UnmarshalSSZ(enc[len(fuluBlindKey):]); err != nil {
return nil, errors.Wrap(err, "could not unmarshal blinded Fulu block")
}
case hasEpbsKey(enc):
rawBlock = &ethpb.SignedBeaconBlockEpbs{}
if err := rawBlock.UnmarshalSSZ(enc[len(epbsKey):]); err != nil {
Expand Down Expand Up @@ -951,7 +952,7 @@ func keyForBlock(blk interfaces.ReadOnlySignedBeaconBlock) ([]byte, error) {
v := blk.Version()

if v >= version.EPBS {
return epb
return epbsKey, nil
}

if v >= version.Fulu {
Expand Down
14 changes: 7 additions & 7 deletions beacon-chain/db/kv/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,19 +539,19 @@ func (s *Store) unmarshalState(_ context.Context, enc []byte, validatorEntries [
}

switch {
case hasFuluKey(enc):
protoState := &ethpb.BeaconStateFulu{}
if err := protoState.UnmarshalSSZ(enc[len(fuluKey):]); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal encoding for Electra")
}
return statenative.InitializeFromProtoUnsafeFulu(protoState)
case hasEpbsKey(enc):
protoState := &ethpb.BeaconStateEPBS{}
if err := protoState.UnmarshalSSZ(enc[len(epbsKey):]); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal encoding for EPBS")
}
return statenative.InitializeFromProtoEpbs(protoState)
case hasElectraKey(enc):
case hasFuluKey(enc):
protoState := &ethpb.BeaconStateFulu{}
if err := protoState.UnmarshalSSZ(enc[len(fuluKey):]); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal encoding for Electra")
}
return statenative.InitializeFromProtoUnsafeFulu(protoState)
case HasElectraKey(enc):
protoState := &ethpb.BeaconStateElectra{}
if err := protoState.UnmarshalSSZ(enc[len(ElectraKey):]); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal encoding for Electra")
Expand Down
4 changes: 3 additions & 1 deletion beacon-chain/db/kv/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/rand"
"encoding/binary"
mathRand "math/rand"

"strconv"
"testing"
"time"
Expand Down Expand Up @@ -178,6 +177,9 @@ func TestState_CanSaveRetrieve(t *testing.T) {
reset := features.InitWithReset(&features.Flags{EnableHistoricalSpaceRepresentation: enableFlag})

for _, tc := range cases {
if tc.name == "epbs" && enableFlag {
t.Skip("Skipping epbs test as EnableHistoricalSpaceRepresentation is true")
}
t.Run(tc.name+" - EnableHistoricalSpaceRepresentation is "+strconv.FormatBool(enableFlag), func(t *testing.T) {
rootNonce := byte('0')
if enableFlag {
Expand Down
10 changes: 5 additions & 5 deletions beacon-chain/rpc/eth/config/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestGetSpec(t *testing.T) {
config.ElectraForkEpoch = 107
config.FuluForkVersion = []byte("FuluForkVersion")
config.FuluForkEpoch = 109
config.EPBSForkVersion = []byte("EPBSForkVersion")
config.EPBSForkVersion = []byte("Eip7732ForkVersion")
config.EPBSForkEpoch = 110
config.BLSWithdrawalPrefixByte = byte('b')
config.ETH1AddressWithdrawalPrefixByte = byte('c')
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestGetSpec(t *testing.T) {
data, ok := resp.Data.(map[string]interface{})
require.Equal(t, true, ok)

assert.Equal(t, 165, len(data))
assert.Equal(t, 171, len(data))
for k, v := range data {
t.Run(k, func(t *testing.T) {
switch k {
Expand Down Expand Up @@ -279,9 +279,9 @@ func TestGetSpec(t *testing.T) {
assert.Equal(t, "0x"+hex.EncodeToString([]byte("FuluForkVersion")), v)
case "FULU_FORK_EPOCH":
assert.Equal(t, "109", v)
case "EPBS_FORK_VERSION":
assert.Equal(t, "0x"+hex.EncodeToString([]byte("EPBSForkVersion")), v)
case "EPBS_FORK_EPOCH":
case "EIP7732_FORK_VERSION":
assert.Equal(t, "0x"+hex.EncodeToString([]byte("Eip7732ForkVersion")), v)
case "EIP7732_FORK_EPOCH":
assert.Equal(t, "110", v)
case "MIN_ANCHOR_POW_BLOCK_DIFFICULTY":
assert.Equal(t, "1000", v)
Expand Down
Loading

0 comments on commit 723a69b

Please sign in to comment.