refactor(storev2): change error namespace (#19698)
This commit is contained in:
parent
0f5314c031
commit
f69dabe241
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
"github.com/syndtr/goleveldb/leveldb/errors"
|
||||
dberrors "github.com/syndtr/goleveldb/leveldb/errors"
|
||||
"github.com/syndtr/goleveldb/leveldb/filter"
|
||||
"github.com/syndtr/goleveldb/leveldb/iterator"
|
||||
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||
@ -15,6 +15,7 @@ import (
|
||||
|
||||
corestore "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/store/v2"
|
||||
"cosmossdk.io/store/v2/errors"
|
||||
)
|
||||
|
||||
// GoLevelDB implements RawDB using github.com/syndtr/goleveldb/leveldb.
|
||||
@ -54,11 +55,11 @@ func NewGoLevelDBWithOpts(name, dir string, o *opt.Options) (*GoLevelDB, error)
|
||||
// Get implements RawDB.
|
||||
func (db *GoLevelDB) Get(key []byte) ([]byte, error) {
|
||||
if len(key) == 0 {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
res, err := db.db.Get(key, nil)
|
||||
if err != nil {
|
||||
if err == errors.ErrNotFound {
|
||||
if err == dberrors.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
@ -78,10 +79,10 @@ func (db *GoLevelDB) Has(key []byte) (bool, error) {
|
||||
// Set implements RawDB.
|
||||
func (db *GoLevelDB) Set(key, value []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if value == nil {
|
||||
return store.ErrValueNil
|
||||
return errors.ErrValueNil
|
||||
}
|
||||
if err := db.db.Put(key, value, nil); err != nil {
|
||||
return err
|
||||
@ -92,10 +93,10 @@ func (db *GoLevelDB) Set(key, value []byte) error {
|
||||
// SetSync implements RawDB.
|
||||
func (db *GoLevelDB) SetSync(key, value []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if value == nil {
|
||||
return store.ErrValueNil
|
||||
return errors.ErrValueNil
|
||||
}
|
||||
if err := db.db.Put(key, value, &opt.WriteOptions{Sync: true}); err != nil {
|
||||
return err
|
||||
@ -106,7 +107,7 @@ func (db *GoLevelDB) SetSync(key, value []byte) error {
|
||||
// Delete implements RawDB.
|
||||
func (db *GoLevelDB) Delete(key []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if err := db.db.Delete(key, nil); err != nil {
|
||||
return err
|
||||
@ -117,7 +118,7 @@ func (db *GoLevelDB) Delete(key []byte) error {
|
||||
// DeleteSync implements RawDB.
|
||||
func (db *GoLevelDB) DeleteSync(key []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
err := db.db.Delete(key, &opt.WriteOptions{Sync: true})
|
||||
if err != nil {
|
||||
@ -195,7 +196,7 @@ func (db *GoLevelDB) NewBatchWithSize(size int) store.RawBatch {
|
||||
// Iterator implements RawDB.
|
||||
func (db *GoLevelDB) Iterator(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
itr := db.db.NewIterator(&util.Range{Start: start, Limit: end}, nil)
|
||||
return newGoLevelDBIterator(itr, start, end, false), nil
|
||||
@ -204,7 +205,7 @@ func (db *GoLevelDB) Iterator(start, end []byte) (corestore.Iterator, error) {
|
||||
// ReverseIterator implements RawDB.
|
||||
func (db *GoLevelDB) ReverseIterator(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
itr := db.db.NewIterator(&util.Range{Start: start, Limit: end}, nil)
|
||||
return newGoLevelDBIterator(itr, start, end, true), nil
|
||||
@ -363,13 +364,13 @@ func newGoLevelDBBatchWithSize(db *GoLevelDB, size int) *goLevelDBBatch {
|
||||
// Set implements RawBatch.
|
||||
func (b *goLevelDBBatch) Set(key, value []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if value == nil {
|
||||
return store.ErrValueNil
|
||||
return errors.ErrValueNil
|
||||
}
|
||||
if b.batch == nil {
|
||||
return store.ErrBatchClosed
|
||||
return errors.ErrBatchClosed
|
||||
}
|
||||
b.batch.Put(key, value)
|
||||
return nil
|
||||
@ -378,10 +379,10 @@ func (b *goLevelDBBatch) Set(key, value []byte) error {
|
||||
// Delete implements RawBatch.
|
||||
func (b *goLevelDBBatch) Delete(key []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if b.batch == nil {
|
||||
return store.ErrBatchClosed
|
||||
return errors.ErrBatchClosed
|
||||
}
|
||||
b.batch.Delete(key)
|
||||
return nil
|
||||
@ -399,7 +400,7 @@ func (b *goLevelDBBatch) WriteSync() error {
|
||||
|
||||
func (b *goLevelDBBatch) write(sync bool) error {
|
||||
if b.batch == nil {
|
||||
return store.ErrBatchClosed
|
||||
return errors.ErrBatchClosed
|
||||
}
|
||||
err := b.db.db.Write(b.batch, &opt.WriteOptions{Sync: sync})
|
||||
if err != nil {
|
||||
@ -421,7 +422,7 @@ func (b *goLevelDBBatch) Close() error {
|
||||
// GetByteSize implements RawBatch
|
||||
func (b *goLevelDBBatch) GetByteSize() (int, error) {
|
||||
if b.batch == nil {
|
||||
return 0, store.ErrBatchClosed
|
||||
return 0, errors.ErrBatchClosed
|
||||
}
|
||||
return len(b.batch.Dump()), nil
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
|
||||
corestore "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/store/v2"
|
||||
"cosmossdk.io/store/v2/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -64,7 +65,7 @@ func NewMemDB() *MemDB {
|
||||
// Get implements DB.
|
||||
func (db *MemDB) Get(key []byte) ([]byte, error) {
|
||||
if len(key) == 0 {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
db.mtx.RLock()
|
||||
defer db.mtx.RUnlock()
|
||||
@ -79,7 +80,7 @@ func (db *MemDB) Get(key []byte) ([]byte, error) {
|
||||
// Has implements DB.
|
||||
func (db *MemDB) Has(key []byte) (bool, error) {
|
||||
if len(key) == 0 {
|
||||
return false, store.ErrKeyEmpty
|
||||
return false, errors.ErrKeyEmpty
|
||||
}
|
||||
db.mtx.RLock()
|
||||
defer db.mtx.RUnlock()
|
||||
@ -90,10 +91,10 @@ func (db *MemDB) Has(key []byte) (bool, error) {
|
||||
// Set implements DB.
|
||||
func (db *MemDB) Set(key, value []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if value == nil {
|
||||
return store.ErrValueNil
|
||||
return errors.ErrValueNil
|
||||
}
|
||||
db.mtx.Lock()
|
||||
defer db.mtx.Unlock()
|
||||
@ -115,7 +116,7 @@ func (db *MemDB) SetSync(key, value []byte) error {
|
||||
// Delete implements DB.
|
||||
func (db *MemDB) Delete(key []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
db.mtx.Lock()
|
||||
defer db.mtx.Unlock()
|
||||
@ -181,7 +182,7 @@ func (db *MemDB) NewBatchWithSize(size int) store.RawBatch {
|
||||
// Takes out a read-lock on the database until the iterator is closed.
|
||||
func (db *MemDB) Iterator(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
return newMemDBIterator(db, start, end, false), nil
|
||||
}
|
||||
@ -190,7 +191,7 @@ func (db *MemDB) Iterator(start, end []byte) (corestore.Iterator, error) {
|
||||
// Takes out a read-lock on the database until the iterator is closed.
|
||||
func (db *MemDB) ReverseIterator(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
return newMemDBIterator(db, start, end, true), nil
|
||||
}
|
||||
@ -198,7 +199,7 @@ func (db *MemDB) ReverseIterator(start, end []byte) (corestore.Iterator, error)
|
||||
// IteratorNoMtx makes an iterator with no mutex.
|
||||
func (db *MemDB) IteratorNoMtx(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
return newMemDBIteratorMtxChoice(db, start, end, false, false), nil
|
||||
}
|
||||
@ -206,7 +207,7 @@ func (db *MemDB) IteratorNoMtx(start, end []byte) (corestore.Iterator, error) {
|
||||
// ReverseIteratorNoMtx makes an iterator with no mutex.
|
||||
func (db *MemDB) ReverseIteratorNoMtx(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
return newMemDBIteratorMtxChoice(db, start, end, true, false), nil
|
||||
}
|
||||
@ -395,13 +396,13 @@ func newMemDBBatch(db *MemDB) *memDBBatch {
|
||||
// Set implements Batch.
|
||||
func (b *memDBBatch) Set(key, value []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if value == nil {
|
||||
return store.ErrValueNil
|
||||
return errors.ErrValueNil
|
||||
}
|
||||
if b.ops == nil {
|
||||
return store.ErrBatchClosed
|
||||
return errors.ErrBatchClosed
|
||||
}
|
||||
b.size += len(key) + len(value)
|
||||
b.ops = append(b.ops, operation{opTypeSet, key, value})
|
||||
@ -411,10 +412,10 @@ func (b *memDBBatch) Set(key, value []byte) error {
|
||||
// Delete implements Batch.
|
||||
func (b *memDBBatch) Delete(key []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if b.ops == nil {
|
||||
return store.ErrBatchClosed
|
||||
return errors.ErrBatchClosed
|
||||
}
|
||||
b.size += len(key)
|
||||
b.ops = append(b.ops, operation{opTypeDelete, key, nil})
|
||||
@ -424,7 +425,7 @@ func (b *memDBBatch) Delete(key []byte) error {
|
||||
// Write implements Batch.
|
||||
func (b *memDBBatch) Write() error {
|
||||
if b.ops == nil {
|
||||
return store.ErrBatchClosed
|
||||
return errors.ErrBatchClosed
|
||||
}
|
||||
b.db.mtx.Lock()
|
||||
defer b.db.mtx.Unlock()
|
||||
@ -459,7 +460,7 @@ func (b *memDBBatch) Close() error {
|
||||
// GetByteSize implements Batch
|
||||
func (b *memDBBatch) GetByteSize() (int, error) {
|
||||
if b.ops == nil {
|
||||
return 0, store.ErrBatchClosed
|
||||
return 0, errors.ErrBatchClosed
|
||||
}
|
||||
return b.size, nil
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
corestore "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/store/v2"
|
||||
"cosmossdk.io/store/v2/errors"
|
||||
)
|
||||
|
||||
// PrefixDB wraps a namespace of another database as a logical database.
|
||||
@ -29,7 +30,7 @@ func NewPrefixDB(db store.RawDB, prefix []byte) *PrefixDB {
|
||||
// Get implements RawDB.
|
||||
func (pdb *PrefixDB) Get(key []byte) ([]byte, error) {
|
||||
if len(key) == 0 {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
pkey := pdb.prefixed(key)
|
||||
@ -43,7 +44,7 @@ func (pdb *PrefixDB) Get(key []byte) ([]byte, error) {
|
||||
// Has implements RawDB.
|
||||
func (pdb *PrefixDB) Has(key []byte) (bool, error) {
|
||||
if len(key) == 0 {
|
||||
return false, store.ErrKeyEmpty
|
||||
return false, errors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
ok, err := pdb.db.Has(pdb.prefixed(key))
|
||||
@ -57,7 +58,7 @@ func (pdb *PrefixDB) Has(key []byte) (bool, error) {
|
||||
// Iterator implements RawDB.
|
||||
func (pdb *PrefixDB) Iterator(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
var pstart, pend []byte
|
||||
@ -78,7 +79,7 @@ func (pdb *PrefixDB) Iterator(start, end []byte) (corestore.Iterator, error) {
|
||||
// ReverseIterator implements RawDB.
|
||||
func (pdb *PrefixDB) ReverseIterator(start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
var pstart, pend []byte
|
||||
@ -277,10 +278,10 @@ func newPrefixBatch(prefix []byte, source store.RawBatch) prefixDBBatch {
|
||||
// Set implements RawBatch.
|
||||
func (pb prefixDBBatch) Set(key, value []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
if value == nil {
|
||||
return store.ErrValueNil
|
||||
return errors.ErrValueNil
|
||||
}
|
||||
pkey := append(cp(pb.prefix), key...)
|
||||
return pb.source.Set(pkey, value)
|
||||
@ -289,7 +290,7 @@ func (pb prefixDBBatch) Set(key, value []byte) error {
|
||||
// Delete implements RawBatch.
|
||||
func (pb prefixDBBatch) Delete(key []byte) error {
|
||||
if len(key) == 0 {
|
||||
return store.ErrKeyEmpty
|
||||
return errors.ErrKeyEmpty
|
||||
}
|
||||
pkey := append(cp(pb.prefix), key...)
|
||||
return pb.source.Delete(pkey)
|
||||
@ -313,7 +314,7 @@ func (pb prefixDBBatch) Close() error {
|
||||
// GetByteSize implements RawBatch
|
||||
func (pb prefixDBBatch) GetByteSize() (int, error) {
|
||||
if pb.source == nil {
|
||||
return 0, store.ErrBatchClosed
|
||||
return 0, errors.ErrBatchClosed
|
||||
}
|
||||
return pb.source.GetByteSize()
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package store
|
||||
package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -7,9 +7,12 @@ import (
|
||||
)
|
||||
|
||||
// StoreCodespace defines the store package's unique error code space.
|
||||
const StoreCodespace = "store"
|
||||
const StoreCodespace = "storev2"
|
||||
|
||||
var (
|
||||
// ErrInvalidProof is returned when a proof is invalid
|
||||
ErrInvalidProof = errors.Register(StoreCodespace, 2, "invalid proof")
|
||||
|
||||
// ErrTxDecode is returned if we cannot parse a transaction
|
||||
ErrTxDecode = errors.Register(StoreCodespace, 3, "tx parse error")
|
||||
|
||||
@ -6,11 +6,9 @@ import (
|
||||
ics23 "github.com/cosmos/ics23/go"
|
||||
|
||||
"cosmossdk.io/errors"
|
||||
storeerrors "cosmossdk.io/store/v2/errors"
|
||||
)
|
||||
|
||||
// ErrInvalidProof is returned when a proof is invalid
|
||||
var ErrInvalidProof = errors.Register("store", 2, "invalid proof")
|
||||
|
||||
// Proof operation types
|
||||
const (
|
||||
ProofOpIAVLCommitment = "ics23:iavl"
|
||||
@ -100,7 +98,7 @@ func (op CommitmentOp) Run(args [][]byte) ([][]byte, error) {
|
||||
// calculate root from proof
|
||||
root, err := op.Proof.Calculate()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(ErrInvalidProof, "could not calculate root for proof: %v", err)
|
||||
return nil, errors.Wrapf(storeerrors.ErrInvalidProof, "could not calculate root for proof: %v", err)
|
||||
}
|
||||
|
||||
// Only support an existence proof or nonexistence proof (batch proofs currently unsupported)
|
||||
@ -109,17 +107,17 @@ func (op CommitmentOp) Run(args [][]byte) ([][]byte, error) {
|
||||
// Args are nil, so we verify the absence of the key.
|
||||
absent := ics23.VerifyNonMembership(op.Spec, root, op.Proof, op.Key)
|
||||
if !absent {
|
||||
return nil, errors.Wrapf(ErrInvalidProof, "proof did not verify absence of key: %s", string(op.Key))
|
||||
return nil, errors.Wrapf(storeerrors.ErrInvalidProof, "proof did not verify absence of key: %s", string(op.Key))
|
||||
}
|
||||
|
||||
case 1:
|
||||
// Args is length 1, verify existence of key with value args[0]
|
||||
if !ics23.VerifyMembership(op.Spec, root, op.Proof, op.Key, args[0]) {
|
||||
return nil, errors.Wrapf(ErrInvalidProof, "proof did not verify existence of key %s with given value %x", op.Key, args[0])
|
||||
return nil, errors.Wrapf(storeerrors.ErrInvalidProof, "proof did not verify existence of key %s with given value %x", op.Key, args[0])
|
||||
}
|
||||
|
||||
default:
|
||||
return nil, errors.Wrapf(ErrInvalidProof, "args must be length 0 or 1, got: %d", len(args))
|
||||
return nil, errors.Wrapf(storeerrors.ErrInvalidProof, "args must be length 0 or 1, got: %d", len(args))
|
||||
}
|
||||
|
||||
return [][]byte{root}, nil
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"math"
|
||||
|
||||
"cosmossdk.io/errors"
|
||||
"cosmossdk.io/store/v2"
|
||||
storeerrors "cosmossdk.io/store/v2/errors"
|
||||
snapshotstypes "cosmossdk.io/store/v2/snapshots/types"
|
||||
)
|
||||
|
||||
@ -72,7 +72,7 @@ func (w *ChunkWriter) CloseWithError(err error) {
|
||||
// Write implements io.Writer.
|
||||
func (w *ChunkWriter) Write(data []byte) (int, error) {
|
||||
if w.closed {
|
||||
return 0, errors.Wrap(store.ErrLogic, "cannot write to closed ChunkWriter")
|
||||
return 0, errors.Wrap(storeerrors.ErrLogic, "cannot write to closed ChunkWriter")
|
||||
}
|
||||
nTotal := 0
|
||||
for len(data) > 0 {
|
||||
@ -174,7 +174,7 @@ func ValidRestoreHeight(format uint32, height uint64) error {
|
||||
}
|
||||
|
||||
if height == 0 {
|
||||
return errors.Wrap(store.ErrLogic, "cannot restore snapshot at height 0")
|
||||
return errors.Wrap(storeerrors.ErrLogic, "cannot restore snapshot at height 0")
|
||||
}
|
||||
if height > uint64(math.MaxInt64) {
|
||||
return errors.Wrapf(snapshotstypes.ErrInvalidMetadata,
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/store/v2"
|
||||
storeerrors "cosmossdk.io/store/v2/errors"
|
||||
"cosmossdk.io/store/v2/snapshots/types"
|
||||
)
|
||||
|
||||
@ -117,10 +118,10 @@ func (m *Manager) begin(op operation) error {
|
||||
// beginLocked begins an operation while already holding the mutex.
|
||||
func (m *Manager) beginLocked(op operation) error {
|
||||
if op == opNone {
|
||||
return errorsmod.Wrap(store.ErrLogic, "can't begin a none operation")
|
||||
return errorsmod.Wrap(storeerrors.ErrLogic, "can't begin a none operation")
|
||||
}
|
||||
if m.operation != opNone {
|
||||
return errorsmod.Wrapf(store.ErrConflict, "a %v operation is in progress", m.operation)
|
||||
return errorsmod.Wrapf(storeerrors.ErrConflict, "a %v operation is in progress", m.operation)
|
||||
}
|
||||
m.operation = op
|
||||
return nil
|
||||
@ -166,7 +167,7 @@ func (m *Manager) GetSnapshotBlockRetentionHeights() int64 {
|
||||
// Create creates a snapshot and returns its metadata.
|
||||
func (m *Manager) Create(height uint64) (*types.Snapshot, error) {
|
||||
if m == nil {
|
||||
return nil, errorsmod.Wrap(store.ErrLogic, "Snapshot Manager is nil")
|
||||
return nil, errorsmod.Wrap(storeerrors.ErrLogic, "Snapshot Manager is nil")
|
||||
}
|
||||
|
||||
err := m.begin(opSnapshot)
|
||||
@ -180,7 +181,7 @@ func (m *Manager) Create(height uint64) (*types.Snapshot, error) {
|
||||
return nil, errorsmod.Wrap(err, "failed to examine latest snapshot")
|
||||
}
|
||||
if latest != nil && latest.Height >= height {
|
||||
return nil, errorsmod.Wrapf(store.ErrConflict,
|
||||
return nil, errorsmod.Wrapf(storeerrors.ErrConflict,
|
||||
"a more recent snapshot already exists at height %v", latest.Height)
|
||||
}
|
||||
|
||||
@ -237,7 +238,7 @@ func (m *Manager) createSnapshot(height uint64, ch chan<- io.ReadCloser) {
|
||||
// It is used to migrate the state from the original store to the store/v2.
|
||||
func (m *Manager) CreateMigration(height uint64, protoWriter WriteCloser) error {
|
||||
if m == nil {
|
||||
return errorsmod.Wrap(store.ErrLogic, "Snapshot Manager is nil")
|
||||
return errorsmod.Wrap(storeerrors.ErrLogic, "Snapshot Manager is nil")
|
||||
}
|
||||
|
||||
err := m.begin(opSnapshot)
|
||||
@ -306,7 +307,7 @@ func (m *Manager) Restore(snapshot types.Snapshot) error {
|
||||
return errorsmod.Wrapf(types.ErrUnknownFormat, "snapshot format %v", snapshot.Format)
|
||||
}
|
||||
if snapshot.Height == 0 {
|
||||
return errorsmod.Wrap(store.ErrLogic, "cannot restore snapshot at height 0")
|
||||
return errorsmod.Wrap(storeerrors.ErrLogic, "cannot restore snapshot at height 0")
|
||||
}
|
||||
if snapshot.Height > uint64(math.MaxInt64) {
|
||||
return errorsmod.Wrapf(types.ErrInvalidMetadata,
|
||||
@ -415,11 +416,11 @@ func (m *Manager) doRestoreSnapshot(snapshot types.Snapshot, chChunks <-chan io.
|
||||
}
|
||||
metadata := nextItem.GetExtension()
|
||||
if metadata == nil {
|
||||
return errorsmod.Wrapf(store.ErrLogic, "unknown snapshot item %T", nextItem.Item)
|
||||
return errorsmod.Wrapf(storeerrors.ErrLogic, "unknown snapshot item %T", nextItem.Item)
|
||||
}
|
||||
extension, ok := m.extensions[metadata.Name]
|
||||
if !ok {
|
||||
return errorsmod.Wrapf(store.ErrLogic, "unknown extension snapshotter %s", metadata.Name)
|
||||
return errorsmod.Wrapf(storeerrors.ErrLogic, "unknown extension snapshotter %s", metadata.Name)
|
||||
}
|
||||
if !IsFormatSupported(extension, metadata.Format) {
|
||||
return errorsmod.Wrapf(types.ErrUnknownFormat, "format %v for extension %s", metadata.Format, metadata.Name)
|
||||
@ -448,11 +449,11 @@ func (m *Manager) RestoreChunk(chunk []byte) (bool, error) {
|
||||
m.mtx.Lock()
|
||||
defer m.mtx.Unlock()
|
||||
if m.operation != opRestore {
|
||||
return false, errorsmod.Wrap(store.ErrLogic, "no restore operation in progress")
|
||||
return false, errorsmod.Wrap(storeerrors.ErrLogic, "no restore operation in progress")
|
||||
}
|
||||
|
||||
if int(m.restoreChunkIndex) >= len(m.restoreSnapshot.Metadata.ChunkHashes) {
|
||||
return false, errorsmod.Wrap(store.ErrLogic, "received unexpected chunk")
|
||||
return false, errorsmod.Wrap(storeerrors.ErrLogic, "received unexpected chunk")
|
||||
}
|
||||
|
||||
// Check if any errors have occurred yet.
|
||||
@ -462,7 +463,7 @@ func (m *Manager) RestoreChunk(chunk []byte) (bool, error) {
|
||||
if done.err != nil {
|
||||
return false, done.err
|
||||
}
|
||||
return false, errorsmod.Wrap(store.ErrLogic, "restore ended unexpectedly")
|
||||
return false, errorsmod.Wrap(storeerrors.ErrLogic, "restore ended unexpectedly")
|
||||
default:
|
||||
}
|
||||
|
||||
@ -498,7 +499,7 @@ func (m *Manager) RestoreChunk(chunk []byte) (bool, error) {
|
||||
return false, done.err
|
||||
}
|
||||
if !done.complete {
|
||||
return false, errorsmod.Wrap(store.ErrLogic, "restore ended prematurely")
|
||||
return false, errorsmod.Wrap(storeerrors.ErrLogic, "restore ended prematurely")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
|
||||
"cosmossdk.io/errors"
|
||||
"cosmossdk.io/store/v2"
|
||||
storeerrors "cosmossdk.io/store/v2/errors"
|
||||
"cosmossdk.io/store/v2/snapshots/types"
|
||||
)
|
||||
|
||||
@ -37,7 +38,7 @@ type Store struct {
|
||||
// NewStore creates a new snapshot store.
|
||||
func NewStore(dir string) (*Store, error) {
|
||||
if dir == "" {
|
||||
return nil, errors.Wrap(store.ErrLogic, "snapshot directory not given")
|
||||
return nil, errors.Wrap(storeerrors.ErrLogic, "snapshot directory not given")
|
||||
}
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
@ -60,7 +61,7 @@ func (s *Store) Delete(height uint64, format uint32) error {
|
||||
saving := s.saving[height]
|
||||
s.mtx.Unlock()
|
||||
if saving {
|
||||
return errors.Wrapf(store.ErrConflict,
|
||||
return errors.Wrapf(storeerrors.ErrConflict,
|
||||
"snapshot for height %v format %v is currently being saved", height, format)
|
||||
}
|
||||
if err := os.RemoveAll(s.pathSnapshot(height, format)); err != nil {
|
||||
@ -248,7 +249,7 @@ func (s *Store) Save(
|
||||
) (*types.Snapshot, error) {
|
||||
defer DrainChunks(chunks)
|
||||
if height == 0 {
|
||||
return nil, errors.Wrap(store.ErrLogic, "snapshot height cannot be 0")
|
||||
return nil, errors.Wrap(storeerrors.ErrLogic, "snapshot height cannot be 0")
|
||||
}
|
||||
|
||||
s.mtx.Lock()
|
||||
@ -256,7 +257,7 @@ func (s *Store) Save(
|
||||
s.saving[height] = true
|
||||
s.mtx.Unlock()
|
||||
if saving {
|
||||
return nil, errors.Wrapf(store.ErrConflict,
|
||||
return nil, errors.Wrapf(storeerrors.ErrConflict,
|
||||
"a snapshot for height %v is already being saved", height)
|
||||
}
|
||||
defer func() {
|
||||
@ -399,10 +400,10 @@ func (s *Store) validateMetadataPath(path string) error {
|
||||
// legacyV1DecodeKey decodes a legacy snapshot key used in a raw kv store.
|
||||
func legacyV1DecodeKey(k []byte) (uint64, uint32, error) {
|
||||
if len(k) != 13 {
|
||||
return 0, 0, errors.Wrapf(store.ErrLogic, "invalid snapshot key with length %v", len(k))
|
||||
return 0, 0, errors.Wrapf(storeerrors.ErrLogic, "invalid snapshot key with length %v", len(k))
|
||||
}
|
||||
if k[0] != keyPrefixSnapshot {
|
||||
return 0, 0, errors.Wrapf(store.ErrLogic, "invalid snapshot key prefix %x", k[0])
|
||||
return 0, 0, errors.Wrapf(storeerrors.ErrLogic, "invalid snapshot key prefix %x", k[0])
|
||||
}
|
||||
|
||||
height := binary.BigEndian.Uint64(k[1:9])
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
|
||||
corestore "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/store/v2"
|
||||
storeerrors "cosmossdk.io/store/v2/errors"
|
||||
"cosmossdk.io/store/v2/storage"
|
||||
)
|
||||
|
||||
@ -148,12 +149,12 @@ func (db *Database) Has(storeKey string, version uint64, key []byte) (bool, erro
|
||||
|
||||
func (db *Database) Get(storeKey string, targetVersion uint64, key []byte) ([]byte, error) {
|
||||
if targetVersion < db.earliestVersion {
|
||||
return nil, store.ErrVersionPruned{EarliestVersion: db.earliestVersion}
|
||||
return nil, storeerrors.ErrVersionPruned{EarliestVersion: db.earliestVersion}
|
||||
}
|
||||
|
||||
prefixedVal, err := getMVCCSlice(db.storage, storeKey, key, targetVersion)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrRecordNotFound) {
|
||||
if errors.Is(err, storeerrors.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@ -268,11 +269,11 @@ func (db *Database) Prune(version uint64) error {
|
||||
|
||||
func (db *Database) Iterator(storeKey string, version uint64, start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, storeerrors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
if start != nil && end != nil && bytes.Compare(start, end) > 0 {
|
||||
return nil, store.ErrStartAfterEnd
|
||||
return nil, storeerrors.ErrStartAfterEnd
|
||||
}
|
||||
|
||||
lowerBound := MVCCEncode(prependStoreKey(storeKey, start), 0)
|
||||
@ -292,11 +293,11 @@ func (db *Database) Iterator(storeKey string, version uint64, start, end []byte)
|
||||
|
||||
func (db *Database) ReverseIterator(storeKey string, version uint64, start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, storeerrors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
if start != nil && end != nil && bytes.Compare(start, end) > 0 {
|
||||
return nil, store.ErrStartAfterEnd
|
||||
return nil, storeerrors.ErrStartAfterEnd
|
||||
}
|
||||
|
||||
lowerBound := MVCCEncode(prependStoreKey(storeKey, start), 0)
|
||||
@ -378,7 +379,7 @@ func getMVCCSlice(db *pebble.DB, storeKey string, key []byte, version uint64) ([
|
||||
defer itr.Close()
|
||||
|
||||
if !itr.Last() {
|
||||
return nil, store.ErrRecordNotFound
|
||||
return nil, storeerrors.ErrRecordNotFound
|
||||
}
|
||||
|
||||
_, vBz, ok := SplitMVCCKey(itr.Key())
|
||||
|
||||
@ -8,11 +8,13 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/linxGnu/grocksdb"
|
||||
"slices"
|
||||
|
||||
"github.com/linxGnu/grocksdb"
|
||||
|
||||
corestore "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/store/v2"
|
||||
"cosmossdk.io/store/v2/errors"
|
||||
"cosmossdk.io/store/v2/storage"
|
||||
"cosmossdk.io/store/v2/storage/util"
|
||||
)
|
||||
@ -98,7 +100,7 @@ func (db *Database) NewBatch(version uint64) (store.Batch, error) {
|
||||
|
||||
func (db *Database) getSlice(storeKey string, version uint64, key []byte) (*grocksdb.Slice, error) {
|
||||
if version < db.tsLow {
|
||||
return nil, store.ErrVersionPruned{EarliestVersion: db.tsLow}
|
||||
return nil, errors.ErrVersionPruned{EarliestVersion: db.tsLow}
|
||||
}
|
||||
|
||||
return db.storage.GetCF(
|
||||
@ -165,11 +167,11 @@ func (db *Database) Prune(version uint64) error {
|
||||
|
||||
func (db *Database) Iterator(storeKey string, version uint64, start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
if start != nil && end != nil && bytes.Compare(start, end) > 0 {
|
||||
return nil, store.ErrStartAfterEnd
|
||||
return nil, errors.ErrStartAfterEnd
|
||||
}
|
||||
|
||||
prefix := storePrefix(storeKey)
|
||||
@ -181,11 +183,11 @@ func (db *Database) Iterator(storeKey string, version uint64, start, end []byte)
|
||||
|
||||
func (db *Database) ReverseIterator(storeKey string, version uint64, start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, errors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
if start != nil && end != nil && bytes.Compare(start, end) > 0 {
|
||||
return nil, store.ErrStartAfterEnd
|
||||
return nil, errors.ErrStartAfterEnd
|
||||
}
|
||||
|
||||
prefix := storePrefix(storeKey)
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
|
||||
corestore "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/store/v2"
|
||||
storeerrors "cosmossdk.io/store/v2/errors"
|
||||
"cosmossdk.io/store/v2/storage"
|
||||
)
|
||||
|
||||
@ -138,7 +139,7 @@ func (db *Database) Has(storeKey string, version uint64, key []byte) (bool, erro
|
||||
|
||||
func (db *Database) Get(storeKey string, targetVersion uint64, key []byte) ([]byte, error) {
|
||||
if targetVersion < db.earliestVersion {
|
||||
return nil, store.ErrVersionPruned{EarliestVersion: db.earliestVersion}
|
||||
return nil, storeerrors.ErrVersionPruned{EarliestVersion: db.earliestVersion}
|
||||
}
|
||||
|
||||
stmt, err := db.storage.Prepare(`
|
||||
@ -217,11 +218,11 @@ func (db *Database) Prune(version uint64) error {
|
||||
|
||||
func (db *Database) Iterator(storeKey string, version uint64, start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, storeerrors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
if start != nil && end != nil && bytes.Compare(start, end) > 0 {
|
||||
return nil, store.ErrStartAfterEnd
|
||||
return nil, storeerrors.ErrStartAfterEnd
|
||||
}
|
||||
|
||||
return newIterator(db, storeKey, version, start, end, false)
|
||||
@ -229,11 +230,11 @@ func (db *Database) Iterator(storeKey string, version uint64, start, end []byte)
|
||||
|
||||
func (db *Database) ReverseIterator(storeKey string, version uint64, start, end []byte) (corestore.Iterator, error) {
|
||||
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
|
||||
return nil, store.ErrKeyEmpty
|
||||
return nil, storeerrors.ErrKeyEmpty
|
||||
}
|
||||
|
||||
if start != nil && end != nil && bytes.Compare(start, end) > 0 {
|
||||
return nil, store.ErrStartAfterEnd
|
||||
return nil, storeerrors.ErrStartAfterEnd
|
||||
}
|
||||
|
||||
return newIterator(db, storeKey, version, start, end, true)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user