fix: removed potential sources of non-determinism in upgrades (#10189)

forced deterministic iteration order in upgrade migrations, x/upgrade and store during upgrades

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
This commit is contained in:
Tomas Tauber
2021-09-28 17:20:43 +02:00
committed by GitHub
co-authored by Robert Zaremba
parent 548c9868bf
commit f757c90f61
4 changed files with 44 additions and 4 deletions
+13 -1
View File
@@ -30,6 +30,7 @@ package module
import (
"encoding/json"
"sort"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
@@ -391,7 +392,18 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version
}
updatedVM := make(VersionMap)
for moduleName, module := range m.Modules {
// for deterministic iteration order
// (as some migrations depend on other modules
// and the order of executing migrations matters)
// TODO: make the order user-configurable?
sortedModNames := make([]string, 0, len(m.Modules))
for key := range m.Modules {
sortedModNames = append(sortedModNames, key)
}
sort.Strings(sortedModNames)
for _, moduleName := range sortedModNames {
module := m.Modules[moduleName]
fromVersion, exists := fromVM[moduleName]
toVersion := module.ConsensusVersion()