mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/catalyst: update simulated beacon for cancun
This commit is contained in:
parent
566754c74a
commit
123a3e589f
1 changed files with 31 additions and 10 deletions
|
|
@ -148,26 +148,41 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
c.feeRecipientLock.Unlock()
|
c.feeRecipientLock.Unlock()
|
||||||
|
|
||||||
// Reset to CurrentBlock in case of the chain was rewound
|
// 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())
|
finalizedHash := c.finalizedBlockHash(header.Number.Uint64())
|
||||||
c.setCurrentState(header.Hash(), *finalizedHash)
|
c.setCurrentState(header.Hash(), *finalizedHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
var random [32]byte
|
var random [32]byte
|
||||||
rand.Read(random[:])
|
rand.Read(random[:])
|
||||||
fcResponse, err := c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, &engine.PayloadAttributes{
|
|
||||||
Timestamp: timestamp,
|
var (
|
||||||
SuggestedFeeRecipient: feeRecipient,
|
attrs = &engine.PayloadAttributes{
|
||||||
Withdrawals: withdrawals,
|
Timestamp: timestamp,
|
||||||
Random: random,
|
SuggestedFeeRecipient: feeRecipient,
|
||||||
})
|
Withdrawals: withdrawals,
|
||||||
|
Random: random,
|
||||||
|
}
|
||||||
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if fcResponse == engine.STATUS_SYNCING {
|
if fcResponse == engine.STATUS_SYNCING {
|
||||||
return errors.New("chain rewind prevented invocation of payload creation")
|
return errors.New("chain rewind prevented invocation of payload creation")
|
||||||
}
|
}
|
||||||
|
|
||||||
envelope, err := c.engineAPI.getPayload(*fcResponse.PayloadID, true)
|
envelope, err := c.engineAPI.getPayload(*fcResponse.PayloadID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -186,8 +201,14 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the payload as canon
|
// Mark the payload as canon
|
||||||
if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil {
|
if isCancun {
|
||||||
return err
|
if _, err = c.engineAPI.NewPayloadV3(*payload, []common.Hash{}, &common.Hash{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.setCurrentState(payload.BlockHash, finalizedHash)
|
c.setCurrentState(payload.BlockHash, finalizedHash)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue