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

Genesis hash rather than chain name in UseSnapshotsByChain #9398

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 9 additions & 7 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 = &params.MainnetGenesisHash
SetDNSDiscoveryDefaults(cfg, *genesisHash)
}
case networkname.DevChainName:
if !ctx.IsSet(NetworkIdFlag.Name) {
Expand All @@ -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
Expand Down
68 changes: 34 additions & 34 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Loading