-
Notifications
You must be signed in to change notification settings - Fork 122
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: v2 migrations #975
feat: v2 migrations #975
Changes from 22 commits
1c5cf77
f7b0e31
ed43d0b
0b4e6b7
70bb621
1861340
96b6fef
1abfc6a
39b8a6f
e9b71fd
57e82a8
75f86f3
1e87457
7db29b6
e380bbb
baa747b
7ddb7e3
d858a33
add0973
2d10e22
ac41852
a135c28
8498fc0
d60b342
a235a1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" | ||
ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
ccvConsumerKeeper Keeper | ||
ccvConsumerParamSpace paramtypes.Subspace | ||
} | ||
|
||
// NewMigrator returns a new Migrator. | ||
func NewMigrator(ccvConsumerKeeper Keeper, ccvConsumerParamSpace paramtypes.Subspace) Migrator { | ||
return Migrator{ccvConsumerKeeper: ccvConsumerKeeper, ccvConsumerParamSpace: ccvConsumerParamSpace} | ||
} | ||
|
||
// Migratev1p2p0MultidenTov2 migrates a consumer from v1.2.0-multiden to v2.0.0. | ||
func (m Migrator) Migratev1p2p0MultidenTov2(ctx sdk.Context) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this function as is not needed. State migration cares about consensus versions and not semver. As both v1.2.0-multiden and v1.0.0 are on the same consensus version (i.e., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But as far as your original comment, the methods were removed 👍 |
||
// Note: If migrating from v1.2.0-multiden to v2.0.0, there are no migrations required. | ||
// This is due to the fact that the former version includes both of: | ||
// - https://github.com/cosmos/interchain-security/commit/54e9852d3c89a2513cd0170a56c6eec894fc878d | ||
// - https://github.com/cosmos/interchain-security/pull/833 | ||
// both of which handle the introduction of new params. | ||
return nil | ||
} | ||
|
||
// Migratev1Tov2 migrates a consumer from v1.0.0 to v2.0.0. | ||
func (m Migrator) Migratev1Tov2(ctx sdk.Context) error { | ||
// Migrate params | ||
MigrateParamsv1Tov2(ctx, m.ccvConsumerParamSpace) | ||
|
||
return nil | ||
} | ||
|
||
// MigrateParamsv1Tov2 migrates the consumer CCV module params from v1.0.0 to v2.0.0, | ||
// setting default values for new params. | ||
func MigrateParamsv1Tov2(ctx sdk.Context, paramsSubspace paramtypes.Subspace) { | ||
// Get old params | ||
var enabled bool | ||
paramsSubspace.Get(ctx, consumertypes.KeyEnabled, &enabled) | ||
var blocksPerDistributionTransmission int64 | ||
paramsSubspace.Get(ctx, consumertypes.KeyBlocksPerDistributionTransmission, &blocksPerDistributionTransmission) | ||
var distributionTransmissionChannel string | ||
paramsSubspace.Get(ctx, consumertypes.KeyDistributionTransmissionChannel, &distributionTransmissionChannel) | ||
var providerFeePoolAddrStr string | ||
paramsSubspace.Get(ctx, consumertypes.KeyProviderFeePoolAddrStr, &providerFeePoolAddrStr) | ||
var ccvTimeoutPeriod time.Duration | ||
paramsSubspace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &ccvTimeoutPeriod) | ||
var transferTimeoutPeriod time.Duration | ||
paramsSubspace.Get(ctx, consumertypes.KeyTransferTimeoutPeriod, &transferTimeoutPeriod) | ||
var consumerRedistributionFrac string | ||
paramsSubspace.Get(ctx, consumertypes.KeyConsumerRedistributionFrac, &consumerRedistributionFrac) | ||
var historicalEntries int64 | ||
paramsSubspace.Get(ctx, consumertypes.KeyHistoricalEntries, &historicalEntries) | ||
var unbondingPeriod time.Duration | ||
paramsSubspace.Get(ctx, consumertypes.KeyConsumerUnbondingPeriod, &unbondingPeriod) | ||
|
||
// Recycle old params, set new params to default values | ||
defaultParams := consumertypes.DefaultParams() | ||
newParams := consumertypes.NewParams( | ||
enabled, | ||
blocksPerDistributionTransmission, | ||
distributionTransmissionChannel, | ||
providerFeePoolAddrStr, | ||
ccvTimeoutPeriod, | ||
transferTimeoutPeriod, | ||
consumerRedistributionFrac, | ||
historicalEntries, | ||
unbondingPeriod, | ||
defaultParams.SoftOptOutThreshold, | ||
defaultParams.RewardDenoms, | ||
defaultParams.ProviderRewardDenoms, | ||
) | ||
|
||
// Persist new params | ||
paramsSubspace.SetParamSet(ctx, &newParams) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we now have to pass in param subspace to the app module constructor so the subspace can be used for migrations