Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1726 marker creation missing metadata #1728

Merged
merged 13 commits into from
Nov 3, 2023
Merged
48 changes: 47 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"fmt"
"strings"

icqtypes "github.com/strangelove-ventures/async-icq/v6/types"

Expand All @@ -11,15 +12,19 @@
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
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"
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down Expand Up @@ -120,7 +125,19 @@
},
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
}

Check warning on line 134 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L133-L134

Added lines #L133 - L134 were not covered by tests

updateIbcMarkerDenomMetadata(ctx, app)
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved

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
Expand All @@ -136,6 +153,7 @@
setupICQ(ctx, app)
updateMaxSupply(ctx, app)
setExchangeParams(ctx, app)
updateIbcMarkerDenomMetadata(ctx, app)

return vm, nil
},
Expand Down Expand Up @@ -361,3 +379,31 @@
}
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.HasSuffix(record.GetDenom(), "ibc/") {
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
denomTrace := transfertypes.ParseDenomTrace(record.GetDenom())
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 chain " + chainID,
}
err := app.MarkerKeeper.SetDenomMetaData(ctx, markerMetadata, authtypes.NewModuleAddress(types.ModuleName))
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
panic(fmt.Sprintf("unable to set denom metadata for %v with base denom %v and chain-id %v: %v", record.GetDenom(), denomTrace.BaseDenom, chainID, err))

Check warning on line 402 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L388-L402

Added lines #L388 - L402 were not covered by tests
}
}
}
return false

Check warning on line 406 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L406

Added line #L406 was not covered by tests
})
ctx.Logger().Info("Done updating ibc marker denom metadata")
}
14 changes: 14 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions x/ibchooks/marker_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ 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,
Expand All @@ -124,10 +124,10 @@ func (h MarkerHooks) addDenomMetaData(ctx sdktypes.Context, packet exported.Pack
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
}
Expand All @@ -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
}
Expand Down
Loading