From fcc879a4ecd0eecc69435ae950eb1b34d2f49a2c Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Sun, 12 Jun 2022 22:30:15 +0200 Subject: [PATCH 1/2] sample upgrade handler to run migration to support denoms with slashes --- testing/simapp/app.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 94d5640aa17..2a7b814b3d7 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "path/filepath" + "reflect" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" @@ -602,6 +603,31 @@ func NewSimApp( app.SetEndBlocker(app.EndBlocker) + app.UpgradeKeeper.SetUpgradeHandler("supportSlashedDenomsUpgrade", + func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // list of traces that must replace the old traces in store + var newTraces []ibctransfertypes.DenomTrace + app.TransferKeeper.IterateDenomTraces(ctx, + func(dt ibctransfertypes.DenomTrace) bool { + // check if the new way of splitting FullDenom + // into Trace and BaseDenom is the same as the current + // DenomTrace. + // If it isn't then store the new DenomTrace in the list of new traces. + newTrace := ibctransfertypes.ParseDenomTrace(dt.GetFullDenomPath()) + if !reflect.DeepEqual(newTrace, dt) { + newTraces = append(newTraces, newTrace) + } + return false + }) + + // replace the outdated traces with the new trace information + for _, nt := range newTraces { + app.TransferKeeper.SetDenomTrace(ctx, nt) + } + + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }) + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) From 7a164eef80ef341dea0d03a4d22eda510f40497a Mon Sep 17 00:00:00 2001 From: crodriguezvega Date: Mon, 13 Jun 2022 20:56:54 +0200 Subject: [PATCH 2/2] add validation check of denom trace --- testing/simapp/app.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 2a7b814b3d7..1649394f736 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -610,13 +610,14 @@ func NewSimApp( app.TransferKeeper.IterateDenomTraces(ctx, func(dt ibctransfertypes.DenomTrace) bool { // check if the new way of splitting FullDenom - // into Trace and BaseDenom is the same as the current - // DenomTrace. + // into Trace and BaseDenom passes validation and + // is the same as the current DenomTrace. // If it isn't then store the new DenomTrace in the list of new traces. newTrace := ibctransfertypes.ParseDenomTrace(dt.GetFullDenomPath()) - if !reflect.DeepEqual(newTrace, dt) { + if err := newTrace.Validate(); err == nil && !reflect.DeepEqual(newTrace, dt) { newTraces = append(newTraces, newTrace) } + return false })