From ba95a698c28ec0fc7c8d100a2c3f6d5db7dbb229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=B2=E5=87=80?= <54979375+du5@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:44:34 +0800 Subject: [PATCH] Refactor ApplyFlagsForEthConfig to handle different pruning modes based on chainId (#507) --- ethdb/prune/storage_mode.go | 5 +++++ turbo/cli/flags.go | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ethdb/prune/storage_mode.go b/ethdb/prune/storage_mode.go index c889bbc4c96..f2884278faf 100644 --- a/ethdb/prune/storage_mode.go +++ b/ethdb/prune/storage_mode.go @@ -85,6 +85,11 @@ type Mode struct { Experiments Experiments } +func (m *Mode) SetPruneMode(blocks, history uint64) { + m.Blocks = Distance(blocks) + m.History = Distance(history) +} + type BlockAmount interface { PruneTo(stageHead uint64) uint64 Enabled() bool diff --git a/turbo/cli/flags.go b/turbo/cli/flags.go index 365e868829b..d63f715ba45 100644 --- a/turbo/cli/flags.go +++ b/turbo/cli/flags.go @@ -306,15 +306,18 @@ func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config, logger log. if err != nil { utils.Fatalf(fmt.Sprintf("error while parsing mode: %v", err)) } + // Full mode prunes all but the latest state if ctx.String(PruneModeFlag.Name) == "full" { - mode.Blocks = prune.Distance(math.MaxUint64) - mode.History = prune.Distance(0) + mode.SetPruneMode(math.MaxUint64, 0) } // Minimal mode prunes all but the latest state including blocks if ctx.String(PruneModeFlag.Name) == "minimal" { - mode.Blocks = prune.Distance(2048) // 2048 is just some blocks to allow reorgs - mode.History = prune.Distance(0) + if chainId == 56 { + mode.SetPruneMode(90_000, 90_000) // 90_000 about 3 day + } else { + mode.SetPruneMode(2048, 0) // 2048 is just some blocks to allow reorgs + } } cfg.BlobPrune = ctx.Bool(PruneBscBlobSidecarsFlag.Name)