Skip to content

Commit

Permalink
HFork flags and configs (#2265) (#2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbandura authored Mar 13, 2024
1 parent 6211e07 commit 91a4db9
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 42 deletions.
7 changes: 2 additions & 5 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// makeFullNode loads geth configuration and creates the Ethereum backend.
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
stack, cfg := makeConfigNode(ctx)
if ctx.GlobalIsSet(utils.OverrideGingerbreadFlag.Name) {
cfg.Eth.OverrideGingerbread = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideGingerbreadFlag.Name))
}
if ctx.GlobalIsSet(utils.OverrideGingerbreadP2Flag.Name) {
cfg.Eth.OverrideGingerbreadP2 = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideGingerbreadP2Flag.Name))
if ctx.GlobalIsSet(utils.OverrideHForkFlag.Name) {
cfg.Eth.OverrideHFork = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideHForkFlag.Name))
}
backend, _ := utils.RegisterEthService(stack, &cfg.Eth)

Expand Down
3 changes: 1 addition & 2 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ var (
utils.NoUSBFlag,
utils.USBFlag,
// utils.SmartCardDaemonPathFlag,
utils.OverrideGingerbreadFlag,
utils.OverrideGingerbreadP2Flag,
utils.OverrideHForkFlag,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
utils.TxPoolJournalFlag,
Expand Down
11 changes: 3 additions & 8 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,9 @@ var (
}

// Hard fork activation overrides
OverrideGingerbreadFlag = cli.Uint64Flag{
Name: "override.gingerbread",
Usage: "Manually specify the gingerbread fork block, overriding the bundled setting",
}

OverrideGingerbreadP2Flag = cli.Uint64Flag{
Name: "override.gingerbreadp2",
Usage: "Manually specify the gingerbread p2 fork block, overriding the bundled setting",
OverrideHForkFlag = cli.Uint64Flag{
Name: "override.hfork",
Usage: "Manually specify the hfork block, overriding the bundled setting",
}

BloomFilterSizeFlag = cli.Uint64Flag{
Expand Down
12 changes: 4 additions & 8 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ func (e *GenesisMismatchError) Error() string {
//
// The returned chain configuration is never nil.
func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
return SetupGenesisBlockWithOverride(db, genesis, nil, nil)
return SetupGenesisBlockWithOverride(db, genesis, nil)
}

func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideGingerbread, overrideGingerbreadP2 *big.Int) (*params.ChainConfig, common.Hash, error) {
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideHFork *big.Int) (*params.ChainConfig, common.Hash, error) {
if genesis != nil && (genesis.Config == nil || genesis.Config.Istanbul == nil) {
return params.MainnetChainConfig, common.Hash{}, errGenesisNoConfig
}
Expand Down Expand Up @@ -204,13 +204,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override

// Get the existing chain configuration.
newcfg := genesis.configOrDefault(stored)
if overrideGingerbread != nil {
newcfg.GingerbreadBlock = overrideGingerbread
if overrideHFork != nil {
newcfg.HForkBlock = overrideHFork
}
if overrideGingerbreadP2 != nil {
newcfg.GingerbreadP2Block = overrideGingerbreadP2
}

if err := newcfg.CheckConfigForkOrder(); err != nil {
return newcfg, common.Hash{}, err
}
Expand Down
1 change: 1 addition & 0 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func setDefaults(cfg *Config) {
EspressoBlock: new(big.Int),
GingerbreadBlock: new(big.Int),
GingerbreadP2Block: new(big.Int),
HForkBlock: new(big.Int),
}
}
if cfg.Time == nil {
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideGingerbread, config.OverrideGingerbreadP2)
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideHFork)
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
return nil, genesisErr
}
Expand Down
7 changes: 2 additions & 5 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,8 @@ type Config struct {
// CheckpointOracle is the configuration for checkpoint oracle.
CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"`

// Gingerbread block override (TODO: remove after the fork)
OverrideGingerbread *big.Int `toml:",omitempty"`

// Gingerbread block override (TODO: remove after the fork)
OverrideGingerbreadP2 *big.Int `toml:",omitempty"`
// HFork block override (TODO: remove after the fork)
OverrideHFork *big.Int `toml:",omitempty"`

// The minimum required peers in order for syncing to be initiated, if left
// at 0 then the default will be used.
Expand Down
16 changes: 5 additions & 11 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
return nil, err
}
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis,
config.OverrideGingerbread, config.OverrideGingerbreadP2)
config.OverrideHFork)
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
return nil, genesisErr
}
Expand Down
2 changes: 2 additions & 0 deletions mycelo/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (cfg *Config) ChainConfig() *params.ChainConfig {
EspressoBlock: cfg.Hardforks.EspressoBlock,
GingerbreadBlock: cfg.Hardforks.GingerbreadBlock,
GingerbreadP2Block: cfg.Hardforks.GingerbreadP2Block,
HForkBlock: cfg.Hardforks.HForkBlock,

Istanbul: &params.IstanbulConfig{
Epoch: cfg.Istanbul.Epoch,
Expand All @@ -105,6 +106,7 @@ type HardforkConfig struct {
EspressoBlock *big.Int `json:"espressoBlock"`
GingerbreadBlock *big.Int `json:"gingerbreadBlock"`
GingerbreadP2Block *big.Int `json:"gingerbreadP2Block"`
HForkBlock *big.Int `json:"hforkBlock"`
}

// MultiSigParameters are the initial configuration parameters for a MultiSig contract
Expand Down
22 changes: 21 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ var (
EspressoBlock: big.NewInt(11838440),
GingerbreadBlock: big.NewInt(21616000),
GingerbreadP2Block: big.NewInt(21616000),
HForkBlock: nil, // TBD

Istanbul: &IstanbulConfig{
Epoch: 17280,
ProposerPolicy: 2,
Expand Down Expand Up @@ -94,6 +96,8 @@ var (
EspressoBlock: big.NewInt(9195000),
GingerbreadBlock: big.NewInt(18785000),
GingerbreadP2Block: big.NewInt(19157000),
HForkBlock: nil, // TBD

Istanbul: &IstanbulConfig{
Epoch: 17280,
ProposerPolicy: 2,
Expand Down Expand Up @@ -121,6 +125,8 @@ var (
EspressoBlock: big.NewInt(9472000),
GingerbreadBlock: big.NewInt(19814000),
GingerbreadP2Block: big.NewInt(19814000),
HForkBlock: nil, // TBD

Istanbul: &IstanbulConfig{
Epoch: 17280,
ProposerPolicy: 2,
Expand Down Expand Up @@ -153,6 +159,7 @@ var (
EspressoBlock: big.NewInt(0),
GingerbreadBlock: big.NewInt(0),
GingerbreadP2Block: big.NewInt(0),
HForkBlock: big.NewInt(0),

Istanbul: &IstanbulConfig{
Epoch: 30000,
Expand Down Expand Up @@ -305,6 +312,7 @@ type ChainConfig struct {
EspressoBlock *big.Int `json:"espressoBlock,omitempty"` // Espresso switch block (nil = no fork, 0 = already activated)
GingerbreadBlock *big.Int `json:"gingerbreadBlock,omitempty"` // Gingerbread switch block (nil = no fork, 0 = already activated)
GingerbreadP2Block *big.Int `json:"gingerbreadP2Block,omitempty"` // GingerbreadP2 switch block (nil = no fork, 0 = already activated)
HForkBlock *big.Int `json:"hforkBlock,omitempty"` // HFork switch block (nil = no fork, 0 = already activated)

Istanbul *IstanbulConfig `json:"istanbul,omitempty"`
// This does not belong here but passing it to every function is not possible since that breaks
Expand Down Expand Up @@ -347,7 +355,7 @@ func (c *ChainConfig) String() string {
} else {
engine = "MockEngine"
}
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v Churrito: %v, Donut: %v, Espresso: %v, Gingerbread: %v, Gingerbread P2: %v, Engine: %v}",
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v Churrito: %v, Donut: %v, Espresso: %v, Gingerbread: %v, Gingerbread P2: %v, HForkBlock: %v, Engine: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand All @@ -367,6 +375,7 @@ func (c *ChainConfig) String() string {
c.EspressoBlock,
c.GingerbreadBlock,
c.GingerbreadP2Block,
c.HForkBlock,
engine,
)
}
Expand Down Expand Up @@ -455,6 +464,10 @@ func (c *ChainConfig) IsGingerbreadP2(num *big.Int) bool {
return isForked(c.GingerbreadP2Block, num)
}

func (c *ChainConfig) IsHFork(num *big.Int) bool {
return isForked(c.HForkBlock, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -496,6 +509,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "espressoBlock", block: c.EspressoBlock},
{name: "gingerbreadBlock", block: c.GingerbreadBlock},
{name: "gingerbreadP2Block", block: c.GingerbreadP2Block},
{name: "hforkBlock", block: c.HForkBlock},
} {
if lastFork.name != "" {
// Next one must be higher number
Expand Down Expand Up @@ -576,6 +590,9 @@ func (c *ChainConfig) checkCeloCompatible(newcfg *ChainConfig, head *big.Int) *C
if isForkIncompatible(c.GingerbreadP2Block, newcfg.GingerbreadP2Block, head) {
return newCompatError("Gingerbread p2 fork block", c.GingerbreadP2Block, newcfg.GingerbreadP2Block)
}
if isForkIncompatible(c.HForkBlock, newcfg.HForkBlock, head) {
return newCompatError("HFork block", c.HForkBlock, newcfg.HForkBlock)
}
return nil
}

Expand Down Expand Up @@ -692,6 +709,8 @@ func (c *ChainConfig) OverrideChainIdConfig(chainId *big.Int) *ChainConfig {
func (c *ChainConfig) DisableGingerbread() *ChainConfig {
c.GingerbreadBlock = nil
c.GingerbreadP2Block = nil
// Since gingerbread is disabled disable following forks as well
c.HForkBlock = nil
return c
}

Expand All @@ -714,6 +733,7 @@ func (c *ChainConfig) DeepCopy() *ChainConfig {
EspressoBlock: copyBigIntOrNil(c.EspressoBlock),
GingerbreadBlock: copyBigIntOrNil(c.GingerbreadBlock),
GingerbreadP2Block: copyBigIntOrNil(c.GingerbreadP2Block),
HForkBlock: copyBigIntOrNil(c.HForkBlock),

Istanbul: &IstanbulConfig{
Epoch: c.Istanbul.Epoch,
Expand Down

0 comments on commit 91a4db9

Please sign in to comment.