Skip to content

Commit 312e02b

Browse files
zzyalbertholiman
andauthored
core/state/snapshot: fix BAD BLOCK error when snapshot is generating (ethereum#23635)
* core/state/snapshot: fix BAD BLOCK error when snapshot is generating * core/state/snapshot: alternative fix for the snapshot generator * add comments and minor update Co-authored-by: Martin Holst Swende <[email protected]>
1 parent 0183256 commit 312e02b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

core/state/snapshot/generate.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ func (dl *diskLayer) generate(stats *generatorStats) {
560560
default:
561561
}
562562
if batch.ValueSize() > ethdb.IdealBatchSize || abort != nil {
563+
if bytes.Compare(currentLocation, dl.genMarker) < 0 {
564+
log.Error("Snapshot generator went backwards",
565+
"currentLocation", fmt.Sprintf("%x", currentLocation),
566+
"genMarker", fmt.Sprintf("%x", dl.genMarker))
567+
}
568+
563569
// Flush out the batch anyway no matter it's empty or not.
564570
// It's possible that all the states are recovered and the
565571
// generation indeed makes progress.
@@ -634,8 +640,14 @@ func (dl *diskLayer) generate(stats *generatorStats) {
634640
stats.storage += common.StorageSize(1 + common.HashLength + dataLen)
635641
stats.accounts++
636642
}
643+
marker := accountHash[:]
644+
// If the snap generation goes here after interrupted, genMarker may go backward
645+
// when last genMarker is consisted of accountHash and storageHash
646+
if accMarker != nil && bytes.Equal(marker, accMarker) && len(dl.genMarker) > common.HashLength {
647+
marker = dl.genMarker[:]
648+
}
637649
// If we've exceeded our batch allowance or termination was requested, flush to disk
638-
if err := checkAndFlush(accountHash[:]); err != nil {
650+
if err := checkAndFlush(marker); err != nil {
639651
return err
640652
}
641653
// If the iterated account is the contract, create a further loop to

0 commit comments

Comments
 (0)