Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove dead code in cacheMergeIterator Domain() #13433

Merged
merged 11 commits into from Oct 5, 2022

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Oct 3, 2022

Description

TL;DR: because the parent and the cache's domain is always the same, there's no point in doing these comparisons.

Here both parent and cache are created using the same input start and end:

func (store *Store) iterator(start, end []byte, ascending bool) types.Iterator {
store.mtx.Lock()
defer store.mtx.Unlock()
var parent, cache types.Iterator
if ascending {
parent = store.parent.Iterator(start, end)
} else {
parent = store.parent.ReverseIterator(start, end)
}
store.dirtyItems(start, end)
cache = newMemIterator(start, end, store.sortedCache, store.deleted, ascending)
return newCacheMergeIterator(parent, cache, ascending)
}

The parent seems to always just take the start and end, store it in the iterator struct and then return it in its own Domain():

https://github.com/tendermint/tm-db/blob/b599fa5d668d5a68812ec5ebeccb9eb05235bb3a/goleveldb_iterator.go#L41-L53

https://github.com/tendermint/tm-db/blob/b599fa5d668d5a68812ec5ebeccb9eb05235bb3a/prefixdb_iterator.go#L57-L69

https://github.com/tendermint/tm-db/blob/b599fa5d668d5a68812ec5ebeccb9eb05235bb3a/rocksdb_iterator.go#L43-L55

And the cache (cache = newMemIterator(start, end, store.sortedCache, store.deleted, ascending)) does exactly the same (uses tm-db.MemDB):

https://github.com/tendermint/tm-db/blob/b599fa5d668d5a68812ec5ebeccb9eb05235bb3a/memdb_iterator.go#L34-L43

https://github.com/tendermint/tm-db/blob/b599fa5d668d5a68812ec5ebeccb9eb05235bb3a/memdb_iterator.go#L114-L117

If I'm not missing anything we can just use the parent or cache's domain indistinctly.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@codecov
Copy link

codecov bot commented Oct 3, 2022

Codecov Report

Merging #13433 (0f056b0) into main (facac1c) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13433      +/-   ##
==========================================
- Coverage   53.98%   53.98%   -0.01%     
==========================================
  Files         641      641              
  Lines       55032    55020      -12     
==========================================
- Hits        29711    29704       -7     
+ Misses      22936    22934       -2     
+ Partials     2385     2382       -3     
Impacted Files Coverage Δ
store/cachekv/memiterator.go 93.54% <100.00%> (+0.21%) ⬆️
store/cachekv/mergeiterator.go 88.97% <100.00%> (+2.39%) ⬆️
crypto/keys/internal/ecdsa/privkey.go 81.13% <0.00%> (-1.89%) ⬇️
x/group/keeper/keeper.go 56.64% <0.00%> (+0.39%) ⬆️

@facundomedica facundomedica marked this pull request as ready for review October 3, 2022 01:03
@facundomedica facundomedica requested a review from a team as a code owner October 3, 2022 01:03
@facundomedica facundomedica marked this pull request as draft October 3, 2022 02:51
@facundomedica facundomedica marked this pull request as ready for review October 3, 2022 14:10
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! nit: changelog

CHANGELOG.md Outdated Show resolved Hide resolved
facundomedica and others added 2 commits October 4, 2022 10:09
@tac0turtle tac0turtle merged commit 87e46b2 into main Oct 5, 2022
@tac0turtle tac0turtle deleted the facu/simplify-domain branch October 5, 2022 06:46
Wryhder pushed a commit to Wryhder/cosmos-sdk that referenced this pull request Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants