mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
consensus/beacon: flip to post-merge check
It is somehow easier to implement this way.
This commit is contained in:
parent
c7e4e89a5f
commit
31e96f6317
1 changed files with 5 additions and 5 deletions
|
|
@ -72,12 +72,12 @@ func New(ethone consensus.Engine) *Beacon {
|
|||
return &Beacon{ethone: ethone}
|
||||
}
|
||||
|
||||
// isPreMerge reports whether the given block number is assumed to be pre-merge.
|
||||
// isPostMerge reports whether the given block number is assumed to be post-merge.
|
||||
// Here we check the MergeNetsplitBlock to allow configuring networks with a PoW or
|
||||
// PoA chain for unit testing purposes.
|
||||
func isPreMerge(config *params.ChainConfig, block uint64) bool {
|
||||
func isPostMerge(config *params.ChainConfig, block uint64) bool {
|
||||
mergedAtGenesis := config.TerminalTotalDifficulty != nil && config.TerminalTotalDifficulty.Sign() == 0
|
||||
return !mergedAtGenesis && config.MergeNetsplitBlock != nil && block < config.MergeNetsplitBlock.Uint64()
|
||||
return mergedAtGenesis || config.MergeNetsplitBlock != nil && block >= config.MergeNetsplitBlock.Uint64()
|
||||
}
|
||||
|
||||
// Author implements consensus.Engine, returning the verified author of the block.
|
||||
|
|
@ -327,7 +327,7 @@ func (beacon *Beacon) verifyHeaders(chain consensus.ChainHeaderReader, headers [
|
|||
// Prepare implements consensus.Engine, initializing the difficulty field of a
|
||||
// header to conform to the beacon protocol. The changes are done inline.
|
||||
func (beacon *Beacon) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
|
||||
if isPreMerge(chain.Config(), header.Number.Uint64()) {
|
||||
if !isPostMerge(chain.Config(), header.Number.Uint64()) {
|
||||
return beacon.ethone.Prepare(chain, header)
|
||||
}
|
||||
header.Difficulty = beaconDifficulty
|
||||
|
|
@ -437,7 +437,7 @@ func (beacon *Beacon) SealHash(header *types.Header) common.Hash {
|
|||
// the difficulty that a new block should have when created at time
|
||||
// given the parent block's time and difficulty.
|
||||
func (beacon *Beacon) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
|
||||
if isPreMerge(chain.Config(), parent.Number.Uint64()+1) {
|
||||
if !isPostMerge(chain.Config(), parent.Number.Uint64()+1) {
|
||||
return beacon.ethone.CalcDifficulty(chain, time, parent)
|
||||
}
|
||||
return beaconDifficulty
|
||||
|
|
|
|||
Loading…
Reference in a new issue