diff --git a/memiavl/db.go b/memiavl/db.go index 7dd13daed1..38f3093a3b 100644 --- a/memiavl/db.go +++ b/memiavl/db.go @@ -792,6 +792,13 @@ func (db *DB) SaveVersion(updateCommitInfo bool) ([]byte, int64, error) { return db.MultiTree.SaveVersion(updateCommitInfo) } +func (db *DB) WorkingCommitInfo() *storetypes.CommitInfo { + db.mtx.Lock() + defer db.mtx.Unlock() + + return db.MultiTree.WorkingCommitInfo() +} + func (db *DB) WorkingHash() []byte { db.mtx.Lock() defer db.mtx.Unlock() diff --git a/memiavl/multitree.go b/memiavl/multitree.go index cd67fb6300..60ef55a853 100644 --- a/memiavl/multitree.go +++ b/memiavl/multitree.go @@ -269,9 +269,14 @@ func (t *MultiTree) ApplyChangeSets(changeSets []*NamedChangeSet) error { return nil } -func (t *MultiTree) WorkingHash() []byte { +// WorkingCommitInfo returns the commit info for the working tree +func (t *MultiTree) WorkingCommitInfo() *storetypes.CommitInfo { version := nextVersion(t.lastCommitInfo.Version, t.initialVersion) - return t.buildCommitInfo(version).Hash() + return t.buildCommitInfo(version) +} + +func (t *MultiTree) WorkingHash() []byte { + return t.WorkingCommitInfo().Hash() } // SaveVersion bumps the versions of all the stores and optionally returns the new app hash @@ -294,7 +299,7 @@ func (t *MultiTree) SaveVersion(updateCommitInfo bool) ([]byte, int64, error) { return hash, t.lastCommitInfo.Version, nil } -func (t *MultiTree) buildCommitInfo(version int64) storetypes.CommitInfo { +func (t *MultiTree) buildCommitInfo(version int64) *storetypes.CommitInfo { var infos []storetypes.StoreInfo for _, entry := range t.trees { infos = append(infos, storetypes.StoreInfo{ @@ -306,7 +311,7 @@ func (t *MultiTree) buildCommitInfo(version int64) storetypes.CommitInfo { }) } - return storetypes.CommitInfo{ + return &storetypes.CommitInfo{ Version: version, StoreInfos: infos, } @@ -315,7 +320,7 @@ func (t *MultiTree) buildCommitInfo(version int64) storetypes.CommitInfo { // UpdateCommitInfo update lastCommitInfo based on current status of trees. // it's needed if `updateCommitInfo` is set to `false` in `ApplyChangeSet`. func (t *MultiTree) UpdateCommitInfo() []byte { - t.lastCommitInfo = t.buildCommitInfo(t.lastCommitInfo.Version) + t.lastCommitInfo = *t.buildCommitInfo(t.lastCommitInfo.Version) return t.lastCommitInfo.Hash() } diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 2ad2717ec8..9f8c69cff1 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -90,14 +90,17 @@ func (rs *Store) flush() error { } // WorkingHash returns the app hash of the working tree, -// it's only compatible with sdk 0.47 and later. // // Implements interface Committer. func (rs *Store) WorkingHash() []byte { if err := rs.flush(); err != nil { panic(err) } - return rs.db.WorkingHash() + commitInfo := rs.db.WorkingCommitInfo() + if rs.sdk46Compact { + commitInfo = amendCommitInfo(commitInfo, rs.storesParams) + } + return commitInfo.Hash() } // Implements interface Committer