From af264b8cfc08627881a9fdfb5b0cf69092d603d6 Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Fri, 26 Aug 2022 22:34:39 -0600 Subject: [PATCH] add denom traces migration --- .drone.yml | 8 ++++---- app/upgrades.go | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 763774cd4..29287b682 100644 --- a/.drone.yml +++ b/.drone.yml @@ -75,12 +75,12 @@ steps: password: from_secret: docker_password tags: - - v7-alpha + - v7-rc when: event: - push branch: - - ica-testing + - add-denom-traces-migration - name: docker_release image: plugins/docker:18 settings: @@ -341,7 +341,7 @@ steps: - ./scripts/ci/upgrade/proposal.sh - name: stargaze-upgraded pull: true - image: publicawesome/stargaze:v7-alpha + image: publicawesome/stargaze:v7-rc commands: - ./scripts/ci/upgrade/run-upgrade.sh environment: @@ -396,6 +396,6 @@ depends_on: - ibc-integration-test --- kind: signature -hmac: 0b778bfb2eaa3b852127d6a595c16dcd3aa9697d7e6cc50d172deccf8eb4b9ab +hmac: 83236df0cf43bf7972a6a9c949af5d1c0b01791cb081b0f03d2d6e2d6ddc40cc ... diff --git a/app/upgrades.go b/app/upgrades.go index 0bda06156..f8a2ca0c8 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -15,11 +15,16 @@ import ( icacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" + ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" ) // next upgrade name const upgradeName = "v7" +func equalTraces(dtA, dtB ibctransfertypes.DenomTrace) bool { + return dtA.BaseDenom == dtB.BaseDenom && dtA.Path == dtB.Path +} + // RegisterUpgradeHandlers returns upgrade handlers func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) { app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { @@ -51,6 +56,26 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) { } // initialize ICS27 module icamodule.InitModule(ctx, controllerParams, hostParams) + + // fix denom traces + // 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 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 err := newTrace.Validate(); err == nil && !equalTraces(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, cfg, fromVM) })