Skip to content

Commit

Permalink
chore: Add check for uneven stores' height (backport cosmos#14410) (c…
Browse files Browse the repository at this point in the history
…osmos#15115)

Co-authored-by: khanh-notional <[email protected]>
Co-authored-by: marbar3778 <[email protected]>
  • Loading branch information
3 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 9fb51f0 commit 6a105fe
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (cli) [#14953](https://github.com/cosmos/cosmos-sdk/pull/14953) Enable profiling block replay during abci handshake with `--cpu-profile`.
* (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.

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

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.1
github.com/tendermint/go-amino v0.16.0
github.com/tendermint/tendermint v0.34.26
github.com/tendermint/tendermint v0.34.24
github.com/tendermint/tm-db v0.6.7
github.com/tidwall/btree v1.5.0
golang.org/x/crypto v0.5.0
Expand Down Expand Up @@ -162,7 +162,6 @@ replace (
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

github.com/jhump/protoreflect => github.com/jhump/protoreflect v1.9.0
// use informal system fork of tendermint
github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.26
Expand Down
9 changes: 9 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,15 @@ type storeParams struct {
initialVersion uint64
}

func newStoreParams(key types.StoreKey, db dbm.DB, typ types.StoreType, initialVersion uint64) storeParams { // nolint
return storeParams{
key: key,
db: db,
typ: typ,
initialVersion: initialVersion,
}
}

func GetLatestVersion(db dbm.DB) int64 {
bz, err := db.Get([]byte(latestVersionKey))
if err != nil {
Expand Down
28 changes: 27 additions & 1 deletion store/rootmulti/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func TestMultistoreLoadWithUpgrade(t *testing.T) {
migratedID := restore.Commit()
require.Equal(t, migratedID.Version, int64(2))

reload, _ := newMultiStoreWithModifiedMounts(db, types.PruneNothing)
reload, _ := newMultiStoreWithModifiedMounts(db, pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
// unmount store3 since store3 was deleted
unmountStore(reload, "store3")

Expand Down Expand Up @@ -669,6 +669,32 @@ func TestUnevenStoresHeightCheck(t *testing.T) {
require.Nil(t, err)
}

// TestUnevenStoresHeightCheck tests if loading root store correctly errors when
// there's any module store with the wrong height
func TestUnevenStoresHeightCheck(t *testing.T) {
var db dbm.DB = dbm.NewMemDB()
store := newMultiStoreWithMounts(db, pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
err := store.LoadLatestVersion()
require.Nil(t, err)

// commit to increment store's height
store.Commit()

// mount store4 to root store
store.MountStoreWithDB(types.NewKVStoreKey("store4"), types.StoreTypeIAVL, nil)

// load the stores without upgrades
err = store.LoadLatestVersion()
require.Error(t, err)

// now, let's load with upgrades...
upgrades := &types.StoreUpgrades{
Added: []string{"store4"},
}
err = store.LoadLatestVersionAndUpgrade(upgrades)
require.Nil(t, err)
}

func TestSetInitialVersion(t *testing.T) {
db := coretesting.NewMemDB()
multi := newMultiStoreWithMounts(db, pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
Expand Down
7 changes: 0 additions & 7 deletions x/upgrade/types/storeloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ func TestSetLoader(t *testing.T) {

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

// "execute" one block
_, err = newApp.FinalizeBlock(&abci.FinalizeBlockRequest{Height: upgradeHeight})
require.NoError(t, err)
_, err = newApp.Commit()
require.NoError(t, err)
require.Equal(t, upgradeHeight, newApp.LastBlockHeight())

// check db is properly updated
checkStore(t, db, upgradeHeight, tc.loadStoreKey, k, v)
})
Expand Down

0 comments on commit 6a105fe

Please sign in to comment.