Skip to content

Commit 8dcdeb2

Browse files
committed
simulators/ethereum/engine: fix clmock method versions usage
1 parent 421bd79 commit 8dcdeb2

File tree

2 files changed

+27
-43
lines changed

2 files changed

+27
-43
lines changed

simulators/ethereum/engine/clmock/clmock.go

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,24 @@ func TimestampToBeaconRoot(timestamp uint64) common.Hash {
391391
return beaconRoot
392392
}
393393

394+
func (cl *CLMocker) ForkchoiceUpdatedVersion(timestamp uint64) int {
395+
if cl.IsCancun(timestamp) {
396+
return 3
397+
} else if cl.IsShanghai(timestamp) {
398+
return 2
399+
}
400+
return 1
401+
}
402+
403+
func (cl *CLMocker) NewPayloadVersion(timestamp uint64) int {
404+
if cl.IsCancun(timestamp) {
405+
return 3
406+
} else if cl.IsShanghai(timestamp) {
407+
return 2
408+
}
409+
return 1
410+
}
411+
394412
func (cl *CLMocker) RequestNextPayload() {
395413
// Generate a random value for the PrevRandao field
396414
nextPrevRandao := common.Hash{}
@@ -417,19 +435,8 @@ func (cl *CLMocker) RequestNextPayload() {
417435

418436
ctx, cancel := context.WithTimeout(cl.TestContext, globals.RPCTimeout)
419437
defer cancel()
420-
var (
421-
resp api.ForkChoiceResponse
422-
fcUVersion int
423-
err error
424-
)
425-
if cl.IsCancun(cl.LatestPayloadAttributes.Timestamp) {
426-
fcUVersion = 3
427-
} else if cl.IsShanghai(cl.LatestPayloadAttributes.Timestamp) {
428-
fcUVersion = 2
429-
} else {
430-
fcUVersion = 1
431-
}
432-
resp, err = cl.NextBlockProducer.ForkchoiceUpdated(ctx, fcUVersion, &cl.LatestForkchoice, &cl.LatestPayloadAttributes)
438+
fcUVersion := cl.ForkchoiceUpdatedVersion(cl.LatestPayloadAttributes.Timestamp)
439+
resp, err := cl.NextBlockProducer.ForkchoiceUpdated(ctx, fcUVersion, &cl.LatestForkchoice, &cl.LatestPayloadAttributes)
433440
if err != nil {
434441
cl.Fatalf("CLMocker: Could not send forkchoiceUpdatedV%d (%v): %v", fcUVersion, cl.NextBlockProducer.ID(), err)
435442
}
@@ -488,9 +495,9 @@ func (cl *CLMocker) broadcastNextNewPayload() {
488495
}
489496
}
490497
// Broadcast the executePayload to all clients
491-
responses := cl.BroadcastNewPayload(&cl.LatestPayloadBuilt, versionedHashes, cl.LatestPayloadAttributes.BeaconRoot)
498+
version := cl.NewPayloadVersion(cl.LatestPayloadBuilt.Timestamp)
492499
validations := 0
493-
for _, resp := range responses {
500+
for _, resp := range cl.BroadcastNewPayload(&cl.LatestPayloadBuilt, versionedHashes, cl.LatestPayloadAttributes.BeaconRoot, version) {
494501
if resp.Error != nil {
495502
cl.Logf("CLMocker: BroadcastNewPayload Error (%v): %v\n", resp.Container, resp.Error)
496503
} else {
@@ -529,10 +536,7 @@ func (cl *CLMocker) broadcastNextNewPayload() {
529536
}
530537

531538
func (cl *CLMocker) broadcastLatestForkchoice() {
532-
version := 1
533-
if cl.IsShanghai(cl.LatestExecutedPayload.Timestamp) {
534-
version = 2
535-
}
539+
version := cl.ForkchoiceUpdatedVersion(cl.LatestExecutedPayload.Timestamp)
536540
for _, resp := range cl.BroadcastForkchoiceUpdated(&cl.LatestForkchoice, nil, version) {
537541
if resp.Error != nil {
538542
cl.Logf("CLMocker: BroadcastForkchoiceUpdated Error (%v): %v\n", resp.Container, resp.Error)
@@ -701,25 +705,13 @@ type ExecutePayloadOutcome struct {
701705
Error error
702706
}
703707

704-
func (cl *CLMocker) BroadcastNewPayload(payload *typ.ExecutableData, versionedHashes *[]common.Hash, beaconRoot *common.Hash) []ExecutePayloadOutcome {
708+
func (cl *CLMocker) BroadcastNewPayload(payload *typ.ExecutableData, versionedHashes *[]common.Hash, beaconRoot *common.Hash, version int) []ExecutePayloadOutcome {
705709
responses := make([]ExecutePayloadOutcome, len(cl.EngineClients))
706710
for i, ec := range cl.EngineClients {
707711
responses[i].Container = ec.ID()
708712
ctx, cancel := context.WithTimeout(cl.TestContext, globals.RPCTimeout)
709713
defer cancel()
710-
var (
711-
execPayloadResp api.PayloadStatusV1
712-
err error
713-
)
714-
if cl.IsCancun(payload.Timestamp) {
715-
execPayloadResp, err = ec.NewPayloadV3(ctx, payload, versionedHashes, beaconRoot)
716-
} else if cl.IsShanghai(payload.Timestamp) {
717-
execPayloadResp, err = ec.NewPayloadV2(ctx, payload)
718-
} else {
719-
edv1 := &typ.ExecutableDataV1{}
720-
edv1.FromExecutableData(payload)
721-
execPayloadResp, err = ec.NewPayloadV1(ctx, edv1)
722-
}
714+
execPayloadResp, err := ec.NewPayload(ctx, version, payload, versionedHashes, beaconRoot)
723715
if err != nil {
724716
cl.Errorf("CLMocker: Could not ExecutePayloadV1: %v", err)
725717
responses[i].Error = err
@@ -745,15 +737,7 @@ func (cl *CLMocker) BroadcastForkchoiceUpdated(fcstate *api.ForkchoiceStateV1, p
745737
if cl.IsOptimisticallySyncing() || newPayloadStatus.Status == "VALID" {
746738
ctx, cancel := context.WithTimeout(cl.TestContext, globals.RPCTimeout)
747739
defer cancel()
748-
var (
749-
fcUpdatedResp api.ForkChoiceResponse
750-
err error
751-
)
752-
if version == 2 {
753-
fcUpdatedResp, err = ec.ForkchoiceUpdatedV2(ctx, fcstate, payloadAttr)
754-
} else if version == 1 {
755-
fcUpdatedResp, err = ec.ForkchoiceUpdatedV1(ctx, fcstate, payloadAttr)
756-
}
740+
fcUpdatedResp, err := ec.ForkchoiceUpdated(ctx, version, fcstate, payloadAttr)
757741
if err != nil {
758742
cl.Errorf("CLMocker: Could not ForkchoiceUpdatedV1: %v", err)
759743
responses[i].Error = err

simulators/ethereum/engine/suites/engine/tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@ func blockStatusReorg(t *test.Env) {
20242024
}
20252025

20262026
// Send custom payload and fcU to it
2027-
t.CLMock.BroadcastNewPayload(customizedPayload, nil, nil)
2027+
t.CLMock.BroadcastNewPayload(customizedPayload, nil, nil, t.CLMock.NewPayloadVersion(customizedPayload.Timestamp))
20282028
t.CLMock.BroadcastForkchoiceUpdated(&api.ForkchoiceStateV1{
20292029
HeadBlockHash: customizedPayload.BlockHash,
20302030
SafeBlockHash: t.CLMock.LatestForkchoice.SafeBlockHash,

0 commit comments

Comments
 (0)