Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multistore: fix SetInitialVersion #8048

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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