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

Upgrade height judgment error #6346

Closed
dreamer-zq opened this issue Jun 5, 2020 · 7 comments · Fixed by #7817
Closed

Upgrade height judgment error #6346

dreamer-zq opened this issue Jun 5, 2020 · 7 comments · Fixed by #7817

Comments

@dreamer-zq
Copy link
Collaborator

dreamer-zq commented Jun 5, 2020

if upgradeHeight == ms.LastCommitID().Version {

There are two errors in this place:

  1. The CommitMultiStore has not been loaded yet, so ms.LastCommitID().Version is always equal to 0;

  2. When the upgrade height is reached, the pain in the beginblocker, so the height has not yet been submitted, Should use ms.LastCommitID().Version == upgradeHeight-1

@anilcse
Copy link
Collaborator

anilcse commented Jun 5, 2020

The implementation looks correct for me.

  1. The app will have access to ms.LastCommitID().Version
  2. The upgradeHeight refers to the height at which upgrade should happen. The upgrade should not be triggered before that height. ms.LastCommitID().Version == upgradeHeight, the logic looks fine for me.

cc @aaronc @ethanfrey

@ethanfrey
Copy link
Contributor

  1. The CommitMultiStore has not been loaded yet, so ms.LastCommitID().Version is always equal to 0;

At least in the standard gaia app (and all xrnd apps that tested this in public testnets), this is definitely not 0 and is loaded first.

  1. When the upgrade height is reached, the pain in the beginblocker, so the height has not yet been submitted, Should use ms.LastCommitID().Version == upgradeHeight-1

This is a valid point and should be well documented. I think the current implementation is if you set an upgrade height to 54000, then block 54000 will be run with the old code and then the upgrade occurs before running 54001. This should be checked and documented in any case. Also, maybe we rename upgradeHeight to upgradeAfterBlock and then it is clear the given block number is run before the upgrade is applied (if that is the case)

@dreamer-zq
Copy link
Collaborator Author

dreamer-zq commented Jun 9, 2020

Of course, it may be my understanding error, but I also tested it several times, and it does not load the height correctly. I think there may be a problem in this place:

func (app *BaseApp) LoadLatestVersion() error {
	err := app.storeLoader(app.cms)
	if err != nil {
		return fmt.Errorf("failed to load latest version: %w", err)
	}

	return app.init()
}

When calling app.storeLoader(app.cms), app.cms is not loaded, and then ms.LastCommitID().Version is used directly, so the version is always 0. I think that before calling ms.LastCommitID(), app.cms.LoadLatestVersion() should be called first. But in the logic of upgrading, I didn't see it. I don't know if my understanding is correct. For example: the modified code is as follows:

func (app *BaseApp) LoadLatestVersion() error {
        if err := app.cms.LoadLatestVersion() ;err != nil {
              return err
        }
	err := app.storeLoader(app.cms)
	if err != nil {
		return fmt.Errorf("failed to load latest version: %w", err)
	}

	return app.init()
}

@ethanfrey @anilcse

@ethanfrey
Copy link
Contributor

The issue is what you set app.storeLoader() to be.

The two StoreLoaders we provide as standard options both load the cms. In fact, the default is DefaultStoreLoader which is nothing more than cms.LoadLatestVersion()

The issue is likely a misconfiguration of storeLoader in your application.

@dreamer-zq
Copy link
Collaborator Author

Thanks, it is possible that the method I used is wrong or the order of the code is wrong

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2020

This issue 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.

@alessio
Copy link
Contributor

alessio commented Nov 6, 2020

Does this affect Launchpad as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants