Skip to content

Commit e5bc789

Browse files
authored
consensus/beacon: fix isPostMerge for mainnet (#31191)
This fixes a regression introduced in #31153 where we didn't consider mainnet to be in PoS, causing #31190. The problem is, `params.MainnetChainConfig` does not have a defined `MergeNetsplitBlock`, so it isn't considered to be in PoS in `CalcDifficulty`.
1 parent 68de26e commit e5bc789

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

consensus/beacon/consensus.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ func New(ethone consensus.Engine) *Beacon {
7575
// isPostMerge reports whether the given block number is assumed to be post-merge.
7676
// Here we check the MergeNetsplitBlock to allow configuring networks with a PoW or
7777
// PoA chain for unit testing purposes.
78-
func isPostMerge(config *params.ChainConfig, block uint64) bool {
78+
func isPostMerge(config *params.ChainConfig, blockNum uint64, timestamp uint64) bool {
7979
mergedAtGenesis := config.TerminalTotalDifficulty != nil && config.TerminalTotalDifficulty.Sign() == 0
80-
return mergedAtGenesis || config.MergeNetsplitBlock != nil && block >= config.MergeNetsplitBlock.Uint64()
80+
return mergedAtGenesis ||
81+
config.MergeNetsplitBlock != nil && blockNum >= config.MergeNetsplitBlock.Uint64() ||
82+
config.ShanghaiTime != nil && timestamp >= *config.ShanghaiTime
8183
}
8284

8385
// Author implements consensus.Engine, returning the verified author of the block.
@@ -327,7 +329,7 @@ func (beacon *Beacon) verifyHeaders(chain consensus.ChainHeaderReader, headers [
327329
// Prepare implements consensus.Engine, initializing the difficulty field of a
328330
// header to conform to the beacon protocol. The changes are done inline.
329331
func (beacon *Beacon) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
330-
if !isPostMerge(chain.Config(), header.Number.Uint64()) {
332+
if !isPostMerge(chain.Config(), header.Number.Uint64(), header.Time) {
331333
return beacon.ethone.Prepare(chain, header)
332334
}
333335
header.Difficulty = beaconDifficulty
@@ -437,7 +439,7 @@ func (beacon *Beacon) SealHash(header *types.Header) common.Hash {
437439
// the difficulty that a new block should have when created at time
438440
// given the parent block's time and difficulty.
439441
func (beacon *Beacon) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
440-
if !isPostMerge(chain.Config(), parent.Number.Uint64()+1) {
442+
if !isPostMerge(chain.Config(), parent.Number.Uint64()+1, time) {
441443
return beacon.ethone.CalcDifficulty(chain, time, parent)
442444
}
443445
return beaconDifficulty

0 commit comments

Comments
 (0)