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

feat!: add memo to IBC transfers of ICS rewards (backport #2290) #2312

Merged
merged 10 commits into from
Sep 27, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `[x/consumer]` Populate the memo on the IBC transfer packets used to send ICS rewards.
with the required consumer chain Id to identify the consumer to the provider.
- `[x/provider]` Identify the source of ICS rewards from the IBC transfer packet memo.
([\#2290](https://github.com/cosmos/interchain-security/pull/2290))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `[x/consumer]` Populate the memo on the IBC transfer packets used to send ICS rewards.
with the required consumer chain Id to identify the consumer to the provider.
- `[x/provider]` Identify the source of ICS rewards from the IBC transfer packet memo.
([\#2290](https://github.com/cosmos/interchain-security/pull/2290))
178 changes: 178 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,183 @@
# Upgrading Replicated Security

<<<<<<< HEAD
=======
## Unreleased

### Consumer

Upgrading a consumer from v4.4.x to v4.5.x and from v5.x or v6.1.x to v6.2.x requires state migrations. The following migrators should be added to the upgrade handler of the consumer chain:


```go
// InitializeConsumerId sets the consumer Id parameter in the consumer module,
// to the consumer id for which the consumer is registered on the provider chain.
// The consumer id can be obtained in by querying the provider, e.g. by using the
// QueryConsumerIdFromClientId query.
func InitializeConsumerId(ctx sdk.Context, consumerKeeper consumerkeeper.Keeper) error {
params, err := consumerKeeper.GetParams(ctx)
if err != nil {
return err
}
params.ConsumerId = ConsumerId
return consumerKeeper.SetParams(ctx, params)
}
```

### Provider

Upgrading a provider from v5.1.x requires state migrations. The following migrators should be added to the upgrade handler of the provider chain:

```go
// InitializeMaxProviderConsensusParam initializes the MaxProviderConsensusValidators parameter.
// It is set to 180, which is the current number of validators participating in consensus on the Cosmos Hub.
// This parameter will be used to govern the number of validators participating in consensus on the Cosmos Hub,
// and takes over this role from the MaxValidators parameter in the staking module.
func InitializeMaxProviderConsensusParam(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
params := providerKeeper.GetParams(ctx)
params.MaxProviderConsensusValidators = NewMaxProviderConsensusValidators
providerKeeper.SetParams(ctx, params)
}
```

```go
// SetMaxValidators sets the MaxValidators parameter in the staking module to 200,
// which is the current number of 180 plus 20.
// This is done in concert with the introduction of the inactive-validators feature
// in Interchain Security, after which the number of validators
// participating in consensus on the Cosmos Hub will be governed by the
// MaxProviderConsensusValidators parameter in the provider module.
func SetMaxValidators(ctx sdk.Context, stakingKeeper stakingkeeper.Keeper) error {
params, err := stakingKeeper.GetParams(ctx)
if err != nil {
return err
}
params.MaxValidators = NewMaxValidators
return stakingKeeper.SetParams(ctx, params)
}
```

```go
// InitializeLastProviderConsensusValidatorSet initializes the last provider consensus validator set
// by setting it to the first 180 validators from the current validator set of the staking module.
func InitializeLastProviderConsensusValidatorSet(ctx sdk.Context, providerKeeper providerkeeper.Keeper, stakingKeeper stakingkeeper.Keeper) error {
vals, err := stakingKeeper.GetBondedValidatorsByPower(ctx)
if err != nil {
return err
}
// cut the validator set to the first 180 validators
if len(vals) > NewMaxProviderConsensusValidators {
vals = vals[:NewMaxProviderConsensusValidators]
}
// create consensus validators for the staking validators
lastValidators := []providertypes.ConsensusValidator{}
for _, val := range vals {
consensusVal, err := providerKeeper.CreateProviderConsensusValidator(ctx, val)
if err != nil {
return err
}

lastValidators = append(lastValidators, consensusVal)
}
return providerKeeper.SetLastProviderConsensusValSet(ctx, lastValidators)
}
```

```go
// SetICSConsumerMetadata sets the metadata for launched consumer chains
func SetICSConsumerMetadata(ctx sdk.Context, providerKeeper providerkeeper.Keeper) error {
for _, consumerID := range providerKeeper.GetAllActiveConsumerIds(ctx) {
phase := providerKeeper.GetConsumerPhase(ctx, consumerID)
if phase != providertypes.CONSUMER_PHASE_LAUNCHED {
continue
}
chainID, err := providerKeeper.GetConsumerChainId(ctx, consumerID)
if err != nil {
ctx.Logger().Error(
fmt.Sprintf("cannot get chain ID for consumer chain, consumerID(%s)", consumerID),
)
continue
}

// example of setting the metadata for Stride
if chainID == "stride-1" {
metadata := providertypes.ConsumerMetadata{
Name: "Stride",
Description: "Description",
Metadata: "Metadata",
}
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
}
}
}
}
```

```go
// MigrateICSProposals migrates deprecated proposals
func MigrateICSProposals(ctx sdk.Context, msgServer providertypes.MsgServer, providerKeeper providerkeeper.Keeper, govKeeper govkeeper.Keeper) error {
proposals := []govtypesv1.Proposal{}
err := govKeeper.Proposals.Walk(ctx, nil, func(key uint64, proposal govtypesv1.Proposal) (stop bool, err error) {
proposals = append(proposals, proposal)
return false, nil // go through the entire collection
})
if err != nil {
return errorsmod.Wrapf(err, "iterating through proposals")
}
for _, proposal := range proposals {
err := MigrateICSLegacyProposal(ctx, msgServer, providerKeeper, govKeeper, proposal)
if err != nil {
return errorsmod.Wrapf(err, "migrating legacy proposal %d", proposal.Id)
}

err = MigrateICSProposal(ctx, msgServer, providerKeeper, govKeeper, proposal)
if err != nil {
return errorsmod.Wrapf(err, "migrating proposal %d", proposal.Id)
}
}
return nil
}

// MigrateICSLegacyProposal migrates the following proposals
// - ConsumerAdditionProposal
// - ConsumerRemovalProposal
// - ConsumerModificationProposal
// - ChangeRewardDenomsProposal

// MigrateICSProposal migrates the following proposals
// - MsgConsumerAddition
// - MsgConsumerRemoval
// - MsgConsumerModification
```

For an example, see the [Gaia v20 upgrade handler](https://github.com/cosmos/gaia/blob/e4656093955578b2efa6e8c2ea8dd8823008bba3/app/upgrades/v20/upgrades.go#L43).

### Consumer

Upgrading the consumer from `v5.0.0` or `v5.2.0` will not require state migration.

## [v5.1.x](https://github.com/cosmos/interchain-security/releases/tag/v5.1.0)

### Provider

***Note that providers using v5.0.0 cannot upgrade to v5.1.0 cleanly***

Providers using versions `v4.0.x`, `v4.1.x`, `v4.2.x`, `v4.3.x` and `v4.4.x` can upgrade to `v5.1.0`.

Upgrading from `v4.x` to `v5.1.0` will upgrade the provider `consensus version` to 7.

Upgrade code will be executed automatically during the upgrade procedure.

### Consumer

Upgrading the consumer from `v5.0.0` to `v5.1.0` will not require state migration.

>>>>>>> 0d782959 (feat!: add memo to IBC transfers of ICS rewards (#2290))
This guide provides instructions for upgrading to specific versions of Replicated Security.

## [v4.4.x](https://github.com/cosmos/interchain-security/releases/tag/v4.4.0)
Expand Down
4 changes: 4 additions & 0 deletions proto/interchain_security/ccv/v1/shared_consumer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ message ConsumerParams {
// The period after which a consumer can retry sending a throttled packet.
google.protobuf.Duration retry_delay_period = 13
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];

// The consumer ID of this consumer chain. Used by the consumer module to send
// ICS rewards.
string consumer_id = 14;
}

// ConsumerGenesisState defines shared genesis information between provider and
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/action_rapid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func CreateSubmitChangeRewardDenomsProposalActionGen() *rapid.Generator[SubmitCh
return SubmitChangeRewardDenomsProposalAction{
From: GetValidatorIDGen().Draw(t, "From"),
Deposit: rapid.Uint().Draw(t, "Deposit"),
Denom: rapid.String().Draw(t, "Denom"),
Denoms: rapid.SliceOf(rapid.String()).Draw(t, "Denoms"),
}
})
}
Expand Down
Loading
Loading