Skip to content

Commit 4679fa8

Browse files
jwasingerstevemilk
authored andcommitted
all: remove TerminalTotalDifficultyPassed (ethereum#30609)
rebased ethereum#29766 . The downstream branch appears to have been deleted and I don't have perms to push to that fork. `TerminalTotalDifficultyPassed` is removed. `TerminalTotalDifficulty` must now be non-nil, and it is expected that networks are already merged: we can only import PoW/Clique chains, not produce blocks on them. --------- Co-authored-by: stevemilk <wangpeculiar@gmail.com>
1 parent b406794 commit 4679fa8

35 files changed

+378
-442
lines changed

cmd/devp2p/internal/ethtest/testdata/genesis.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"shanghaiTime": 780,
1919
"cancunTime": 840,
2020
"terminalTotalDifficulty": 9454784,
21-
"terminalTotalDifficultyPassed": true,
2221
"ethash": {}
2322
},
2423
"nonce": "0x0",

cmd/geth/genesis_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var customGenesisTests = []struct {
2929
query string
3030
result string
3131
}{
32-
// Genesis file with an empty chain configuration (ensure missing fields work)
32+
// Genesis file with a mostly-empty chain configuration (ensure missing fields work)
3333
{
3434
genesis: `{
3535
"alloc" : {},
@@ -41,8 +41,8 @@ var customGenesisTests = []struct {
4141
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
4242
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
4343
"timestamp" : "0x00",
44-
"config" : {
45-
"terminalTotalDifficultyPassed": true
44+
"config": {
45+
"terminalTotalDifficulty": 0
4646
}
4747
}`,
4848
query: "eth.getBlock(0).nonce",
@@ -64,7 +64,7 @@ var customGenesisTests = []struct {
6464
"homesteadBlock" : 42,
6565
"daoForkBlock" : 141,
6666
"daoForkSupport" : true,
67-
"terminalTotalDifficultyPassed" : true
67+
"terminalTotalDifficulty": 0
6868
}
6969
}`,
7070
query: "eth.getBlock(0).nonce",
@@ -114,8 +114,8 @@ func TestCustomBackend(t *testing.T) {
114114
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
115115
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
116116
"timestamp" : "0x00",
117-
"config" : {
118-
"terminalTotalDifficultyPassed": true
117+
"config": {
118+
"terminalTotalDifficulty": 0
119119
}
120120
}`
121121
type backendTest struct {

cmd/geth/testdata/clique.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"byzantiumBlock": 0,
99
"constantinopleBlock": 0,
1010
"petersburgBlock": 0,
11-
"terminalTotalDifficultyPassed": true,
11+
"terminalTotalDifficulty": 0,
1212
"clique": {
1313
"period": 5,
1414
"epoch": 30000
@@ -22,4 +22,4 @@
2222
"balance": "300000"
2323
}
2424
}
25-
}
25+
}

cmd/utils/flags.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,9 +1867,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18671867
if err != nil {
18681868
Fatalf("Could not read genesis from database: %v", err)
18691869
}
1870-
if !genesis.Config.TerminalTotalDifficultyPassed {
1871-
Fatalf("Bad developer-mode genesis configuration: terminalTotalDifficultyPassed must be true")
1872-
}
18731870
if genesis.Config.TerminalTotalDifficulty == nil {
18741871
Fatalf("Bad developer-mode genesis configuration: terminalTotalDifficulty must be specified")
18751872
} else if genesis.Config.TerminalTotalDifficulty.Cmp(big.NewInt(0)) != 0 {

consensus/beacon/consensus.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ func errOut(n int, err error) chan error {
116116
func (beacon *Beacon) splitHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) ([]*types.Header, []*types.Header, error) {
117117
// TTD is not defined yet, all headers should be in legacy format.
118118
ttd := chain.Config().TerminalTotalDifficulty
119-
if ttd == nil {
120-
return headers, nil, nil
121-
}
122119
ptd := chain.GetTd(headers[0].ParentHash, headers[0].Number.Uint64()-1)
123120
if ptd == nil {
124121
return nil, nil, consensus.ErrUnknownAncestor
@@ -495,9 +492,6 @@ func (beacon *Beacon) SetThreads(threads int) {
495492
// It depends on the parentHash already being stored in the database.
496493
// If the parentHash is not stored in the database a UnknownAncestor error is returned.
497494
func IsTTDReached(chain consensus.ChainHeaderReader, parentHash common.Hash, parentNumber uint64) (bool, error) {
498-
if chain.Config().TerminalTotalDifficulty == nil {
499-
return false, nil
500-
}
501495
td := chain.GetTd(parentHash, parentNumber)
502496
if td == nil {
503497
return false, consensus.ErrUnknownAncestor

core/block_validator_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
113113
}
114114
copy(gspec.ExtraData[32:], addr[:])
115115

116+
// chain_maker has no blockchain to retrieve the TTD from, setting to nil
117+
// is a hack to signal it to generate pre-merge blocks
118+
gspec.Config.TerminalTotalDifficulty = nil
116119
td := 0
117120
genDb, blocks, _ := GenerateChainWithGenesis(gspec, engine, 8, nil)
121+
118122
for i, block := range blocks {
119123
header := block.Header()
120124
if i > 0 {
@@ -145,7 +149,6 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
145149
}
146150
preBlocks = blocks
147151
gspec.Config.TerminalTotalDifficulty = big.NewInt(int64(td))
148-
t.Logf("Set ttd to %v\n", gspec.Config.TerminalTotalDifficulty)
149152
postBlocks, _ = GenerateChain(gspec.Config, preBlocks[len(preBlocks)-1], engine, genDb, 8, func(i int, gen *BlockGen) {
150153
gen.SetPoS()
151154
})

core/blockchain_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4092,7 +4092,6 @@ func TestEIP3651(t *testing.T) {
40924092
gspec.Config.BerlinBlock = common.Big0
40934093
gspec.Config.LondonBlock = common.Big0
40944094
gspec.Config.TerminalTotalDifficulty = common.Big0
4095-
gspec.Config.TerminalTotalDifficultyPassed = true
40964095
gspec.Config.ShanghaiTime = u64(0)
40974096
signer := types.LatestSigner(gspec.Config)
40984097

core/chain_makers_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func TestGeneratePOSChain(t *testing.T) {
5757
db = rawdb.NewMemoryDatabase()
5858
)
5959

60-
config.TerminalTotalDifficultyPassed = true
6160
config.TerminalTotalDifficulty = common.Big0
6261
config.ShanghaiTime = u64(0)
6362
config.CancunTime = u64(0)

core/forkid/forkid_test.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,26 +378,25 @@ func TestTimeBasedForkInGenesis(t *testing.T) {
378378
forkidHash = checksumToBytes(crc32.ChecksumIEEE(genesis.Hash().Bytes()))
379379
config = func(shanghai, cancun uint64) *params.ChainConfig {
380380
return &params.ChainConfig{
381-
ChainID: big.NewInt(1337),
382-
HomesteadBlock: big.NewInt(0),
383-
DAOForkBlock: nil,
384-
DAOForkSupport: true,
385-
EIP150Block: big.NewInt(0),
386-
EIP155Block: big.NewInt(0),
387-
EIP158Block: big.NewInt(0),
388-
ByzantiumBlock: big.NewInt(0),
389-
ConstantinopleBlock: big.NewInt(0),
390-
PetersburgBlock: big.NewInt(0),
391-
IstanbulBlock: big.NewInt(0),
392-
MuirGlacierBlock: big.NewInt(0),
393-
BerlinBlock: big.NewInt(0),
394-
LondonBlock: big.NewInt(0),
395-
TerminalTotalDifficulty: big.NewInt(0),
396-
TerminalTotalDifficultyPassed: true,
397-
MergeNetsplitBlock: big.NewInt(0),
398-
ShanghaiTime: &shanghai,
399-
CancunTime: &cancun,
400-
Ethash: new(params.EthashConfig),
381+
ChainID: big.NewInt(1337),
382+
HomesteadBlock: big.NewInt(0),
383+
DAOForkBlock: nil,
384+
DAOForkSupport: true,
385+
EIP150Block: big.NewInt(0),
386+
EIP155Block: big.NewInt(0),
387+
EIP158Block: big.NewInt(0),
388+
ByzantiumBlock: big.NewInt(0),
389+
ConstantinopleBlock: big.NewInt(0),
390+
PetersburgBlock: big.NewInt(0),
391+
IstanbulBlock: big.NewInt(0),
392+
MuirGlacierBlock: big.NewInt(0),
393+
BerlinBlock: big.NewInt(0),
394+
LondonBlock: big.NewInt(0),
395+
TerminalTotalDifficulty: big.NewInt(0),
396+
MergeNetsplitBlock: big.NewInt(0),
397+
ShanghaiTime: &shanghai,
398+
CancunTime: &cancun,
399+
Ethash: new(params.EthashConfig),
401400
}
402401
}
403402
)

core/genesis_test.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -257,31 +257,30 @@ func newDbConfig(scheme string) *triedb.Config {
257257
func TestVerkleGenesisCommit(t *testing.T) {
258258
var verkleTime uint64 = 0
259259
verkleConfig := &params.ChainConfig{
260-
ChainID: big.NewInt(1),
261-
HomesteadBlock: big.NewInt(0),
262-
DAOForkBlock: nil,
263-
DAOForkSupport: false,
264-
EIP150Block: big.NewInt(0),
265-
EIP155Block: big.NewInt(0),
266-
EIP158Block: big.NewInt(0),
267-
ByzantiumBlock: big.NewInt(0),
268-
ConstantinopleBlock: big.NewInt(0),
269-
PetersburgBlock: big.NewInt(0),
270-
IstanbulBlock: big.NewInt(0),
271-
MuirGlacierBlock: big.NewInt(0),
272-
BerlinBlock: big.NewInt(0),
273-
LondonBlock: big.NewInt(0),
274-
ArrowGlacierBlock: big.NewInt(0),
275-
GrayGlacierBlock: big.NewInt(0),
276-
MergeNetsplitBlock: nil,
277-
ShanghaiTime: &verkleTime,
278-
CancunTime: &verkleTime,
279-
PragueTime: &verkleTime,
280-
VerkleTime: &verkleTime,
281-
TerminalTotalDifficulty: big.NewInt(0),
282-
TerminalTotalDifficultyPassed: true,
283-
Ethash: nil,
284-
Clique: nil,
260+
ChainID: big.NewInt(1),
261+
HomesteadBlock: big.NewInt(0),
262+
DAOForkBlock: nil,
263+
DAOForkSupport: false,
264+
EIP150Block: big.NewInt(0),
265+
EIP155Block: big.NewInt(0),
266+
EIP158Block: big.NewInt(0),
267+
ByzantiumBlock: big.NewInt(0),
268+
ConstantinopleBlock: big.NewInt(0),
269+
PetersburgBlock: big.NewInt(0),
270+
IstanbulBlock: big.NewInt(0),
271+
MuirGlacierBlock: big.NewInt(0),
272+
BerlinBlock: big.NewInt(0),
273+
LondonBlock: big.NewInt(0),
274+
ArrowGlacierBlock: big.NewInt(0),
275+
GrayGlacierBlock: big.NewInt(0),
276+
MergeNetsplitBlock: nil,
277+
ShanghaiTime: &verkleTime,
278+
CancunTime: &verkleTime,
279+
PragueTime: &verkleTime,
280+
VerkleTime: &verkleTime,
281+
TerminalTotalDifficulty: big.NewInt(0),
282+
Ethash: nil,
283+
Clique: nil,
285284
}
286285

287286
genesis := &Genesis{

core/state_processor_test.go

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,22 @@ func u64(val uint64) *uint64 { return &val }
5151
func TestStateProcessorErrors(t *testing.T) {
5252
var (
5353
config = &params.ChainConfig{
54-
ChainID: big.NewInt(1),
55-
HomesteadBlock: big.NewInt(0),
56-
EIP150Block: big.NewInt(0),
57-
EIP155Block: big.NewInt(0),
58-
EIP158Block: big.NewInt(0),
59-
ByzantiumBlock: big.NewInt(0),
60-
ConstantinopleBlock: big.NewInt(0),
61-
PetersburgBlock: big.NewInt(0),
62-
IstanbulBlock: big.NewInt(0),
63-
MuirGlacierBlock: big.NewInt(0),
64-
BerlinBlock: big.NewInt(0),
65-
LondonBlock: big.NewInt(0),
66-
Ethash: new(params.EthashConfig),
67-
TerminalTotalDifficulty: big.NewInt(0),
68-
TerminalTotalDifficultyPassed: true,
69-
ShanghaiTime: new(uint64),
70-
CancunTime: new(uint64),
54+
ChainID: big.NewInt(1),
55+
HomesteadBlock: big.NewInt(0),
56+
EIP150Block: big.NewInt(0),
57+
EIP155Block: big.NewInt(0),
58+
EIP158Block: big.NewInt(0),
59+
ByzantiumBlock: big.NewInt(0),
60+
ConstantinopleBlock: big.NewInt(0),
61+
PetersburgBlock: big.NewInt(0),
62+
IstanbulBlock: big.NewInt(0),
63+
MuirGlacierBlock: big.NewInt(0),
64+
BerlinBlock: big.NewInt(0),
65+
LondonBlock: big.NewInt(0),
66+
Ethash: new(params.EthashConfig),
67+
TerminalTotalDifficulty: big.NewInt(0),
68+
ShanghaiTime: new(uint64),
69+
CancunTime: new(uint64),
7170
}
7271
signer = types.LatestSigner(config)
7372
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
@@ -257,7 +256,7 @@ func TestStateProcessorErrors(t *testing.T) {
257256
want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1, baseFee: 875000000",
258257
},
259258
} {
260-
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config)
259+
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config, false)
261260
_, err := blockchain.InsertChain(types.Blocks{block})
262261
if err == nil {
263262
t.Fatal("block imported without errors")
@@ -306,7 +305,7 @@ func TestStateProcessorErrors(t *testing.T) {
306305
want: "could not apply tx 0 [0x88626ac0d53cb65308f2416103c62bb1f18b805573d4f96a3640bbbfff13c14f]: transaction type not supported",
307306
},
308307
} {
309-
block := GenerateBadBlock(gspec.ToBlock(), ethash.NewFaker(), tt.txs, gspec.Config)
308+
block := GenerateBadBlock(gspec.ToBlock(), ethash.NewFaker(), tt.txs, gspec.Config, true)
310309
_, err := blockchain.InsertChain(types.Blocks{block})
311310
if err == nil {
312311
t.Fatal("block imported without errors")
@@ -345,7 +344,7 @@ func TestStateProcessorErrors(t *testing.T) {
345344
want: "could not apply tx 0 [0x88626ac0d53cb65308f2416103c62bb1f18b805573d4f96a3640bbbfff13c14f]: sender not an eoa: address 0x71562b71999873DB5b286dF957af199Ec94617F7, codehash: 0x9280914443471259d4570a8661015ae4a5b80186dbc619658fb494bebc3da3d1",
346345
},
347346
} {
348-
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config)
347+
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config, false)
349348
_, err := blockchain.InsertChain(types.Blocks{block})
350349
if err == nil {
351350
t.Fatal("block imported without errors")
@@ -361,9 +360,9 @@ func TestStateProcessorErrors(t *testing.T) {
361360
// valid, and no proper post-state can be made. But from the perspective of the blockchain, the block is sufficiently
362361
// valid to be considered for import:
363362
// - valid pow (fake), ancestry, difficulty, gaslimit etc
364-
func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Transactions, config *params.ChainConfig) *types.Block {
363+
func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Transactions, config *params.ChainConfig, isPOW bool) *types.Block {
365364
difficulty := big.NewInt(0)
366-
if !config.TerminalTotalDifficultyPassed {
365+
if isPOW {
367366
fakeChainReader := newChainMaker(nil, config, engine)
368367
difficulty = engine.CalcDifficulty(fakeChainReader, parent.Time()+10, &types.Header{
369368
Number: parent.Number(),
@@ -441,25 +440,22 @@ var (
441440
func TestProcessVerkle(t *testing.T) {
442441
var (
443442
config = &params.ChainConfig{
444-
ChainID: big.NewInt(1),
445-
HomesteadBlock: big.NewInt(0),
446-
EIP150Block: big.NewInt(0),
447-
EIP155Block: big.NewInt(0),
448-
EIP158Block: big.NewInt(0),
449-
ByzantiumBlock: big.NewInt(0),
450-
ConstantinopleBlock: big.NewInt(0),
451-
PetersburgBlock: big.NewInt(0),
452-
IstanbulBlock: big.NewInt(0),
453-
MuirGlacierBlock: big.NewInt(0),
454-
BerlinBlock: big.NewInt(0),
455-
LondonBlock: big.NewInt(0),
456-
Ethash: new(params.EthashConfig),
457-
ShanghaiTime: u64(0),
458-
VerkleTime: u64(0),
459-
TerminalTotalDifficulty: common.Big0,
460-
TerminalTotalDifficultyPassed: true,
461-
// TODO uncomment when proof generation is merged
462-
// ProofInBlocks: true,
443+
ChainID: big.NewInt(1),
444+
HomesteadBlock: big.NewInt(0),
445+
EIP150Block: big.NewInt(0),
446+
EIP155Block: big.NewInt(0),
447+
EIP158Block: big.NewInt(0),
448+
ByzantiumBlock: big.NewInt(0),
449+
ConstantinopleBlock: big.NewInt(0),
450+
PetersburgBlock: big.NewInt(0),
451+
IstanbulBlock: big.NewInt(0),
452+
MuirGlacierBlock: big.NewInt(0),
453+
BerlinBlock: big.NewInt(0),
454+
LondonBlock: big.NewInt(0),
455+
Ethash: new(params.EthashConfig),
456+
ShanghaiTime: u64(0),
457+
VerkleTime: u64(0),
458+
TerminalTotalDifficulty: common.Big0,
463459
}
464460
signer = types.LatestSigner(config)
465461
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")

0 commit comments

Comments
 (0)