Skip to content

Commit 2eaff98

Browse files
authored
Merge branch 'main' into son/lockup_unbond_sync
2 parents 0c26ac3 + 8a0244b commit 2eaff98

18 files changed

+238
-32
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
228228
* (types/mempool) [#21744](https://github.com/cosmos/cosmos-sdk/pull/21744) Update types/mempool.Mempool interface to take decoded transactions. This avoid to decode the transaction twice.
229229
* (x/auth/tx/config) [#21822](https://github.com/cosmos/cosmos-sdk/pull/21822) Sign mode textual is no more automatically added to tx config when using runtime. Should be added manually on the server side.
230230
* (x/auth/tx/config) [#21822](https://github.com/cosmos/cosmos-sdk/pull/21822) This depinject module now only provide txconfig and tx config options. `x/validate` now handles the providing of ante/post handlers, alongside tx validators for v2. The corresponding app config options have been removed from the depinject module config.
231+
* (x/crisis) [#20809](https://github.com/cosmos/cosmos-sdk/pull/20809) Crisis module was removed from the Cosmos SDK.
231232

232233
### Client Breaking Changes
233234

Diff for: runtime/v2/store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Store interface {
4343
Query(storeKey []byte, version uint64, key []byte, prove bool) (storev2.QueryResult, error)
4444

4545
// GetStateStorage returns the SS backend.
46-
GetStateStorage() storev2.VersionedDatabase
46+
GetStateStorage() storev2.VersionedWriter
4747

4848
// GetStateCommitment returns the SC backend.
4949
GetStateCommitment() storev2.Committer

Diff for: store/v2/commitment/store.go

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ func (c *CommitStore) GetProof(storeKey []byte, version uint64, key []byte) ([]p
275275
return []proof.CommitmentOp{commitOp, *storeCommitmentOp}, nil
276276
}
277277

278+
// Get implements store.VersionedReader.
278279
func (c *CommitStore) Get(storeKey []byte, version uint64, key []byte) ([]byte, error) {
279280
tree, ok := c.multiTrees[conv.UnsafeBytesToStr(storeKey)]
280281
if !ok {

Diff for: store/v2/database.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@ import (
77
"cosmossdk.io/store/v2/proof"
88
)
99

10-
// VersionedDatabase defines an API for a versioned database that allows reads,
10+
// VersionedWriter defines an API for a versioned database that allows reads,
1111
// writes, iteration and commitment over a series of versions.
12-
type VersionedDatabase interface {
12+
type VersionedWriter interface {
13+
VersionedReader
14+
15+
SetLatestVersion(version uint64) error
16+
ApplyChangeset(version uint64, cs *corestore.Changeset) error
17+
18+
// Close releases associated resources. It should NOT be idempotent. It must
19+
// only be called once and any call after may panic.
20+
io.Closer
21+
}
22+
23+
type VersionedReader interface {
1324
Has(storeKey []byte, version uint64, key []byte) (bool, error)
1425
Get(storeKey []byte, version uint64, key []byte) ([]byte, error)
26+
1527
GetLatestVersion() (uint64, error)
16-
SetLatestVersion(version uint64) error
28+
VersionExists(v uint64) (bool, error)
1729

1830
Iterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)
1931
ReverseIterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)
2032

21-
ApplyChangeset(version uint64, cs *corestore.Changeset) error
22-
2333
// Close releases associated resources. It should NOT be idempotent. It must
2434
// only be called once and any call after may panic.
2535
io.Closer
@@ -53,18 +63,14 @@ type Committer interface {
5363
// GetProof returns the proof of existence or non-existence for the given key.
5464
GetProof(storeKey []byte, version uint64, key []byte) ([]proof.CommitmentOp, error)
5565

56-
// Get returns the value for the given key at the given version.
57-
//
58-
// NOTE: This method only exists to support migration from IAVL v0/v1 to v2.
59-
// Once migration is complete, this method should be removed and/or not used.
60-
Get(storeKey []byte, version uint64, key []byte) ([]byte, error)
61-
6266
// SetInitialVersion sets the initial version of the committer.
6367
SetInitialVersion(version uint64) error
6468

6569
// GetCommitInfo returns the CommitInfo for the given version.
6670
GetCommitInfo(version uint64) (*proof.CommitInfo, error)
6771

72+
Get(storeKey []byte, version uint64, key []byte) ([]byte, error)
73+
6874
// Close releases associated resources. It should NOT be idempotent. It must
6975
// only be called once and any call after may panic.
7076
io.Closer

Diff for: store/v2/mock/db_mock.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: store/v2/mock/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type StateCommitter interface {
1212

1313
// StateStorage is a mock of store.VersionedDatabase
1414
type StateStorage interface {
15-
store.VersionedDatabase
15+
store.VersionedWriter
1616
store.UpgradableDatabase
1717
store.Pruner
1818
store.PausablePruner

Diff for: store/v2/root/store.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Store struct {
3838
dbCloser io.Closer
3939

4040
// stateStorage reflects the state storage backend
41-
stateStorage store.VersionedDatabase
41+
stateStorage store.VersionedWriter
4242

4343
// stateCommitment reflects the state commitment (SC) backend
4444
stateCommitment store.Committer
@@ -74,7 +74,7 @@ type Store struct {
7474
func New(
7575
dbCloser io.Closer,
7676
logger corelog.Logger,
77-
ss store.VersionedDatabase,
77+
ss store.VersionedWriter,
7878
sc store.Committer,
7979
pm *pruning.Manager,
8080
mm *migration.Manager,
@@ -127,19 +127,21 @@ func (s *Store) StateLatest() (uint64, corestore.ReaderMap, error) {
127127
return v, NewReaderMap(v, s), nil
128128
}
129129

130+
// StateAt checks if the requested version is present in ss.
130131
func (s *Store) StateAt(v uint64) (corestore.ReaderMap, error) {
131-
// TODO(bez): We may want to avoid relying on the SC metadata here. Instead,
132-
// we should add a VersionExists() method to the VersionedDatabase interface.
133-
//
134-
// Ref: https://github.com/cosmos/cosmos-sdk/issues/19091
135-
if cInfo, err := s.stateCommitment.GetCommitInfo(v); err != nil || cInfo == nil {
136-
return nil, fmt.Errorf("failed to get commit info for version %d: %w", v, err)
132+
// check if version is present in state storage
133+
isExist, err := s.stateStorage.VersionExists(v)
134+
if err != nil {
135+
return nil, err
136+
}
137+
if !isExist {
138+
return nil, fmt.Errorf("version %d does not exist", v)
137139
}
138140

139141
return NewReaderMap(v, s), nil
140142
}
141143

142-
func (s *Store) GetStateStorage() store.VersionedDatabase {
144+
func (s *Store) GetStateStorage() store.VersionedWriter {
143145
return s.stateStorage
144146
}
145147

Diff for: store/v2/root/store_mock_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"cosmossdk.io/store/v2/pruning"
1717
)
1818

19-
func newTestRootStore(ss store.VersionedDatabase, sc store.Committer) *Store {
19+
func newTestRootStore(ss store.VersionedWriter, sc store.Committer) *Store {
2020
noopLog := coretesting.NewNopLogger()
2121
pm := pruning.NewManager(sc.(store.Pruner), ss.(store.Pruner), nil, nil)
2222
return &Store{

Diff for: store/v2/root/store_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (s *RootStoreTestSuite) newStoreWithPruneConfig(config *store.PruningOption
9090
s.rootStore = rs
9191
}
9292

93-
func (s *RootStoreTestSuite) newStoreWithBackendMount(ss store.VersionedDatabase, sc store.Committer, pm *pruning.Manager) {
93+
func (s *RootStoreTestSuite) newStoreWithBackendMount(ss store.VersionedWriter, sc store.Committer, pm *pruning.Manager) {
9494
noopLog := coretesting.NewNopLogger()
9595

9696
rs, err := New(dbm.NewMemDB(), noopLog, ss, sc, pm, nil, nil)

Diff for: store/v2/storage/database.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Database interface {
1616
Get(storeKey []byte, version uint64, key []byte) ([]byte, error)
1717
GetLatestVersion() (uint64, error)
1818
SetLatestVersion(version uint64) error
19+
VersionExists(version uint64) (bool, error)
1920

2021
Iterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)
2122
ReverseIterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error)

Diff for: store/v2/storage/pebbledb/db.go

+9
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ func (db *Database) GetLatestVersion() (uint64, error) {
137137
return binary.LittleEndian.Uint64(bz), closer.Close()
138138
}
139139

140+
func (db *Database) VersionExists(version uint64) (bool, error) {
141+
latestVersion, err := db.GetLatestVersion()
142+
if err != nil {
143+
return false, err
144+
}
145+
146+
return latestVersion >= version && version >= db.earliestVersion, nil
147+
}
148+
140149
func (db *Database) setPruneHeight(pruneVersion uint64) error {
141150
db.earliestVersion = pruneVersion + 1
142151

Diff for: store/v2/storage/rocksdb/db.go

+9
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ func (db *Database) GetLatestVersion() (uint64, error) {
131131
return binary.LittleEndian.Uint64(bz), nil
132132
}
133133

134+
func (db *Database) VersionExists(version uint64) (bool, error) {
135+
latestVersion, err := db.GetLatestVersion()
136+
if err != nil {
137+
return false, err
138+
}
139+
140+
return latestVersion >= version && version >= db.tsLow, nil
141+
}
142+
134143
func (db *Database) Has(storeKey []byte, version uint64, key []byte) (bool, error) {
135144
slice, err := db.getSlice(storeKey, version, key)
136145
if err != nil {

Diff for: store/v2/storage/rocksdb/db_noflag.go

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func (db *Database) GetLatestVersion() (uint64, error) {
3636
panic("rocksdb requires a build flag")
3737
}
3838

39+
func (db *Database) VersionExists(version uint64) (bool, error) {
40+
panic("rocksdb requires a build flag")
41+
}
42+
3943
func (db *Database) Has(storeKey []byte, version uint64, key []byte) (bool, error) {
4044
panic("rocksdb requires a build flag")
4145
}

Diff for: store/v2/storage/sqlite/db.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ func (db *Database) NewBatch(version uint64) (store.Batch, error) {
103103
}
104104

105105
func (db *Database) GetLatestVersion() (uint64, error) {
106-
stmt, err := db.storage.Prepare("SELECT value FROM state_storage WHERE store_key = ? AND key = ?")
106+
stmt, err := db.storage.Prepare(`
107+
SELECT value
108+
FROM state_storage
109+
WHERE store_key = ? AND key = ?
110+
`)
107111
if err != nil {
108112
return 0, fmt.Errorf("failed to prepare SQL statement: %w", err)
109113
}
@@ -123,6 +127,15 @@ func (db *Database) GetLatestVersion() (uint64, error) {
123127
return latestHeight, nil
124128
}
125129

130+
func (db *Database) VersionExists(v uint64) (bool, error) {
131+
latestVersion, err := db.GetLatestVersion()
132+
if err != nil {
133+
return false, err
134+
}
135+
136+
return latestVersion >= v && v >= db.earliestVersion, nil
137+
}
138+
126139
func (db *Database) SetLatestVersion(version uint64) error {
127140
_, err := db.storage.Exec(reservedUpsertStmt, reservedStoreKey, keyLatestHeight, version, 0, version)
128141
if err != nil {

Diff for: store/v2/storage/storage_bench_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ import (
2424
var storeKey1 = []byte("store1")
2525

2626
var (
27-
backends = map[string]func(dataDir string) (store.VersionedDatabase, error){
28-
"rocksdb_versiondb_opts": func(dataDir string) (store.VersionedDatabase, error) {
27+
backends = map[string]func(dataDir string) (store.VersionedWriter, error){
28+
"rocksdb_versiondb_opts": func(dataDir string) (store.VersionedWriter, error) {
2929
db, err := rocksdb.New(dataDir)
3030
return storage.NewStorageStore(db, coretesting.NewNopLogger()), err
3131
},
32-
"pebbledb_default_opts": func(dataDir string) (store.VersionedDatabase, error) {
32+
"pebbledb_default_opts": func(dataDir string) (store.VersionedWriter, error) {
3333
db, err := pebbledb.New(dataDir)
3434
if err == nil && db != nil {
3535
db.SetSync(false)
3636
}
3737

3838
return storage.NewStorageStore(db, coretesting.NewNopLogger()), err
3939
},
40-
"btree_sqlite": func(dataDir string) (store.VersionedDatabase, error) {
40+
"btree_sqlite": func(dataDir string) (store.VersionedWriter, error) {
4141
db, err := sqlite.New(dataDir)
4242
return storage.NewStorageStore(db, coretesting.NewNopLogger()), err
4343
},

0 commit comments

Comments
 (0)