From 452c349e7f093b09d314dae6f7edd5e6965bd95a Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Fri, 10 Jan 2025 13:02:14 -0500 Subject: [PATCH] Allow simulated_beacon to work when some forks are inactive I know there has been prior discussions on handling that. I think it would be fine to add the last extra miles so it's possible to better test the chain in various conditions, for me around tracing in particular. It appears the code of the simulated beacon is now already architectured to enable easily support different forks with the `newPayload` function that determines how to construct the right payload based on the the parameters pass to it. Seems that it's relatively easy to also select the right payload version based on the blockchain state. I understand that could be seen as an extra maintenance burden though. If there is consensus on merging the PR, happy to check to also handle V1 is seen important. --- eth/catalyst/simulated_beacon.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index a24ff52101..e21c816eaf 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -171,6 +171,11 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u return fmt.Errorf("failed to sync txpool: %w", err) } + payloadVersion := engine.PayloadV3 + if header := c.eth.BlockChain().CurrentBlock(); !c.eth.BlockChain().Config().IsCancun(header.Number, timestamp) { + payloadVersion = engine.PayloadV2 + } + var random [32]byte rand.Read(random[:]) fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{ @@ -179,7 +184,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u Withdrawals: withdrawals, Random: random, BeaconRoot: &common.Hash{}, - }, engine.PayloadV3, false) + }, payloadVersion, false) if err != nil { return err } @@ -217,8 +222,18 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c)) } } + + beaconRoot := &common.Hash{} + requests := envelope.Requests + + if payloadVersion == engine.PayloadV2 { + blobHashes = nil + beaconRoot = nil + requests = nil + } + // Mark the payload as canon - _, err = c.engineAPI.newPayload(*payload, blobHashes, &common.Hash{}, envelope.Requests, false) + _, err = c.engineAPI.newPayload(*payload, blobHashes, beaconRoot, requests, false) if err != nil { return err }