diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 616daac214..e9e5df7fd4 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -161,6 +161,9 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { 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)) + } backend, _ := utils.RegisterEthService(stack, &cfg.Eth) // Configure GraphQL if requested diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b0438d87e6..0e2c964717 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -74,6 +74,7 @@ var ( utils.USBFlag, // utils.SmartCardDaemonPathFlag, utils.OverrideGingerbreadFlag, + utils.OverrideGingerbreadP2Flag, utils.TxPoolLocalsFlag, utils.TxPoolNoLocalsFlag, utils.TxPoolJournalFlag, diff --git a/cmd/mycelo/genesis_commands.go b/cmd/mycelo/genesis_commands.go index 1f738bccc1..d5d34f9098 100644 --- a/cmd/mycelo/genesis_commands.go +++ b/cmd/mycelo/genesis_commands.go @@ -58,6 +58,10 @@ var templateFlags = []cli.Flag{ Name: "forks.gingerbread", Usage: "Optional flag to allow gingerbread fork overwritting (default: 0, disable: -1)", }, + cli.Int64Flag{ + Name: "forks.gingerbreadp2", + Usage: "Optional flag to allow gingerbread p2 fork overwritting (default: 0, disable: -1)", + }, } var buildpathFlag = cli.StringFlag{ @@ -183,6 +187,15 @@ func envFromTemplate(ctx *cli.Context, workdir string) (*env.Environment, *genes genesisConfig.Hardforks.GingerbreadBlock = gingerbreadBlock + if ctx.IsSet("forks.gingerbreadp2") { + gingerbreadP2BlockNumber := ctx.Int64("forks.gingerbreadp2") + if gingerbreadP2BlockNumber < 0 { + genesisConfig.Hardforks.GingerbreadP2Block = nil + } else { + genesisConfig.Hardforks.GingerbreadP2Block = big.NewInt(gingerbreadP2BlockNumber) + } + } + return env, genesisConfig, nil } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a89f999e03..549f5e10bc 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -243,6 +243,11 @@ var ( 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", + } + BloomFilterSizeFlag = cli.Uint64Flag{ Name: "bloomfilter.size", Usage: "Megabytes of memory allocated to bloom-filter for pruning", diff --git a/core/genesis.go b/core/genesis.go index ed9784f7dd..538d3d7c88 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -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) + return SetupGenesisBlockWithOverride(db, genesis, nil, nil) } -func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideGingerbread *big.Int) (*params.ChainConfig, common.Hash, error) { +func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideGingerbread, overrideGingerbreadP2 *big.Int) (*params.ChainConfig, common.Hash, error) { if genesis != nil && (genesis.Config == nil || genesis.Config.Istanbul == nil) { return params.MainnetChainConfig, common.Hash{}, errGenesisNoConfig } @@ -207,6 +207,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override if overrideGingerbread != nil { newcfg.GingerbreadBlock = overrideGingerbread } + if overrideGingerbreadP2 != nil { + newcfg.GingerbreadP2Block = overrideGingerbreadP2 + } if err := newcfg.CheckConfigForkOrder(); err != nil { return newcfg, common.Hash{}, err diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 005cd276ef..bf0336053e 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -52,6 +52,7 @@ func TestStateProcessorErrors(t *testing.T) { DonutBlock: big.NewInt(0), EspressoBlock: big.NewInt(0), GingerbreadBlock: big.NewInt(0), + GingerbreadP2Block: big.NewInt(0), Faker: true, FakeBaseFee: common.Big3, } diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 5c406f7e70..894c9b71b0 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -74,7 +74,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter { if cfg.JumpTable[STOP] == nil { var jt JumpTable switch { - case evm.chainRules.IsGingerbread: + case evm.chainRules.IsGingerbread, evm.chainRules.IsGingerbreadP2: jt = gingerbreadInstructionSet case evm.chainRules.IsEspresso: jt = espressoInstructionSet diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 1780c60115..315add0500 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -68,6 +68,7 @@ func setDefaults(cfg *Config) { DonutBlock: new(big.Int), EspressoBlock: new(big.Int), GingerbreadBlock: new(big.Int), + GingerbreadP2Block: new(big.Int), } } if cfg.Time == nil { diff --git a/eth/backend.go b/eth/backend.go index 9b1d466b31..2fca8aa29c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -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) + chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideGingerbread, config.OverrideGingerbreadP2) if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { return nil, genesisErr } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 4d5be4234f..ee9d5a3007 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -165,6 +165,9 @@ type Config struct { // 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"` + // The minimum required peers in order for syncing to be initiated, if left // at 0 then the default will be used. MinSyncPeers int `toml:",omitempty"` diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index e8207f7220..e4c5b72adb 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -64,6 +64,7 @@ func (c Config) MarshalTOML() (interface{}, error) { Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` OverrideGingerbread *big.Int `toml:",omitempty"` + OverrideGingerbreadP2 *big.Int `toml:",omitempty"` MinSyncPeers int `toml:",omitempty"` } var enc Config @@ -114,6 +115,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.Checkpoint = c.Checkpoint enc.CheckpointOracle = c.CheckpointOracle enc.OverrideGingerbread = c.OverrideGingerbread + enc.OverrideGingerbreadP2 = c.OverrideGingerbreadP2 enc.MinSyncPeers = c.MinSyncPeers return &enc, nil } @@ -168,6 +170,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` OverrideGingerbread *big.Int `toml:",omitempty"` + OverrideGingerbreadP2 *big.Int `toml:",omitempty"` MinSyncPeers *int `toml:",omitempty"` } var dec Config @@ -315,6 +318,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverrideGingerbread != nil { c.OverrideGingerbread = dec.OverrideGingerbread } + if dec.OverrideGingerbreadP2 != nil { + c.OverrideGingerbreadP2 = dec.OverrideGingerbreadP2 + } if dec.MinSyncPeers != nil { c.MinSyncPeers = *dec.MinSyncPeers } diff --git a/les/client.go b/les/client.go index 756155479f..c1b700166b 100644 --- a/les/client.go +++ b/les/client.go @@ -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.OverrideGingerbread, config.OverrideGingerbreadP2) if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat { return nil, genesisErr } diff --git a/miner/stress/1559/main.go b/miner/stress/1559/main.go index a89a140fea..dc0f1c0b75 100644 --- a/miner/stress/1559/main.go +++ b/miner/stress/1559/main.go @@ -185,6 +185,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis { genesis.Config = params.BaklavaChainConfig genesis.Config.GingerbreadBlock = gingerbreadBlock + genesis.Config.GingerbreadP2Block = gingerbreadBlock genesis.Config.ChainID = big.NewInt(18) genesis.Config.EIP150Hash = common.Hash{} diff --git a/mycelo/genesis/config.go b/mycelo/genesis/config.go index ef9178a8f9..f5621e4b3e 100644 --- a/mycelo/genesis/config.go +++ b/mycelo/genesis/config.go @@ -82,10 +82,11 @@ func (cfg *Config) ChainConfig() *params.ChainConfig { PetersburgBlock: common.Big0, IstanbulBlock: common.Big0, - ChurritoBlock: cfg.Hardforks.ChurritoBlock, - DonutBlock: cfg.Hardforks.DonutBlock, - EspressoBlock: cfg.Hardforks.EspressoBlock, - GingerbreadBlock: cfg.Hardforks.GingerbreadBlock, + ChurritoBlock: cfg.Hardforks.ChurritoBlock, + DonutBlock: cfg.Hardforks.DonutBlock, + EspressoBlock: cfg.Hardforks.EspressoBlock, + GingerbreadBlock: cfg.Hardforks.GingerbreadBlock, + GingerbreadP2Block: cfg.Hardforks.GingerbreadP2Block, Istanbul: ¶ms.IstanbulConfig{ Epoch: cfg.Istanbul.Epoch, @@ -99,10 +100,11 @@ func (cfg *Config) ChainConfig() *params.ChainConfig { // HardforkConfig contains celo hardforks activation blocks type HardforkConfig struct { - ChurritoBlock *big.Int `json:"churritoBlock"` - DonutBlock *big.Int `json:"donutBlock"` - EspressoBlock *big.Int `json:"espressoBlock"` - GingerbreadBlock *big.Int `json:"gingerbreadBlock"` + ChurritoBlock *big.Int `json:"churritoBlock"` + DonutBlock *big.Int `json:"donutBlock"` + EspressoBlock *big.Int `json:"espressoBlock"` + GingerbreadBlock *big.Int `json:"gingerbreadBlock"` + GingerbreadP2Block *big.Int `json:"gingerbreadP2Block"` } // MultiSigParameters are the initial configuration parameters for a MultiSig contract diff --git a/mycelo/genesis/genesis.go b/mycelo/genesis/genesis.go index b017cc7c86..c81029e440 100644 --- a/mycelo/genesis/genesis.go +++ b/mycelo/genesis/genesis.go @@ -37,10 +37,11 @@ func CreateCommonGenesisConfig(chainID *big.Int, adminAccountAddress common.Addr genesisConfig.GenesisTimestamp = uint64(time.Now().Unix()) genesisConfig.Istanbul = istanbulConfig genesisConfig.Hardforks = HardforkConfig{ - ChurritoBlock: common.Big0, - DonutBlock: common.Big0, - EspressoBlock: common.Big0, - GingerbreadBlock: gingerbreadBlock, + ChurritoBlock: common.Big0, + DonutBlock: common.Big0, + EspressoBlock: common.Big0, + GingerbreadBlock: gingerbreadBlock, + GingerbreadP2Block: gingerbreadBlock, } // Make admin account manager of Governance & Reserve diff --git a/params/config.go b/params/config.go index 122e4d870e..01b46ea093 100644 --- a/params/config.go +++ b/params/config.go @@ -646,6 +646,7 @@ func (c *ChainConfig) OverrideChainIdConfig(chainId *big.Int) *ChainConfig { func (c *ChainConfig) DisableGingerbread() *ChainConfig { c.GingerbreadBlock = nil + c.GingerbreadP2Block = nil return c } diff --git a/tests/init.go b/tests/init.go index 1c0b2f8925..bd52b72888 100644 --- a/tests/init.go +++ b/tests/init.go @@ -185,6 +185,22 @@ var Forks = map[string]*params.ChainConfig{ EspressoBlock: big.NewInt(0), GingerbreadBlock: big.NewInt(0), }, + "GingerbreadP2": { + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + ChurritoBlock: big.NewInt(0), + DonutBlock: big.NewInt(0), + EspressoBlock: big.NewInt(0), + GingerbreadBlock: big.NewInt(0), + GingerbreadP2Block: big.NewInt(0), + }, } // Returns the set of defined fork names