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.
pull/31084/head
Matthieu Vachon 3 weeks ago
parent 3fcbb6735e
commit 452c349e7f
  1. 19
      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
}

Loading…
Cancel
Save