From 27f67a5210b939c135829b2bacfd7c4e9fa14171 Mon Sep 17 00:00:00 2001 From: buddho Date: Mon, 23 Sep 2024 17:53:32 +0800 Subject: [PATCH] feat: add Prague hardfork (#2718) --- 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 | 16 +++++++++++++--- 9 files changed, 45 insertions(+), 3 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 0433c9d051..ff6e52ed27 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -65,6 +65,7 @@ var ( utils.OverridePassedForkTime, utils.OverrideBohr, utils.OverridePascal, + utils.OverridePrague, utils.OverrideVerkle, utils.MultiDataBaseFlag, }, utils.DatabaseFlags), @@ -267,6 +268,10 @@ func initGenesis(ctx *cli.Context) error { v := ctx.Uint64(utils.OverridePascal.Name) overrides.OverridePascal = &v } + if ctx.IsSet(utils.OverridePrague.Name) { + v := ctx.Uint64(utils.OverridePrague.Name) + overrides.OverridePrague = &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 44f57f5d95..4be0ff6655 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -199,6 +199,10 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { v := ctx.Uint64(utils.OverridePascal.Name) cfg.Eth.OverridePascal = &v } + if ctx.IsSet(utils.OverridePrague.Name) { + v := ctx.Uint64(utils.OverridePrague.Name) + cfg.Eth.OverridePrague = &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 47b7b99e81..e5e954cb8b 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -75,6 +75,7 @@ var ( utils.OverridePassedForkTime, utils.OverrideBohr, utils.OverridePascal, + utils.OverridePrague, utils.OverrideVerkle, utils.OverrideFullImmutabilityThreshold, utils.OverrideMinBlocksForBlobRequests, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index ff16a6b0f4..858f396901 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -323,6 +323,11 @@ var ( Usage: "Manually specify the Pascal fork timestamp, overriding the bundled setting", Category: flags.EthCategory, } + OverridePrague = &cli.Uint64Flag{ + Name: "override.prague", + Usage: "Manually specify the Prague 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 e88f4120fc..02d27031fd 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -219,6 +219,7 @@ type ChainOverrides struct { OverridePassedForkTime *uint64 OverrideBohr *uint64 OverridePascal *uint64 + OverridePrague *uint64 OverrideVerkle *uint64 } @@ -260,6 +261,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g if overrides != nil && overrides.OverridePascal != nil { config.PascalTime = overrides.OverridePascal } + if overrides != nil && overrides.OverridePrague != nil { + config.PragueTime = overrides.OverridePrague + } if overrides != nil && overrides.OverrideVerkle != nil { config.VerkleTime = overrides.OverrideVerkle } diff --git a/eth/backend.go b/eth/backend.go index 62c129ab84..930924e7a6 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -203,6 +203,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { chainConfig.PascalTime = config.OverridePascal overrides.OverridePascal = config.OverridePascal } + if config.OverridePrague != nil { + chainConfig.PragueTime = config.OverridePrague + overrides.OverridePrague = config.OverridePrague + } 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 96ce8f5ddc..e40ec440cf 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -197,6 +197,9 @@ type Config struct { // OverridePascal (TODO: remove after the fork) OverridePascal *uint64 `toml:",omitempty"` + // OverridePrague (TODO: remove after the fork) + OverridePrague *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 e1293c89f0..bfad53a4d2 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -73,6 +73,7 @@ func (c Config) MarshalTOML() (interface{}, error) { OverridePassedForkTime *uint64 `toml:",omitempty"` OverrideBohr *uint64 `toml:",omitempty"` OverridePascal *uint64 `toml:",omitempty"` + OverridePrague *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve uint64 } @@ -133,6 +134,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.OverridePassedForkTime = c.OverridePassedForkTime enc.OverrideBohr = c.OverrideBohr enc.OverridePascal = c.OverridePascal + enc.OverridePrague = c.OverridePrague enc.OverrideVerkle = c.OverrideVerkle enc.BlobExtraReserve = c.BlobExtraReserve return &enc, nil @@ -197,6 +199,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { OverridePassedForkTime *uint64 `toml:",omitempty"` OverrideBohr *uint64 `toml:",omitempty"` OverridePascal *uint64 `toml:",omitempty"` + OverridePrague *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve *uint64 } @@ -372,6 +375,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverridePascal != nil { c.OverridePascal = dec.OverridePascal } + if dec.OverridePrague != nil { + c.OverridePrague = dec.OverridePrague + } if dec.OverrideVerkle != nil { c.OverrideVerkle = dec.OverrideVerkle } diff --git a/params/config.go b/params/config.go index f768c0517f..1c07b294cf 100644 --- a/params/config.go +++ b/params/config.go @@ -157,6 +157,7 @@ var ( BohrTime: newUint64(1727317200), // 2024-09-26 02:20:00 AM UTC // TODO PascalTime: nil, + PragueTime: nil, Parlia: &ParliaConfig{ Period: 3, @@ -200,6 +201,7 @@ var ( BohrTime: newUint64(1724116996), // 2024-08-20 01:23:16 AM UTC // TODO PascalTime: nil, + PragueTime: nil, Parlia: &ParliaConfig{ Period: 3, @@ -244,6 +246,7 @@ var ( BohrTime: newUint64(0), // TODO PascalTime: newUint64(0), + PragueTime: newUint64(0), Parlia: &ParliaConfig{ Period: 3, @@ -649,7 +652,12 @@ func (c *ChainConfig) String() string { PascalTime = big.NewInt(0).SetUint64(*c.PascalTime) } - 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, HaberFixTime: %v, BohrTime: %v, PascalTime: %v, Engine: %v}", + var PragueTime *big.Int + if c.PragueTime != nil { + PragueTime = big.NewInt(0).SetUint64(*c.PragueTime) + } + + 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, HaberFixTime: %v, BohrTime: %v, PascalTime: %v, PragueTime: %v, Engine: %v}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -690,6 +698,7 @@ func (c *ChainConfig) String() string { HaberFixTime, BohrTime, PascalTime, + PragueTime, engine, ) } @@ -1071,7 +1080,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "haberFixTime", timestamp: c.HaberFixTime}, {name: "bohrTime", timestamp: c.BohrTime}, {name: "pascalTime", timestamp: c.PascalTime}, - {name: "pragueTime", timestamp: c.PragueTime, optional: true}, + {name: "pragueTime", timestamp: c.PragueTime}, {name: "verkleTime", timestamp: c.VerkleTime, optional: true}, } { if lastFork.name != "" { @@ -1413,7 +1422,7 @@ type Rules struct { IsHertz bool IsHertzfix bool IsShanghai, IsKepler, IsFeynman, IsCancun, IsHaber bool - IsBohr, IsPrague, IsVerkle bool + IsBohr, IsPascal, IsPrague, IsVerkle bool } // Rules ensures c's ChainID is not nil. @@ -1450,6 +1459,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsCancun: c.IsCancun(num, timestamp), IsHaber: c.IsHaber(num, timestamp), IsBohr: c.IsBohr(num, timestamp), + IsPascal: c.IsPascal(num, timestamp), IsPrague: c.IsPrague(num, timestamp), IsVerkle: c.IsVerkle(num, timestamp), }