multistore: fix SetInitialVersion (#8048)
This commit is contained in:
parent
7ad2aab2c4
commit
6476b09b64
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user