Skip to content

Commit d98d70f

Browse files
authored
cmd/utils, eth: disallow invalid snap sync / snapshot flag combos (#28657)
* eth: prevent startup in snap mode without snapshots * cmd/utils: try to fix bad flag combos wrt snap sync and snapshot generation
1 parent fff843c commit d98d70f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cmd/utils/flags.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,10 +1677,16 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
16771677
if ctx.IsSet(CacheLogSizeFlag.Name) {
16781678
cfg.FilterLogCacheSize = ctx.Int(CacheLogSizeFlag.Name)
16791679
}
1680-
if !ctx.Bool(SnapshotFlag.Name) {
1680+
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
16811681
// If snap-sync is requested, this flag is also required
16821682
if cfg.SyncMode == downloader.SnapSync {
1683-
log.Info("Snap sync requested, enabling --snapshot")
1683+
if !ctx.Bool(SnapshotFlag.Name) {
1684+
log.Warn("Snap sync requested, enabling --snapshot")
1685+
}
1686+
if cfg.SnapshotCache == 0 {
1687+
log.Warn("Snap sync requested, resetting --cache.snapshot")
1688+
cfg.SnapshotCache = ctx.Int(CacheFlag.Name) * CacheSnapshotFlag.Value / 100
1689+
}
16841690
} else {
16851691
cfg.TrieCleanCache += cfg.SnapshotCache
16861692
cfg.SnapshotCache = 0 // Disabled

eth/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ func newHandler(config *handlerConfig) (*handler, error) {
178178
log.Info("Enabled snap sync", "head", head.Number, "hash", head.Hash())
179179
}
180180
}
181+
// If snap sync is requested but snapshots are disabled, fail loudly
182+
if h.snapSync.Load() && config.Chain.Snapshots() == nil {
183+
return nil, errors.New("snap sync not supported with snapshots disabled")
184+
}
181185
// Construct the downloader (long sync)
182186
h.downloader = downloader.New(config.Database, h.eventMux, h.chain, nil, h.removePeer, h.enableSyncedFeatures)
183187
if ttd := h.chain.Config().TerminalTotalDifficulty; ttd != nil {

0 commit comments

Comments
 (0)