Last active
July 5, 2022 01:14
-
-
Save zeroFruit/c2041e626f9d4315e289dc0f19b7ba98 to your computer and use it in GitHub Desktop.
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade - ModuleManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM VersionMap) (VersionMap, error) { | |
... | |
updatedVM := VersionMap{} | |
for _, moduleName := range modules { | |
module := m.Modules[moduleName] | |
fromVersion, exists := fromVM[moduleName] | |
toVersion := module.ConsensusVersion() | |
// We run migration if the module is specified in `fromVM`. | |
// Otherwise we run InitGenesis. | |
// | |
// The module won't exist in the fromVM in two cases: | |
// 1. A new module is added. In this case we run InitGenesis with an | |
// empty genesis state. | |
// 2. An existing chain is upgrading from version < 0.43 to v0.43+ for the first time. | |
// In this case, all modules have yet to be added to x/upgrade's VersionMap store. | |
if exists { | |
err := c.runModuleMigrations(ctx, moduleName, fromVersion, toVersion) | |
if err != nil { | |
return nil, err | |
} | |
} | |
... | |
updatedVM[moduleName] = toVersion | |
} | |
return updatedVM, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment