diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 72238cbb1e..61378a3661 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -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) } } diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index efe2618779..7934b514d1 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -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) {