From 240d7af7d3ecd6e43b2697cfdc923e2096c6f7f5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 Mar 2021 20:54:13 -0400 Subject: [PATCH 1/2] Make module.Manager.RunMigrations handle module additions correctly --- 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 ba6a6a47a6ce..4c4c2c4aaa6e 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 ok && fromVersion > 0 { + err := c.runModuleMigrations(ctx, moduleName, fromVersion, toVersion) + if err != nil { + return nil, err + } } + + updatedVM[moduleName] = toVersion } return updatedVM, nil From 1459145c4b51e354c09d071bb74546735a10c094 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 24 Mar 2021 20:55:47 -0400 Subject: [PATCH 2/2] fix if --- types/module/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/module.go b/types/module/module.go index 4c4c2c4aaa6e..d123a05d192b 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -351,7 +351,7 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version // 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 ok && fromVersion > 0 { + if fromVersion > 0 { err := c.runModuleMigrations(ctx, moduleName, fromVersion, toVersion) if err != nil { return nil, err