Skip to content

Commit

Permalink
adjust pruneblock local var
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang committed Jul 20, 2022
1 parent 48df920 commit 1a619bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1a619bc

Please sign in to comment.