diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3eb91e3e756..a4bf1d4470c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1618,11 +1618,6 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C cfg.SentinelPort = ctx.Uint64(SentinelPortFlag.Name) cfg.ForcePartialCommit = ctx.Bool(ForcePartialCommitFlag.Name) - cfg.Sync.UseSnapshots = ethconfig.UseSnapshotsByChainName(ctx.String(ChainFlag.Name)) - if ctx.IsSet(SnapshotFlag.Name) { //force override default by cli - cfg.Sync.UseSnapshots = ctx.Bool(SnapshotFlag.Name) - } - cfg.Dirs = nodeConfig.Dirs cfg.Snapshot.KeepBlocks = ctx.Bool(SnapKeepBlocksFlag.Name) cfg.Snapshot.Produce = !ctx.Bool(SnapStopFlag.Name) @@ -1708,11 +1703,12 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C } // Override any default configs for hard coded networks. chain := ctx.String(ChainFlag.Name) + var genesisHash *libcommon.Hash switch chain { default: genesis := core.GenesisBlockByChainName(chain) - genesisHash := params.GenesisHashByChainName(chain) + genesisHash = params.GenesisHashByChainName(chain) if (genesis == nil) || (genesisHash == nil) { Fatalf("ChainDB name is not recognized: %s", chain) return @@ -1724,7 +1720,8 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C SetDNSDiscoveryDefaults(cfg, *genesisHash) case "": if cfg.NetworkID == 1 { - SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash) + genesisHash = ¶ms.MainnetGenesisHash + SetDNSDiscoveryDefaults(cfg, *genesisHash) } case networkname.DevChainName: if !ctx.IsSet(NetworkIdFlag.Name) { @@ -1746,6 +1743,11 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C } } + cfg.Sync.UseSnapshots = genesisHash != nil && ethconfig.UseSnapshotsByChain(*genesisHash) + if ctx.IsSet(SnapshotFlag.Name) { //force override default by cli + cfg.Sync.UseSnapshots = ctx.Bool(SnapshotFlag.Name) + } + if ctx.IsSet(OverrideCancunFlag.Name) { cfg.OverrideCancunTime = flags.GlobalBig(ctx, OverrideCancunFlag.Name) cfg.TxPool.OverrideCancunTime = cfg.OverrideCancunTime diff --git a/eth/backend.go b/eth/backend.go index 9842cc85238..75735c210d1 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -239,40 +239,6 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger } latestBlockBuiltStore := builder.NewLatestBlockBuiltStore() - if err := chainKv.Update(context.Background(), func(tx kv.RwTx) error { - if err = stagedsync.UpdateMetrics(tx); err != nil { - return err - } - - config.Prune, err = prune.EnsureNotChanged(tx, config.Prune) - if err != nil { - return err - } - - config.HistoryV3, err = kvcfg.HistoryV3.WriteOnce(tx, config.HistoryV3) - if err != nil { - return err - } - - isCorrectSync, useSnapshots, err := snap.EnsureNotChanged(tx, config.Snapshot) - if err != nil { - return err - } - // if we are in the incorrect syncmode then we change it to the appropriate one - if !isCorrectSync { - config.Sync.UseSnapshots = useSnapshots - config.Snapshot.Enabled = ethconfig.UseSnapshotsByChainName(config.Genesis.Config.ChainName) && useSnapshots - } - return nil - }); err != nil { - return nil, err - } - if !config.Sync.UseSnapshots { - if err := downloader.CreateProhibitNewDownloadsFile(dirs.Snap); err != nil { - return nil, err - } - } - ctx, ctxCancel := context.WithCancel(context.Background()) // kv_remote architecture does blocks on stream.Send - means current architecture require unlimited amount of txs to provide good throughput @@ -317,6 +283,40 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger backend.genesisBlock = genesis backend.genesisHash = genesis.Hash() + if err := chainKv.Update(context.Background(), func(tx kv.RwTx) error { + if err = stagedsync.UpdateMetrics(tx); err != nil { + return err + } + + config.Prune, err = prune.EnsureNotChanged(tx, config.Prune) + if err != nil { + return err + } + + config.HistoryV3, err = kvcfg.HistoryV3.WriteOnce(tx, config.HistoryV3) + if err != nil { + return err + } + + isCorrectSync, useSnapshots, err := snap.EnsureNotChanged(tx, config.Snapshot) + if err != nil { + return err + } + // if we are in the incorrect syncmode then we change it to the appropriate one + if !isCorrectSync { + config.Sync.UseSnapshots = useSnapshots + config.Snapshot.Enabled = ethconfig.UseSnapshotsByChain(backend.genesisHash) && useSnapshots + } + return nil + }); err != nil { + return nil, err + } + if !config.Sync.UseSnapshots { + if err := downloader.CreateProhibitNewDownloadsFile(dirs.Snap); err != nil { + return nil, err + } + } + logger.Info("Initialised chain configuration", "config", chainConfig, "genesis", genesis.Hash()) // Check if we have an already initialized chain and fall back to diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index a66e54cf44f..7cc485602dd 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -29,11 +29,12 @@ import ( "github.com/c2h5oh/datasize" "github.com/ledgerwatch/erigon-lib/chain" - "github.com/ledgerwatch/erigon-lib/chain/networkname" "github.com/ledgerwatch/erigon-lib/common" + libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/datadir" "github.com/ledgerwatch/erigon-lib/downloader/downloadercfg" "github.com/ledgerwatch/erigon-lib/txpool/txpoolcfg" + "github.com/ledgerwatch/erigon/cl/beacon/beacon_router_configuration" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/consensus/ethash/ethashcfg" @@ -277,18 +278,18 @@ type Sync struct { } // Chains where snapshots are enabled by default -var ChainsWithSnapshots = map[string]struct{}{ - networkname.MainnetChainName: {}, - networkname.SepoliaChainName: {}, - networkname.GoerliChainName: {}, - networkname.MumbaiChainName: {}, - networkname.AmoyChainName: {}, - networkname.BorMainnetChainName: {}, - networkname.GnosisChainName: {}, - networkname.ChiadoChainName: {}, +var ChainsWithSnapshots = map[libcommon.Hash]struct{}{ + params.MainnetGenesisHash: {}, + params.SepoliaGenesisHash: {}, + params.GoerliGenesisHash: {}, + params.MumbaiGenesisHash: {}, + params.AmoyGenesisHash: {}, + params.BorMainnetGenesisHash: {}, + params.GnosisGenesisHash: {}, + params.ChiadoGenesisHash: {}, } -func UseSnapshotsByChainName(chain string) bool { - _, ok := ChainsWithSnapshots[chain] +func UseSnapshotsByChain(genesis libcommon.Hash) bool { + _, ok := ChainsWithSnapshots[genesis] return ok }