From 697d8d52f97aa50d15a6d0819ef7f713eb3bbbdf Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 25 Mar 2021 15:51:38 -0400 Subject: [PATCH] Make module.Manager.RunMigrations handle new modules correctly (#8988) * Make module.Manager.RunMigrations handle module additions correctly * fix if Co-authored-by: Alessio Treglia --- types/module/module.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index ba6a6a47a..d123a05d1 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -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