From 8b9558bb4da59e3e9e248aafa598d73eb850974a Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 30 May 2024 11:51:34 +0800 Subject: [PATCH] params/config: add Bohr hardfork (#2497) --- cmd/geth/chaincmd.go | 5 +++++ cmd/geth/config.go | 4 ++++ cmd/geth/main.go | 1 + cmd/utils/flags.go | 5 +++++ core/genesis.go | 4 ++++ eth/backend.go | 4 ++++ eth/ethconfig/config.go | 3 +++ eth/ethconfig/gen_config.go | 6 ++++++ params/config.go | 30 ++++++++++++++++++++++++++++-- 9 files changed, 60 insertions(+), 2 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 7f810dbe20..6ffc150de1 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -64,6 +64,7 @@ var ( utils.CachePreimagesFlag, utils.OverrideCancun, utils.OverrideHaber, + utils.OverrideBohr, utils.OverrideVerkle, }, utils.DatabaseFlags), Description: ` @@ -261,6 +262,10 @@ func initGenesis(ctx *cli.Context) error { v := ctx.Uint64(utils.OverrideHaber.Name) overrides.OverrideHaber = &v } + if ctx.IsSet(utils.OverrideBohr.Name) { + v := ctx.Uint64(utils.OverrideBohr.Name) + overrides.OverrideBohr = &v + } if ctx.IsSet(utils.OverrideVerkle.Name) { v := ctx.Uint64(utils.OverrideVerkle.Name) overrides.OverrideVerkle = &v diff --git a/cmd/geth/config.go b/cmd/geth/config.go index d35e088ff2..e535dc8155 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -193,6 +193,10 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { v := ctx.Uint64(utils.OverrideHaber.Name) cfg.Eth.OverrideHaber = &v } + if ctx.IsSet(utils.OverrideBohr.Name) { + v := ctx.Uint64(utils.OverrideBohr.Name) + cfg.Eth.OverrideBohr = &v + } if ctx.IsSet(utils.OverrideVerkle.Name) { v := ctx.Uint64(utils.OverrideVerkle.Name) cfg.Eth.OverrideVerkle = &v diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 4689290d6b..9763794f7e 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -74,6 +74,7 @@ var ( utils.RialtoHash, utils.OverrideCancun, utils.OverrideHaber, + utils.OverrideBohr, utils.OverrideVerkle, utils.OverrideFullImmutabilityThreshold, utils.OverrideMinBlocksForBlobRequests, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 99fd72a937..8707840692 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -315,6 +315,11 @@ var ( Usage: "Manually specify the Haber fork timestamp, overriding the bundled setting", Category: flags.EthCategory, } + OverrideBohr = &cli.Uint64Flag{ + Name: "override.bohr", + Usage: "Manually specify the Bohr fork timestamp, overriding the bundled setting", + Category: flags.EthCategory, + } OverrideVerkle = &cli.Uint64Flag{ Name: "override.verkle", Usage: "Manually specify the Verkle fork timestamp, overriding the bundled setting", diff --git a/core/genesis.go b/core/genesis.go index b4833ac8a6..986f2c79d8 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -218,6 +218,7 @@ func (e *GenesisMismatchError) Error() string { type ChainOverrides struct { OverrideCancun *uint64 OverrideHaber *uint64 + OverrideBohr *uint64 OverrideVerkle *uint64 } @@ -250,6 +251,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g if overrides != nil && overrides.OverrideHaber != nil { config.HaberTime = overrides.OverrideHaber } + if overrides != nil && overrides.OverrideBohr != nil { + config.BohrTime = overrides.OverrideBohr + } if overrides != nil && overrides.OverrideVerkle != nil { config.VerkleTime = overrides.OverrideVerkle } diff --git a/eth/backend.go b/eth/backend.go index 89ce49ad1d..23136d719c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -187,6 +187,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { chainConfig.HaberTime = config.OverrideHaber overrides.OverrideHaber = config.OverrideHaber } + if config.OverrideBohr != nil { + chainConfig.BohrTime = config.OverrideBohr + overrides.OverrideBohr = config.OverrideBohr + } if config.OverrideVerkle != nil { chainConfig.VerkleTime = config.OverrideVerkle overrides.OverrideVerkle = config.OverrideVerkle diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 0b69b62219..a389a52fde 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -194,6 +194,9 @@ type Config struct { // OverrideHaber (TODO: remove after the fork) OverrideHaber *uint64 `toml:",omitempty"` + // OverrideBohr (TODO: remove after the fork) + OverrideBohr *uint64 `toml:",omitempty"` + // OverrideVerkle (TODO: remove after the fork) OverrideVerkle *uint64 `toml:",omitempty"` diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 4ed328d632..26c4587fe4 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -72,6 +72,7 @@ func (c Config) MarshalTOML() (interface{}, error) { RPCTxFeeCap float64 OverrideCancun *uint64 `toml:",omitempty"` OverrideHaber *uint64 `toml:",omitempty"` + OverrideBohr *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve uint64 } @@ -131,6 +132,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.RPCTxFeeCap = c.RPCTxFeeCap enc.OverrideCancun = c.OverrideCancun enc.OverrideHaber = c.OverrideHaber + enc.OverrideBohr = c.OverrideBohr enc.OverrideVerkle = c.OverrideVerkle enc.BlobExtraReserve = c.BlobExtraReserve return &enc, nil @@ -194,6 +196,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { RPCTxFeeCap *float64 OverrideCancun *uint64 `toml:",omitempty"` OverrideHaber *uint64 `toml:",omitempty"` + OverrideBohr *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve *uint64 } @@ -366,6 +369,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverrideHaber != nil { c.OverrideHaber = dec.OverrideHaber } + if dec.OverrideBohr != nil { + c.OverrideBohr = dec.OverrideBohr + } if dec.OverrideVerkle != nil { c.OverrideVerkle = dec.OverrideVerkle } diff --git a/params/config.go b/params/config.go index 610afc470f..e8d7049c36 100644 --- a/params/config.go +++ b/params/config.go @@ -153,6 +153,7 @@ var ( FeynmanFixTime: newUint64(1713419340), // 2024-04-18 05:49:00 AM UTC CancunTime: newUint64(1718863500), // 2024-06-20 06:05:00 AM UTC HaberTime: newUint64(1718863500), // 2024-06-20 06:05:00 AM UTC + BohrTime: nil, Parlia: &ParliaConfig{ Period: 3, @@ -192,6 +193,7 @@ var ( FeynmanFixTime: newUint64(1711342800), // 2024-03-25 5:00:00 AM UTC CancunTime: newUint64(1713330442), // 2024-04-17 05:07:22 AM UTC HaberTime: newUint64(1716962820), // 2024-05-29 06:07:00 AM UTC + BohrTime: nil, Parlia: &ParliaConfig{ Period: 3, @@ -232,6 +234,7 @@ var ( FeynmanFixTime: newUint64(0), CancunTime: newUint64(0), HaberTime: newUint64(0), + BohrTime: newUint64(0), Parlia: &ParliaConfig{ Period: 3, @@ -509,6 +512,7 @@ type ChainConfig struct { FeynmanFixTime *uint64 `json:"feynmanFixTime,omitempty"` // FeynmanFix switch time (nil = no fork, 0 = already activated) CancunTime *uint64 `json:"cancunTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun) HaberTime *uint64 `json:"haberTime,omitempty"` // Haber switch time (nil = no fork, 0 = already on haber) + BohrTime *uint64 `json:"bohrTime,omitempty"` // Bohr switch time (nil = no fork, 0 = already on bohr) PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague) VerkleTime *uint64 `json:"verkleTime,omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle) @@ -619,7 +623,12 @@ func (c *ChainConfig) String() string { HaberTime = big.NewInt(0).SetUint64(*c.HaberTime) } - 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, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime: %v, FeynmanTime: %v, FeynmanFixTime: %v, CancunTime: %v, HaberTime: %v, Engine: %v}", + var BohrTime *big.Int + if c.BohrTime != nil { + BohrTime = big.NewInt(0).SetUint64(*c.BohrTime) + } + + 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, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime: %v, FeynmanTime: %v, FeynmanFixTime: %v, CancunTime: %v, HaberTime: %v, BohrTime: %v, Engine: %v}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -657,6 +666,7 @@ func (c *ChainConfig) String() string { FeynmanFixTime, CancunTime, HaberTime, + BohrTime, engine, ) } @@ -929,6 +939,20 @@ func (c *ChainConfig) IsHaber(num *big.Int, time uint64) bool { return c.IsLondon(num) && isTimestampForked(c.HaberTime, time) } +// IsBohr returns whether time is either equal to the Bohr fork time or greater. +func (c *ChainConfig) IsBohr(num *big.Int, time uint64) bool { + return c.IsLondon(num) && isTimestampForked(c.BohrTime, time) +} + +// IsOnBohr returns whether currentBlockTime is either equal to the Bohr fork time or greater firstly. +func (c *ChainConfig) IsOnBohr(currentBlockNumber *big.Int, lastBlockTime uint64, currentBlockTime uint64) bool { + lastBlockNumber := new(big.Int) + if currentBlockNumber.Cmp(big.NewInt(1)) >= 0 { + lastBlockNumber.Sub(currentBlockNumber, big.NewInt(1)) + } + return !c.IsBohr(lastBlockNumber, lastBlockTime) && c.IsBohr(currentBlockNumber, currentBlockTime) +} + // IsPrague returns whether num is either equal to the Prague fork time or greater. func (c *ChainConfig) IsPrague(num *big.Int, time uint64) bool { return c.IsLondon(num) && isTimestampForked(c.PragueTime, time) @@ -993,6 +1017,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "feynmanFixTime", timestamp: c.FeynmanFixTime}, {name: "cancunTime", timestamp: c.CancunTime}, {name: "haberTime", timestamp: c.HaberTime}, + {name: "bohrTime", timestamp: c.BohrTime}, {name: "pragueTime", timestamp: c.PragueTime, optional: true}, {name: "verkleTime", timestamp: c.VerkleTime, optional: true}, } { @@ -1323,7 +1348,7 @@ type Rules struct { IsHertz bool IsHertzfix bool IsShanghai, IsKepler, IsFeynman, IsCancun, IsHaber bool - IsPrague, IsVerkle bool + IsBohr, IsPrague, IsVerkle bool } // Rules ensures c's ChainID is not nil. @@ -1359,6 +1384,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsFeynman: c.IsFeynman(num, timestamp), IsCancun: c.IsCancun(num, timestamp), IsHaber: c.IsHaber(num, timestamp), + IsBohr: c.IsBohr(num, timestamp), IsPrague: c.IsPrague(num, timestamp), IsVerkle: c.IsVerkle(num, timestamp), }