Skip to content

Commit

Permalink
Merge branch 'master' into fix_power_reduction_test_cast_int64
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 authored Nov 13, 2020
2 parents 8bc429d + 6e3fab8 commit 9e9dbf3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
4 changes: 3 additions & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ func (rs *Store) TracingEnabled() bool {
// LastCommitID implements Committer/CommitStore.
func (rs *Store) LastCommitID() types.CommitID {
if rs.lastCommitInfo == nil {
return types.CommitID{}
return types.CommitID{
Version: getLatestVersion(rs.db),
}
}

return rs.lastCommitInfo.CommitID()
Expand Down
4 changes: 2 additions & 2 deletions x/upgrade/types/storeloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
// pattern. This is useful for custom upgrade loading logic.
func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *store.StoreUpgrades) baseapp.StoreLoader {
return func(ms sdk.CommitMultiStore) error {
if upgradeHeight == ms.LastCommitID().Version {
if upgradeHeight == ms.LastCommitID().Version+1 {
// Check if the current commit version and upgrade height matches
if len(storeUpgrades.Renamed) > 0 || len(storeUpgrades.Deleted) > 0 {
if len(storeUpgrades.Renamed) > 0 || len(storeUpgrades.Deleted) > 0 || len(storeUpgrades.Added) > 0 {
return ms.LoadLatestVersionAndUpgrade(storeUpgrades)
}
}
Expand Down
29 changes: 21 additions & 8 deletions x/upgrade/types/storeloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte
// Test that we can make commits and then reload old versions.
// Test that LoadLatestVersion actually does.
func TestSetLoader(t *testing.T) {
upgradeHeight := int64(5)

// set a temporary home dir
homeDir := t.TempDir()
upgradeInfoFilePath := filepath.Join(homeDir, "upgrade-info.json")
upgradeInfo := &store.UpgradeInfo{
Name: "test", Height: 0,
Name: "test", Height: upgradeHeight,
}

data, err := json.Marshal(upgradeInfo)
Expand All @@ -92,7 +94,7 @@ func TestSetLoader(t *testing.T) {
loadStoreKey: "foo",
},
"rename with inline opts": {
setLoader: useUpgradeLoader(0, &store.StoreUpgrades{
setLoader: useUpgradeLoader(upgradeHeight, &store.StoreUpgrades{
Renamed: []store.StoreRename{{
OldKey: "foo",
NewKey: "bar",
Expand All @@ -116,25 +118,36 @@ func TestSetLoader(t *testing.T) {

// load the app with the existing db
opts := []func(*baseapp.BaseApp){baseapp.SetPruning(store.PruneNothing)}

origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...)
origapp.MountStores(sdk.NewKVStoreKey(tc.origStoreKey))
err := origapp.LoadLatestVersion()
require.Nil(t, err)

for i := int64(2); i <= upgradeHeight-1; i++ {
origapp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: i}})
res := origapp.Commit()
require.NotNil(t, res.Data)
}

if tc.setLoader != nil {
opts = append(opts, tc.setLoader)
}

// load the new app with the original app db
app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...)
capKey := sdk.NewKVStoreKey("main")
app.MountStores(capKey)
app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey))
err := app.LoadLatestVersion()
err = app.LoadLatestVersion()
require.Nil(t, err)

// "execute" one block
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: upgradeHeight}})
res := app.Commit()
require.NotNil(t, res.Data)

// check db is properly updated
checkStore(t, db, 2, tc.loadStoreKey, k, v)
checkStore(t, db, 2, tc.loadStoreKey, []byte("foo"), nil)
checkStore(t, db, upgradeHeight, tc.loadStoreKey, k, v)
checkStore(t, db, upgradeHeight, tc.loadStoreKey, []byte("foo"), nil)
})
}
}

0 comments on commit 9e9dbf3

Please sign in to comment.