core: default genesis difficulty to zero for merged chains

This commit is contained in:
lightclient 2025-02-03 16:10:34 -07:00
parent 55a18616b1
commit 2f16843c5a
No known key found for this signature in database
GPG key ID: 657913021EF45A6A

View file

@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params/forks"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/triedb" "github.com/ethereum/go-ethereum/triedb"
@ -460,7 +461,13 @@ func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block {
head.GasLimit = params.GenesisGasLimit head.GasLimit = params.GenesisGasLimit
} }
if g.Difficulty == nil && g.Mixhash == (common.Hash{}) { if g.Difficulty == nil && g.Mixhash == (common.Hash{}) {
head.Difficulty = params.GenesisDifficulty if g.Config.LatestFork(g.Timestamp) >= forks.Shanghai {
// If chain is merged at genesis, set difficulty to zero.
head.Difficulty = big.NewInt(0)
} else {
// In case chain is not merged at genesis, set default genesis difficulty.
head.Difficulty = params.GenesisDifficulty
}
} }
if g.Config != nil && g.Config.IsLondon(common.Big0) { if g.Config != nil && g.Config.IsLondon(common.Big0) {
if g.BaseFee != nil { if g.BaseFee != nil {