Skip to content

Commit 7e7d4ff

Browse files
committed
Ignore "not found" db errors in snapshot access
1 parent 4002f12 commit 7e7d4ff

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

core/rawdb/accessors_snapshot.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ package rawdb
1818

1919
import (
2020
"encoding/binary"
21+
"errors"
2122

23+
"github.com/cockroachdb/pebble"
2224
"github.com/ethereum/go-ethereum/common"
2325
"github.com/ethereum/go-ethereum/ethdb"
26+
"github.com/ethereum/go-ethereum/ethdb/memorydb"
2427
"github.com/ethereum/go-ethereum/log"
28+
"github.com/syndtr/goleveldb/leveldb"
2529
)
2630

2731
// ReadSnapshotDisabled retrieves if the snapshot maintenance is disabled.
@@ -72,9 +76,20 @@ func DeleteSnapshotRoot(db ethdb.KeyValueWriter) {
7276
}
7377
}
7478

79+
func isDbErrNotFound(err error) bool {
80+
return errors.Is(err, leveldb.ErrNotFound) || errors.Is(err, pebble.ErrNotFound) || errors.Is(err, memorydb.ErrMemorydbNotFound)
81+
}
82+
83+
func ignoreNotFound(blob []byte, err error) ([]byte, error) {
84+
if isDbErrNotFound(err) {
85+
return nil, nil
86+
}
87+
return blob, err
88+
}
89+
7590
// ReadAccountSnapshot retrieves the snapshot entry of an account trie leaf.
7691
func ReadAccountSnapshot(db ethdb.KeyValueReader, hash common.Hash) ([]byte, error) {
77-
return db.Get(accountSnapshotKey(hash))
92+
return ignoreNotFound(db.Get(accountSnapshotKey(hash)))
7893
}
7994

8095
// WriteAccountSnapshot stores the snapshot entry of an account trie leaf.
@@ -93,7 +108,7 @@ func DeleteAccountSnapshot(db ethdb.KeyValueWriter, hash common.Hash) {
93108

94109
// ReadStorageSnapshot retrieves the snapshot entry of an storage trie leaf.
95110
func ReadStorageSnapshot(db ethdb.KeyValueReader, accountHash, storageHash common.Hash) ([]byte, error) {
96-
return db.Get(storageSnapshotKey(accountHash, storageHash))
111+
return ignoreNotFound(db.Get(storageSnapshotKey(accountHash, storageHash)))
97112
}
98113

99114
// WriteStorageSnapshot stores the snapshot entry of an storage trie leaf.

0 commit comments

Comments
 (0)