Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/catalyst: update simulated beacon for cancun #28829

Merged
merged 10 commits into from
Feb 29, 2024
41 changes: 31 additions & 10 deletions eth/catalyst/simulated_beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,41 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
c.feeRecipientLock.Unlock()

// Reset to CurrentBlock in case of the chain was rewound
if header := c.eth.BlockChain().CurrentBlock(); c.curForkchoiceState.HeadBlockHash != header.Hash() {
var (
header = c.eth.BlockChain().CurrentBlock()
number = new(big.Int).Add(header.Number, big.NewInt(1))
isCancun = c.eth.BlockChain().Config().IsCancun(number, timestamp)
)
if c.curForkchoiceState.HeadBlockHash != header.Hash() {
finalizedHash := c.finalizedBlockHash(header.Number.Uint64())
c.setCurrentState(header.Hash(), *finalizedHash)
}

var random [32]byte
rand.Read(random[:])
fcResponse, err := c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, &engine.PayloadAttributes{
Timestamp: timestamp,
SuggestedFeeRecipient: feeRecipient,
Withdrawals: withdrawals,
Random: random,
})

var (
attrs = &engine.PayloadAttributes{
Timestamp: timestamp,
SuggestedFeeRecipient: feeRecipient,
Withdrawals: withdrawals,
Random: random,
s1na marked this conversation as resolved.
Show resolved Hide resolved
}
fcResponse engine.ForkChoiceResponse
err error
)
if isCancun {
attrs.BeaconRoot = &common.Hash{}
fcResponse, err = c.engineAPI.ForkchoiceUpdatedV3(c.curForkchoiceState, attrs)
} else {
fcResponse, err = c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, attrs)
}
if err != nil {
return err
}
if fcResponse == engine.STATUS_SYNCING {
return errors.New("chain rewind prevented invocation of payload creation")
}

envelope, err := c.engineAPI.getPayload(*fcResponse.PayloadID, true)
if err != nil {
return err
Expand All @@ -186,8 +201,14 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
}

// Mark the payload as canon
if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil {
return err
if isCancun {
if _, err = c.engineAPI.NewPayloadV3(*payload, []common.Hash{}, &common.Hash{}); err != nil {
s1na marked this conversation as resolved.
Show resolved Hide resolved
return err
}
} else {
if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil {
return err
}
}
c.setCurrentState(payload.BlockHash, finalizedHash)

Expand Down
Loading