Skip to content

Commit

Permalink
fix: nested iterator on cache store (cosmos#14798)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang authored and JeancarloBarrios committed Sep 28, 2024
1 parent d6ae2f2 commit 3a3aa8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- (store) [#14798](https://github.com/cosmos/cosmos-sdk/pull/14798) Copy btree to avoid the problem of modify while iteration.
- (cli) [#14799](https://github.com/cosmos/cosmos-sdk/pull/14799) Fix Evidence CLI query flag parsing (backport #13458)

## [v0.46.8](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.8) - 2022-01-23
Expand Down
6 changes: 6 additions & 0 deletions store/cachekv/internal/btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func (bt *BTree) ReverseIterator(start, end []byte) (*memIterator, error) {
return NewMemIterator(start, end, bt, make(map[string]struct{}), false), nil
}

func (bt *BTree) Copy() *BTree {
return &BTree{
tree: *bt.tree.Copy(),
}
}

// item is a btree item with byte slices as keys and values
type item struct {
key []byte
Expand Down
2 changes: 1 addition & 1 deletion store/cachekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (store *Store) iterator(start, end []byte, ascending bool) types.Iterator {
}

store.dirtyItems(start, end)
cache = internal.NewMemIterator(start, end, store.sortedCache, store.deleted, ascending)
cache = internal.NewMemIterator(start, end, store.sortedCache.Copy(), store.deleted, ascending)

return internal.NewCacheMergeIterator(parent, cache, ascending)
}
Expand Down

0 comments on commit 3a3aa8f

Please sign in to comment.