From de1ba89732404567f85b4cc7ca91fbd08d78de7c Mon Sep 17 00:00:00 2001 From: buddh0 Date: Wed, 24 Jul 2024 19:22:47 +0800 Subject: [PATCH] cmd/utils: add new flag OverridePassedForkTime --- cmd/geth/chaincmd.go | 5 +++++ cmd/geth/config.go | 4 ++++ cmd/geth/main.go | 1 + cmd/utils/flags.go | 5 +++++ core/genesis.go | 14 ++++++++++++-- eth/backend.go | 10 ++++++++++ eth/ethconfig/config.go | 3 +++ eth/ethconfig/gen_config.go | 6 ++++++ 8 files changed, 46 insertions(+), 2 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index afcb474848..870527434d 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -62,6 +62,7 @@ var ( ArgsUsage: "", Flags: flags.Merge([]cli.Flag{ utils.CachePreimagesFlag, + utils.OverridePassedForkTime, utils.OverrideBohr, utils.OverrideVerkle, utils.MultiDataBaseFlag, @@ -253,6 +254,10 @@ func initGenesis(ctx *cli.Context) error { defer stack.Close() var overrides core.ChainOverrides + if ctx.IsSet(utils.OverridePassedForkTime.Name) { + v := ctx.Uint64(utils.OverridePassedForkTime.Name) + overrides.OverridePassedForkTime = &v + } if ctx.IsSet(utils.OverrideBohr.Name) { v := ctx.Uint64(utils.OverrideBohr.Name) overrides.OverrideBohr = &v diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 6d4875ccf4..5c829a2f76 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -185,6 +185,10 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { params.RialtoGenesisHash = common.HexToHash(v) } + if ctx.IsSet(utils.OverridePassedForkTime.Name) { + v := ctx.Uint64(utils.OverridePassedForkTime.Name) + cfg.Eth.OverridePassedForkTime = &v + } if ctx.IsSet(utils.OverrideBohr.Name) { v := ctx.Uint64(utils.OverrideBohr.Name) cfg.Eth.OverrideBohr = &v diff --git a/cmd/geth/main.go b/cmd/geth/main.go index dd1caaccd0..a851c8d373 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -72,6 +72,7 @@ var ( utils.USBFlag, utils.SmartCardDaemonPathFlag, utils.RialtoHash, + utils.OverridePassedForkTime, utils.OverrideBohr, utils.OverrideVerkle, utils.OverrideFullImmutabilityThreshold, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index b573b48bb7..049908857f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -305,6 +305,11 @@ var ( Usage: "Manually specify the Rialto Genesis Hash, to trigger builtin network logic", Category: flags.EthCategory, } + OverridePassedForkTime = &cli.Uint64Flag{ + Name: "override.passedforktime", + Usage: "Manually specify the hard fork timestamp except the last one, overriding the bundled setting", + Category: flags.EthCategory, + } OverrideBohr = &cli.Uint64Flag{ Name: "override.bohr", Usage: "Manually specify the Bohr fork timestamp, overriding the bundled setting", diff --git a/core/genesis.go b/core/genesis.go index 544d7104f4..60d45f86ae 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -216,8 +216,9 @@ func (e *GenesisMismatchError) Error() string { // ChainOverrides contains the changes to chain config // Typically, these modifications involve hardforks that are not enabled on the BSC mainnet, intended for testing purposes. type ChainOverrides struct { - OverrideBohr *uint64 - OverrideVerkle *uint64 + OverridePassedForkTime *uint64 + OverrideBohr *uint64 + OverrideVerkle *uint64 } // SetupGenesisBlock writes or updates the genesis block in db. @@ -243,6 +244,15 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g } applyOverrides := func(config *params.ChainConfig) { if config != nil { + if overrides != nil && overrides.OverridePassedForkTime != nil { + config.ShanghaiTime = overrides.OverridePassedForkTime + config.KeplerTime = overrides.OverridePassedForkTime + config.FeynmanTime = overrides.OverridePassedForkTime + config.FeynmanFixTime = overrides.OverridePassedForkTime + config.CancunTime = overrides.OverridePassedForkTime + config.HaberTime = overrides.OverridePassedForkTime + config.HaberFixTime = overrides.OverridePassedForkTime + } if overrides != nil && overrides.OverrideBohr != nil { config.BohrTime = overrides.OverrideBohr } diff --git a/eth/backend.go b/eth/backend.go index aa0b90e49c..0d434a9130 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -185,6 +185,16 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { } // Override the chain config with provided settings. var overrides core.ChainOverrides + if config.OverridePassedForkTime != nil { + chainConfig.ShanghaiTime = config.OverridePassedForkTime + chainConfig.KeplerTime = config.OverridePassedForkTime + chainConfig.FeynmanTime = config.OverridePassedForkTime + chainConfig.FeynmanFixTime = config.OverridePassedForkTime + chainConfig.CancunTime = config.OverridePassedForkTime + chainConfig.HaberTime = config.OverridePassedForkTime + chainConfig.HaberFixTime = config.OverridePassedForkTime + overrides.OverridePassedForkTime = config.OverridePassedForkTime + } if config.OverrideBohr != nil { chainConfig.BohrTime = config.OverrideBohr overrides.OverrideBohr = config.OverrideBohr diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index b9c8fce918..4bda880fce 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -188,6 +188,9 @@ type Config struct { // send-transaction variants. The unit is ether. RPCTxFeeCap float64 + // OverridePassedForkTime + OverridePassedForkTime *uint64 `toml:",omitempty"` + // OverrideBohr (TODO: remove after the fork) OverrideBohr *uint64 `toml:",omitempty"` diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 44066e423f..f23df3aefe 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -70,6 +70,7 @@ func (c Config) MarshalTOML() (interface{}, error) { RPCGasCap uint64 RPCEVMTimeout time.Duration RPCTxFeeCap float64 + OverridePassedForkTime *uint64 `toml:",omitempty"` OverrideBohr *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve uint64 @@ -128,6 +129,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.RPCGasCap = c.RPCGasCap enc.RPCEVMTimeout = c.RPCEVMTimeout enc.RPCTxFeeCap = c.RPCTxFeeCap + enc.OverridePassedForkTime = c.OverridePassedForkTime enc.OverrideBohr = c.OverrideBohr enc.OverrideVerkle = c.OverrideVerkle enc.BlobExtraReserve = c.BlobExtraReserve @@ -190,6 +192,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { RPCGasCap *uint64 RPCEVMTimeout *time.Duration RPCTxFeeCap *float64 + OverridePassedForkTime *uint64 `toml:",omitempty"` OverrideBohr *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve *uint64 @@ -357,6 +360,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.RPCTxFeeCap != nil { c.RPCTxFeeCap = *dec.RPCTxFeeCap } + if dec.OverridePassedForkTime != nil { + c.OverridePassedForkTime = dec.OverridePassedForkTime + } if dec.OverrideBohr != nil { c.OverrideBohr = dec.OverrideBohr }