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

deps!: Bump ICS #3292

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
no_valupdates_genutil "github.com/cosmos/interchain-security/v5/x/ccv/no_valupdates_genutil"
no_valupdates_staking "github.com/cosmos/interchain-security/v5/x/ccv/no_valupdates_staking"
icsproviderclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

"cosmossdk.io/x/evidence"
Expand Down Expand Up @@ -138,10 +137,6 @@ func newBasicManagerFromManager(app *GaiaApp) module.BasicManager {
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
icsproviderclient.ConsumerAdditionProposalHandler,
icsproviderclient.ConsumerRemovalProposalHandler,
icsproviderclient.ConsumerModificationProposalHandler,
icsproviderclient.ChangeRewardDenomsProposalHandler,
},
),
})
Expand Down
139 changes: 137 additions & 2 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import (
"context"

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

errorsmod "cosmossdk.io/errors"
upgradetypes "cosmossdk.io/x/upgrade/types"

codec "github.com/cosmos/cosmos-sdk/codec/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/gaia/v20/app/keepers"
)

Expand Down Expand Up @@ -62,6 +66,16 @@
return vm, errorsmod.Wrapf(err, "initializing LastProviderConsensusValSet during migration")
}

// Migrate proposals
govKeeper := keepers.GovKeeper
govKeeper.Proposals.Walk(ctx, nil, func(key uint64, proposal govtypes.Proposal) (stop bool, err error) {

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

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `govKeeper.Proposals.Walk` is not checked (errcheck)

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

View workflow job for this annotation

GitHub Actions / Analyze

Error return value of `govKeeper.Proposals.Walk` is not checked (errcheck)
err = MigrateProposal(ctx, *govKeeper, proposal)
if err != nil {
return true, errorsmod.Wrapf(err, "migrating proposal %d", key)
}
return false, nil
})

ctx.Logger().Info("Upgrade v20 complete")
return vm, nil
}
Expand Down Expand Up @@ -110,7 +124,7 @@
}

// create consensus validators for the staking validators
lastValidators := []types.ConsensusValidator{}
lastValidators := []providertypes.ConsensusValidator{}
for _, val := range vals {
consensusVal, err := providerKeeper.CreateProviderConsensusValidator(ctx, val)
if err != nil {
Expand All @@ -123,3 +137,124 @@
providerKeeper.SetLastProviderConsensusValSet(ctx, lastValidators)
return nil
}

// MigrateLegacyConsumerAddition converts a ConsumerAdditionProposal to a MsgConsumerAdditionProposal
// and returns it as `Any` suitable to replace the legacy message.
// `authority` contains the signer address
func MigrateLegacyConsumerAddition(msg providertypes.ConsumerAdditionProposal, authority string) (*codec.Any, error) {
sdkMsg := providertypes.MsgConsumerAddition{
ChainId: msg.ChainId,
InitialHeight: msg.InitialHeight,
GenesisHash: msg.GenesisHash,
BinaryHash: msg.BinaryHash,
SpawnTime: msg.SpawnTime,
UnbondingPeriod: msg.UnbondingPeriod,
CcvTimeoutPeriod: msg.CcvTimeoutPeriod,
TransferTimeoutPeriod: msg.TransferTimeoutPeriod,
ConsumerRedistributionFraction: msg.ConsumerRedistributionFraction,
BlocksPerDistributionTransmission: msg.BlocksPerDistributionTransmission,
HistoricalEntries: msg.HistoricalEntries,
DistributionTransmissionChannel: msg.DistributionTransmissionChannel,
Top_N: msg.Top_N,
ValidatorsPowerCap: msg.ValidatorsPowerCap,
ValidatorSetCap: msg.ValidatorSetCap,
Allowlist: msg.Allowlist,
Denylist: msg.Denylist,
Authority: authority,
MinStake: msg.MinStake,
AllowInactiveVals: msg.AllowInactiveVals,
}
return codec.NewAnyWithValue(&sdkMsg)
}

// MigrateLegacyConsumerRemoval converts a ConsumerRemovalProposal to a MsgConsumerRemovalProposal
// and returns it as `Any` suitable to replace the legacy message.
// `authority` contains the signer address
func MigrateLegacyConsumerRemoval(msg providertypes.ConsumerRemovalProposal, authority string) (*codec.Any, error) {
sdkMsg := providertypes.MsgConsumerRemoval{
ChainId: msg.ChainId,
StopTime: msg.StopTime,
Authority: authority,
}
return codec.NewAnyWithValue(&sdkMsg)
}

// MigrateConsumerModificationProposal converts a ConsumerModificationProposal to a MsgConsumerModificationProposal
// and returns it as `Any` suitable to replace the legacy message.
// `authority` contains the signer address
func MigrateConsumerModificationProposal(msg providertypes.ConsumerModificationProposal, authority string) (*codec.Any, error) {
sdkMsg := providertypes.MsgConsumerModification{
ChainId: msg.ChainId,
Allowlist: msg.Allowlist,
Denylist: msg.Denylist,
Authority: authority,
}
return codec.NewAnyWithValue(&sdkMsg)
}

// MigrateChangeRewardDenomsProposal converts a ChangeRewardDenomsProposal to a MigrateChangeRewardDenomsProposal
// and returns it as `Any` suitable to replace the legacy message.
// `authority` contains the signer address
func MigrateChangeRewardDenomsProposal(msg providertypes.ChangeRewardDenomsProposal, authority string) (*codec.Any, error) {
sdkMsg := providertypes.MsgChangeRewardDenoms{
DenomsToAdd: msg.GetDenomsToAdd(),
DenomsToRemove: msg.GetDenomsToRemove(),
Authority: authority,
}
return codec.NewAnyWithValue(&sdkMsg)
}

// MigrateProposal migrates a proposal by converting legacy messages to new messages.
func MigrateProposal(ctx sdk.Context, govKeeper govkeeper.Keeper, proposal govtypes.Proposal) error {
for idx, msg := range proposal.GetMessages() {
sdkLegacyMsg, isLegacyProposal := msg.GetCachedValue().(*govtypes.MsgExecLegacyContent)
if !isLegacyProposal {
continue
}
content, err := govtypes.LegacyContentFromMessage(sdkLegacyMsg)
if err != nil {
continue
}

msgAdd, ok := content.(*providertypes.ConsumerAdditionProposal)
if ok {
anyMsg, err := MigrateLegacyConsumerAddition(*msgAdd, govKeeper.GetAuthority())
if err != nil {
return err
}
proposal.Messages[idx] = anyMsg
continue // skip the rest of the loop
}

msgRemove, ok := content.(*providertypes.ConsumerRemovalProposal)
if ok {
anyMsg, err := MigrateLegacyConsumerRemoval(*msgRemove, govKeeper.GetAuthority())
if err != nil {
return err
}
proposal.Messages[idx] = anyMsg
continue // skip the rest of the loop
}

msgMod, ok := content.(*providertypes.ConsumerModificationProposal)
if ok {
anyMsg, err := MigrateConsumerModificationProposal(*msgMod, govKeeper.GetAuthority())
if err != nil {
return err
}
proposal.Messages[idx] = anyMsg
continue // skip the rest of the loop
}

msgChangeRewardDenoms, ok := content.(*providertypes.ChangeRewardDenomsProposal)
if ok {
anyMsg, err := MigrateChangeRewardDenomsProposal(*msgChangeRewardDenoms, govKeeper.GetAuthority())
if err != nil {
return err
}
proposal.Messages[idx] = anyMsg
continue // skip the rest of the loop
}
}
return govKeeper.SetProposal(ctx, proposal)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/cosmos/ibc-apps/modules/rate-limiting/v8 v8.0.0
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.4.0
github.com/cosmos/interchain-security/v5 v5.0.0-20240806104629-29327696b8e6
github.com/cosmos/interchain-security/v5 v5.0.0-20240823135732-3a0c55f65769
github.com/google/gofuzz v1.2.0
github.com/gorilla/mux v1.8.1
github.com/ory/dockertest/v3 v3.11.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZD
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/interchain-security/v5 v5.0.0-20240806104629-29327696b8e6 h1:aFwnbEdeMUaQg9ZU+Pm8fE3CzZM2gG5jSeAvYOd+hoU=
github.com/cosmos/interchain-security/v5 v5.0.0-20240806104629-29327696b8e6/go.mod h1:sT6a/OIwwkXuH9fBzt5IBa4lrlWO8etgQ+b59pIE8k4=
github.com/cosmos/interchain-security/v5 v5.0.0-20240823135732-3a0c55f65769 h1:R1ncQp/CwgV/u2fWebEWdp/o3IiINb3RuWEg4ATrEGQ=
github.com/cosmos/interchain-security/v5 v5.0.0-20240823135732-3a0c55f65769/go.mod h1:y3LdR1GPxF8SMFRb/V38OWGZNwEriJDFlka/hoH1GEk=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/e2e_ics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@

func (s *IntegrationTestSuite) writeAddRemoveConsumerProposals(c *chain, consumerChainID string) {
hash, _ := json.Marshal("Z2VuX2hhc2g=")
addProp := &providertypes.ConsumerAdditionProposal{
Title: "Create consumer chain",
Description: "First consumer chain",
ChainId: consumerChainID,
addMsg := &providertypes.MsgConsumerAddition{

Check failure on line 34 in tests/e2e/e2e_ics_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

addMsg declared and not used

Check failure on line 34 in tests/e2e/e2e_ics_test.go

View workflow job for this annotation

GitHub Actions / Analyze

addMsg declared and not used

Check failure on line 34 in tests/e2e/e2e_ics_test.go

View workflow job for this annotation

GitHub Actions / test-e2e

addMsg declared and not used
ChainId: consumerChainID,
InitialHeight: ibcclienttypes.Height{
RevisionHeight: 1,
},
Expand All @@ -49,8 +47,9 @@
HistoricalEntries: 10000,
Top_N: 95,
}

addPropWithDeposit := ConsumerAdditionProposalWithDeposit{
ConsumerAdditionProposal: *addProp,

Check failure on line 52 in tests/e2e/e2e_ics_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: addProp (typecheck)

Check failure on line 52 in tests/e2e/e2e_ics_test.go

View workflow job for this annotation

GitHub Actions / Analyze

undefined: addProp (typecheck)

Check failure on line 52 in tests/e2e/e2e_ics_test.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: addProp
Deposit: "1000uatom",
// Summary is
Summary: "Summary for the First consumer chain addition proposal",
Expand Down Expand Up @@ -103,7 +102,7 @@
submitGovFlags := []string{"consumer-addition", configFile(proposalAddConsumerChainFilename)}
depositGovFlags := []string{strconv.Itoa(proposalCounter), depositAmount.String()}
voteGovFlags := []string{strconv.Itoa(proposalCounter), "yes"}
s.submitLegacyGovProposal(chainAAPIEndpoint, sender, proposalCounter, providertypes.ProposalTypeConsumerAddition, submitGovFlags, depositGovFlags, voteGovFlags, "vote", false)
s.submitGovProposal(chainAAPIEndpoint, sender, proposalCounter, providertypes.ProposalTypeConsumerAddition, submitGovFlags, depositGovFlags, voteGovFlags, "vote")

// Query and assert consumer has been added
s.execQueryConsumerChains(s.chainA, 0, gaiaHomePath, validateConsumerAddition, consumerChainID)
Expand All @@ -113,7 +112,7 @@
submitGovFlags = []string{"consumer-removal", configFile(proposalRemoveConsumerChainFilename)}
depositGovFlags = []string{strconv.Itoa(proposalCounter), depositAmount.String()}
voteGovFlags = []string{strconv.Itoa(proposalCounter), "yes"}
s.submitLegacyGovProposal(chainAAPIEndpoint, sender, proposalCounter, providertypes.ProposalTypeConsumerRemoval, submitGovFlags, depositGovFlags, voteGovFlags, "vote", false)
s.submitGovProposal(chainAAPIEndpoint, sender, proposalCounter, providertypes.ProposalTypeConsumerRemoval, submitGovFlags, depositGovFlags, voteGovFlags, "vote")
// Query and assert consumer has been removed
s.execQueryConsumerChains(s.chainA, 0, gaiaHomePath, validateConsumerRemoval, consumerChainID)
}
Expand Down
Loading