Skip to content

Commit

Permalink
Add Canyon network upgrade flags
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Nov 1, 2023
1 parent 92a36e8 commit bb50cfa
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/erigon-el/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func NewBackend(stack *node.Node, config *ethconfig.Config, logger log.Logger) (
genesisSpec = nil
}
var genesisErr error
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime, tmpdir, logger)
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime, config.OverrideOptimismCanyonTime, tmpdir, logger)
if _, ok := genesisErr.(*chain.ConfigCompatError); genesisErr != nil && !ok {
return genesisErr
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (
"crypto/ecdsa"
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"math/big"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/urfave/cli/v2"

"golang.org/x/exp/slices"

"github.com/c2h5oh/datasize"
Expand Down Expand Up @@ -112,6 +113,10 @@ var (
Name: "override.shanghaiTime",
Usage: "Manually specify Shanghai fork time, overriding the bundled setting",
}
OverrideOptimismCanyonFlag = flags.BigFlag{
Name: "override.canyon",
Usage: "Manually specify the Optimsim Canyon fork time, overriding the bundled setting",
}
// Ethash settings
EthashCachesInMemoryFlag = cli.IntFlag{
Name: "ethash.cachesinmem",
Expand Down Expand Up @@ -1638,7 +1643,10 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
cfg.Genesis = readGenesis(ctx.String(GenesisPathFlag.Name))
//log.Info("Using custom developer period", "seconds", cfg.Genesis.Config.Clique.Period)
}

if ctx.IsSet(OverrideOptimismCanyonFlag.Name) {
cfg.OverrideOptimismCanyonTime = flags.GlobalBig(ctx, OverrideOptimismCanyonFlag.Name)
cfg.TxPool.OverrideOptimismCanyonTime = cfg.OverrideOptimismCanyonTime
}
if ctx.IsSet(OverrideShanghaiTime.Name) {
cfg.OverrideShanghaiTime = flags.GlobalBig(ctx, OverrideShanghaiTime.Name)
cfg.TxPool.OverrideShanghaiTime = cfg.OverrideShanghaiTime
Expand Down
6 changes: 3 additions & 3 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGenesisBlockHashes(t *testing.T) {
t.Fatal(err)
}
defer tx.Rollback()
_, block, err := core.WriteGenesisBlock(tx, genesis, nil, "", logger)
_, block, err := core.WriteGenesisBlock(tx, genesis, nil, nil, "", logger)
require.NoError(t, err)
expect := params.GenesisHashByChainName(network)
require.NotNil(t, expect, network)
Expand Down Expand Up @@ -80,13 +80,13 @@ func TestCommitGenesisIdempotency(t *testing.T) {
defer tx.Rollback()

genesis := core.GenesisBlockByChainName(networkname.MainnetChainName)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, "", logger)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, nil, "", logger)
require.NoError(t, err)
seq, err := tx.ReadSequence(kv.EthTx)
require.NoError(t, err)
require.Equal(t, uint64(2), seq)

_, _, err = core.WriteGenesisBlock(tx, genesis, nil, "", logger)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, nil, "", logger)
require.NoError(t, err)
seq, err = tx.ReadSequence(kv.EthTx)
require.NoError(t, err)
Expand Down
11 changes: 7 additions & 4 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ import (
//
// The returned chain configuration is never nil.
func CommitGenesisBlock(db kv.RwDB, genesis *types.Genesis, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
return CommitGenesisBlockWithOverride(db, genesis, nil, tmpDir, logger)
return CommitGenesisBlockWithOverride(db, genesis, nil, nil, tmpDir, logger)
}

func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, overrideShanghaiTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, overrideShanghaiTime, overrideOptimismCanyonTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
tx, err := db.BeginRw(context.Background())
if err != nil {
return nil, nil, err
}
defer tx.Rollback()
c, b, err := WriteGenesisBlock(tx, genesis, overrideShanghaiTime, tmpDir, logger)
c, b, err := WriteGenesisBlock(tx, genesis, overrideShanghaiTime, overrideOptimismCanyonTime, tmpDir, logger)
if err != nil {
return c, b, err
}
Expand All @@ -85,7 +85,7 @@ func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, override
return c, b, nil
}

func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideShanghaiTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideShanghaiTime, overrideOptimismCanyonTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
var storedBlock *types.Block
if genesis != nil && genesis.Config == nil {
return params.AllProtocolChanges, nil, types.ErrGenesisNoConfig
Expand All @@ -100,6 +100,9 @@ func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideShanghaiTime
if overrideShanghaiTime != nil {
config.ShanghaiTime = overrideShanghaiTime
}
if config.IsOptimism() && overrideOptimismCanyonTime != nil {
config.CanyonTime = overrideOptimismCanyonTime
}
if config.IsOptimism() && config.ChainID != nil {
if config.ChainID.Cmp(params.OptimismGoerliChainConfig.ChainID) == 0 {
config.RegolithTime = params.OptimismGoerliChainConfig.RegolithTime
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
genesisSpec = nil
}
var genesisErr error
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime, tmpdir, logger)
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime, config.OverrideOptimismCanyonTime, tmpdir, logger)
if _, ok := genesisErr.(*chain.ConfigCompatError); genesisErr != nil && !ok {
return genesisErr
}
Expand Down
3 changes: 2 additions & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ type Config struct {
SentinelAddr string
SentinelPort uint64

OverrideShanghaiTime *big.Int `toml:",omitempty"`
OverrideShanghaiTime *big.Int `toml:",omitempty"`
OverrideOptimismCanyonTime *big.Int `toml:",omitempty"`

DropUselessPeers bool

Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ var DefaultFlags = []cli.Flag{
&utils.HeimdallgRPCAddressFlag,
&utils.EthStatsURLFlag,
&utils.OverrideShanghaiTime,
&utils.OverrideOptimismCanyonFlag,
&utils.RollupSequencerHTTPFlag,
&utils.RollupHistoricalRPCFlag,
&utils.RollupHistoricalRPCTimeoutFlag,
Expand Down

0 comments on commit bb50cfa

Please sign in to comment.