Skip to content

Commit b37e445

Browse files
committed
add disk layer as the last layer when prune
1 parent 3d42dd1 commit b37e445

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎core/state/pruner/pruner.go‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta
189189
// Pruning is done, now drop the "useless" layers from the snapshot.
190190
// Firstly, flushing the target layer into the disk. After that all
191191
// diff layers below the target will all be merged into the disk.
192-
if err := snaptree.Cap(root, 0); err != nil {
193-
return err
192+
if root != snaptree.DiskRoot() {
193+
if err := snaptree.Cap(root, 0); err != nil {
194+
return err
195+
}
194196
}
195197
// Secondly, flushing the snapshot journal into the disk. All diff
196198
// layers upon are dropped silently. Eventually the entire snapshot
@@ -275,18 +277,25 @@ func (p *Pruner) Prune(root common.Hash) error {
275277
// bottom-most diff layer. Try to find the bottom-most snapshot
276278
// layer with state available.
277279
//
278-
// Note HEAD and HEAD-1 is ignored. Usually there is the associated
280+
// Note HEAD is ignored. Usually there is the associated
279281
// state available, but we don't want to use the topmost state
280282
// as the pruning target.
281283
var found bool
282-
for i := len(layers) - 2; i >= 2; i-- {
284+
for i := len(layers) - 2; i >= 1; i-- {
283285
if blob := rawdb.ReadTrieNode(p.db, layers[i].Root()); len(blob) != 0 {
284286
root = layers[i].Root()
285287
found = true
286288
log.Info("Selecting middle-layer as the pruning target", "root", root, "depth", i)
287289
break
288290
}
289291
}
292+
if !found {
293+
if blob := rawdb.ReadTrieNode(p.db, p.snaptree.DiskRoot()); len(blob) != 0 {
294+
root = p.snaptree.DiskRoot()
295+
found = true
296+
log.Info("Selecting disk-layer as the pruning target", "root", root)
297+
}
298+
}
290299
if !found {
291300
if len(layers) > 0 {
292301
return errors.New("no snapshot paired state")

0 commit comments

Comments
 (0)