Skip to content

Commit 6476b09

Browse files
authored
multistore: fix SetInitialVersion (#8048)
1 parent 7ad2aab commit 6476b09

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

store/rootmulti/store.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,12 @@ func (rs *Store) SetInitialVersion(version int64) error {
549549

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

store/rootmulti/store_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,18 @@ func TestSetInitialVersion(t *testing.T) {
657657
db := dbm.NewMemDB()
658658
multi := newMultiStoreWithMounts(db, types.PruneNothing)
659659

660+
require.NoError(t, multi.LoadLatestVersion())
661+
660662
multi.SetInitialVersion(5)
661663
require.Equal(t, int64(5), multi.initialVersion)
662664

663665
multi.Commit()
664666
require.Equal(t, int64(5), multi.LastCommitID().Version)
667+
668+
ckvs := multi.GetCommitKVStore(multi.keysByName["store1"])
669+
iavlStore, ok := ckvs.(*iavl.Store)
670+
require.True(t, ok)
671+
require.True(t, iavlStore.VersionExists(5))
665672
}
666673

667674
func BenchmarkMultistoreSnapshot100K(b *testing.B) {

0 commit comments

Comments
 (0)