Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Improvements

* [#1684](https://github.com/crypto-org-chain/cronos/pull/1684) versiondb NewKVStore accept string as store name.
* [#1688](https://github.com/crypto-org-chain/cronos/pull/1688) Add Timestamp api to versiondb iterator.

*Nov 6, 2024*

Expand Down
10 changes: 8 additions & 2 deletions versiondb/tsrocksdb/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tsrocksdb
import (
"bytes"

"cosmossdk.io/store/types"
"github.com/crypto-org-chain/cronos/versiondb"
"github.com/linxGnu/grocksdb"
)

Expand All @@ -14,7 +14,7 @@ type rocksDBIterator struct {
isInvalid bool
}

var _ types.Iterator = (*rocksDBIterator)(nil)
var _ versiondb.Iterator = (*rocksDBIterator)(nil)

func newRocksDBIterator(source *grocksdb.Iterator, prefix, start, end []byte, isReverse bool) *rocksDBIterator {
if isReverse {
Expand Down Expand Up @@ -94,6 +94,12 @@ func (itr *rocksDBIterator) Valid() bool {
return true
}

// Timestamp implements Iterator.
func (itr *rocksDBIterator) Timestamp() []byte {
itr.assertIsValid()
return moveSliceToBytes(itr.source.Timestamp())
}

// Key implements Iterator.
func (itr *rocksDBIterator) Key() []byte {
itr.assertIsValid()
Expand Down
4 changes: 2 additions & 2 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s Store) GetLatestVersion() (int64, error) {
}

// IteratorAtVersion implements VersionStore interface
func (s Store) IteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error) {
func (s Store) IteratorAtVersion(storeKey string, start, end []byte, version *int64) (versiondb.Iterator, error) {
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
return nil, errKeyEmpty
}
Expand All @@ -140,7 +140,7 @@ func (s Store) IteratorAtVersion(storeKey string, start, end []byte, version *in
}

// ReverseIteratorAtVersion implements VersionStore interface
func (s Store) ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error) {
func (s Store) ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (versiondb.Iterator, error) {
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
return nil, errKeyEmpty
}
Expand Down
10 changes: 8 additions & 2 deletions versiondb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import (
"cosmossdk.io/store/types"
)

type Iterator interface {
types.Iterator

Timestamp() []byte
}

// VersionStore is a versioned storage of a flat key-value pairs.
// it don't need to support merkle proof, so could be implemented in a much more efficient way.
// `nil` version means the latest version.
type VersionStore interface {
GetAtVersion(storeKey string, key []byte, version *int64) ([]byte, error)
HasAtVersion(storeKey string, key []byte, version *int64) (bool, error)
IteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error)
ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error)
IteratorAtVersion(storeKey string, start, end []byte, version *int64) (Iterator, error)
ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (Iterator, error)
GetLatestVersion() (int64, error)

// Persist the change set of a block,
Expand Down