From 0c86f2467e795e620aaab6d1851fd7146556f2b8 Mon Sep 17 00:00:00 2001 From: Giulio rebuffo Date: Sat, 21 Dec 2024 00:49:28 +0100 Subject: [PATCH] E3: make state snapshots download optional (#13107) --- cmd/utils/flags.go | 7 +++++++ eth/ethconfig/config.go | 15 ++++++++------- turbo/snapshotsync/snapshotsync.go | 8 ++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d1a9b1a882b..722ec2aad00 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -675,6 +675,11 @@ var ( Name: ethconfig.FlagSnapStateStop, Usage: "Workaround to stop producing new state files, if you meet some state-related critical bug. It will stop aggregate DB history in a state files. DB will grow and may slightly slow-down - and removing this flag in future will not fix this effect (db size will not greatly reduce).", } + SnapSkipStateSnapshotDownloadFlag = cli.BoolFlag{ + Name: "snap.skip-state-snapshot-download", + Usage: "Skip state download and start from genesis block", + Value: false, + } TorrentVerbosityFlag = cli.IntFlag{ Name: "torrent.verbosity", Value: 2, @@ -749,6 +754,7 @@ var ( Usage: "Enable WRITE_MAP feature for fast database writes and fast commit times", Value: true, } + HealthCheckFlag = cli.BoolFlag{ Name: "healthcheck", Usage: "Enabling grpc health check", @@ -1860,6 +1866,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C cfg.Snapshot.KeepBlocks = ctx.Bool(SnapKeepBlocksFlag.Name) cfg.Snapshot.ProduceE2 = !ctx.Bool(SnapStopFlag.Name) cfg.Snapshot.ProduceE3 = !ctx.Bool(SnapStateStopFlag.Name) + cfg.Snapshot.DisableDownloadE3 = ctx.Bool(SnapSkipStateSnapshotDownloadFlag.Name) cfg.Snapshot.NoDownloader = ctx.Bool(NoDownloaderFlag.Name) cfg.Snapshot.Verify = ctx.Bool(DownloaderVerifyFlag.Name) cfg.Snapshot.DownloaderAddr = strings.TrimSpace(ctx.String(DownloaderAddrFlag.Name)) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 8ea5f2bbab1..d8f9c9e9cc5 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -135,13 +135,14 @@ func init() { //go:generate gencodec -dir . -type Config -formats toml -out gen_config.go type BlocksFreezing struct { - KeepBlocks bool // produce new snapshots of blocks but don't remove blocks from DB - ProduceE2 bool // produce new block files - ProduceE3 bool // produce new state files - NoDownloader bool // possible to use snapshots without calling Downloader - Verify bool // verify snapshots on startup - DownloaderAddr string - ChainName string + KeepBlocks bool // produce new snapshots of blocks but don't remove blocks from DB + ProduceE2 bool // produce new block files + ProduceE3 bool // produce new state files + NoDownloader bool // possible to use snapshots without calling Downloader + Verify bool // verify snapshots on startup + DisableDownloadE3 bool // disable download state snapshots + DownloaderAddr string + ChainName string } func (s BlocksFreezing) String() string { diff --git a/turbo/snapshotsync/snapshotsync.go b/turbo/snapshotsync/snapshotsync.go index 7bbfee50d17..9182cfb319a 100644 --- a/turbo/snapshotsync/snapshotsync.go +++ b/turbo/snapshotsync/snapshotsync.go @@ -158,7 +158,7 @@ func adjustBlockPrune(blocks, minBlocksToDownload uint64) uint64 { return blocks - blocks%snaptype.Erigon2MergeLimit } -func shouldUseStepsForPruning(name string) bool { +func isStateSnapshot(name string) bool { return strings.HasPrefix(name, "idx") || strings.HasPrefix(name, "history") || strings.HasPrefix(name, "accessor") } @@ -182,7 +182,7 @@ func buildBlackListForPruning(pruneMode bool, stepPrune, minBlockToDownload, blo } var _, to uint64 var err error - if shouldUseStepsForPruning(name) { + if isStateSnapshot(name) { // parse "from" (0) and "to" (64) from the name // parse the snapshot "kind". e.g kind of 'idx/v1-accounts.0-64.ef' is "idx/v1-accounts" rangeString := strings.Split(name, ".")[1] @@ -337,6 +337,10 @@ func WaitForDownloader(ctx context.Context, logPrefix string, dirs datadir.Dirs, if caplin == OnlyCaplin && !strings.Contains(p.Name, "beaconblocks") && !strings.Contains(p.Name, "blobsidecars") && !strings.Contains(p.Name, "caplin") { continue } + + if isStateSnapshot(p.Name) && blockReader.FreezingCfg().DisableDownloadE3 { + continue + } if !blobs && strings.Contains(p.Name, "blobsidecars") { continue }