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

core: assign default difficulty to zero for chain without ethash #31067

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
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
Loading