Skip to content

Commit 0e4c13a

Browse files
committed
consensus/beacon: remove TestingTTDBlock
1 parent 4cda8f0 commit 0e4c13a

File tree

6 files changed

+16
-49
lines changed

6 files changed

+16
-49
lines changed

consensus/beacon/consensus.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ var (
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).
6363
type 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.
334326
func (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.
452436
func (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

eth/catalyst/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) {
6464
engine := beacon.New(ethash.NewFaker())
6565
if merged {
6666
config.TerminalTotalDifficulty = common.Big0
67-
} else {
68-
engine.TestingTTDBlock(uint64(n))
67+
config.MergeNetsplitBlock = common.Big0
6968
}
69+
7070
genesis := &core.Genesis{
7171
Config: &config,
7272
Alloc: types.GenesisAlloc{

eth/gasprice/gasprice_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, cancunBlock *big.Int, pe
147147
config.LondonBlock = londonBlock
148148
config.ArrowGlacierBlock = londonBlock
149149
config.GrayGlacierBlock = londonBlock
150-
150+
if cancunBlock != nil {
151+
// Enable the merge with cancun fork.
152+
config.MergeNetsplitBlock = cancunBlock
153+
}
151154
engine := beacon.New(ethash.NewFaker())
152-
engine.TestingTTDBlock(testHead + 1)
153-
154-
td := params.GenesisDifficulty.Uint64()
155155

156156
if cancunBlock != nil {
157157
ts := gspec.Timestamp + cancunBlock.Uint64()*10 // fixed 10 sec block time in blockgen
@@ -209,10 +209,9 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, cancunBlock *big.Int, pe
209209
b.AddTx(types.MustSignNewTx(key, signer, blobTx))
210210
}
211211
}
212-
td += b.Difficulty().Uint64()
213212
})
213+
214214
// Construct testing chain
215-
gspec.Config.TerminalTotalDifficulty = new(big.Int).SetUint64(td)
216215
chain, err := core.NewBlockChain(db, &core.CacheConfig{TrieCleanNoPrefetch: true}, gspec, nil, engine, vm.Config{}, nil)
217216
if err != nil {
218217
t.Fatalf("Failed to create local chain, %v", err)

eth/protocols/eth/handler_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int,
7474
config = params.TestChainConfig
7575
engine = beacon.New(ethash.NewFaker())
7676
)
77-
if !shanghai {
78-
engine.TestingTTDBlock(math.MaxUint64)
79-
} else {
77+
if shanghai {
8078
config = &params.ChainConfig{
8179
ChainID: big.NewInt(1),
8280
HomesteadBlock: big.NewInt(0),

eth/tracers/internal/tracetest/supply_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ func TestSupplyOmittedFields(t *testing.T) {
7575
}
7676
)
7777

78-
gspec.Config.TerminalTotalDifficulty = big.NewInt(0)
79-
8078
out, _, err := testSupplyTracer(t, gspec, func(b *core.BlockGen) {
8179
b.SetPoS()
8280
})
@@ -546,7 +544,6 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
546544

547545
func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockGen)) ([]supplyInfo, *core.BlockChain, error) {
548546
engine := beacon.New(ethash.NewFaker())
549-
engine.TestingTTDBlock(1)
550547

551548
traceOutputPath := filepath.ToSlash(t.TempDir())
552549
traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl")

graphql/graphql_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"io"
24-
"math"
2524
"math/big"
2625
"net/http"
2726
"strings"
@@ -459,15 +458,13 @@ func newGQLService(t *testing.T, stack *node.Node, shanghai bool, gspec *core.Ge
459458
var engine = beacon.New(ethash.NewFaker())
460459
if shanghai {
461460
gspec.Config.TerminalTotalDifficulty = common.Big0
461+
gspec.Config.MergeNetsplitBlock = common.Big0
462462
// GenerateChain will increment timestamps by 10.
463463
// Shanghai upgrade at block 1.
464464
shanghaiTime := uint64(5)
465465
gspec.Config.ShanghaiTime = &shanghaiTime
466-
} else {
467-
// set an arbitrary large ttd as chains are required to be known to be merged
468-
gspec.Config.TerminalTotalDifficulty = big.NewInt(math.MaxInt64)
469-
engine.TestingTTDBlock(math.MaxUint64)
470466
}
467+
471468
ethBackend, err := eth.New(stack, ethConf)
472469
if err != nil {
473470
t.Fatalf("could not create eth backend: %v", err)

0 commit comments

Comments
 (0)