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:
co-authored by
Robert Zaremba
parent
548c9868bf
commit
f757c90f61
+13
-1
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user