diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index dd5d6e34fc..9826f59d83 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -37,6 +37,7 @@ import ( "github.com/ethereum/go-ethereum/core/state/snapshot" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" @@ -70,6 +71,7 @@ var ( Flags: []cli.Flag{ utils.DataDirFlag, utils.AncientFlag, + utils.PruneAncientDataFlag, utils.RopstenFlag, utils.SepoliaFlag, utils.RinkebyFlag, @@ -243,7 +245,7 @@ block is used. ) func accessDb(ctx *cli.Context, stack *node.Node) (ethdb.Database, error) { - //The layer of tries trees that keep in memory. + // The layer of tries trees that keep in memory. TriesInMemory := int(ctx.GlobalUint64(utils.TriesInMemoryFlag.Name)) chaindb := utils.MakeChainDatabase(ctx, stack, false, true) defer chaindb.Close() @@ -256,7 +258,7 @@ func accessDb(ctx *cli.Context, stack *node.Node) (ethdb.Database, error) { return nil, errors.New("failed to load head block") } headHeader := headBlock.Header() - //Make sure the MPT and snapshot matches before pruning, otherwise the node can not start. + // Make sure the MPT and snapshot matches before pruning, otherwise the node can not start. snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, TriesInMemory, headBlock.Root(), false, false, false, false) if err != nil { log.Error("snaptree error", "err", err) @@ -416,7 +418,7 @@ func pruneBlock(ctx *cli.Context) error { log.Info("backup block successfully") - //After backing up successfully, rename the new ancientdb name to the original one, and delete the old ancientdb + // After backing up successfully, rename the new ancientdb name to the original one, and delete the old ancientdb if err := blockpruner.AncientDbReplacer(); err != nil { return err } @@ -427,6 +429,12 @@ func pruneBlock(ctx *cli.Context) error { } func pruneState(ctx *cli.Context) error { + if ctx.GlobalIsSet(utils.PruneAncientDataFlag.Name) { // prune ancient only take effect on full sync. + if err := ctx.GlobalSet(utils.SyncModeFlag.Name, downloader.FullSync.String()); err != nil { + return err + } + } + stack, config := makeConfigNode(ctx) defer stack.Close() diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5c58c542e7..7e7896515f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2020,7 +2020,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly, disableFree chainDb, err = stack.OpenDatabase(name, cache, handles, "", readonly) } else { name := "chaindata" - chainDb, err = stack.OpenDatabaseWithFreezer(name, cache, handles, ctx.GlobalString(AncientFlag.Name), "", readonly, disableFreeze, false, false) + chainDb, err = stack.OpenDatabaseWithFreezer(name, cache, handles, ctx.GlobalString(AncientFlag.Name), "", readonly, disableFreeze, false, ctx.GlobalIsSet(PruneAncientDataFlag.Name)) } if err != nil { Fatalf("Could not open database: %v", err) diff --git a/tests/testdata b/tests/testdata index 092a8834dc..7497b116a0 160000 --- a/tests/testdata +++ b/tests/testdata @@ -1 +1 @@ -Subproject commit 092a8834dc445e683103689d6f0e75a5d380a190 +Subproject commit 7497b116a019beb26215cbea4028df068dea06be