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:
parent
7568b6680a
commit
697d8d52f9
|
@ -346,11 +346,19 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version
|
||||||
|
|
||||||
updatedVM := make(VersionMap)
|
updatedVM := make(VersionMap)
|
||||||
for moduleName, module := range m.Modules {
|
for moduleName, module := range m.Modules {
|
||||||
err := c.runModuleMigrations(ctx, moduleName, fromVM[moduleName], module.ConsensusVersion())
|
fromVersion := fromVM[moduleName]
|
||||||
updatedVM[moduleName] = module.ConsensusVersion()
|
toVersion := module.ConsensusVersion()
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
// 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
|
return updatedVM, nil
|
||||||
|
|
Loading…
Reference in New Issue