Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
domiwei committed Nov 28, 2024
1 parent a8c0688 commit ba4fa9b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
32 changes: 32 additions & 0 deletions cl/spectest/consensus_tests/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,35 @@ func operationWithdrawalRequstHandler(t *testing.T, root fs.FS, c spectest.TestC
assert.EqualValues(t, haveRoot, expectedRoot)
return nil
}

func operationExecutionPayloadHandler(t *testing.T, root fs.FS, c spectest.TestCase) error {
preState, err := spectest.ReadBeaconState(root, c.Version(), "pre.ssz_snappy")
require.NoError(t, err)
postState, err := spectest.ReadBeaconState(root, c.Version(), "post.ssz_snappy")
expectedError := os.IsNotExist(err)
if err != nil && !expectedError {
return err
}
body := cltypes.NewBeaconBody(&clparams.MainnetBeaconConfig, c.Version())
if err := spectest.ReadSszOld(root, body, c.Version(), "body.ssz_snappy"); err != nil {
return err
}
if err := c.Machine.ProcessExecutionPayload(preState, body); err != nil {
//if err := machine.ProcessBlock(c.Machine, preState, body); err != nil {
if expectedError {
return nil
}
return err
}
if expectedError {
return errors.New("expected error")
}
haveRoot, err := preState.HashSSZ()
require.NoError(t, err)

expectedRoot, err := postState.HashSSZ()
require.NoError(t, err)

assert.EqualValues(t, haveRoot, expectedRoot)
return nil
}
22 changes: 21 additions & 1 deletion cl/transition/impl/eth2/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,42 @@ func (I *impl) ProcessWithdrawals(
}

// ProcessExecutionPayload sets the latest payload header accordinly.
func (I *impl) ProcessExecutionPayload(s abstract.BeaconState, parentHash, prevRandao common.Hash, time uint64, payloadHeader *cltypes.Eth1Header) error {
func (I *impl) ProcessExecutionPayload(s abstract.BeaconState, body cltypes.GenericBeaconBody) error {
payloadHeader, err := body.GetPayloadHeader()
if err != nil {
return err
}
parentHash := payloadHeader.ParentHash
prevRandao := payloadHeader.PrevRandao
time := payloadHeader.Time
if state.IsMergeTransitionComplete(s) {
// Verify consistency of the parent hash with respect to the previous execution payload header
// assert payload.parent_hash == state.latest_execution_payload_header.block_hash
if parentHash != s.LatestExecutionPayloadHeader().BlockHash {
return errors.New("ProcessExecutionPayload: invalid eth1 chain. mismatching parent")
}
}
if prevRandao != s.GetRandaoMixes(state.Epoch(s)) {
// Verify prev_randao
// assert payload.prev_randao == get_randao_mix(state, get_current_epoch(state))
return fmt.Errorf(
"ProcessExecutionPayload: randao mix mismatches with mix digest, expected %x, got %x",
s.GetRandaoMixes(state.Epoch(s)),
prevRandao,
)
}
if time != state.ComputeTimestampAtSlot(s, s.Slot()) {
// Verify timestamp
// assert payload.timestamp == compute_timestamp_at_slot(state, state.slot)
return errors.New("ProcessExecutionPayload: invalid Eth1 timestamp")
}

// Verify commitments are under limit
// assert len(body.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK
if body.GetBlobKzgCommitments().Len() > int(s.BeaconConfig().MaxBlobsPerBlock) {
return errors.New("ProcessExecutionPayload: too many blob commitments")
}

s.SetLatestExecutionPayloadHeader(payloadHeader)
return nil
}
Expand Down
5 changes: 1 addition & 4 deletions cl/transition/machine/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ func ProcessBlock(impl BlockProcessor, s abstract.BeaconState, block cltypes.Gen
return fmt.Errorf("processBlock: failed to process withdrawals: %v", err)
}
}
parentHash := payloadHeader.ParentHash
prevRandao := payloadHeader.PrevRandao
time := payloadHeader.Time
if err := impl.ProcessExecutionPayload(s, parentHash, prevRandao, time, payloadHeader); err != nil {
if err := impl.ProcessExecutionPayload(s, body); err != nil {
return fmt.Errorf("processBlock: failed to process execution payload: %v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cl/transition/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type SlotProcessor interface {
type BlockHeaderProcessor interface {
ProcessBlockHeader(s abstract.BeaconState, slot, proposerIndex uint64, parentRoot common.Hash, bodyRoot [32]byte) error
ProcessWithdrawals(s abstract.BeaconState, withdrawals *solid.ListSSZ[*cltypes.Withdrawal]) error
ProcessExecutionPayload(s abstract.BeaconState, parentHash, prevRandao common.Hash, time uint64, payloadHeader *cltypes.Eth1Header) error
ProcessExecutionPayload(s abstract.BeaconState, body cltypes.GenericBeaconBody) error
ProcessRandao(s abstract.BeaconState, randao [96]byte, proposerIndex uint64) error
ProcessEth1Data(state abstract.BeaconState, eth1Data *cltypes.Eth1Data) error
ProcessSyncAggregate(s abstract.BeaconState, sync *cltypes.SyncAggregate) error
Expand Down

0 comments on commit ba4fa9b

Please sign in to comment.