Skip to content

Commit

Permalink
set metadata for launched consumer chains
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Sep 3, 2024
1 parent 08a85ae commit 2b63228
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

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

Check failure on line 8 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / Analyze

ST1019: package "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" is being imported more than once (stylecheck)

Check failure on line 8 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1019: package "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" is being imported more than once (stylecheck)
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

Check failure on line 9 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / Analyze

ST1019(related information): other import of "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" (stylecheck)

Check failure on line 9 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1019(related information): other import of "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" (stylecheck)

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -73,6 +74,12 @@ func CreateUpgradeHandler(
return vm, errorsmod.Wrapf(err, "migrating ICS legacy proposals during migration")
}

ctx.Logger().Info("Setting ICS consumers metadata...")
err = SetICSConsumerMetadata(ctx, keepers.ProviderKeeper)
if err != nil {
return vm, errorsmod.Wrapf(err, "setting ICS consumers metadata during migration")
}

ctx.Logger().Info("Upgrade v20 complete")
return vm, nil
}
Expand Down Expand Up @@ -690,3 +697,49 @@ func MigrateChangeRewardDenomsProposal(
}
return nil
}

// SetICSConsumerMetadata sets the metadata for launched consumer chains
func SetICSConsumerMetadata(ctx sdk.Context, providerKeeper providerkeeper.Keeper) error {
for _, consumerId := range providerKeeper.GetAllActiveConsumerIds(ctx) {

Check failure on line 703 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / Analyze

var-naming: range var consumerId should be consumerID (revive)

Check failure on line 703 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: range var consumerId should be consumerID (revive)
phase := providerKeeper.GetConsumerPhase(ctx, consumerId)
if phase != types.ConsumerPhase_CONSUMER_PHASE_LAUNCHED {
continue
}
chainId, err := providerKeeper.GetConsumerChainId(ctx, consumerId)

Check failure on line 708 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / Analyze

var-naming: var chainId should be chainID (revive)

Check failure on line 708 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: var chainId should be chainID (revive)
if err != nil {
ctx.Logger().Error(
fmt.Sprintf("cannot get chain ID for consumer chain, consumerId(%s)", consumerId),
)
continue
}

if chainId == "stride-1" {
metadata := providertypes.ConsumerMetadata{
Name: "Stride",
Description: "",
Metadata: "https://github.com/Stride-Labs/stride",
}
err = providerKeeper.SetConsumerMetadata(ctx, consumerId, metadata)
if err != nil {
ctx.Logger().Error(
fmt.Sprintf("cannot set consumer metadata, consumerId(%s), chainId(%s): %s", consumerId, chainId, err.Error()),
)
continue
}
} else if chainId == "neutron-1" {
metadata := providertypes.ConsumerMetadata{
Name: "Neutron",
Description: "",
Metadata: "https://github.com/neutron-org/neutron",
}
err = providerKeeper.SetConsumerMetadata(ctx, consumerId, metadata)
if err != nil {
ctx.Logger().Error(
fmt.Sprintf("cannot set consumer metadata, consumerId(%s), chainId(%s): %s", consumerId, chainId, err.Error()),
)
continue
}
}
}
return nil
}

0 comments on commit 2b63228

Please sign in to comment.