Skip to content

Commit

Permalink
feat: add metadata for Stride and Neutron in upgrade handler (#3318)
Browse files Browse the repository at this point in the history
* add metadata for Stride and Neutron

* fix linter

* fix linter
  • Loading branch information
mpoke committed Sep 6, 2024
1 parent 495bbb7 commit 5c1754f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ docker-build-all: docker-build-debug docker-build-hermes
### Linting ###
###############################################################################
golangci_lint_cmd=golangci-lint
golangci_version=v1.53.3
golangci_version=v1.60.1

lint:
@echo "--> Running linter"
Expand Down
29 changes: 27 additions & 2 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v20

import (
"context"
"encoding/json"
"fmt"

providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper"
Expand Down Expand Up @@ -725,6 +726,18 @@ func SetICSConsumerMetadata(ctx sdk.Context, providerKeeper providerkeeper.Keepe
}

if chainID == "stride-1" {
var metatadaField string
if u, err := json.Marshal(map[string]string{
"phase": "mainnet",
"forge_json_url": "https://github.com/Stride-Labs/stride/main/forge.json",
}); err != nil {
ctx.Logger().Error(
fmt.Sprintf("cannot marshal metadata, consumerID(%s), chainID(%s): %s", consumerID, chainID, err.Error()),
)
metatadaField = ""
} else {
metatadaField = string(u)
}
metadata := providertypes.ConsumerMetadata{
Name: "Stride",
Description: "The Stride blockchain has a single purpose: to provide the best liquid staking service for chains in the Cosmos ecosystem. " +
Expand All @@ -734,7 +747,7 @@ func SetICSConsumerMetadata(ctx sdk.Context, providerKeeper providerkeeper.Keepe
"Like the Cosmos Hub, Stride is a highly secure minimalist blockchain, with no smart contracts and no other apps beside the core liquid staking protocol. " +
"The Stride codebase has been fully audited by numerous security firms, and receives continuous auditing from Informal Systems. " +
"And the Stride blockchain is protected by IBC rate-limiting.",
Metadata: "https://github.com/Stride-Labs/stride",
Metadata: metatadaField,
}
err = providerKeeper.SetConsumerMetadata(ctx, consumerID, metadata)
if err != nil {
Expand All @@ -744,6 +757,18 @@ func SetICSConsumerMetadata(ctx sdk.Context, providerKeeper providerkeeper.Keepe
continue
}
} else if chainID == "neutron-1" {
var metatadaField string
if u, err := json.Marshal(map[string]string{
"phase": "mainnet",
"forge_json_url": "https://github.com/neutron-org/neutron/main/forge.json",
}); err != nil {
ctx.Logger().Error(
fmt.Sprintf("cannot marshal metadata, consumerID(%s), chainID(%s): %s", consumerID, chainID, err.Error()),
)
metatadaField = ""
} else {
metatadaField = string(u)
}
metadata := providertypes.ConsumerMetadata{
Name: "Neutron",
Description: "Neutron is the only blockchain network specifically designed to support Integrated Applications. " +
Expand All @@ -754,7 +779,7 @@ func SetICSConsumerMetadata(ctx sdk.Context, providerKeeper providerkeeper.Keepe
"They can deploy and manage capital and integrations across multiple chains, maximising network effects and the ubiquity of their denominations.\n" +
"These features allow Integrated Applications to establish stronger moats around their technology and business model, while providing a competitive edge that standard applications lack. " +
"This makes them inherently more attractive and competitive, as they operate on an enhanced platform offering higher performance and broader reach compared to traditional applications.",
Metadata: "https://github.com/neutron-org/neutron",
Metadata: metatadaField,
}
err = providerKeeper.SetConsumerMetadata(ctx, consumerID, metadata)
if err != nil {
Expand Down
57 changes: 57 additions & 0 deletions app/upgrades/v20/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package v20_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

"github.com/cosmos/gaia/v20/app/helpers"
v20 "github.com/cosmos/gaia/v20/app/upgrades/v20"
)

func TestSetICSConsumerMetadata(t *testing.T) {
gaiaApp := helpers.Setup(t)
ctx := gaiaApp.NewUncachedContext(true, tmproto.Header{})

pk := gaiaApp.ProviderKeeper

// Add consumer chains
neutronConsumerID := pk.FetchAndIncrementConsumerId(ctx)
pk.SetConsumerChainId(ctx, neutronConsumerID, "neutron-1")
pk.SetConsumerPhase(ctx, neutronConsumerID, providertypes.CONSUMER_PHASE_LAUNCHED)
strideConsumerID := pk.FetchAndIncrementConsumerId(ctx)
pk.SetConsumerChainId(ctx, strideConsumerID, "stride-1")
pk.SetConsumerPhase(ctx, strideConsumerID, providertypes.CONSUMER_PHASE_LAUNCHED)

err := v20.SetICSConsumerMetadata(ctx, pk)
require.NoError(t, err)

metadata, err := pk.GetConsumerMetadata(ctx, neutronConsumerID)
require.NoError(t, err)
require.Equal(t, "Neutron", metadata.Name)
expectedMetadataField := map[string]string{
"phase": "mainnet",
"forge_json_url": "https://github.com/neutron-org/neutron/main/forge.json",
}
metadataField := map[string]string{}
err = json.Unmarshal([]byte(metadata.Metadata), &metadataField)
require.NoError(t, err)
require.Equal(t, expectedMetadataField, metadataField)

metadata, err = pk.GetConsumerMetadata(ctx, strideConsumerID)
require.NoError(t, err)
require.Equal(t, "Stride", metadata.Name)
expectedMetadataField = map[string]string{
"phase": "mainnet",
"forge_json_url": "https://github.com/Stride-Labs/stride/main/forge.json",
}
metadataField = map[string]string{}
err = json.Unmarshal([]byte(metadata.Metadata), &metadataField)
require.NoError(t, err)
require.Equal(t, expectedMetadataField, metadataField)
}

0 comments on commit 5c1754f

Please sign in to comment.