Skip to content

Commit

Permalink
add denom traces migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jhernandezb committed Aug 27, 2022
1 parent a68339f commit af264b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -396,6 +396,6 @@ depends_on:
- ibc-integration-test
---
kind: signature
hmac: 0b778bfb2eaa3b852127d6a595c16dcd3aa9697d7e6cc50d172deccf8eb4b9ab
hmac: 83236df0cf43bf7972a6a9c949af5d1c0b01791cb081b0f03d2d6e2d6ddc40cc

...
25 changes: 25 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})

Expand Down

0 comments on commit af264b8

Please sign in to comment.