6161// is only used for necessary consensus checks. The legacy consensus engine can be any
6262// engine implements the consensus interface (except the beacon itself).
6363type Beacon struct {
64- ethone consensus.Engine // Original consensus engine used in eth1, e.g. ethash or clique
65- ttdblock * uint64 // Merge block-number for testchain generation without TTDs
64+ ethone consensus.Engine // Original consensus engine used in eth1, e.g. ethash or clique
6665}
6766
6867// New creates a consensus engine with the given embedded eth1 engine.
@@ -73,16 +72,9 @@ func New(ethone consensus.Engine) *Beacon {
7372 return & Beacon {ethone : ethone }
7473}
7574
76- // TestingTTDBlock is a replacement mechanism for TTD-based pre-/post-merge
77- // splitting. With chain history deletion, TD calculations become impossible.
78- // This is fine for progressing the live chain, but to be able to generate test
79- // chains, we do need a split point. This method supports setting an explicit
80- // block number to use as the splitter *for testing*, instead of having to keep
81- // the notion of TDs in the client just for testing.
82- //
83- // The block with supplied number is regarded as the last pre-merge block.
84- func (beacon * Beacon ) TestingTTDBlock (number uint64 ) {
85- beacon .ttdblock = & number
75+ func isPreMerge (config * params.ChainConfig , block uint64 ) bool {
76+ return ! (config .TerminalTotalDifficulty != nil && config .TerminalTotalDifficulty .Sign () == 0 ) ||
77+ (config .MergeNetsplitBlock != nil && block < config .MergeNetsplitBlock .Uint64 ())
8678}
8779
8880// Author implements consensus.Engine, returning the verified author of the block.
@@ -332,15 +324,7 @@ func (beacon *Beacon) verifyHeaders(chain consensus.ChainHeaderReader, headers [
332324// Prepare implements consensus.Engine, initializing the difficulty field of a
333325// header to conform to the beacon protocol. The changes are done inline.
334326func (beacon * Beacon ) Prepare (chain consensus.ChainHeaderReader , header * types.Header ) error {
335- // The beacon engine requires access to total difficulties to be able to
336- // seal pre-merge and post-merge blocks. With the transition to removing
337- // old blocks, TDs become unaccessible, thus making TTD based pre-/post-
338- // merge decisions impossible.
339- //
340- // We do not need to seal non-merge blocks anymore live, but we do need
341- // to be able to generate test chains, thus we're reverting to a testing-
342- // settable field to direct that.
343- if beacon .ttdblock != nil && * beacon .ttdblock >= header .Number .Uint64 () {
327+ if isPreMerge (chain .Config (), header .Number .Uint64 ()) {
344328 return beacon .ethone .Prepare (chain , header )
345329 }
346330 header .Difficulty = beaconDifficulty
@@ -450,15 +434,7 @@ func (beacon *Beacon) SealHash(header *types.Header) common.Hash {
450434// the difficulty that a new block should have when created at time
451435// given the parent block's time and difficulty.
452436func (beacon * Beacon ) CalcDifficulty (chain consensus.ChainHeaderReader , time uint64 , parent * types.Header ) * big.Int {
453- // The beacon engine requires access to total difficulties to be able to
454- // seal pre-merge and post-merge blocks. With the transition to removing
455- // old blocks, TDs become unaccessible, thus making TTD based pre-/post-
456- // merge decisions impossible.
457- //
458- // We do not need to seal non-merge blocks anymore live, but we do need
459- // to be able to generate test chains, thus we're reverting to a testing-
460- // settable field to direct that.
461- if beacon .ttdblock != nil && * beacon .ttdblock > parent .Number .Uint64 () {
437+ if isPreMerge (chain .Config (), parent .Number .Uint64 ()+ 1 ) {
462438 return beacon .ethone .CalcDifficulty (chain , time , parent )
463439 }
464440 return beaconDifficulty
0 commit comments