Skip to content

Commit 91a4db9

Browse files
authored
HFork flags and configs (#2265) (#2282)
1 parent 6211e07 commit 91a4db9

File tree

11 files changed

+43
-42
lines changed

11 files changed

+43
-42
lines changed

cmd/geth/config.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
158158
// makeFullNode loads geth configuration and creates the Ethereum backend.
159159
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
160160
stack, cfg := makeConfigNode(ctx)
161-
if ctx.GlobalIsSet(utils.OverrideGingerbreadFlag.Name) {
162-
cfg.Eth.OverrideGingerbread = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideGingerbreadFlag.Name))
163-
}
164-
if ctx.GlobalIsSet(utils.OverrideGingerbreadP2Flag.Name) {
165-
cfg.Eth.OverrideGingerbreadP2 = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideGingerbreadP2Flag.Name))
161+
if ctx.GlobalIsSet(utils.OverrideHForkFlag.Name) {
162+
cfg.Eth.OverrideHFork = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideHForkFlag.Name))
166163
}
167164
backend, _ := utils.RegisterEthService(stack, &cfg.Eth)
168165

cmd/geth/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ var (
7373
utils.NoUSBFlag,
7474
utils.USBFlag,
7575
// utils.SmartCardDaemonPathFlag,
76-
utils.OverrideGingerbreadFlag,
77-
utils.OverrideGingerbreadP2Flag,
76+
utils.OverrideHForkFlag,
7877
utils.TxPoolLocalsFlag,
7978
utils.TxPoolNoLocalsFlag,
8079
utils.TxPoolJournalFlag,

cmd/utils/flags.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,9 @@ var (
238238
}
239239

240240
// Hard fork activation overrides
241-
OverrideGingerbreadFlag = cli.Uint64Flag{
242-
Name: "override.gingerbread",
243-
Usage: "Manually specify the gingerbread fork block, overriding the bundled setting",
244-
}
245-
246-
OverrideGingerbreadP2Flag = cli.Uint64Flag{
247-
Name: "override.gingerbreadp2",
248-
Usage: "Manually specify the gingerbread p2 fork block, overriding the bundled setting",
241+
OverrideHForkFlag = cli.Uint64Flag{
242+
Name: "override.hfork",
243+
Usage: "Manually specify the hfork block, overriding the bundled setting",
249244
}
250245

251246
BloomFilterSizeFlag = cli.Uint64Flag{

core/genesis.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ func (e *GenesisMismatchError) Error() string {
148148
//
149149
// The returned chain configuration is never nil.
150150
func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
151-
return SetupGenesisBlockWithOverride(db, genesis, nil, nil)
151+
return SetupGenesisBlockWithOverride(db, genesis, nil)
152152
}
153153

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

205205
// Get the existing chain configuration.
206206
newcfg := genesis.configOrDefault(stored)
207-
if overrideGingerbread != nil {
208-
newcfg.GingerbreadBlock = overrideGingerbread
207+
if overrideHFork != nil {
208+
newcfg.HForkBlock = overrideHFork
209209
}
210-
if overrideGingerbreadP2 != nil {
211-
newcfg.GingerbreadP2Block = overrideGingerbreadP2
212-
}
213-
214210
if err := newcfg.CheckConfigForkOrder(); err != nil {
215211
return newcfg, common.Hash{}, err
216212
}

core/vm/runtime/runtime.go

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func setDefaults(cfg *Config) {
6969
EspressoBlock: new(big.Int),
7070
GingerbreadBlock: new(big.Int),
7171
GingerbreadP2Block: new(big.Int),
72+
HForkBlock: new(big.Int),
7273
}
7374
}
7475
if cfg.Time == nil {

eth/backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
131131
if err != nil {
132132
return nil, err
133133
}
134-
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideGingerbread, config.OverrideGingerbreadP2)
134+
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideHFork)
135135
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
136136
return nil, genesisErr
137137
}

eth/ethconfig/config.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,8 @@ type Config struct {
162162
// CheckpointOracle is the configuration for checkpoint oracle.
163163
CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"`
164164

165-
// Gingerbread block override (TODO: remove after the fork)
166-
OverrideGingerbread *big.Int `toml:",omitempty"`
167-
168-
// Gingerbread block override (TODO: remove after the fork)
169-
OverrideGingerbreadP2 *big.Int `toml:",omitempty"`
165+
// HFork block override (TODO: remove after the fork)
166+
OverrideHFork *big.Int `toml:",omitempty"`
170167

171168
// The minimum required peers in order for syncing to be initiated, if left
172169
// at 0 then the default will be used.

eth/ethconfig/gen_config.go

+5-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

les/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
104104
return nil, err
105105
}
106106
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis,
107-
config.OverrideGingerbread, config.OverrideGingerbreadP2)
107+
config.OverrideHFork)
108108
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
109109
return nil, genesisErr
110110
}

mycelo/genesis/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (cfg *Config) ChainConfig() *params.ChainConfig {
8787
EspressoBlock: cfg.Hardforks.EspressoBlock,
8888
GingerbreadBlock: cfg.Hardforks.GingerbreadBlock,
8989
GingerbreadP2Block: cfg.Hardforks.GingerbreadP2Block,
90+
HForkBlock: cfg.Hardforks.HForkBlock,
9091

9192
Istanbul: &params.IstanbulConfig{
9293
Epoch: cfg.Istanbul.Epoch,
@@ -105,6 +106,7 @@ type HardforkConfig struct {
105106
EspressoBlock *big.Int `json:"espressoBlock"`
106107
GingerbreadBlock *big.Int `json:"gingerbreadBlock"`
107108
GingerbreadP2Block *big.Int `json:"gingerbreadP2Block"`
109+
HForkBlock *big.Int `json:"hforkBlock"`
108110
}
109111

110112
// MultiSigParameters are the initial configuration parameters for a MultiSig contract

params/config.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ var (
6767
EspressoBlock: big.NewInt(11838440),
6868
GingerbreadBlock: big.NewInt(21616000),
6969
GingerbreadP2Block: big.NewInt(21616000),
70+
HForkBlock: nil, // TBD
71+
7072
Istanbul: &IstanbulConfig{
7173
Epoch: 17280,
7274
ProposerPolicy: 2,
@@ -94,6 +96,8 @@ var (
9496
EspressoBlock: big.NewInt(9195000),
9597
GingerbreadBlock: big.NewInt(18785000),
9698
GingerbreadP2Block: big.NewInt(19157000),
99+
HForkBlock: nil, // TBD
100+
97101
Istanbul: &IstanbulConfig{
98102
Epoch: 17280,
99103
ProposerPolicy: 2,
@@ -121,6 +125,8 @@ var (
121125
EspressoBlock: big.NewInt(9472000),
122126
GingerbreadBlock: big.NewInt(19814000),
123127
GingerbreadP2Block: big.NewInt(19814000),
128+
HForkBlock: nil, // TBD
129+
124130
Istanbul: &IstanbulConfig{
125131
Epoch: 17280,
126132
ProposerPolicy: 2,
@@ -153,6 +159,7 @@ var (
153159
EspressoBlock: big.NewInt(0),
154160
GingerbreadBlock: big.NewInt(0),
155161
GingerbreadP2Block: big.NewInt(0),
162+
HForkBlock: big.NewInt(0),
156163

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

309317
Istanbul *IstanbulConfig `json:"istanbul,omitempty"`
310318
// This does not belong here but passing it to every function is not possible since that breaks
@@ -347,7 +355,7 @@ func (c *ChainConfig) String() string {
347355
} else {
348356
engine = "MockEngine"
349357
}
350-
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}",
358+
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}",
351359
c.ChainID,
352360
c.HomesteadBlock,
353361
c.DAOForkBlock,
@@ -367,6 +375,7 @@ func (c *ChainConfig) String() string {
367375
c.EspressoBlock,
368376
c.GingerbreadBlock,
369377
c.GingerbreadP2Block,
378+
c.HForkBlock,
370379
engine,
371380
)
372381
}
@@ -455,6 +464,10 @@ func (c *ChainConfig) IsGingerbreadP2(num *big.Int) bool {
455464
return isForked(c.GingerbreadP2Block, num)
456465
}
457466

467+
func (c *ChainConfig) IsHFork(num *big.Int) bool {
468+
return isForked(c.HForkBlock, num)
469+
}
470+
458471
// CheckCompatible checks whether scheduled fork transitions have been imported
459472
// with a mismatching chain configuration.
460473
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
@@ -496,6 +509,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
496509
{name: "espressoBlock", block: c.EspressoBlock},
497510
{name: "gingerbreadBlock", block: c.GingerbreadBlock},
498511
{name: "gingerbreadP2Block", block: c.GingerbreadP2Block},
512+
{name: "hforkBlock", block: c.HForkBlock},
499513
} {
500514
if lastFork.name != "" {
501515
// Next one must be higher number
@@ -576,6 +590,9 @@ func (c *ChainConfig) checkCeloCompatible(newcfg *ChainConfig, head *big.Int) *C
576590
if isForkIncompatible(c.GingerbreadP2Block, newcfg.GingerbreadP2Block, head) {
577591
return newCompatError("Gingerbread p2 fork block", c.GingerbreadP2Block, newcfg.GingerbreadP2Block)
578592
}
593+
if isForkIncompatible(c.HForkBlock, newcfg.HForkBlock, head) {
594+
return newCompatError("HFork block", c.HForkBlock, newcfg.HForkBlock)
595+
}
579596
return nil
580597
}
581598

@@ -692,6 +709,8 @@ func (c *ChainConfig) OverrideChainIdConfig(chainId *big.Int) *ChainConfig {
692709
func (c *ChainConfig) DisableGingerbread() *ChainConfig {
693710
c.GingerbreadBlock = nil
694711
c.GingerbreadP2Block = nil
712+
// Since gingerbread is disabled disable following forks as well
713+
c.HForkBlock = nil
695714
return c
696715
}
697716

@@ -714,6 +733,7 @@ func (c *ChainConfig) DeepCopy() *ChainConfig {
714733
EspressoBlock: copyBigIntOrNil(c.EspressoBlock),
715734
GingerbreadBlock: copyBigIntOrNil(c.GingerbreadBlock),
716735
GingerbreadP2Block: copyBigIntOrNil(c.GingerbreadP2Block),
736+
HForkBlock: copyBigIntOrNil(c.HForkBlock),
717737

718738
Istanbul: &IstanbulConfig{
719739
Epoch: c.Istanbul.Epoch,

0 commit comments

Comments
 (0)