mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
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.
This commit is contained in:
parent
3fcbb6735e
commit
452c349e7f
1 changed files with 17 additions and 2 deletions
|
|
@ -171,6 +171,11 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
return fmt.Errorf("failed to sync txpool: %w", err)
|
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
|
var random [32]byte
|
||||||
rand.Read(random[:])
|
rand.Read(random[:])
|
||||||
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{
|
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{
|
||||||
|
|
@ -179,7 +184,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
Withdrawals: withdrawals,
|
Withdrawals: withdrawals,
|
||||||
Random: random,
|
Random: random,
|
||||||
BeaconRoot: &common.Hash{},
|
BeaconRoot: &common.Hash{},
|
||||||
}, engine.PayloadV3, false)
|
}, payloadVersion, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -217,8 +222,18 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
|
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
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue