Skip to content

Commit

Permalink
multistore: fix SetInitialVersion (#8048)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Nov 30, 2020
1 parent 7ad2aab commit 6476b09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,12 @@ func (rs *Store) SetInitialVersion(version int64) error {

// Loop through all the stores, if it's an IAVL store, then set initial
// version on it.
for _, commitKVStore := range rs.stores {
if storeWithVersion, ok := commitKVStore.(types.StoreWithInitialVersion); ok {
storeWithVersion.SetInitialVersion(version)
for key, store := range rs.stores {
if store.GetStoreType() == types.StoreTypeIAVL {
// If the store is wrapped with an inter-block cache, we must first unwrap
// it to get the underlying IAVL store.
store = rs.GetCommitKVStore(key)
store.(*iavl.Store).SetInitialVersion(version)
}
}

Expand Down
7 changes: 7 additions & 0 deletions store/rootmulti/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,18 @@ func TestSetInitialVersion(t *testing.T) {
db := dbm.NewMemDB()
multi := newMultiStoreWithMounts(db, types.PruneNothing)

require.NoError(t, multi.LoadLatestVersion())

multi.SetInitialVersion(5)
require.Equal(t, int64(5), multi.initialVersion)

multi.Commit()
require.Equal(t, int64(5), multi.LastCommitID().Version)

ckvs := multi.GetCommitKVStore(multi.keysByName["store1"])
iavlStore, ok := ckvs.(*iavl.Store)
require.True(t, ok)
require.True(t, iavlStore.VersionExists(5))
}

func BenchmarkMultistoreSnapshot100K(b *testing.B) {
Expand Down

0 comments on commit 6476b09

Please sign in to comment.