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

Problem: nft module store is not initialized after upgrade #552

Merged
merged 1 commit into from
May 18, 2021

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented May 17, 2021

Solution:

  • call SetStoreLoader to initialise nft module store

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Solution:
- call SetStoreLoader to initialise nft module store
@codecov
Copy link

codecov bot commented May 17, 2021

Codecov Report

Merging #552 (f6e8310) into master (f9285ff) will increase coverage by 2.82%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #552      +/-   ##
==========================================
+ Coverage   17.94%   20.76%   +2.82%     
==========================================
  Files          69       69              
  Lines        8994     9135     +141     
==========================================
+ Hits         1614     1897     +283     
+ Misses       6869     6686     -183     
- Partials      511      552      +41     
Flag Coverage Δ
integration_tests 17.94% <ø> (+<0.01%) ⬆️
unit_tests 11.13% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
app/app.go 17.00% <0.00%> (-83.00%) ⬇️
config/config.go 55.55% <0.00%> (-11.12%) ⬇️
x/nft/keeper/querier.go 7.90% <0.00%> (+0.56%) ⬆️
x/nft/types/msgs.go 13.43% <0.00%> (+1.49%) ⬆️
x/nft/keeper/invariants.go 7.40% <0.00%> (+7.40%) ⬆️
x/nft/types/validation.go 38.88% <0.00%> (+10.31%) ⬆️
x/nft/keeper/keeper.go 83.33% <0.00%> (+21.21%) ⬆️
x/nft/client/cli/tx.go 76.04% <0.00%> (+32.29%) ⬆️
x/nft/client/cli/query.go 68.35% <0.00%> (+34.81%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9285ff...f6e8310. Read the comment docs.

Comment on lines +423 to +436
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == planName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{nfttypes.StoreKey},
Renamed: []storetypes.StoreRename{},
Deleted: []string{},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
Copy link
Contributor

Choose a reason for hiding this comment

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

should this just be called once / inside SetUpgradeHandler ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the override only works before storage constructed, so it need to happen pretty early. while upgrade handler is called in abci event.

Copy link
Collaborator Author

@yihuang yihuang May 18, 2021

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://github.com/cosmos/cosmos-sdk/blob/master/x/upgrade/types/storeloader.go#L13
And before apply the upgrade, it'll check the height again, so it should be safe here.

@@ -414,6 +415,27 @@ func New(
)
app.SetEndBlocker(app.EndBlocker)

planName := "v2.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

can this fetched from other place?
because two places hard-coded

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the plan name only specified once here.

panic(err)
}

if upgradeInfo.Name == planName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could add some explain for IsSkipHeight,
such as height > upgradeInfo.Height?

Copy link
Contributor

Choose a reason for hiding this comment

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

in latest planName is different from "2.0.0"?
and not fall into this step?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cosmos-sdk has a feature that you can skip upgrades in command line:

$ chain-maind start --help
...
      --unsafe-skip-upgrades ints                       Skip a set of upgrade heights to continue the old binary

Copy link
Contributor

@leejw51crypto leejw51crypto left a comment

Choose a reason for hiding this comment

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

lgtm

@tomtau tomtau merged commit 234b451 into crypto-org-chain:master May 18, 2021
@yihuang yihuang deleted the fix-upgrade-migration branch May 18, 2021 03:40
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.

4 participants