diff --git a/app/upgrades.go b/app/upgrades.go index f1464af68c..dcd1945508 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -2,6 +2,7 @@ package app import ( "fmt" + "strings" icqtypes "github.com/strangelove-ventures/async-icq/v6/types" @@ -11,15 +12,18 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper" attributetypes "github.com/provenance-io/provenance/x/attribute/types" "github.com/provenance-io/provenance/x/exchange" "github.com/provenance-io/provenance/x/hold" ibchookstypes "github.com/provenance-io/provenance/x/ibchooks/types" + "github.com/provenance-io/provenance/x/marker/types" msgfeetypes "github.com/provenance-io/provenance/x/msgfees/types" oracletypes "github.com/provenance-io/provenance/x/oracle/types" triggertypes "github.com/provenance-io/provenance/x/trigger/types" @@ -120,7 +124,19 @@ var upgrades = map[string]appUpgrade{ }, Added: []string{icqtypes.ModuleName, oracletypes.ModuleName, ibchookstypes.StoreKey, hold.ModuleName, exchange.ModuleName}, }, - "saffron-rc2": {}, // upgrade for v1.17.0-rc2 + "saffron-rc2": { // upgrade for v1.17.0-rc2 + Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { + var err error + vm, err = runModuleMigrations(ctx, app, vm) + if err != nil { + return nil, err + } + + updateIbcMarkerDenomMetadata(ctx, app) + + return vm, nil + }, + }, "saffron": { // upgrade for v1.17.0, Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { var err error @@ -136,6 +152,7 @@ var upgrades = map[string]appUpgrade{ setupICQ(ctx, app) updateMaxSupply(ctx, app) setExchangeParams(ctx, app) + updateIbcMarkerDenomMetadata(ctx, app) return vm, nil }, @@ -361,3 +378,41 @@ func setExchangeParams(ctx sdk.Context, app *App) { } ctx.Logger().Info("Done ensuring exchange module params are set.") } + +// updateIbcMarkerDenomMetadata iterates markers and creates denom metadata for ibc markers +// TODO: Remove with the saffron handlers. +func updateIbcMarkerDenomMetadata(ctx sdk.Context, app *App) { + ctx.Logger().Info("Updating ibc marker denom metadata") + app.MarkerKeeper.IterateMarkers(ctx, func(record types.MarkerAccountI) bool { + if !strings.HasPrefix(record.GetDenom(), "ibc/") { + return false + } + + hash, err := transfertypes.ParseHexHash(strings.TrimPrefix(record.GetDenom(), "ibc/")) + if err != nil { + ctx.Logger().Error(fmt.Sprintf("invalid denom trace hash: %s, error: %s", hash.String(), err)) + return false + } + denomTrace, found := app.TransferKeeper.GetDenomTrace(ctx, hash) + if !found { + ctx.Logger().Error(fmt.Sprintf("trace not found: %s, error: %s", hash.String(), err)) + return false + } + + parts := strings.Split(denomTrace.Path, "/") + if len(parts) == 2 && parts[0] == "transfer" { + ctx.Logger().Info(fmt.Sprintf("Adding metadata to %s", record.GetDenom())) + chainID := app.Ics20MarkerHooks.GetChainID(ctx, parts[0], parts[1], app.IBCKeeper) + markerMetadata := banktypes.Metadata{ + Base: record.GetDenom(), + Name: chainID + "/" + denomTrace.BaseDenom, + Display: chainID + "/" + denomTrace.BaseDenom, + Description: denomTrace.BaseDenom + " from " + chainID, + } + app.BankKeeper.SetDenomMetaData(ctx, markerMetadata) + } + + return false + }) + ctx.Logger().Info("Done updating ibc marker denom metadata") +} diff --git a/app/upgrades_test.go b/app/upgrades_test.go index f264b24dee..1a7aa2a0bc 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -433,6 +433,18 @@ func (s *UpgradeTestSuite) TestSaffronRC1() { s.AssertUpgradeHandlerLogs("saffron-rc1", expInLog, nil) } +func (s *UpgradeTestSuite) TestSaffronRC2() { + // Each part is (hopefully) tested thoroughly on its own. + // So for this test, just make sure there's log entries for each part being done. + + expInLog := []string{ + "INF Updating ibc marker denom metadata", + "INF Done updating ibc marker denom metadata", + } + + s.AssertUpgradeHandlerLogs("saffron-rc2", expInLog, nil) +} + func (s *UpgradeTestSuite) TestSaffron() { // Each part is (hopefully) tested thoroughly on its own. // So for this test, just make sure there's log entries for each part being done. @@ -445,6 +457,8 @@ func (s *UpgradeTestSuite) TestSaffron() { "INF Updating MaxSupply marker param", "INF Done updating MaxSupply marker param", "INF Ensuring exchange module params are set.", + "INF Updating ibc marker denom metadata", + "INF Done updating ibc marker denom metadata", } s.AssertUpgradeHandlerLogs("saffron", expInLog, nil) diff --git a/x/ibchooks/marker_hooks.go b/x/ibchooks/marker_hooks.go index 7dd9fb33af..73f86e61e9 100644 --- a/x/ibchooks/marker_hooks.go +++ b/x/ibchooks/marker_hooks.go @@ -114,20 +114,20 @@ func (h MarkerHooks) getExistingSupply(ctx sdktypes.Context, marker *markertypes // addDenomMetaData adds denom metadata for ibc token func (h MarkerHooks) addDenomMetaData(ctx sdktypes.Context, packet exported.PacketI, ibcKeeper *ibckeeper.Keeper, ibcDenom string, data transfertypes.FungibleTokenPacketData) error { - chainID := h.GetChainID(ctx, packet, ibcKeeper) + chainID := h.GetChainID(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), ibcKeeper) markerMetadata := banktypes.Metadata{ Base: ibcDenom, Name: chainID + "/" + data.Denom, Display: chainID + "/" + data.Denom, - Description: data.Denom + " from chain " + chainID, + Description: data.Denom + " from " + chainID, } return h.MarkerKeeper.SetDenomMetaData(ctx, markerMetadata, authtypes.NewModuleAddress(types.ModuleName)) } -// GetChainID returns the source chain id from packet for `07-tendermint` client connection or returns `unknown` -func (h MarkerHooks) GetChainID(ctx sdktypes.Context, packet exported.PacketI, ibcKeeper *ibckeeper.Keeper) string { +// GetChainID returns the source chain id from packet for a `07-tendermint` client connection or returns `unknown` +func (h MarkerHooks) GetChainID(ctx sdktypes.Context, sourcePort, sourceChannel string, ibcKeeper *ibckeeper.Keeper) string { chainID := "unknown" - channel, found := ibcKeeper.ChannelKeeper.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) + channel, found := ibcKeeper.ChannelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { return chainID } @@ -139,11 +139,9 @@ func (h MarkerHooks) GetChainID(ctx sdktypes.Context, packet exported.PacketI, i if !found { return chainID } - if clientState.ClientType() == "07-tendermint" { - tmClientState, ok := clientState.(*tendermintclient.ClientState) - if ok { - chainID = tmClientState.ChainId - } + tmClientState, ok := clientState.(*tendermintclient.ClientState) + if ok { + return tmClientState.ChainId } return chainID } diff --git a/x/ibchooks/marker_hooks_test.go b/x/ibchooks/marker_hooks_test.go index f991f353cb..70a6b61eb8 100644 --- a/x/ibchooks/marker_hooks_test.go +++ b/x/ibchooks/marker_hooks_test.go @@ -160,7 +160,7 @@ func (suite *MarkerHooksTestSuite) TestAddUpdateMarker() { assert.Equal(t, marker.GetDenom(), metadata.Base, "Metadata Base should equal marker denom") assert.Equal(t, "testchain2/"+tc.denom, metadata.Name, "Metadata Name should be chainid/denom") assert.Equal(t, "testchain2/"+tc.denom, metadata.Display, "Metadata Display should be chainid/denom") - assert.Equal(t, tc.denom+" from chain testchain2", metadata.Description, "Metadata Description is incorrect") + assert.Equal(t, tc.denom+" from testchain2", metadata.Description, "Metadata Description is incorrect") assert.Len(t, marker.GetAccessList(), len(tc.expTransAuths), "Resulting access list does not equal expect length") for _, access := range marker.GetAccessList() { assert.Len(t, access.GetAccessList(), 1, "Expecting permissions list to only one item")