Skip to content

Commit

Permalink
Pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
piersy committed Feb 11, 2025
1 parent f89f139 commit 1426122
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ func initGenesis(ctx *cli.Context) error {
triedb := utils.MakeTrieDatabase(ctx, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false, genesis.IsVerkle())
defer triedb.Close()

// Set ignore defaults here so that our genesis is not inited with default
// values for gasLimit, difficulty or uncleHash which celo did not historically set.
// Set initing genesis here, to signal that we are in an initGenesis flow.
genesis.SetInitingGenesis()
_, hash, _, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ func (g *Genesis) toBlockWithRoot(stateRoot, storageRootMessagePasser common.Has
head.Coinbase = g.Coinbase
head.Root = stateRoot

// When initialising the genesis we don't want to override unset gasLimit or
// difficulty fields since these fields were not present at the celo chain genesis.
// Avoid setting default values for gasLimit and difficulty on migrated
// chains.
if !g.Config.IsMigratedChain() {
if g.GasLimit == 0 {
head.GasLimit = params.GenesisGasLimit
Expand All @@ -636,7 +636,6 @@ func (g *Genesis) toBlockWithRoot(stateRoot, storageRootMessagePasser common.Has
if g.BaseFee != nil {
head.BaseFee = g.BaseFee
} else {
// If defaults are not ignored, set default values for base fee.
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
}
}
Expand Down
5 changes: 4 additions & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type extblock struct {

type BlockType interface {
HasOptimismWithdrawalsRoot(blkTime uint64) bool
IsGingerbread(blockNumber *big.Int) bool
IsMigratedChain() bool
}

Expand Down Expand Up @@ -287,7 +288,9 @@ func NewBlock(header *Header, body *Body, receipts []*Receipt, hasher TrieHasher
b.header.Bloom = CreateBloom(receipts)
}

if len(uncles) == 0 && !bType.IsMigratedChain() {
// We prevent setting the EmptyUncleHash only when we are on a migrated
// chain and the block is pre-gingerbread.
if len(uncles) == 0 && !(bType.IsMigratedChain() && !bType.IsGingerbread(header.Number)) {
b.header.UncleHash = EmptyUncleHash
} else {
b.header.UncleHash = CalcUncleHash(uncles)
Expand Down
6 changes: 6 additions & 0 deletions core/types/block_config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "math/big"

type BlockConfig struct {
CustomWithdrawalsRoot bool
}
Expand All @@ -12,6 +14,10 @@ func (bc *BlockConfig) IsMigratedChain() bool {
return false
}

func (bc *BlockConfig) IsGingerbread(blockNumber *big.Int) bool {
return true
}

var (
DefaultBlockConfig = &BlockConfig{CustomWithdrawalsRoot: false}
IsthmusBlockConfig = &BlockConfig{CustomWithdrawalsRoot: true}
Expand Down
1 change: 1 addition & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ func (c *ChainConfig) IsGingerbread(num *big.Int) bool {
}

// Returns whether this is config for a chain that has been migrated to cel2.
// (I.E. cel2 is configured but non zero)
func (c *ChainConfig) IsMigratedChain() bool {
return c.Cel2Time != nil && *c.Cel2Time > 0
}
Expand Down

0 comments on commit 1426122

Please sign in to comment.