Skip to content
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

refactor: interchainstaking params #541

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions proto/quicksilver/interchainstaking/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,10 @@ package quicksilver.interchainstaking.v1;
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "quicksilver/interchainstaking/v1/interchainstaking.proto";
import "quicksilver/interchainstaking/v1/params.proto";

option go_package = "github.com/ingenuity-build/quicksilver/x/interchainstaking/types";

message Params_v1 {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

uint64 deposit_interval = 1;
uint64 validatorset_interval = 2;
string commission_rate = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

uint64 deposit_interval = 1;
uint64 validatorset_interval = 2;
string commission_rate = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
bool unbonding_enabled = 4;
}

message DelegationsForZone {
string chain_id = 1;
repeated Delegation delegations = 2;
Expand Down
32 changes: 32 additions & 0 deletions proto/quicksilver/interchainstaking/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "quicksilver/interchainstaking/v1/proposals.proto";
import "quicksilver/interchainstaking/v1/params.proto";

option go_package = "github.com/ingenuity-build/quicksilver/x/interchainstaking/types";

Expand Down Expand Up @@ -60,8 +61,17 @@ service Msg {
body : "*"
};
}

// Update the params of the module through gov v1 type.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) {
option (google.api.http) = {
post : "/quicksilver/tx/v1/interchainstaking/update_params"
body : "*"
};
}
}


// MsgRequestRedemption represents a message type to request a burn of qAssets
// for native assets.
message MsgRequestRedemption {
Expand Down Expand Up @@ -93,3 +103,25 @@ message MsgRequestRedemptionResponse {}

// MsgSignalIntentResponse defines the MsgSignalIntent response type.
message MsgSignalIntentResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov
// unless overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// params defines the x/interchainstaking parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [ (gogoproto.nullable) = false ];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
34 changes: 34 additions & 0 deletions proto/quicksilver/interchainstaking/v1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";
package quicksilver.interchainstaking.v1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/ingenuity-build/quicksilver/x/interchainstaking/types";

message Params_v1 {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

uint64 deposit_interval = 1;
uint64 validatorset_interval = 2;
string commission_rate = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

uint64 deposit_interval = 1;
uint64 validatorset_interval = 2;
string commission_rate = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
bool unbonding_enabled = 4;
}
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion x/interchainstaking/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
// InitGenesis initializes the interchainstaking module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(err)
}

// set registered zones info from genesis
for _, zone := range genState.Zones {
Expand Down
3 changes: 2 additions & 1 deletion x/interchainstaking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (k *Keeper) BeginBlocker(ctx sdk.Context) {
if len(zone.IbcNextValidatorsHash) == 0 || !bytes.Equal(zone.IbcNextValidatorsHash, tmConsState.NextValidatorsHash.Bytes()) {
k.Logger(ctx).Info("IBC ValSet has changed; requerying valset")
// trigger valset update.
period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)
query := stakingTypes.QueryValidatorsRequest{}
err := k.EmitValSetQuery(ctx, zone.ConnectionId, zone, query, sdkmath.NewInt(period))
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion x/interchainstaking/keeper/ibc_channel_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ func (k *Keeper) HandleChannelOpenAck(ctx sdk.Context, portID, connectionID stri
return err
}

params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)

k.ICQKeeper.MakeRequest(
ctx,
connectionID,
zone.ZoneID(),
"cosmos.bank.v1beta1.Query/AllBalances",
bz,
sdk.NewInt(int64(k.GetParam(ctx, types.KeyDepositInterval))),
sdk.NewInt(period),
types.ModuleName,
"allbalances",
0,
Expand Down
12 changes: 8 additions & 4 deletions x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@

if found && denomTrace.BaseDenom != zone.BaseDenom {
// k.Logger(ctx).Error("got withdrawal account and NOT staking denom", "rx", receivedCoin.Denom, "trace_base_denom", denomTrace.BaseDenom, "zone_base_denom", zone.BaseDenom)
feeAmount := sdk.NewDecFromInt(receivedCoin.Amount).Mul(k.GetCommissionRate(ctx)).TruncateInt()
params := k.GetParams(ctx)
feeAmount := sdk.NewDecFromInt(receivedCoin.Amount).Mul(params.CommissionRate).TruncateInt()
rewardCoin := receivedCoin.SubAmount(feeAmount)
zoneAddress, err := addressutils.AccAddressFromBech32(zone.WithdrawalAddress.Address, "")
if err != nil {
Expand Down Expand Up @@ -479,7 +480,8 @@
}
}

period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)
query := stakingtypes.QueryValidatorsRequest{}

return k.EmitValSetQuery(ctx, zone.ConnectionId, zone, query, sdkmath.NewInt(period))
Expand Down Expand Up @@ -1099,7 +1101,8 @@
}
k.SetDelegation(ctx, zone, delegation)

period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)
query := stakingtypes.QueryValidatorsRequest{}
err := k.EmitValSetQuery(ctx, zone.ConnectionId, zone, query, sdkmath.NewInt(period))
if err != nil {
Expand Down Expand Up @@ -1181,8 +1184,9 @@
baseDenomAmount := withdrawBalance.Balances.AmountOf(zone.BaseDenom)
// calculate fee (fee = amount * rate)

params := k.GetParams(ctx)

Check warning on line 1187 in x/interchainstaking/keeper/ibc_packet_handlers.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/ibc_packet_handlers.go#L1187

Added line #L1187 was not covered by tests
baseDenomFee := sdk.NewDecFromInt(baseDenomAmount).
Mul(k.GetCommissionRate(ctx)).
Mul(params.CommissionRate).

Check warning on line 1189 in x/interchainstaking/keeper/ibc_packet_handlers.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/ibc_packet_handlers.go#L1189

Added line #L1189 was not covered by tests
TruncateInt()

// prepare rewards distribution
Expand Down
39 changes: 0 additions & 39 deletions x/interchainstaking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,45 +384,6 @@ func (k *Keeper) depositInterval(ctx sdk.Context) zoneItrFn {
}
}

func (k *Keeper) GetParam(ctx sdk.Context, key []byte) uint64 {
var out uint64
k.paramStore.Get(ctx, key, &out)
return out
}

func (k *Keeper) GetUnbondingEnabled(ctx sdk.Context) bool {
var out bool
k.paramStore.Get(ctx, types.KeyUnbondingEnabled, &out)
return out
}

func (k *Keeper) GetCommissionRate(ctx sdk.Context) sdk.Dec {
var out sdk.Dec
k.paramStore.Get(ctx, types.KeyCommissionRate, &out)
return out
}

// MigrateParams fetches params, adds ClaimsEnabled field and re-sets params.
func (k *Keeper) MigrateParams(ctx sdk.Context) {
params := types.Params{}
params.DepositInterval = k.GetParam(ctx, types.KeyDepositInterval)
params.CommissionRate = k.GetCommissionRate(ctx)
params.ValidatorsetInterval = k.GetParam(ctx, types.KeyValidatorSetInterval)
params.UnbondingEnabled = false

k.paramStore.SetParamSet(ctx, &params)
}

func (k *Keeper) GetParams(clientCtx sdk.Context) (params types.Params) {
k.paramStore.GetParamSet(clientCtx, &params)
return params
}

// SetParams sets the distribution parameters to the param space.
func (k *Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramStore.SetParamSet(ctx, &params)
}

func (k *Keeper) SetZoneIDForPortConnection(ctx sdk.Context, portID, connectionID, zoneID string) {
key := fmt.Sprintf("%s-%s", portID, connectionID)
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixPortConnectionZone)
Expand Down
23 changes: 20 additions & 3 deletions x/interchainstaking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"strconv"
"strings"

sdkioerrors "cosmossdk.io/errors"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -146,7 +148,8 @@

// query val set for base zone
if !zone.IsSubzone() {
period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)
query := stakingTypes.QueryValidatorsRequest{}
err = k.EmitValSetQuery(ctx, zone.ConnectionId, zone, query, sdkmath.NewInt(period))
if err != nil {
Expand Down Expand Up @@ -316,7 +319,8 @@
return &types.MsgUpdateZoneResponse{}, err
}

period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)

Check warning on line 323 in x/interchainstaking/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/msg_server.go#L322-L323

Added lines #L322 - L323 were not covered by tests
query := stakingTypes.QueryValidatorsRequest{}
err := k.EmitValSetQuery(ctx, zone.ConnectionId, &zone, query, sdkmath.NewInt(period))
if err != nil {
Expand All @@ -338,7 +342,7 @@
func (k msgServer) RequestRedemption(goCtx context.Context, msg *types.MsgRequestRedemption) (*types.MsgRequestRedemptionResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if !k.Keeper.GetUnbondingEnabled(ctx) {
if !k.GetParams(ctx).UnbondingEnabled {
return nil, fmt.Errorf("unbonding is currently disabled")
}

Expand Down Expand Up @@ -553,3 +557,16 @@

return &types.MsgGovCloseChannelResponse{}, nil
}

func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.authority != req.Authority {
return nil, sdkioerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
}

Check warning on line 564 in x/interchainstaking/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/msg_server.go#L561-L564

Added lines #L561 - L564 were not covered by tests

ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.SetParams(ctx, req.Params); err != nil {
return nil, err
}

Check warning on line 569 in x/interchainstaking/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/msg_server.go#L566-L569

Added lines #L566 - L569 were not covered by tests

return &types.MsgUpdateParamsResponse{}, nil

Check warning on line 571 in x/interchainstaking/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/msg_server.go#L571

Added line #L571 was not covered by tests
}
32 changes: 32 additions & 0 deletions x/interchainstaking/keeper/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ingenuity-build/quicksilver/x/interchainstaking/types"
)

// GetParams returns the total set of x/airdrop parameters.
func (k *Keeper) GetParams(ctx sdk.Context) (p types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyPrefixParams)
if bz == nil {
return p
}

Check warning on line 15 in x/interchainstaking/keeper/params.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/params.go#L14-L15

Added lines #L14 - L15 were not covered by tests

k.cdc.MustUnmarshal(bz, &p)
return p
}

// SetParams sets the x/airdrop parameters to the param space.
func (k *Keeper) SetParams(ctx sdk.Context, p types.Params) error {
if err := p.Validate(); err != nil {
return err
}

Check warning on line 25 in x/interchainstaking/keeper/params.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/params.go#L24-L25

Added lines #L24 - L25 were not covered by tests

store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&p)
store.Set(types.KeyPrefixParams, bz)

return nil
}
36 changes: 36 additions & 0 deletions x/interchainstaking/keeper/params_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ingenuity-build/quicksilver/x/interchainstaking/types"
)

func (k *Keeper) GetParamLegacy(ctx sdk.Context, key []byte) uint64 {
var out uint64
k.paramStore.Get(ctx, key, &out)
return out

Check warning on line 12 in x/interchainstaking/keeper/params_legacy.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/params_legacy.go#L9-L12

Added lines #L9 - L12 were not covered by tests
}

func (k *Keeper) GetUnbondingEnabledLegacy(ctx sdk.Context) bool {
var out bool
k.paramStore.Get(ctx, types.KeyUnbondingEnabled, &out)
return out

Check warning on line 18 in x/interchainstaking/keeper/params_legacy.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/params_legacy.go#L15-L18

Added lines #L15 - L18 were not covered by tests
}

func (k *Keeper) GetCommissionRateLegacy(ctx sdk.Context) sdk.Dec {
var out sdk.Dec
k.paramStore.Get(ctx, types.KeyCommissionRate, &out)
return out

Check warning on line 24 in x/interchainstaking/keeper/params_legacy.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/params_legacy.go#L21-L24

Added lines #L21 - L24 were not covered by tests
}

// MigrateParams fetches params, adds ClaimsEnabled field and re-sets params.
func (k *Keeper) MigrateParams(ctx sdk.Context) {
params := types.Params{}
params.DepositInterval = k.GetParamLegacy(ctx, types.KeyDepositInterval)
params.CommissionRate = k.GetCommissionRateLegacy(ctx)
params.ValidatorsetInterval = k.GetParamLegacy(ctx, types.KeyValidatorSetInterval)
params.UnbondingEnabled = false

k.paramStore.SetParamSet(ctx, &params)

Check warning on line 35 in x/interchainstaking/keeper/params_legacy.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/params_legacy.go#L28-L35

Added lines #L28 - L35 were not covered by tests
}
6 changes: 4 additions & 2 deletions x/interchainstaking/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@

// query val set for base zone
if !zone.IsSubzone() {
period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)

Check warning on line 125 in x/interchainstaking/keeper/proposal_handler.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/proposal_handler.go#L124-L125

Added lines #L124 - L125 were not covered by tests
query := stakingTypes.QueryValidatorsRequest{}
err = k.EmitValSetQuery(ctx, zone.ConnectionId, zone, query, sdkmath.NewInt(period))
if err != nil {
Expand Down Expand Up @@ -281,7 +282,8 @@
return err
}

period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
params := k.GetParams(ctx)
period := int64(params.ValidatorsetInterval)

Check warning on line 286 in x/interchainstaking/keeper/proposal_handler.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/keeper/proposal_handler.go#L285-L286

Added lines #L285 - L286 were not covered by tests
query := stakingTypes.QueryValidatorsRequest{}
err := k.EmitValSetQuery(ctx, zone.ConnectionId, &zone, query, sdkmath.NewInt(period))
if err != nil {
Expand Down
Loading
Loading