Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulators/ethereum/engine: Update post-merge forks to activate later in pre-merge test #901

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/erigon/mapper.jq
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def to_bool:
"muirGlacierBlock": env.HIVE_FORK_MUIR_GLACIER|to_int,
"berlinBlock": env.HIVE_FORK_BERLIN|to_int,
"londonBlock": env.HIVE_FORK_LONDON|to_int,
"mergeNetsplitBlock": env.HIVE_MERGE_BLOCK_ID|to_int,
"terminalTotalDifficulty": env.HIVE_TERMINAL_TOTAL_DIFFICULTY|to_int,
"shanghaiTime": env.HIVE_SHANGHAI_TIMESTAMP|to_int,
"cancunTime": env.HIVE_CANCUN_TIMESTAMP|to_int,
Expand Down
2 changes: 1 addition & 1 deletion clients/go-ethereum/mapper.jq
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def to_bool:
"yolov2Block": env.HIVE_FORK_BERLIN|to_int,
"yolov3Block": env.HIVE_FORK_BERLIN|to_int,
"londonBlock": env.HIVE_FORK_LONDON|to_int,
"mergeForkBlock": env.HIVE_MERGE_BLOCK_ID|to_int,
"mergeNetsplitBlock": env.HIVE_MERGE_BLOCK_ID|to_int,
"terminalTotalDifficulty": env.HIVE_TERMINAL_TOTAL_DIFFICULTY|to_int,
"shanghaiTime": env.HIVE_SHANGHAI_TIMESTAMP|to_int,
"cancunTime": env.HIVE_CANCUN_TIMESTAMP|to_int,
Expand Down
1 change: 1 addition & 0 deletions clients/reth/mapper.jq
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def to_bool:
"londonBlock": env.HIVE_FORK_LONDON|to_int,
"arrowGlacierBlock": env.HIVE_FORK_ARROW_GLACIER|to_int,
"grayGlacierBlock": env.HIVE_FORK_GRAY_GLACIER|to_int,
"parisBlock": env.HIVE_MERGE_BLOCK_ID|to_int,
"terminalTotalDifficulty": env.HIVE_TERMINAL_TOTAL_DIFFICULTY|to_int,
"terminalTotalDifficultyPassed": env.HIVE_TERMINAL_TOTAL_DIFFICULTY_PASSED|to_bool,
"shanghaiTime": env.HIVE_SHANGHAI_TIMESTAMP|to_int,
Expand Down
4 changes: 4 additions & 0 deletions simulators/ethereum/engine/config/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ type Fork string

const (
NA Fork = ""
London Fork = "London"
Paris Fork = "Paris"
Shanghai Fork = "Shanghai"
Cancun Fork = "Cancun"
)

func (f Fork) PreviousFork() Fork {
switch f {
case Paris:
return London
case Shanghai:
return Paris
case Cancun:
Expand All @@ -28,6 +31,7 @@ func (f Fork) PreviousFork() Fork {

type ForkConfig struct {
LondonNumber *big.Int
ParisNumber *big.Int
ShanghaiTimestamp *big.Int
CancunTimestamp *big.Int
}
Expand Down
20 changes: 14 additions & 6 deletions simulators/ethereum/engine/config/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
)

func (f *ForkConfig) ConfigGenesis(genesis *core.Genesis) error {
if f.ParisNumber != nil {
genesis.Config.MergeNetsplitBlock = f.ParisNumber
if genesis.Number >= f.ParisNumber.Uint64() {
removePoW(genesis)
}
}
if f.ShanghaiTimestamp != nil {
shanghaiTime := f.ShanghaiTimestamp.Uint64()
genesis.Config.ShanghaiTime = &shanghaiTime

if genesis.Timestamp >= shanghaiTime {
// Remove PoW altogether
genesis.Difficulty = common.Big0
genesis.Config.TerminalTotalDifficulty = common.Big0
genesis.Config.Clique = nil
genesis.ExtraData = []byte{}
removePoW(genesis)
}
}
if f.CancunTimestamp != nil {
Expand All @@ -28,3 +29,10 @@ func (f *ForkConfig) ConfigGenesis(genesis *core.Genesis) error {
}
return nil
}

func removePoW(genesis *core.Genesis) {
genesis.Difficulty = common.Big0
genesis.Config.TerminalTotalDifficulty = common.Big0
genesis.Config.Clique = nil
genesis.ExtraData = []byte{}
}
9 changes: 7 additions & 2 deletions simulators/ethereum/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ func makeRunner(tests []test.Spec, nodeType string) func(t *hivesim.T) {
if forkConfig.LondonNumber != nil {
newParams = newParams.Set("HIVE_FORK_LONDON", fmt.Sprintf("%d", forkConfig.LondonNumber))
}
if forkConfig.ParisNumber != nil {
newParams = newParams.Set("HIVE_MERGE_BLOCK_ID", fmt.Sprintf("%d", forkConfig.ParisNumber))
}
if forkConfig.ShanghaiTimestamp != nil {
newParams = newParams.Set("HIVE_SHANGHAI_TIMESTAMP", fmt.Sprintf("%d", forkConfig.ShanghaiTimestamp))
// Ensure the merge transition is activated before shanghai.
newParams = newParams.Set("HIVE_MERGE_BLOCK_ID", "0")
// Ensure merge transition is activated before shanghai if not already
if forkConfig.ParisNumber == nil {
newParams = newParams.Set("HIVE_MERGE_BLOCK_ID", "0")
}
if forkConfig.CancunTimestamp != nil {
newParams = newParams.Set("HIVE_CANCUN_TIMESTAMP", fmt.Sprintf("%d", forkConfig.CancunTimestamp))
}
Expand Down
4 changes: 3 additions & 1 deletion simulators/ethereum/engine/suites/engine/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ func (s NonZeroPreMergeFork) GetForkConfig() *config.ForkConfig {
if forkConfig == nil {
return nil
}
// Merge fork & pre-merge happen at block 1
forkConfig.LondonNumber = common.Big1
// All post merge forks must happen at the same time as the latest fork
forkConfig.ParisNumber = common.Big1
// Post-merge fork happens at block 2
mainFork := s.GetMainFork()
if mainFork == config.Cancun {
forkConfig.ShanghaiTimestamp = new(big.Int).Set(forkConfig.CancunTimestamp)
Expand Down
3 changes: 2 additions & 1 deletion simulators/ethereum/engine/suites/engine/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,10 @@ func init() {

// Misc Tests
Tests = append(Tests,
// Pre-merge & merge fork occur at block 1, post-merge forks occur at block 2
NonZeroPreMergeFork{
BaseSpec: test.BaseSpec{
ForkHeight: 1,
ForkHeight: 2,
},
},
)
Expand Down