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

improve UX around running InitGenesis() in RunMigrations() #15120

Closed
p0mvn opened this issue Feb 21, 2023 · 6 comments
Closed

improve UX around running InitGenesis() in RunMigrations() #15120

p0mvn opened this issue Feb 21, 2023 · 6 comments
Assignees
Labels
C:genesis relating to chain genesis C:x/genutil genutil module issues

Comments

@p0mvn
Copy link
Member

p0mvn commented Feb 21, 2023

Summary

Currently, the default behaviour for any new module is to run InitGenesis() in RunMigrations(). This is called from the upgrade handler:

} else {
ctx.Logger().Info(fmt.Sprintf("adding a new module: %s", moduleName))
if module, ok := m.Modules[moduleName].(HasGenesis); ok {
moduleValUpdates := module.InitGenesis(ctx, c.cdc, module.DefaultGenesis(c.cdc))
// The module manager assumes only one module will update the
// validator set, and it can't be a new module.
if len(moduleValUpdates) > 0 {
return nil, errorsmod.Wrapf(sdkerrors.ErrLogic, "validator InitGenesis update is already set by another module")
}
}

However, this is not always desired as the chain might be migrating state from old module to a new module. The call to InitGenesis() erases any migrated parameters and state, leading to problems that are hard to identify and debug.

Problem Definition

In Osmosis, we've run into this issue on 2 different occasions. In both cases, this problem ended up being non-trivial to debug as we simply observed missing parameters after e2e testing our upgrades and no additional context. We have come up with a workaround:
https://github.com/osmosis-labs/osmosis/blob/b49e35e180fdffa8dfe2730f2105803b9045bf89/app/upgrades/v15/upgrades.go#L41-L44

It should also be possible to call RunMigrations() prior to performing any inter-module migrations in the upgrade handler to avoid having RunMigrations() overwrite the inter-module state changes.

However, both approaches not solve the major problem around UX and the difficulty with identifying and debugging it. There should be a guard against missing this low-level but important detail.

Proposal

We should make it so that chain developers must specifically identify for which new modules to run InitGenesis() during the upgrade. If a new module is added without an explicit setting to disable or enable running InitGenesis() during the next upgrade, the binary should not start and spit out a descriptive error message about where to configure this.

@github-actions github-actions bot added the needs-triage Issue that needs to be triaged label Feb 21, 2023
@tac0turtle
Copy link
Member

@julienrbrt brought this up today, he was going to start looking into it.

@tac0turtle tac0turtle added C:genesis relating to chain genesis C:x/genutil genutil module issues T:Sprint and removed needs-triage Issue that needs to be triaged labels Feb 21, 2023
@github-project-automation github-project-automation bot moved this to 📝 Todo in Cosmos-SDK Feb 21, 2023
@julienrbrt
Copy link
Member

julienrbrt commented Feb 21, 2023

Yes, somewhat related too: #5041
I'll start on it after my logger PR.

@julienrbrt julienrbrt self-assigned this Feb 21, 2023
@julienrbrt julienrbrt moved this from 📝 Todo to 💪 In Progress in Cosmos-SDK Mar 30, 2023
@ValarDragon
Copy link
Contributor

Is this slated for SDK v0.48, or a future release?

@julienrbrt
Copy link
Member

Is this slated for SDK v0.48, or a future release?

Thanks for the reminder, given v0.48 is not feature frozen yet, I will open the PR before :)

@ValarDragon
Copy link
Contributor

TYSM!!

@julienrbrt julienrbrt moved this from 💪 In Progress to 📝 Todo in Cosmos-SDK Jun 30, 2023
@tac0turtle tac0turtle removed this from Cosmos-SDK Aug 18, 2023
@julienrbrt
Copy link
Member

We haven't really changed how migrations were done for v2 and kept it the same.
While the UX has footguns, it is explained in the RunMigrations() what to do to avoid them:

// As an app developer, if you wish to skip running InitGenesis for your new
// module "foo", you need to manually pass a `fromVM` argument to this function
// foo's module version set to its latest ConsensusVersion. That way, the diff
// between the function's `fromVM` and `udpatedVM` will be empty, hence not
// running anything for foo.

Given that for most users that won't be the case, and the extra configurability of RunMigrations() was making it less usable, I am going to close this as won't do.

@julienrbrt julienrbrt closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:genesis relating to chain genesis C:x/genutil genutil module issues
Projects
None yet
Development

No branches or pull requests

4 participants