Skip to content

Commit

Permalink
Gingerbread P2 (#2172)
Browse files Browse the repository at this point in the history
Flags and block variable for the second part of the gingerbread hard fork
  • Loading branch information
gastonponti authored Aug 11, 2023
1 parent fc20d69 commit b77d52a
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 27 deletions.
3 changes: 3 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var (
utils.USBFlag,
// utils.SmartCardDaemonPathFlag,
utils.OverrideGingerbreadFlag,
utils.OverrideGingerbreadP2Flag,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
utils.TxPoolJournalFlag,
Expand Down
13 changes: 13 additions & 0 deletions cmd/mycelo/genesis_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions miner/stress/1559/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
18 changes: 10 additions & 8 deletions mycelo/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &params.IstanbulConfig{
Epoch: cfg.Istanbul.Epoch,
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions mycelo/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 29 additions & 10 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var (
DonutBlock: big.NewInt(6774000),
EspressoBlock: big.NewInt(11838440),
GingerbreadBlock: nil,
GingerbreadP2Block: nil,
Istanbul: &IstanbulConfig{
Epoch: 17280,
ProposerPolicy: 2,
Expand All @@ -92,6 +93,7 @@ var (
DonutBlock: big.NewInt(5002000),
EspressoBlock: big.NewInt(9195000),
GingerbreadBlock: nil,
GingerbreadP2Block: nil,
Istanbul: &IstanbulConfig{
Epoch: 17280,
ProposerPolicy: 2,
Expand All @@ -118,6 +120,7 @@ var (
DonutBlock: big.NewInt(4960000),
EspressoBlock: big.NewInt(9472000),
GingerbreadBlock: nil,
GingerbreadP2Block: nil,
Istanbul: &IstanbulConfig{
Epoch: 17280,
ProposerPolicy: 2,
Expand Down Expand Up @@ -145,10 +148,11 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),

ChurritoBlock: big.NewInt(0),
DonutBlock: big.NewInt(0),
EspressoBlock: big.NewInt(0),
GingerbreadBlock: big.NewInt(0),
ChurritoBlock: big.NewInt(0),
DonutBlock: big.NewInt(0),
EspressoBlock: big.NewInt(0),
GingerbreadBlock: big.NewInt(0),
GingerbreadP2Block: big.NewInt(0),

Istanbul: &IstanbulConfig{
Epoch: 30000,
Expand Down Expand Up @@ -251,10 +255,11 @@ type ChainConfig struct {
// MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
// BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin)
// LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london)
ChurritoBlock *big.Int `json:"churritoBlock,omitempty"` // Churrito switch block (nil = no fork, 0 = already activated)
DonutBlock *big.Int `json:"donutBlock,omitempty"` // Donut switch block (nil = no fork, 0 = already activated)
EspressoBlock *big.Int `json:"espressoBlock,omitempty"` // Espresso switch block (nil = no fork, 0 = already activated)
GingerbreadBlock *big.Int `json:"gingerbreadBlock,omitempty"` // Gingerbread switch block (nil = no fork, 0 = already activated)
ChurritoBlock *big.Int `json:"churritoBlock,omitempty"` // Churrito switch block (nil = no fork, 0 = already activated)
DonutBlock *big.Int `json:"donutBlock,omitempty"` // Donut switch block (nil = no fork, 0 = already activated)
EspressoBlock *big.Int `json:"espressoBlock,omitempty"` // Espresso switch block (nil = no fork, 0 = already activated)
GingerbreadBlock *big.Int `json:"gingerbreadBlock,omitempty"` // Gingerbread switch block (nil = no fork, 0 = already activated)
GingerbreadP2Block *big.Int `json:"gingerbreadP2Block,omitempty"` // GingerbreadP2 switch block (nil = no fork, 0 = already activated)

Istanbul *IstanbulConfig `json:"istanbul,omitempty"`
// This does not belong here but passing it to every function is not possible since that breaks
Expand Down Expand Up @@ -297,7 +302,7 @@ func (c *ChainConfig) String() string {
} else {
engine = "MockEngine"
}
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, Engine: %v}",
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}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand All @@ -316,6 +321,7 @@ func (c *ChainConfig) String() string {
c.DonutBlock,
c.EspressoBlock,
c.GingerbreadBlock,
c.GingerbreadP2Block,
engine,
)
}
Expand Down Expand Up @@ -399,6 +405,11 @@ func (c *ChainConfig) IsGingerbread(num *big.Int) bool {
return isForked(c.GingerbreadBlock, num)
}

// IsGingerbreadP2 returns whether num represents a block number after the GingerbreadP2 fork
func (c *ChainConfig) IsGingerbreadP2(num *big.Int) bool {
return isForked(c.GingerbreadP2Block, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -439,6 +450,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "donutBlock", block: c.DonutBlock},
{name: "espressoBlock", block: c.EspressoBlock},
{name: "gingerbreadBlock", block: c.GingerbreadBlock},
{name: "gingerbreadP2Block", block: c.GingerbreadP2Block},
} {
if lastFork.name != "" {
// Next one must be higher number
Expand Down Expand Up @@ -516,6 +528,9 @@ func (c *ChainConfig) checkCeloCompatible(newcfg *ChainConfig, head *big.Int) *C
if isForkIncompatible(c.GingerbreadBlock, newcfg.GingerbreadBlock, head) {
return newCompatError("Gingerbread fork block", c.GingerbreadBlock, newcfg.GingerbreadBlock)
}
if isForkIncompatible(c.GingerbreadP2Block, newcfg.GingerbreadP2Block, head) {
return newCompatError("Gingerbread p2 fork block", c.GingerbreadP2Block, newcfg.GingerbreadP2Block)
}
return nil
}

Expand Down Expand Up @@ -584,7 +599,8 @@ type Rules struct {
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon bool
IsChurrito, IsDonut, IsEspresso, IsGingerbread bool
IsChurrito, IsDonut, IsEspresso bool
IsGingerbread, IsGingerbreadP2 bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -609,6 +625,7 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
IsDonut: c.IsDonut(num),
IsEspresso: c.IsEspresso(num),
IsGingerbread: c.IsGingerbread(num),
IsGingerbreadP2: c.IsGingerbreadP2(num),
}
}

Expand All @@ -629,6 +646,7 @@ func (c *ChainConfig) OverrideChainIdConfig(chainId *big.Int) *ChainConfig {

func (c *ChainConfig) DisableGingerbread() *ChainConfig {
c.GingerbreadBlock = nil
c.GingerbreadP2Block = nil
return c
}

Expand All @@ -650,6 +668,7 @@ func (c *ChainConfig) DeepCopy() *ChainConfig {
DonutBlock: copyBigIntOrNil(c.DonutBlock),
EspressoBlock: copyBigIntOrNil(c.EspressoBlock),
GingerbreadBlock: copyBigIntOrNil(c.GingerbreadBlock),
GingerbreadP2Block: copyBigIntOrNil(c.GingerbreadP2Block),

Istanbul: &IstanbulConfig{
Epoch: c.Istanbul.Epoch,
Expand Down
16 changes: 16 additions & 0 deletions tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b77d52a

Please sign in to comment.