Skip to content

Commit

Permalink
Problem: can't read timestamp in versiondb iterator (#1688)
Browse files Browse the repository at this point in the history
* Problem: can't read timestamp in versiondb iterator

Solution:
- add timestamp api to versiondb iterator

* Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

---------

Signed-off-by: yihuang <[email protected]>
  • Loading branch information
yihuang authored Nov 12, 2024
1 parent 9086913 commit 0c5e998
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
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

0 comments on commit 0c5e998

Please sign in to comment.