Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Canyon Hard Fork] Add Canyon network upgrade flags #97

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Optimism 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
ImTei marked this conversation as resolved.
Show resolved Hide resolved
}
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.19

//fork with minor protobuf file changes and txpool support
replace github.com/ledgerwatch/erigon-lib v0.0.0-20230627104814-797724496a65 => github.com/testinprod-io/erigon-lib v0.0.0-20230724082815-b7b8746e624b
replace github.com/ledgerwatch/erigon-lib v0.0.0-20230627104814-797724496a65 => github.com/testinprod-io/erigon-lib v0.0.0-20231102042317-293c0e76a349

//for local dev:
//replace github.com/ledgerwatch/erigon-lib v0.0.0-20230423044930-fc9dd74e6407 => ../erigon-lib
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/supranational/blst v0.3.10 h1:CMciDZ/h4pXDDXQASe8ZGTNKUiVNxVVA5hpci2Uuhuk=
github.com/supranational/blst v0.3.10/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/testinprod-io/erigon-lib v0.0.0-20230724082815-b7b8746e624b h1:cPYa78vooawGwLNQ2YlaP7/7Cwkmoerua2e7zS/DsJg=
github.com/testinprod-io/erigon-lib v0.0.0-20230724082815-b7b8746e624b/go.mod h1:yq49cI1Z1S+aS0gj6ERZU03UIrseMmDRj4zWa1EA96Y=
github.com/testinprod-io/erigon-lib v0.0.0-20231102042317-293c0e76a349 h1:ukPVzVJeJ/wt0mJd0HaxT/FCvIysNMPV6gwSTGXBr50=
github.com/testinprod-io/erigon-lib v0.0.0-20231102042317-293c0e76a349/go.mod h1:yq49cI1Z1S+aS0gj6ERZU03UIrseMmDRj4zWa1EA96Y=
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e h1:cR8/SYRgyQCt5cNCMniB/ZScMkhI9nk8U5C7SbISXjo=
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e/go.mod h1:Tu4lItkATkonrYuvtVjG0/rhy15qrNGNTjPdaphtZ/8=
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
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