From f19fbe3fb837c7b7c8bc704fcd479891fe77dec2 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 14 Sep 2018 10:53:21 +0900 Subject: [PATCH] Merge PR #2330: iterate over storesParams --- store/rootmultistore.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/store/rootmultistore.go b/store/rootmultistore.go index 8aa2da0ba..7de465f77 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -119,28 +119,28 @@ func (rs *rootMultiStore) LoadVersion(ver int64) error { return err } + // Convert StoreInfos slice to map + infos := make(map[StoreKey]storeInfo) + for _, storeInfo := range cInfo.StoreInfos { + infos[rs.nameToKey(storeInfo.Name)] = storeInfo + } + // Load each Store var newStores = make(map[StoreKey]CommitStore) - for _, storeInfo := range cInfo.StoreInfos { - key, commitID := rs.nameToKey(storeInfo.Name), storeInfo.Core.CommitID - storeParams := rs.storesParams[key] - store, err := rs.loadCommitStoreFromParams(key, commitID, storeParams) + for key, storeParams := range rs.storesParams { + var id CommitID + info, ok := infos[key] + if ok { + id = info.Core.CommitID + } + + store, err := rs.loadCommitStoreFromParams(key, id, storeParams) if err != nil { return fmt.Errorf("failed to load rootMultiStore: %v", err) } newStores[key] = store } - // TODO: detecting transient is quite adhoc - // If any nontransient CommitStoreLoaders were not used, return error. - for key, param := range rs.storesParams { - if param.typ != sdk.StoreTypeTransient { - if _, ok := newStores[key]; !ok { - return fmt.Errorf("unused CommitStoreLoader: %v", key) - } - } - } - // Success. rs.lastCommitID = cInfo.CommitID() rs.stores = newStores