-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
313 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
|
||
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" | ||
) | ||
|
||
// Legacy: used for migration only! | ||
// GetConsumerParamsLegacy returns the params for the consumer ccv module from x/param subspace | ||
// which will be depreacted soon | ||
func (k Keeper) GetConsumerParamsLegacy(ctx sdk.Context, paramSpace paramtypes.Subspace) ccvtypes.Params { | ||
return ccvtypes.NewParams( | ||
getEnabled(ctx, paramSpace), | ||
getBlocksPerDistributionTransmission(ctx, paramSpace), | ||
getDistributionTransmissionChannel(ctx, paramSpace), | ||
getProviderFeePoolAddrStr(ctx, paramSpace), | ||
getCCVTimeoutPeriod(ctx, paramSpace), | ||
getTransferTimeoutPeriod(ctx, paramSpace), | ||
getConsumerRedistributionFrac(ctx, paramSpace), | ||
getHistoricalEntries(ctx, paramSpace), | ||
getUnbondingPeriod(ctx, paramSpace), | ||
getSoftOptOutThreshold(ctx, paramSpace), | ||
getRewardDenoms(ctx, paramSpace), | ||
getProviderRewardDenoms(ctx, paramSpace), | ||
) | ||
} | ||
|
||
// getEnabled returns the enabled flag for the consumer module | ||
func getEnabled(ctx sdk.Context, paramStore paramtypes.Subspace) bool { | ||
var enabled bool | ||
paramStore.Get(ctx, ccvtypes.KeyEnabled, &enabled) | ||
return enabled | ||
} | ||
|
||
func getBlocksPerDistributionTransmission(ctx sdk.Context, paramStore paramtypes.Subspace) int64 { | ||
var bpdt int64 | ||
paramStore.Get(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, &bpdt) | ||
return bpdt | ||
} | ||
|
||
func getDistributionTransmissionChannel(ctx sdk.Context, paramStore paramtypes.Subspace) string { | ||
var s string | ||
paramStore.Get(ctx, ccvtypes.KeyDistributionTransmissionChannel, &s) | ||
return s | ||
} | ||
|
||
func getProviderFeePoolAddrStr(ctx sdk.Context, paramStore paramtypes.Subspace) string { | ||
var s string | ||
paramStore.Get(ctx, ccvtypes.KeyProviderFeePoolAddrStr, &s) | ||
return s | ||
} | ||
|
||
// getCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets | ||
func getCCVTimeoutPeriod(ctx sdk.Context, paramStore paramtypes.Subspace) time.Duration { | ||
var p time.Duration | ||
paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) | ||
return p | ||
} | ||
|
||
// getTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets | ||
func getTransferTimeoutPeriod(ctx sdk.Context, paramStore paramtypes.Subspace) time.Duration { | ||
var p time.Duration | ||
paramStore.Get(ctx, ccvtypes.KeyTransferTimeoutPeriod, &p) | ||
return p | ||
} | ||
|
||
// getConsumerRedistributionFrac returns the fraction of tokens allocated to the consumer redistribution | ||
// address during distribution events. The fraction is a string representing a | ||
// decimal number. For example "0.75" would represent 75%. | ||
func getConsumerRedistributionFrac(ctx sdk.Context, paramStore paramtypes.Subspace) string { | ||
var str string | ||
paramStore.Get(ctx, ccvtypes.KeyConsumerRedistributionFrac, &str) | ||
return str | ||
} | ||
|
||
// getHistoricalEntries returns the number of historical info entries to persist in store | ||
func getHistoricalEntries(ctx sdk.Context, paramStore paramtypes.Subspace) int64 { | ||
var n int64 | ||
paramStore.Get(ctx, ccvtypes.KeyHistoricalEntries, &n) | ||
return n | ||
} | ||
|
||
func getUnbondingPeriod(ctx sdk.Context, paramStore paramtypes.Subspace) time.Duration { | ||
var period time.Duration | ||
paramStore.Get(ctx, ccvtypes.KeyConsumerUnbondingPeriod, &period) | ||
return period | ||
} | ||
|
||
// getSoftOptOutThreshold returns the percentage of validators at the bottom of the set | ||
// that can opt out of running the consumer chain | ||
func getSoftOptOutThreshold(ctx sdk.Context, paramStore paramtypes.Subspace) string { | ||
var str string | ||
paramStore.Get(ctx, ccvtypes.KeySoftOptOutThreshold, &str) | ||
return str | ||
} | ||
|
||
func getRewardDenoms(ctx sdk.Context, paramStore paramtypes.Subspace) []string { | ||
var denoms []string | ||
paramStore.Get(ctx, ccvtypes.KeyRewardDenoms, &denoms) | ||
return denoms | ||
} | ||
|
||
func getProviderRewardDenoms(ctx sdk.Context, paramStore paramtypes.Subspace) []string { | ||
var denoms []string | ||
paramStore.Get(ctx, ccvtypes.KeyProviderRewardDenoms, &denoms) | ||
return denoms | ||
} |
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
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 keeper | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" | ||
"github.com/cosmos/interchain-security/v3/x/ccv/provider/types" | ||
|
||
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" | ||
) | ||
|
||
// getTemplateClient returns the template client for provider proposals | ||
func getTemplateClient(ctx sdk.Context, paramSpace paramtypes.Subspace) *ibctmtypes.ClientState { | ||
var cs ibctmtypes.ClientState | ||
paramSpace.Get(ctx, types.KeyTemplateClient, &cs) | ||
return &cs | ||
} | ||
|
||
// getTrustingPeriodFraction returns a TrustingPeriodFraction | ||
// used to compute the provider IBC client's TrustingPeriod as UnbondingPeriod / TrustingPeriodFraction | ||
func getTrustingPeriodFraction(ctx sdk.Context, paramSpace paramtypes.Subspace) string { | ||
var f string | ||
paramSpace.Get(ctx, types.KeyTrustingPeriodFraction, &f) | ||
return f | ||
} | ||
|
||
// getCCVTimeoutPeriod returns the timeout period for sent ibc packets | ||
func getCCVTimeoutPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { | ||
var p time.Duration | ||
paramSpace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) | ||
return p | ||
} | ||
|
||
// getInitTimeoutPeriod returns the init timeout period | ||
func getInitTimeoutPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { | ||
var p time.Duration | ||
paramSpace.Get(ctx, types.KeyInitTimeoutPeriod, &p) | ||
return p | ||
} | ||
|
||
// getVscTimeoutPeriod returns the vsc timeout period | ||
func getVscTimeoutPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { | ||
var p time.Duration | ||
paramSpace.Get(ctx, types.KeyVscTimeoutPeriod, &p) | ||
return p | ||
} | ||
|
||
// getSlashMeterReplenishPeriod returns the period in which: | ||
// Once the slash meter becomes not-full, the slash meter is replenished after this period. | ||
func getSlashMeterReplenishPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { | ||
var p time.Duration | ||
paramSpace.Get(ctx, types.KeySlashMeterReplenishPeriod, &p) | ||
return p | ||
} | ||
|
||
// getSlashMeterReplenishFraction returns the string fraction of total voting power that is replenished | ||
// to the slash meter every replenish period. This param also serves as a maximum fraction of total | ||
// voting power that the slash meter can hold. | ||
func getSlashMeterReplenishFraction(ctx sdk.Context, paramSpace paramtypes.Subspace) string { | ||
var f string | ||
paramSpace.Get(ctx, types.KeySlashMeterReplenishFraction, &f) | ||
return f | ||
} | ||
|
||
// getMaxThrottledPackets returns the maximum amount of throttled slash or vsc matured packets | ||
// that can be queued for a single consumer before the provider chain halts. | ||
func getMaxThrottledPackets(ctx sdk.Context, paramSpace paramtypes.Subspace) int64 { | ||
var p int64 | ||
paramSpace.Get(ctx, types.KeyMaxThrottledPackets, &p) | ||
return p | ||
} | ||
|
||
func getConsumerRewardDenomRegistrationFee(ctx sdk.Context, paramSpace paramtypes.Subspace) sdk.Coin { | ||
var c sdk.Coin | ||
paramSpace.Get(ctx, types.KeyConsumerRewardDenomRegistrationFee, &c) | ||
return c | ||
} | ||
|
||
// Legacy: Only for migration purposes. GetParamsLegacy returns the paramset for the provider | ||
// module from a given param subspace | ||
func GetParamsLegacy(ctx sdk.Context, paramspace paramtypes.Subspace) types.Params { | ||
return types.NewParams( | ||
getTemplateClient(ctx, paramspace), | ||
getTrustingPeriodFraction(ctx, paramspace), | ||
getCCVTimeoutPeriod(ctx, paramspace), | ||
getInitTimeoutPeriod(ctx, paramspace), | ||
getVscTimeoutPeriod(ctx, paramspace), | ||
getSlashMeterReplenishPeriod(ctx, paramspace), | ||
getSlashMeterReplenishFraction(ctx, paramspace), | ||
getMaxThrottledPackets(ctx, paramspace), | ||
getConsumerRewardDenomRegistrationFee(ctx, paramspace), | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" | ||
"github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper" | ||
"github.com/cosmos/interchain-security/v3/x/ccv/provider/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMigrateParams(t *testing.T) { | ||
params := testutil.NewInMemKeeperParams(t) | ||
providerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, params) | ||
defer ctrl.Finish() | ||
|
||
testCases := []struct { | ||
name string | ||
legacyParams func() paramtypes.Subspace | ||
expetedParams types.Params | ||
}{ | ||
{ | ||
"default params", | ||
func() paramtypes.Subspace { | ||
subspace := params.ParamsSubspace | ||
defaultParams := types.DefaultParams() | ||
subspace.SetParamSet(ctx, &defaultParams) | ||
return *subspace | ||
}, | ||
types.DefaultParams(), | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
migrator := keeper.NewMigrator(providerKeeper, tc.legacyParams()) | ||
err := migrator.MigrateParams(ctx) | ||
require.NoError(t, err) | ||
params := providerKeeper.GetParams(ctx) | ||
require.Equal(t, tc.expetedParams, params) | ||
} | ||
} |
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