From 29b7bfbb11296189872a421f83c9e9527442ab10 Mon Sep 17 00:00:00 2001 From: pcw109550 Date: Wed, 1 Nov 2023 20:21:38 +0900 Subject: [PATCH 1/2] Add Canyon network override flags --- cmd/erigon-el/backend/backend.go | 2 +- cmd/utils/flags.go | 12 ++++++++++-- core/genesis_test.go | 6 +++--- core/genesis_write.go | 11 +++++++---- eth/backend.go | 2 +- eth/ethconfig/config.go | 3 ++- turbo/cli/default_flags.go | 1 + 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/cmd/erigon-el/backend/backend.go b/cmd/erigon-el/backend/backend.go index 9aa8b2f08d2..a51103de982 100644 --- a/cmd/erigon-el/backend/backend.go +++ b/cmd/erigon-el/backend/backend.go @@ -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 } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 4fcf15e06af..b7fdcb5a633 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -21,7 +21,6 @@ import ( "crypto/ecdsa" "encoding/json" "fmt" - "github.com/urfave/cli/v2" "math/big" "os" "path/filepath" @@ -29,6 +28,8 @@ import ( "strconv" "strings" + "github.com/urfave/cli/v2" + "golang.org/x/exp/slices" "github.com/c2h5oh/datasize" @@ -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", @@ -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 diff --git a/core/genesis_test.go b/core/genesis_test.go index 05c7d4d778e..74ad6ad1f07 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -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) @@ -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) diff --git a/core/genesis_write.go b/core/genesis_write.go index 34ef842718a..ea2ec67d7b5 100644 --- a/core/genesis_write.go +++ b/core/genesis_write.go @@ -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 } @@ -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 @@ -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 diff --git a/eth/backend.go b/eth/backend.go index ae8273853db..c7167b16dbc 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -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 } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 337dc8e0c24..5219a173f2d 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -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 diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 3383571914e..3cdd62dc6f6 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -146,6 +146,7 @@ var DefaultFlags = []cli.Flag{ &utils.HeimdallgRPCAddressFlag, &utils.EthStatsURLFlag, &utils.OverrideShanghaiTime, + &utils.OverrideOptimismCanyonFlag, &utils.RollupSequencerHTTPFlag, &utils.RollupHistoricalRPCFlag, &utils.RollupHistoricalRPCTimeoutFlag, From 9dabedf00c3be0790f10f3eb3f3204877dcc26cf Mon Sep 17 00:00:00 2001 From: pcw109550 Date: Thu, 2 Nov 2023 13:26:58 +0900 Subject: [PATCH 2/2] Update erigon-lib --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d9954564464..6168b743ad1 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index fd9397199be..5a34bd122ad 100644 --- a/go.sum +++ b/go.sum @@ -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=