Skip to content

Commit 53b1420

Browse files
params: changed CatalystBlock to TerminalTotalDifficulty (#23700)
* params: changed CatalystBlock to TerminalTotalDifficulty * eth/catalyst: comment out unused code
1 parent 8b6e018 commit 53b1420

File tree

6 files changed

+51
-49
lines changed

6 files changed

+51
-49
lines changed

consensus/ethash/consensus.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,6 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uin
330330
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
331331
next := new(big.Int).Add(parent.Number, big1)
332332
switch {
333-
case config.IsCatalyst(next):
334-
return big.NewInt(1)
335333
case config.IsLondon(next):
336334
return calcDifficultyEip3554(time, parent)
337335
case config.IsMuirGlacier(next):
@@ -639,10 +637,6 @@ var (
639637
// reward. The total reward consists of the static block reward and rewards for
640638
// included uncles. The coinbase of each uncle block is also rewarded.
641639
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) {
642-
// Skip block reward in catalyst mode
643-
if config.IsCatalyst(header.Number) {
644-
return
645-
}
646640
// Select the correct block reward based on chain progression
647641
blockReward := FrontierBlockReward
648642
if config.IsByzantium(header.Number) {

consensus/misc/eip1559_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ import (
2929
// do not use e.g. SetInt() on the numbers. For testing only
3030
func copyConfig(original *params.ChainConfig) *params.ChainConfig {
3131
return &params.ChainConfig{
32-
ChainID: original.ChainID,
33-
HomesteadBlock: original.HomesteadBlock,
34-
DAOForkBlock: original.DAOForkBlock,
35-
DAOForkSupport: original.DAOForkSupport,
36-
EIP150Block: original.EIP150Block,
37-
EIP150Hash: original.EIP150Hash,
38-
EIP155Block: original.EIP155Block,
39-
EIP158Block: original.EIP158Block,
40-
ByzantiumBlock: original.ByzantiumBlock,
41-
ConstantinopleBlock: original.ConstantinopleBlock,
42-
PetersburgBlock: original.PetersburgBlock,
43-
IstanbulBlock: original.IstanbulBlock,
44-
MuirGlacierBlock: original.MuirGlacierBlock,
45-
BerlinBlock: original.BerlinBlock,
46-
LondonBlock: original.LondonBlock,
47-
CatalystBlock: original.CatalystBlock,
48-
Ethash: original.Ethash,
49-
Clique: original.Clique,
32+
ChainID: original.ChainID,
33+
HomesteadBlock: original.HomesteadBlock,
34+
DAOForkBlock: original.DAOForkBlock,
35+
DAOForkSupport: original.DAOForkSupport,
36+
EIP150Block: original.EIP150Block,
37+
EIP150Hash: original.EIP150Hash,
38+
EIP155Block: original.EIP155Block,
39+
EIP158Block: original.EIP158Block,
40+
ByzantiumBlock: original.ByzantiumBlock,
41+
ConstantinopleBlock: original.ConstantinopleBlock,
42+
PetersburgBlock: original.PetersburgBlock,
43+
IstanbulBlock: original.IstanbulBlock,
44+
MuirGlacierBlock: original.MuirGlacierBlock,
45+
BerlinBlock: original.BerlinBlock,
46+
LondonBlock: original.LondonBlock,
47+
TerminalTotalDifficulty: original.TerminalTotalDifficulty,
48+
Ethash: original.Ethash,
49+
Clique: original.Clique,
5050
}
5151
}
5252

eth/catalyst/api.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ import (
3939
// Register adds catalyst APIs to the node.
4040
func Register(stack *node.Node, backend *eth.Ethereum) error {
4141
chainconfig := backend.BlockChain().Config()
42-
if chainconfig.CatalystBlock == nil {
43-
return errors.New("catalystBlock is not set in genesis config")
44-
} else if chainconfig.CatalystBlock.Sign() != 0 {
45-
return errors.New("catalystBlock of genesis config must be zero")
42+
if chainconfig.TerminalTotalDifficulty == nil {
43+
return errors.New("catalyst started without valid total difficulty")
4644
}
4745

4846
log.Warn("Catalyst mode enabled")

eth/catalyst/api_test.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,28 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
6262
return genesis, blocks
6363
}
6464

65+
// TODO (MariusVanDerWijden) reenable once engine api is updated to the latest spec
66+
/*
6567
func generateTestChainWithFork(n int, fork int) (*core.Genesis, []*types.Block, []*types.Block) {
6668
if fork >= n {
6769
fork = n - 1
6870
}
6971
db := rawdb.NewMemoryDatabase()
7072
config := &params.ChainConfig{
71-
ChainID: big.NewInt(1337),
72-
HomesteadBlock: big.NewInt(0),
73-
EIP150Block: big.NewInt(0),
74-
EIP155Block: big.NewInt(0),
75-
EIP158Block: big.NewInt(0),
76-
ByzantiumBlock: big.NewInt(0),
77-
ConstantinopleBlock: big.NewInt(0),
78-
PetersburgBlock: big.NewInt(0),
79-
IstanbulBlock: big.NewInt(0),
80-
MuirGlacierBlock: big.NewInt(0),
81-
BerlinBlock: big.NewInt(0),
82-
LondonBlock: big.NewInt(0),
83-
CatalystBlock: big.NewInt(0),
84-
Ethash: new(params.EthashConfig),
73+
ChainID: big.NewInt(1337),
74+
HomesteadBlock: big.NewInt(0),
75+
EIP150Block: big.NewInt(0),
76+
EIP155Block: big.NewInt(0),
77+
EIP158Block: big.NewInt(0),
78+
ByzantiumBlock: big.NewInt(0),
79+
ConstantinopleBlock: big.NewInt(0),
80+
PetersburgBlock: big.NewInt(0),
81+
IstanbulBlock: big.NewInt(0),
82+
MuirGlacierBlock: big.NewInt(0),
83+
BerlinBlock: big.NewInt(0),
84+
LondonBlock: big.NewInt(0),
85+
TerminalTotalDifficulty: big.NewInt(0),
86+
Ethash: new(params.EthashConfig),
8587
}
8688
genesis := &core.Genesis{
8789
Config: config,
@@ -105,6 +107,7 @@ func generateTestChainWithFork(n int, fork int) (*core.Genesis, []*types.Block,
105107
forkedBlocks, _ := core.GenerateChain(config, blocks[fork], engine, db, n-fork, generateFork)
106108
return genesis, blocks, forkedBlocks
107109
}
110+
*/
108111

109112
func TestEth2AssembleBlock(t *testing.T) {
110113
genesis, blocks := generateTestChain()
@@ -156,6 +159,8 @@ func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) {
156159
}
157160
}
158161

162+
// TODO (MariusVanDerWijden) reenable once engine api is updated to the latest spec
163+
/*
159164
func TestEth2NewBlock(t *testing.T) {
160165
genesis, blocks, forkedBlocks := generateTestChainWithFork(10, 4)
161166
n, ethservice := startEthService(t, genesis, blocks[1:5])
@@ -216,6 +221,7 @@ func TestEth2NewBlock(t *testing.T) {
216221
t.Fatalf("Wrong head after inserting fork %x != %x", exp, ethservice.BlockChain().CurrentBlock().Hash())
217222
}
218223
}
224+
*/
219225

220226
// startEthService creates a full node instance for testing.
221227
func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block) (*node.Node, *eth.Ethereum) {

eth/tracers/tracer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestNoStepExec(t *testing.T) {
207207
}
208208

209209
func TestIsPrecompile(t *testing.T) {
210-
chaincfg := &params.ChainConfig{ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: false, EIP150Block: big.NewInt(0), EIP150Hash: common.Hash{}, EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(100), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(200), MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(300), LondonBlock: big.NewInt(0), CatalystBlock: nil, Ethash: new(params.EthashConfig), Clique: nil}
210+
chaincfg := &params.ChainConfig{ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: false, EIP150Block: big.NewInt(0), EIP150Hash: common.Hash{}, EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(100), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(200), MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(300), LondonBlock: big.NewInt(0), TerminalTotalDifficulty: nil, Ethash: new(params.EthashConfig), Clique: nil}
211211
chaincfg.ByzantiumBlock = big.NewInt(100)
212212
chaincfg.IstanbulBlock = big.NewInt(200)
213213
chaincfg.BerlinBlock = big.NewInt(300)

params/config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ type ChainConfig struct {
314314
BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin)
315315
LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london)
316316

317-
CatalystBlock *big.Int `json:"catalystBlock,omitempty"` // Catalyst switch block (nil = no fork, 0 = already on catalyst)
317+
// TerminalTotalDifficulty is the amount of total difficulty reached by
318+
// the network that triggers the consensus upgrade.
319+
TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"`
318320

319321
// Various consensus engines
320322
Ethash *EthashConfig `json:"ethash,omitempty"`
@@ -432,9 +434,12 @@ func (c *ChainConfig) IsLondon(num *big.Int) bool {
432434
return isForked(c.LondonBlock, num)
433435
}
434436

435-
// IsCatalyst returns whether num is either equal to the Merge fork block or greater.
436-
func (c *ChainConfig) IsCatalyst(num *big.Int) bool {
437-
return isForked(c.CatalystBlock, num)
437+
// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
438+
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
439+
if c.TerminalTotalDifficulty == nil {
440+
return false
441+
}
442+
return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0
438443
}
439444

440445
// CheckCompatible checks whether scheduled fork transitions have been imported
@@ -613,7 +618,7 @@ type Rules struct {
613618
ChainID *big.Int
614619
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
615620
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
616-
IsBerlin, IsLondon, IsCatalyst bool
621+
IsBerlin, IsLondon bool
617622
}
618623

619624
// Rules ensures c's ChainID is not nil.
@@ -634,6 +639,5 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
634639
IsIstanbul: c.IsIstanbul(num),
635640
IsBerlin: c.IsBerlin(num),
636641
IsLondon: c.IsLondon(num),
637-
IsCatalyst: c.IsCatalyst(num),
638642
}
639643
}

0 commit comments

Comments
 (0)