-
Notifications
You must be signed in to change notification settings - Fork 145
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
chore: add consumer and provider migrations for ICS v5 #1817
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
package v3 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
storetypes "cosmossdk.io/store/types" | ||
|
||
consumerKeeper "github.com/cosmos/interchain-security/v5/x/ccv/consumer/keeper" | ||
consumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types" | ||
ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" | ||
) | ||
|
||
// MigrateParams migrates the consumers module's parameters from the x/params subspace to the | ||
// MigrateLegacyParams migrates the consumers module's parameters from the x/params subspace to the | ||
// consumer modules store. | ||
func MigrateParams(ctx sdk.Context, keeper consumerKeeper.Keeper, legacyParamspace paramtypes.Subspace) error { | ||
params := consumerKeeper.GetConsumerParamsLegacy(ctx, keeper, legacyParamspace) | ||
func MigrateLegacyParams(ctx sdk.Context, cdc codec.BinaryCodec, store storetypes.KVStore, legacyParamspace ccvtypes.LegacyParamSubspace) error { | ||
ctx.Logger().Info("starting consumer legacy params migration") | ||
params := GetConsumerParamsLegacy(ctx, legacyParamspace) | ||
err := params.Validate() | ||
if err != nil { | ||
return err | ||
} | ||
keeper.SetParams(ctx, params) | ||
keeper.Logger(ctx).Info("successfully migrated provider parameters") | ||
|
||
bz := cdc.MustMarshal(¶ms) | ||
store.Set(consumertypes.ParametersKey(), bz) | ||
ctx.Logger().Info("successfully migrated consumer parameters") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package v3 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/interchain-security/v5/app/encoding" | ||
consumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types" | ||
ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testLegacyParamSubspace struct { | ||
*ccvtypes.ConsumerParams | ||
} | ||
|
||
func newTestLegacyParamsSubspace(p ccvtypes.ConsumerParams) testLegacyParamSubspace { | ||
return testLegacyParamSubspace{ | ||
&p, | ||
} | ||
} | ||
|
||
func (ps testLegacyParamSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { | ||
switch string(key) { | ||
case string(ccvtypes.KeyEnabled): | ||
*ptr.(*bool) = ps.Enabled | ||
case string(ccvtypes.KeyBlocksPerDistributionTransmission): | ||
*ptr.(*int64) = ps.BlocksPerDistributionTransmission | ||
case string(ccvtypes.KeyDistributionTransmissionChannel): | ||
*ptr.(*string) = ps.DistributionTransmissionChannel | ||
case string(ccvtypes.KeyProviderFeePoolAddrStr): | ||
*ptr.(*string) = ps.ProviderFeePoolAddrStr | ||
case string(ccvtypes.KeyCCVTimeoutPeriod): | ||
*ptr.(*time.Duration) = ps.CcvTimeoutPeriod | ||
case string(ccvtypes.KeyTransferTimeoutPeriod): | ||
*ptr.(*time.Duration) = ps.TransferTimeoutPeriod | ||
case string(ccvtypes.KeyConsumerRedistributionFrac): | ||
*ptr.(*string) = ps.ConsumerRedistributionFraction | ||
case string(ccvtypes.KeyHistoricalEntries): | ||
*ptr.(*int64) = ps.HistoricalEntries | ||
case string(ccvtypes.KeyConsumerUnbondingPeriod): | ||
*ptr.(*time.Duration) = ps.UnbondingPeriod | ||
case string(ccvtypes.KeySoftOptOutThreshold): | ||
*ptr.(*string) = ps.SoftOptOutThreshold | ||
case string(ccvtypes.KeyRewardDenoms): | ||
*ptr.(*[]string) = ps.RewardDenoms | ||
case string(ccvtypes.KeyProviderRewardDenoms): | ||
*ptr.(*[]string) = ps.ProviderRewardDenoms | ||
case string(ccvtypes.KeyRetryDelayPeriod): | ||
*ptr.(*time.Duration) = ps.RetryDelayPeriod | ||
default: | ||
panic(fmt.Sprintf("invalid paramspace key: %s", string(key))) | ||
|
||
} | ||
} | ||
|
||
func TestMigrateParams(t *testing.T) { | ||
cdc := encoding.MakeTestEncodingConfig().Codec | ||
storeKey := storetypes.NewKVStoreKey("ccvconsumer") | ||
ctx := testutil.DefaultContext(storeKey, storetypes.NewTransientStoreKey("transient_test")) | ||
store := ctx.KVStore(storeKey) | ||
|
||
defaultParams := ccvtypes.DefaultParams() | ||
legacyParamSubspace := newTestLegacyParamsSubspace(defaultParams) | ||
// confirms that testLegacyParamSubspace works as expected | ||
require.NotPanics(t, func() { | ||
GetConsumerParamsLegacy(ctx, legacyParamSubspace) | ||
}) | ||
|
||
emptyParams := ccvtypes.ConsumerParams{} | ||
bz := store.Get(consumertypes.ParametersKey()) | ||
require.NoError(t, cdc.Unmarshal(bz, &emptyParams)) | ||
require.NotNil(t, emptyParams) | ||
require.Empty(t, emptyParams) | ||
require.NotEqual(t, defaultParams, emptyParams) | ||
|
||
err := MigrateLegacyParams(ctx, cdc, store, legacyParamSubspace) | ||
require.NoError(t, err) | ||
|
||
// check that new params are available after migration and equal to defaults | ||
// legacyParamSubspace was set to match defaultParams | ||
migratedParams := ccvtypes.ConsumerParams{} | ||
paramsBz := store.Get(consumertypes.ParametersKey()) | ||
require.NotEqual(t, bz, paramsBz) | ||
require.NoError(t, cdc.Unmarshal(paramsBz, &migratedParams)) | ||
|
||
require.Equal(t, defaultParams, migratedParams) | ||
require.NotEqual(t, emptyParams, migratedParams) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove as v3.0.0 and v3.1.0 have consensus version 1 and they are both deprecated. The consumer module on >= v3.2.0 has consensus version 2.
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.
Let's leave the migrations as they are written now.
Removing the migrations would make it difficult to figure out what was happening and when. Having all migrations in front of you makes it somewhat easier.
This is from experience we got during provider v2 -> v3 migration which was a mess and some previously registered migrations were just deleted. Due to the deletion previous code versions needed to be cross-checked to make sure we're not dropping something.