Skip to content
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
8 changes: 6 additions & 2 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,12 @@ func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block {
if g.GasLimit == 0 {
head.GasLimit = params.GenesisGasLimit
}
if g.Difficulty == nil && g.Mixhash == (common.Hash{}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ, Why the g.MixHash == (common.Hash{}) is a condition for setting the genesis difficulty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it either. This code is very old.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@fjl fjl Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be related with the idea of how the header MixDigest is used. After the merge, this field was repurposed for the random value. What @MariusVanDerWijden may have been thinking is: "if Mixhash is set in genesis, it means the genesis block is supposed to have a random value (signaling the merge), and thus difficulty will be set to zero."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that was it. It fixed a test case from the testing team if I remember correctly

head.Difficulty = params.GenesisDifficulty
if g.Difficulty == nil {
if g.Config != nil && g.Config.Ethash == nil {
head.Difficulty = big.NewInt(0)
} else if g.Mixhash == (common.Hash{}) {
head.Difficulty = params.GenesisDifficulty
}
}
if g.Config != nil && g.Config.IsLondon(common.Big0) {
if g.BaseFee != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func testSetupGenesis(t *testing.T, scheme string) {
var (
customghash = common.HexToHash("0x89c99d90b79719238d2645c7642f2c9295246e80775b38cfd162b696817fbd50")
customg = Genesis{
Config: &params.ChainConfig{HomesteadBlock: big.NewInt(3)},
Config: &params.ChainConfig{HomesteadBlock: big.NewInt(3), Ethash: &params.EthashConfig{}},
Alloc: types.GenesisAlloc{
{1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
},
}
oldcustomg = customg
)
oldcustomg.Config = &params.ChainConfig{HomesteadBlock: big.NewInt(2)}
oldcustomg.Config = &params.ChainConfig{HomesteadBlock: big.NewInt(2), Ethash: &params.EthashConfig{}}

tests := []struct {
name string
Expand Down