Skip to content

Commit 2728672

Browse files
committed
core/state/pruner: fix compaction after pruning
1 parent 123e934 commit 2728672

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/state/pruner/pruner.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,15 @@ func prune(maindb ethdb.Database, stateBloom *stateBloom, middleStateRoots map[c
188188
cstart := time.Now()
189189

190190
for b := byte(0); b < byte(16); b++ {
191-
log.Info("Compacting database", "range", fmt.Sprintf("%#x-%#x", b, b+1), "elapsed", common.PrettyDuration(time.Since(cstart)))
192-
if err := maindb.Compact([]byte{b}, []byte{b + 1}); err != nil {
191+
var (
192+
start = []byte{b << 4}
193+
end = []byte{(b+1)<<4 - 1}
194+
)
195+
log.Info("Compacting database", "range", fmt.Sprintf("%#x-%#x", start, end), "elapsed", common.PrettyDuration(time.Since(cstart)))
196+
if b == 15 {
197+
end = nil
198+
}
199+
if err := maindb.Compact(start, end); err != nil {
193200
log.Error("Database compaction failed", "error", err)
194201
return err
195202
}
@@ -229,7 +236,7 @@ func (p *Pruner) Prune(root common.Hash) error {
229236
// Reject if the accumulated diff layers are less than 128. It
230237
// means in most of normal cases, there is no associated state
231238
// with bottom-most diff layer.
232-
return errors.New("the snapshot difflayers are less than 128")
239+
return fmt.Errorf("snapshot not old enough yet: need %d more blocks", 128-len(layers))
233240
}
234241
// Use the bottom-most diff layer as the target
235242
root = layers[len(layers)-1].Root()

0 commit comments

Comments
 (0)