Skip to content

Commit 6a105fe

Browse files
mergify[bot]catShaarktac0turtle
authored andcommitted
chore: Add check for uneven stores' height (backport cosmos#14410) (cosmos#15115)
Co-authored-by: khanh-notional <[email protected]> Co-authored-by: marbar3778 <[email protected]>
1 parent 9fb51f0 commit 6a105fe

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4343
### Improvements
4444

4545
* (cli) [#14953](https://github.com/cosmos/cosmos-sdk/pull/14953) Enable profiling block replay during abci handshake with `--cpu-profile`.
46+
* (store) [#14410](https://github.com/cosmos/cosmos-sdk/pull/14410) `rootmulti.Store.loadVersion` has validation to check if all the module stores' height is correct, it will error if any module store has incorrect height.
4647

4748
## [v0.46.9](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.9) - 2022-02-07
4849

go.mod

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ require (
4747
github.com/spf13/viper v1.13.0
4848
github.com/stretchr/testify v1.8.1
4949
github.com/tendermint/go-amino v0.16.0
50-
github.com/tendermint/tendermint v0.34.26
50+
github.com/tendermint/tendermint v0.34.24
5151
github.com/tendermint/tm-db v0.6.7
5252
github.com/tidwall/btree v1.5.0
5353
golang.org/x/crypto v0.5.0
@@ -162,7 +162,6 @@ replace (
162162
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
163163
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
164164
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
165-
166165
github.com/jhump/protoreflect => github.com/jhump/protoreflect v1.9.0
167166
// use informal system fork of tendermint
168167
github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.26

store/rootmulti/store.go

+9
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,15 @@ type storeParams struct {
11001100
initialVersion uint64
11011101
}
11021102

1103+
func newStoreParams(key types.StoreKey, db dbm.DB, typ types.StoreType, initialVersion uint64) storeParams { // nolint
1104+
return storeParams{
1105+
key: key,
1106+
db: db,
1107+
typ: typ,
1108+
initialVersion: initialVersion,
1109+
}
1110+
}
1111+
11031112
func GetLatestVersion(db dbm.DB) int64 {
11041113
bz, err := db.Get([]byte(latestVersionKey))
11051114
if err != nil {

store/rootmulti/store_test.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func TestMultistoreLoadWithUpgrade(t *testing.T) {
301301
migratedID := restore.Commit()
302302
require.Equal(t, migratedID.Version, int64(2))
303303

304-
reload, _ := newMultiStoreWithModifiedMounts(db, types.PruneNothing)
304+
reload, _ := newMultiStoreWithModifiedMounts(db, pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
305305
// unmount store3 since store3 was deleted
306306
unmountStore(reload, "store3")
307307

@@ -669,6 +669,32 @@ func TestUnevenStoresHeightCheck(t *testing.T) {
669669
require.Nil(t, err)
670670
}
671671

672+
// TestUnevenStoresHeightCheck tests if loading root store correctly errors when
673+
// there's any module store with the wrong height
674+
func TestUnevenStoresHeightCheck(t *testing.T) {
675+
var db dbm.DB = dbm.NewMemDB()
676+
store := newMultiStoreWithMounts(db, pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
677+
err := store.LoadLatestVersion()
678+
require.Nil(t, err)
679+
680+
// commit to increment store's height
681+
store.Commit()
682+
683+
// mount store4 to root store
684+
store.MountStoreWithDB(types.NewKVStoreKey("store4"), types.StoreTypeIAVL, nil)
685+
686+
// load the stores without upgrades
687+
err = store.LoadLatestVersion()
688+
require.Error(t, err)
689+
690+
// now, let's load with upgrades...
691+
upgrades := &types.StoreUpgrades{
692+
Added: []string{"store4"},
693+
}
694+
err = store.LoadLatestVersionAndUpgrade(upgrades)
695+
require.Nil(t, err)
696+
}
697+
672698
func TestSetInitialVersion(t *testing.T) {
673699
db := coretesting.NewMemDB()
674700
multi := newMultiStoreWithMounts(db, pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))

x/upgrade/types/storeloader_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ func TestSetLoader(t *testing.T) {
141141

142142
require.Equal(t, upgradeHeight-1, newApp.LastBlockHeight())
143143

144-
// "execute" one block
145-
_, err = newApp.FinalizeBlock(&abci.FinalizeBlockRequest{Height: upgradeHeight})
146-
require.NoError(t, err)
147-
_, err = newApp.Commit()
148-
require.NoError(t, err)
149-
require.Equal(t, upgradeHeight, newApp.LastBlockHeight())
150-
151144
// check db is properly updated
152145
checkStore(t, db, upgradeHeight, tc.loadStoreKey, k, v)
153146
})

0 commit comments

Comments
 (0)