Skip to content

Commit de11e85

Browse files
committed
ethapi: Fix merge transition
1 parent df0bd89 commit de11e85

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

internal/ethapi/simulate.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,13 @@ func (sim *simulator) sanitizeChain(blocks []simBlock) ([]simBlock, error) {
458458
return res, nil
459459
}
460460

461+
func isPostMerge(config *params.ChainConfig, blockNum uint64, timestamp uint64) bool {
462+
mergedAtGenesis := config.TerminalTotalDifficulty != nil && config.TerminalTotalDifficulty.Sign() == 0
463+
return mergedAtGenesis ||
464+
config.MergeNetsplitBlock != nil && blockNum >= config.MergeNetsplitBlock.Uint64() ||
465+
config.ShanghaiTime != nil && timestamp >= *config.ShanghaiTime
466+
}
467+
461468
// makeHeaders makes header object with preliminary fields based on a simulated block.
462469
// Some fields have to be filled post-execution.
463470
// It assumes blocks are in order and numbers have been validated.
@@ -474,22 +481,28 @@ func (sim *simulator) makeHeaders(blocks []simBlock) ([]*types.Header, error) {
474481
overrides := block.BlockOverrides
475482

476483
var withdrawalsHash *common.Hash
477-
if sim.chainConfig.IsShanghai(overrides.Number.ToInt(), (uint64)(*overrides.Time)) {
484+
number := overrides.Number.ToInt()
485+
timestamp := (uint64)(*overrides.Time)
486+
if sim.chainConfig.IsShanghai(number, timestamp) {
478487
withdrawalsHash = &types.EmptyWithdrawalsHash
479488
}
480489
var parentBeaconRoot *common.Hash
481-
if sim.chainConfig.IsCancun(overrides.Number.ToInt(), (uint64)(*overrides.Time)) {
490+
if sim.chainConfig.IsCancun(number, timestamp) {
482491
parentBeaconRoot = &common.Hash{}
483492
if overrides.BeaconRoot != nil {
484493
parentBeaconRoot = overrides.BeaconRoot
485494
}
486495
}
496+
difficulty := header.Difficulty
497+
if isPostMerge(sim.chainConfig, number.Uint64(), timestamp) {
498+
difficulty = big.NewInt(0)
499+
}
487500
header = overrides.MakeHeader(&types.Header{
488501
UncleHash: types.EmptyUncleHash,
489502
ReceiptHash: types.EmptyReceiptsHash,
490503
TxHash: types.EmptyTxsHash,
491504
Coinbase: header.Coinbase,
492-
Difficulty: header.Difficulty,
505+
Difficulty: difficulty,
493506
GasLimit: header.GasLimit,
494507
WithdrawalsHash: withdrawalsHash,
495508
ParentBeaconRoot: parentBeaconRoot,

0 commit comments

Comments
 (0)