From 1a619bcbb7eb7414be2095a7020b100518899222 Mon Sep 17 00:00:00 2001 From: joeycli Date: Wed, 20 Jul 2022 17:50:54 +0800 Subject: [PATCH] adjust pruneblock local var --- cmd/geth/snapshot.go | 23 +++++++++++++++++------ core/state/pruner/pruner.go | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index 1a869a8f2c..d3e1906e45 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -330,10 +330,22 @@ func accessDb(ctx *cli.Context, stack *node.Node) (ethdb.Database, error) { } func pruneBlock(ctx *cli.Context) error { - stack, config := makeConfigNode(ctx) + var ( + stack *node.Node + config gethConfig + chaindb ethdb.Database + err error + + oldAncientPath string + newAncientPath string + blockAmountReserved uint64 + blockpruner *pruner.BlockPruner + ) + + stack, config = makeConfigNode(ctx) defer stack.Close() - blockAmountReserved := ctx.GlobalUint64(utils.BlockAmountReserved.Name) - chaindb, err := accessDb(ctx, stack) + blockAmountReserved = ctx.GlobalUint64(utils.BlockAmountReserved.Name) + chaindb, err = accessDb(ctx, stack) if err != nil { return err } @@ -352,7 +364,6 @@ func pruneBlock(ctx *cli.Context) error { } } - var oldAncientPath string if !ctx.GlobalIsSet(utils.AncientFlag.Name) { return errors.New("datadir.ancient must be set") } else { @@ -367,9 +378,9 @@ func pruneBlock(ctx *cli.Context) error { if path == "" { return errors.New("prune failed, did not specify the AncientPath") } - newAncientPath := filepath.Join(path, "ancient_back") + newAncientPath = filepath.Join(path, "ancient_back") - blockpruner := pruner.NewBlockPruner(chaindb, stack, oldAncientPath, newAncientPath, blockAmountReserved) + blockpruner = pruner.NewBlockPruner(chaindb, stack, oldAncientPath, newAncientPath, blockAmountReserved) lock, exist, err := fileutil.Flock(filepath.Join(oldAncientPath, "PRUNEFLOCK")) if err != nil { diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index a970547b49..30703fa04c 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -437,7 +437,7 @@ func (p *BlockPruner) backUpOldDb(name string, cache, handles int, namespace str } // Write into new ancient_back db. if _, err := rawdb.WriteAncientBlocks(frdbBack, []*types.Block{block}, []types.Receipts{receipts}, td); err != nil { - log.Error("write new ancient error", "error", err) + log.Error("failed to write new ancient", "error", err) return err } // Print the log every 5s for better trace.