Skip to content

Commit c4799b5

Browse files
committed
simulators/ethereum/engine: CLMock: add payload id history
1 parent 0b0390d commit c4799b5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

simulators/ethereum/engine/clmock/clmock.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"crypto/sha256"
66
"encoding/binary"
77
"encoding/json"
8-
"errors"
98
"fmt"
109
"math/big"
1110
"math/rand"
@@ -23,6 +22,7 @@ import (
2322
"github.com/ethereum/go-ethereum/common"
2423
"github.com/ethereum/go-ethereum/core/types"
2524
"github.com/ethereum/hive/hivesim"
25+
"github.com/pkg/errors"
2626
)
2727

2828
var (
@@ -89,6 +89,9 @@ type CLMocker struct {
8989
// Chain History
9090
HeaderHistory map[uint64]*types.Header
9191

92+
// Payload ID History
93+
PayloadIDHistory map[api.PayloadID]interface{}
94+
9295
// PoS Chain History Information
9396
PrevRandaoHistory map[uint64]common.Hash
9497
ExecutedPayloadHistory ExecutableDataHistory
@@ -147,6 +150,7 @@ func NewCLMocker(t *hivesim.T, genesis *core.Genesis, slotsToSafe, slotsToFinali
147150
SlotsToFinalized: slotsToFinalized,
148151
SafeSlotsToImportOptimistically: safeSlotsToImportOptimistically,
149152
PayloadProductionClientDelay: DefaultPayloadProductionClientDelay,
153+
PayloadIDHistory: make(map[api.PayloadID]interface{}),
150154
LatestHeader: nil,
151155
FirstPoSBlockNumber: nil,
152156
LatestHeadNumber: nil,
@@ -417,6 +421,17 @@ func (cl *CLMocker) GeneratePayloadAttributes() {
417421
cl.PrevRandaoHistory[cl.LatestHeader.Number.Uint64()+1] = nextPrevRandao
418422
}
419423

424+
func (cl *CLMocker) AddPayloadID(newPayloadID *api.PayloadID) error {
425+
if newPayloadID == nil {
426+
return errors.New("nil payload ID")
427+
}
428+
if _, ok := cl.PayloadIDHistory[*newPayloadID]; ok {
429+
return fmt.Errorf("Reused payload ID: %v", *newPayloadID)
430+
}
431+
cl.PayloadIDHistory[*newPayloadID] = nil
432+
return nil
433+
}
434+
420435
func (cl *CLMocker) RequestNextPayload() {
421436
ctx, cancel := context.WithTimeout(cl.TestContext, globals.RPCTimeout)
422437
defer cancel()
@@ -431,6 +446,9 @@ func (cl *CLMocker) RequestNextPayload() {
431446
if resp.PayloadStatus.LatestValidHash == nil || *resp.PayloadStatus.LatestValidHash != cl.LatestForkchoice.HeadBlockHash {
432447
cl.Fatalf("CLMocker: Unexpected forkchoiceUpdated LatestValidHash Response from Payload builder: %v != %v", resp.PayloadStatus.LatestValidHash, cl.LatestForkchoice.HeadBlockHash)
433448
}
449+
if err = cl.AddPayloadID(resp.PayloadID); err != nil {
450+
cl.Fatalf("CLMocker: Payload ID failure: %v", err)
451+
}
434452
cl.NextPayloadID = resp.PayloadID
435453
}
436454

0 commit comments

Comments
 (0)