Skip to content

Commit

Permalink
Add Cel2 hardfork
Browse files Browse the repository at this point in the history
This will be the hardfork used to enable all Celo
related features in the op-geth.
  • Loading branch information
palango committed Sep 15, 2023
1 parent 1d173bb commit 3fc33dd
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
v := ctx.Uint64(utils.OverrideOptimismRegolith.Name)
cfg.Eth.OverrideOptimismRegolith = &v
}
if ctx.IsSet(utils.OverrideOptimismCel2.Name) {
v := ctx.Uint64(utils.OverrideOptimismCel2.Name)
cfg.Eth.OverrideOptimismCel2 = &v
}
if ctx.IsSet(utils.OverrideOptimism.Name) {
override := ctx.Bool(utils.OverrideOptimism.Name)
cfg.Eth.OverrideOptimism = &override
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var (
utils.EnablePersonal,
utils.OverrideOptimismBedrock,
utils.OverrideOptimismRegolith,
utils.OverrideOptimismCel2,
utils.OverrideOptimism,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
Expand Down
9 changes: 7 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,17 @@ var (
}
OverrideOptimismBedrock = &flags.BigFlag{
Name: "override.bedrock",
Usage: "Manually specify OptimsimBedrock, overriding the bundled setting",
Usage: "Manually specify OptimismBedrock, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideOptimismRegolith = &flags.BigFlag{
Name: "override.regolith",
Usage: "Manually specify the OptimsimRegolith fork timestamp, overriding the bundled setting",
Usage: "Manually specify the OptimismRegolith fork timestamp, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideOptimismCel2 = &flags.BigFlag{
Name: "override.cel2",
Usage: "Manually specify the OptimismCel2 fork timestamp, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideOptimism = &cli.BoolFlag{
Expand Down
4 changes: 4 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ type ChainOverrides struct {
// optimism
OverrideOptimismBedrock *big.Int
OverrideOptimismRegolith *uint64
OverrideOptimismCel2 *uint64
OverrideOptimism *bool
}

Expand Down Expand Up @@ -319,6 +320,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
if overrides != nil && overrides.OverrideOptimismRegolith != nil {
config.RegolithTime = overrides.OverrideOptimismRegolith
}
if overrides != nil && overrides.OverrideOptimismCel2 != nil {
config.Cel2Time = overrides.OverrideOptimismCel2
}
if overrides != nil && overrides.OverrideOptimism != nil {
if *overrides.OverrideOptimism {
config.Optimism = &params.OptimismConfig{
Expand Down
3 changes: 3 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if config.OverrideOptimismRegolith != nil {
overrides.OverrideOptimismRegolith = config.OverrideOptimismRegolith
}
if config.OverrideOptimismCel2 != nil {
overrides.OverrideOptimismCel2 = config.OverrideOptimismCel2
}
if config.OverrideOptimism != nil {
overrides.OverrideOptimism = config.OverrideOptimism
}
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type Config struct {

OverrideOptimismBedrock *big.Int
OverrideOptimismRegolith *uint64 `toml:",omitempty"`
OverrideOptimismCel2 *uint64 `toml:",omitempty"`
OverrideOptimism *bool

RollupSequencerHTTP string
Expand Down
12 changes: 12 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ type ChainConfig struct {
BedrockBlock *big.Int `json:"bedrockBlock,omitempty"` // Bedrock switch block (nil = no fork, 0 = already on optimism bedrock)
RegolithTime *uint64 `json:"regolithTime,omitempty"` // Regolith switch time (nil = no fork, 0 = already on optimism regolith)

Cel2Time *uint64 `json:"cel2Time,omitempty"` // Cel2 switch time (nil = no fork, 0 = already on optimism cel2)

// TerminalTotalDifficulty is the amount of total difficulty reached by
// the network that triggers the consensus upgrade.
TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"`
Expand Down Expand Up @@ -454,6 +456,9 @@ func (c *ChainConfig) Description() string {
if c.RegolithTime != nil {
banner += fmt.Sprintf(" - Regolith: @%-10v\n", *c.RegolithTime)
}
if c.Cel2Time != nil {
banner += fmt.Sprintf(" - Cel2: @%-10v\n", *c.Cel2Time)
}
return banner
}

Expand Down Expand Up @@ -561,6 +566,10 @@ func (c *ChainConfig) IsRegolith(time uint64) bool {
return isTimestampForked(c.RegolithTime, time)
}

func (c *ChainConfig) IsCel2(time uint64) bool {
return isTimestampForked(c.Cel2Time, time)
}

// IsOptimism returns whether the node is an optimism node or not.
func (c *ChainConfig) IsOptimism() bool {
return c.Optimism != nil
Expand Down Expand Up @@ -889,6 +898,7 @@ type Rules struct {
IsBerlin, IsLondon bool
IsMerge, IsShanghai, IsCancun, IsPrague bool
IsOptimismBedrock, IsOptimismRegolith bool
IsCel2 bool
}

// Rules ensures c's ChainID is not nil.
Expand Down Expand Up @@ -916,5 +926,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
// Optimism
IsOptimismBedrock: c.IsOptimismBedrock(num),
IsOptimismRegolith: c.IsOptimismRegolith(timestamp),
// Celo
IsCel2: c.IsCel2(timestamp),
}
}
19 changes: 19 additions & 0 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,22 @@ func TestConfigRulesRegolith(t *testing.T) {
t.Errorf("expected %v to be regolith", stamp)
}
}

func TestConfigRulesCel2(t *testing.T) {
c := &ChainConfig{
Cel2Time: newUint64(500),
Optimism: &OptimismConfig{},
}
var stamp uint64
if r := c.Rules(big.NewInt(0), true, stamp); r.IsCel2 {
t.Errorf("expected %v to not be Cel2", stamp)
}
stamp = 500
if r := c.Rules(big.NewInt(0), true, stamp); !r.IsCel2 {
t.Errorf("expected %v to be Cel2", stamp)
}
stamp = math.MaxInt64
if r := c.Rules(big.NewInt(0), true, stamp); !r.IsCel2 {
t.Errorf("expected %v to be Cel2", stamp)
}
}

0 comments on commit 3fc33dd

Please sign in to comment.