Skip to content

Commit 9d49275

Browse files
author
HuangYi
committed
simpliy ApplyChangeSet
1 parent b7020ed commit 9d49275

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

memiavl/multitree.go

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"cosmossdk.io/errors"
1313

1414
storetypes "github.com/cosmos/cosmos-sdk/store/types"
15-
"github.com/cosmos/iavl"
1615
"github.com/tidwall/wal"
1716
"golang.org/x/exp/slices"
1817
"golang.org/x/sync/errgroup"
@@ -253,47 +252,27 @@ func (t *MultiTree) ApplyUpgrades(upgrades []*TreeNameUpgrade) error {
253252
func (t *MultiTree) ApplyChangeSet(changeSets []*NamedChangeSet, updateCommitInfo bool) ([]byte, int64, error) {
254253
version := nextVersion(t.lastCommitInfo.Version, t.initialVersion)
255254

256-
var (
257-
infos []storetypes.StoreInfo
258-
csIndex int
259-
)
260-
for _, entry := range t.trees {
261-
var changeSet iavl.ChangeSet
255+
for _, cs := range changeSets {
256+
tree := t.trees[t.treesByName[cs.Name]].tree
262257

263-
if csIndex < len(changeSets) && entry.name == changeSets[csIndex].Name {
264-
changeSet = changeSets[csIndex].Changeset
265-
csIndex++
266-
}
267-
hash, v, err := entry.tree.ApplyChangeSet(changeSet, updateCommitInfo)
258+
_, v, err := tree.ApplyChangeSet(cs.Changeset, updateCommitInfo)
268259
if err != nil {
269260
return nil, 0, err
270261
}
271262
if v != version {
272263
return nil, 0, fmt.Errorf("multi tree version don't match(%d != %d)", v, version)
273264
}
274-
if updateCommitInfo {
275-
infos = append(infos, storetypes.StoreInfo{
276-
Name: entry.name,
277-
CommitId: storetypes.CommitID{
278-
Version: v,
279-
Hash: hash,
280-
},
281-
})
282-
}
283-
}
284-
285-
if csIndex != len(changeSets) {
286-
return nil, 0, fmt.Errorf("non-exhaustive change sets")
287265
}
288266

289267
t.lastCommitInfo.Version = version
290-
t.lastCommitInfo.StoreInfos = infos
291268

292269
var hash []byte
293270
if updateCommitInfo {
271+
hash = t.UpdateCommitInfo()
294272
hash = t.lastCommitInfo.Hash()
295273
}
296-
return hash, t.lastCommitInfo.Version, nil
274+
275+
return hash, version, nil
297276
}
298277

299278
// UpdateCommitInfo update lastCommitInfo based on current status of trees.

0 commit comments

Comments
 (0)