Skip to content

Commit f03d537

Browse files
authored
fix!: add metadata and init params default during permissionless migration (#2243)
* add default metadata during migration * update upgrading instr.
1 parent 4dac95b commit f03d537

File tree

2 files changed

+121
-65
lines changed

2 files changed

+121
-65
lines changed

UPGRADING.md

Lines changed: 107 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,94 +7,138 @@
77
Upgrading a provider from v5.1.x requires state migrations. The following migrators should be added to the upgrade handler of the provider chain:
88

99
```go
10-
// InitializeMaxValidatorsForExistingConsumers initializes the max validators
11-
// parameter for existing consumers to the MaxProviderConsensusValidators parameter.
12-
// This is necessary to avoid those consumer chains having an excessive amount of validators.
13-
func InitializeMaxValidatorsForExistingConsumers(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
14-
maxVals := providerKeeper.GetParams(ctx).MaxProviderConsensusValidators
15-
for _, chainID := range providerKeeper.GetAllRegisteredConsumerChainIDs(ctx) {
16-
providerKeeper.SetValidatorSetCap(ctx, chainID, uint32(maxVals))
17-
}
18-
}
19-
2010
// InitializeMaxProviderConsensusParam initializes the MaxProviderConsensusValidators parameter.
11+
// It is set to 180, which is the current number of validators participating in consensus on the Cosmos Hub.
12+
// This parameter will be used to govern the number of validators participating in consensus on the Cosmos Hub,
13+
// and takes over this role from the MaxValidators parameter in the staking module.
2114
func InitializeMaxProviderConsensusParam(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
2215
params := providerKeeper.GetParams(ctx)
23-
if params.MaxProviderConsensusValidators == 0 {
24-
params.MaxProviderConsensusValidators = 180
25-
providerKeeper.SetParams(ctx, params)
26-
}
16+
params.MaxProviderConsensusValidators = NewMaxProviderConsensusValidators
17+
providerKeeper.SetParams(ctx, params)
2718
}
2819
```
2920

30-
### Governance Proposals
31-
32-
Legacy proposals are not supported anymore by the current version of the provider. Legacy proposals which are still active (voting period or deposit period) and contain one of the following messages that need to be migrated as described below:
33-
- `ConsumerAdditionProposal` needs to be converted to `MsgConsumerAddition`
34-
- `ConsumerModificationProposal` needs to be converted to `MsgConsumerModification`
35-
- `ConsumerRemovalProposal` needs to be converted to `MsgConsumerRemoval`
36-
- `ChangeRewardDenomsProposal` needs to be converted to `MsgChangeRewardDenoms`
37-
38-
The following shows an example on how to migrate a proposal containing a legacy consumer addition proposal message.
39-
Migration for the other messages aobve follows the same pattern. The resulting migration code has to be added to the upgrade handler of the provider chain.
40-
41-
#### Migrate Legacy Proposal Content
21+
```go
22+
// SetMaxValidators sets the MaxValidators parameter in the staking module to 200,
23+
// which is the current number of 180 plus 20.
24+
// This is done in concert with the introduction of the inactive-validators feature
25+
// in Interchain Security, after which the number of validators
26+
// participating in consensus on the Cosmos Hub will be governed by the
27+
// MaxProviderConsensusValidators parameter in the provider module.
28+
func SetMaxValidators(ctx sdk.Context, stakingKeeper stakingkeeper.Keeper) error {
29+
params, err := stakingKeeper.GetParams(ctx)
30+
if err != nil {
31+
return err
32+
}
33+
params.MaxValidators = NewMaxValidators
34+
return stakingKeeper.SetParams(ctx, params)
35+
}
36+
```
4237

4338
```go
39+
// InitializeLastProviderConsensusValidatorSet initializes the last provider consensus validator set
40+
// by setting it to the first 180 validators from the current validator set of the staking module.
41+
func InitializeLastProviderConsensusValidatorSet(ctx sdk.Context, providerKeeper providerkeeper.Keeper, stakingKeeper stakingkeeper.Keeper) error {
42+
vals, err := stakingKeeper.GetBondedValidatorsByPower(ctx)
43+
if err != nil {
44+
return err
45+
}
46+
// cut the validator set to the first 180 validators
47+
if len(vals) > NewMaxProviderConsensusValidators {
48+
vals = vals[:NewMaxProviderConsensusValidators]
49+
}
50+
// create consensus validators for the staking validators
51+
lastValidators := []providertypes.ConsensusValidator{}
52+
for _, val := range vals {
53+
consensusVal, err := providerKeeper.CreateProviderConsensusValidator(ctx, val)
54+
if err != nil {
55+
return err
56+
}
4457

45-
// MigrateLegacyConsumerAddition converts a ConsumerAdditionProposal to a MsgConsumerAdditionProposal
46-
// and returns it as `Any` suitable to replace the legacy message.
47-
// `authority` contains the signer address
48-
func MigrateLegacyConsumerAddition(msg providertypes.ConsumerAdditionProposal, authority string) (*codec.Any, error) {
49-
sdkMsg := providertypes.MsgConsumerAddition{
50-
ChainId: msg.ChainId,
51-
InitialHeight: msg.InitialHeight,
52-
GenesisHash: msg.GenesisHash,
53-
BinaryHash: msg.BinaryHash,
54-
SpawnTime: msg.SpawnTime,
55-
UnbondingPeriod: msg.UnbondingPeriod,
56-
CcvTimeoutPeriod: msg.CcvTimeoutPeriod,
57-
TransferTimeoutPeriod: msg.TransferTimeoutPeriod,
58-
ConsumerRedistributionFraction: msg.ConsumerRedistributionFraction,
59-
BlocksPerDistributionTransmission: msg.BlocksPerDistributionTransmission,
60-
HistoricalEntries: msg.HistoricalEntries,
61-
DistributionTransmissionChannel: msg.DistributionTransmissionChannel,
62-
Top_N: msg.Top_N,
63-
ValidatorsPowerCap: msg.ValidatorsPowerCap,
64-
ValidatorSetCap: msg.ValidatorSetCap,
65-
Allowlist: msg.Allowlist,
66-
Denylist: msg.Denylist,
67-
Authority: authority,
68-
MinStake: msg.MinStake,
69-
AllowInactiveVals: msg.AllowInactiveVals,
58+
lastValidators = append(lastValidators, consensusVal)
7059
}
71-
return codec.NewAnyWithValue(&sdkMsg)
60+
return providerKeeper.SetLastProviderConsensusValSet(ctx, lastValidators)
7261
}
62+
```
7363

74-
func MigrateProposal(proposal proposal govtypes.Proposal) err {
75-
for idx, msg := range proposal.GetMessages() {
76-
sdkLegacyMsg, isLegacyProposal := msg.GetCachedValue().(*govtypes.MsgExecLegacyContent)
77-
if !isLegacyProposal {
64+
```go
65+
// SetICSConsumerMetadata sets the metadata for launched consumer chains
66+
func SetICSConsumerMetadata(ctx sdk.Context, providerKeeper providerkeeper.Keeper) error {
67+
for _, consumerID := range providerKeeper.GetAllActiveConsumerIds(ctx) {
68+
phase := providerKeeper.GetConsumerPhase(ctx, consumerID)
69+
if phase != providertypes.CONSUMER_PHASE_LAUNCHED {
7870
continue
7971
}
80-
content, err := govtypes.LegacyContentFromMessage(sdkLegacyMsg)
72+
chainID, err := providerKeeper.GetConsumerChainId(ctx, consumerID)
8173
if err != nil {
74+
ctx.Logger().Error(
75+
fmt.Sprintf("cannot get chain ID for consumer chain, consumerID(%s)", consumerID),
76+
)
8277
continue
8378
}
8479

85-
msgAdd, ok := content.(*providertypes.ConsumerAdditionProposal)
86-
if ok {
87-
anyMsg, err := migrateLegacyConsumerAddition(*msgAdd, govKeeper.GetAuthority())
80+
// example of setting the metadata for Stride
81+
if chainID == "stride-1" {
82+
metadata := providertypes.ConsumerMetadata{
83+
Name: "Stride",
84+
Description: "Description",
85+
Metadata: "Metadata",
86+
}
87+
err = providerKeeper.SetConsumerMetadata(ctx, consumerID, metadata)
8888
if err != nil {
89-
return err
89+
ctx.Logger().Error(
90+
fmt.Sprintf("cannot set consumer metadata, consumerID(%s), chainID(%s): %s", consumerID, chainID, err.Error()),
91+
)
92+
continue
9093
}
91-
proposal.Messages[idx] = anyMsg
9294
}
9395
}
94-
return govKeeper.SetProposal(ctx, proposal)
9596
}
9697
```
9798

99+
```go
100+
// MigrateICSProposals migrates deprecated proposals
101+
func MigrateICSProposals(ctx sdk.Context, msgServer providertypes.MsgServer, providerKeeper providerkeeper.Keeper, govKeeper govkeeper.Keeper) error {
102+
proposals := []govtypesv1.Proposal{}
103+
err := govKeeper.Proposals.Walk(ctx, nil, func(key uint64, proposal govtypesv1.Proposal) (stop bool, err error) {
104+
proposals = append(proposals, proposal)
105+
return false, nil // go through the entire collection
106+
})
107+
if err != nil {
108+
return errorsmod.Wrapf(err, "iterating through proposals")
109+
}
110+
for _, proposal := range proposals {
111+
err := MigrateICSLegacyProposal(ctx, msgServer, providerKeeper, govKeeper, proposal)
112+
if err != nil {
113+
return errorsmod.Wrapf(err, "migrating legacy proposal %d", proposal.Id)
114+
}
115+
116+
err = MigrateICSProposal(ctx, msgServer, providerKeeper, govKeeper, proposal)
117+
if err != nil {
118+
return errorsmod.Wrapf(err, "migrating proposal %d", proposal.Id)
119+
}
120+
}
121+
return nil
122+
}
123+
124+
// MigrateICSLegacyProposal migrates the following proposals
125+
// - ConsumerAdditionProposal
126+
// - ConsumerRemovalProposal
127+
// - ConsumerModificationProposal
128+
// - ChangeRewardDenomsProposal
129+
130+
// MigrateICSProposal migrates the following proposals
131+
// - MsgConsumerAddition
132+
// - MsgConsumerRemoval
133+
// - MsgConsumerModification
134+
```
135+
136+
For an example, see the [Gaia v20 upgrade handler](https://github.com/cosmos/gaia/blob/e4656093955578b2efa6e8c2ea8dd8823008bba3/app/upgrades/v20/upgrades.go#L43).
137+
138+
### Consumer
139+
140+
Upgrading the consumer from `v5.0.0` or `v5.2.0` will not require state migration.
141+
98142
## [v5.1.x](https://github.com/cosmos/interchain-security/releases/tag/v5.1.0)
99143

100144
### Provider

x/ccv/provider/migrations/v8/migrations.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,20 @@ func MigrateLaunchedConsumerChains(ctx sdk.Context, store storetypes.KVStore, pk
247247
// set ownership -- all existing chains are owned by gov
248248
pk.SetConsumerOwnerAddress(ctx, consumerId, pk.GetAuthority())
249249

250-
// Note: ConsumerMetadata will be populated in the upgrade handler
251-
// Note: InitializationParameters is not needed since the chain is already launched
250+
// Note: ConsumerMetadata will be populated in the upgrade handler.
251+
// Still, add some default values as every chain should have the metadata set.
252+
if err := pk.SetConsumerMetadata(ctx, consumerId, providertypes.ConsumerMetadata{
253+
Name: chainId,
254+
Description: "TBA",
255+
Metadata: "TBA",
256+
}); err != nil {
257+
return err
258+
}
259+
// Note: InitializationParameters are not needed since the chain is already launched.
260+
// Just add the default values.
261+
if err := pk.SetConsumerInitializationParameters(ctx, consumerId, providertypes.ConsumerInitializationParameters{}); err != nil {
262+
return err
263+
}
252264

253265
// migrate power shaping params
254266
topNKey := providertypes.StringIdWithLenKey(LegacyTopNKeyPrefix, chainId)

0 commit comments

Comments
 (0)