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
57 changes: 56 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"fmt"
"strings"

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

Expand All @@ -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"
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 +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)
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 +152,7 @@ var upgrades = map[string]appUpgrade{
setupICQ(ctx, app)
updateMaxSupply(ctx, app)
setExchangeParams(ctx, app)
updateIbcMarkerDenomMetadata(ctx, app)

return vm, nil
},
Expand Down Expand Up @@ -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")
}
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
18 changes: 8 additions & 10 deletions x/ibchooks/marker_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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
2 changes: 1 addition & 1 deletion x/ibchooks/marker_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading