Skip to content

Commit

Permalink
sdk46 compact WorkingHash
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Sep 1, 2023
1 parent 7545feb commit 98e3653
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
7 changes: 7 additions & 0 deletions memiavl/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 10 additions & 5 deletions memiavl/multitree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -306,7 +311,7 @@ func (t *MultiTree) buildCommitInfo(version int64) storetypes.CommitInfo {
})
}

return storetypes.CommitInfo{
return &storetypes.CommitInfo{
Version: version,
StoreInfos: infos,
}
Expand All @@ -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()
}

Expand Down
6 changes: 5 additions & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ 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
Expand Down

0 comments on commit 98e3653

Please sign in to comment.