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

Fix upgrate store loader #7991

Closed
wants to merge 7 commits into from
Closed

Conversation

dgsbl
Copy link

@dgsbl dgsbl commented Nov 20, 2020

Description

Add the deleted store, or the delete operation will not be committed, and the data in old store will not be properly deleted.

@@ -146,8 +146,11 @@ func TestSetLoader(t *testing.T) {
require.NotNil(t, res.Data)

// check db is properly updated
if tc.setLoader != nil {
checkStore(t, db, upgradeHeight, tc.origStoreKey, k, nil)
Copy link
Author

Choose a reason for hiding this comment

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

if the deleted store is not added in the method loadVersion(), the tc.origStoreKey will still have data ,and v will never be nil

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.

looks reasonable to me, but I do not have too much context here. I do recall @ethanfrey implementing this logic so it'd be good to get a review/ACK from him too.

@codecov
Copy link

codecov bot commented Nov 30, 2020

Codecov Report

Merging #7991 (3bdd955) into master (513daba) will increase coverage by 1.32%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7991      +/-   ##
==========================================
+ Coverage   61.61%   62.93%   +1.32%     
==========================================
  Files         606      687      +81     
  Lines       34791    45152   +10361     
==========================================
+ Hits        21435    28416    +6981     
- Misses      11129    13892    +2763     
- Partials     2227     2844     +617     
Impacted Files Coverage Δ
store/rootmulti/store.go 66.12% <100.00%> (+0.07%) ⬆️
x/bank/keeper/grpc_query.go 50.00% <0.00%> (-20.22%) ⬇️
types/module/configurator.go 17.24% <0.00%> (-16.10%) ⬇️
x/auth/module.go 45.65% <0.00%> (-8.64%) ⬇️
client/broadcast.go 57.84% <0.00%> (-8.26%) ⬇️
client/keys/import.go 66.66% <0.00%> (-6.67%) ⬇️
x/evidence/module.go 40.00% <0.00%> (-5.24%) ⬇️
x/slashing/keeper/keeper.go 40.00% <0.00%> (-5.00%) ⬇️
client/keys/list.go 84.00% <0.00%> (-4.89%) ⬇️
x/params/module.go 6.97% <0.00%> (-4.57%) ⬇️
... and 268 more

@amaury1093
Copy link
Contributor

gentle ping for @ethanfrey, I tried to review this PR, but also don't feel super familiar with the code.

@dgsbl dgsbl force-pushed the wangdi-storeloader branch from 2e54825 to ecc5f47 Compare December 1, 2020 02:58
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 22, 2021
@ethanfrey
Copy link
Contributor

I missed this til now. It seems reasonable. I assumed this was committed but too far from the sdk to say for sure now.

It would be good to have a better insight. This is only for store renames, do we need to do something different for deleteStore? Also, if we keep the name after a rename, then we need to explicitly delete it on the next migration to remove it from CommitInfo?

The test that would convince me the most would be to attach a TraceStore to the database, perform this rename (in tests) and check the output of the trace store. Same with deleting a store. To show what operations are actually committed in these simple cases. Also to print out the multistore CommitInfo before and after the upgradeStore operation.

@github-actions github-actions bot removed the stale label Jan 23, 2021
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 10, 2021
@github-actions github-actions bot closed this Mar 16, 2021
@aaronc
Copy link
Member

aaronc commented Mar 16, 2021

I think this shouldn't have been closed. I will try to take a look soon.

@aaronc aaronc added pinned and removed stale labels Mar 16, 2021
@aaronc aaronc reopened this Mar 16, 2021
@technicallyty
Copy link
Contributor

It would be good to have a better insight. This is only for store renames, do we need to do something different for deleteStore? Also, if we keep the name after a rename, then we need to explicitly delete it on the next migration to remove it from CommitInfo?

delete store actually deletes, as its key is put into the newStores map which ensures it gets committed. It is correct that we need to remove these stores from CommitInfo explicitly.

The test that would convince me the most would be to attach a TraceStore to the database, perform this rename (in tests) and check the output of the trace store. Same with deleting a store. To show what operations are actually committed in these simple cases. Also to print out the multistore CommitInfo before and after the upgradeStore operation.

I'm not sure this is possible without editing the loadStores function directly. When LoadLatestVersionAndUpgrade is ran, it doesn't care if you had a traced store or not, since it'll just loop over the keys in memory and cast them to a normal KV store. Only way around this is to edit the loadVersion function directly to utilize tracers, which can be done if needed, but that would be more of a manual test i think.

I was able to get rid of the removed stores from CommitInfo by adding a new field to the root store, removalMap, which will keep a map of keys of stores that needs to be removed. When a commit is run, it adds all known keys except for those in removalMap to commitinfo. once the function is done we remove the entry from the root store's memory and reset the removalMap.

I've created a draft PR implementing this fix

@robert-zaremba
Copy link
Collaborator

shall we close this PR? It seams #9409 superseeds this PR

@amaury1093 amaury1093 closed this Jun 17, 2021
mergify bot pushed a commit that referenced this pull request Jul 12, 2021
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰
v    Before smashing the submit button please review the checkboxes.
v    If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

## Description

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review.
-->

- stores that were renamed are now properly deleted
- deleted/renamed and renamed stores are no longer added to `CommitInfo`
- deleted/renamed stores are now properly removed from rootmulti store's memory

ref: #7991 
closes: N/A

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [x] Re-reviewed `Files changed` in the Github PR explorer
- [x] Review `Codecov Report` in the comment section below once CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants