Make module.Manager.RunMigrations handle new modules correctly (#8988)

* Make module.Manager.RunMigrations handle module additions correctly

* fix if

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
Aaron Craelius 2021-03-25 15:51:38 -04:00 committed by GitHub
parent 7568b6680a
commit 697d8d52f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -346,11 +346,19 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version
updatedVM := make(VersionMap)
for moduleName, module := range m.Modules {
err := c.runModuleMigrations(ctx, moduleName, fromVM[moduleName], module.ConsensusVersion())
updatedVM[moduleName] = module.ConsensusVersion()
if err != nil {
return nil, err
fromVersion := fromVM[moduleName]
toVersion := module.ConsensusVersion()
// only run migrations when the from version is > 0
// from version will be 0 when a new module is added and migrations shouldn't be run in this case
if fromVersion > 0 {
err := c.runModuleMigrations(ctx, moduleName, fromVersion, toVersion)
if err != nil {
return nil, err
}
}
updatedVM[moduleName] = toVersion
}
return updatedVM, nil