-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add consumer and provider migrations for ICS v5 (#1817)
* chore: add consumer migration 2 -> 3 * chore: add provider migration; update params * fix: resolve review nits
- Loading branch information
Showing
11 changed files
with
220 additions
and
49 deletions.
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.