From 0917fc3de7285e1b6a0a5d39699b9ad32a9dd3b2 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 3 Dec 2017 23:17:10 -0800 Subject: [PATCH] rootMultiStore holds lastCommitID --- store/cachemultistore.go | 2 +- store/rootmultistore.go | 28 +++++++--------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/store/cachemultistore.go b/store/cachemultistore.go index 001e05c4ce..9f9be0830b 100644 --- a/store/cachemultistore.go +++ b/store/cachemultistore.go @@ -16,7 +16,7 @@ type cacheMultiStore struct { func newCacheMultiStore(rs *rootMultiStore) cacheMultiStore { cms := cacheMultiStore{ - db: dbm.CacheDB(), + db: rs.db.CacheDB(), version: rs.curVersion, lastCommitID: rs.lastCommitID, substores: make(map[string]CacheWriter, len(rs.substores)), diff --git a/store/rootmultistore.go b/store/rootmultistore.go index e6b7409dd0..d45f96fc04 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -21,7 +21,7 @@ const ( type rootMultiStore struct { db dbm.DB curVersion int64 - lastHash []byte + lastCommitID CommitID storeLoaders map[string]CommitStoreLoader substores map[string]CommitStore } @@ -30,7 +30,6 @@ func NewMultiStore(db dbm.DB) *rootMultiStore { return &rootMultiStore{ db: db, curVersion: 0, - lastHash: nil, storeLoaders: make(map[string]CommitStoreLoader), substores: make(map[string]CommitStore), } @@ -64,7 +63,7 @@ func (rs *rootMultiStore) LoadVersion(ver int64) error { return fmt.Errorf("Failed to load rootMultiStore: %v", err) } rs.curVersion = 1 - rs.lastHash = nil + rs.lastCommitID = CommitID{} rs.substores[name] = store } return nil @@ -98,7 +97,7 @@ func (rs *rootMultiStore) LoadVersion(ver int64) error { // Success. rs.curVersion = ver + 1 - rs.lastHash = state.LastHash + rs.lastCommitID = state.CommitID() rs.substores = newSubstores return nil } @@ -106,7 +105,6 @@ func (rs *rootMultiStore) LoadVersion(ver int64) error { // Commits each substore and gets commitState. func (rs *rootMultiStore) doCommit() commitState { version := rs.curVersion - lastHash := rs.LastHash substores := make([]substore, len(rs.substores)) for name, store := range rs.substores { @@ -127,7 +125,6 @@ func (rs *rootMultiStore) doCommit() commitState { return commitState{ Version: version, - LastHash: lastHash, Substores: substores, } } @@ -157,11 +154,12 @@ func (rs *rootMultiStore) Commit() CommitID { batch.Write() rs.version += 1 - - return CommitID{ + commitID := CommitID{ Version: version, Hash: state.Hash(), } + rs.lastCommitID = commitID + return commitID } // Implements CommitStore @@ -171,16 +169,7 @@ func (rs *rootMultiStore) CacheWrap() CacheWriter { // Get the last committed CommitID func (rs *rootMultiStore) LastCommitID() CommitID { - - // If we haven't committed yet, return a zero CommitID - if rs.curVersion == 0 { - return CommitID{} - } - - return CommitID{ - Version: rs.curVersion - 1, - Hash: rs.LastHash, - } + return rs.lastCommitID } // Implements MultiStore @@ -212,9 +201,6 @@ type commitState struct { // Version Version int64 - // Last hash (memoization) - LastHash []byte - // Substore info for Substores []substore }