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

feat: add consumer params upgrade message #1814

Merged
merged 5 commits into from
Apr 24, 2024
Merged
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
15 changes: 8 additions & 7 deletions app/consumer-democracy/proposals_whitelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ var LegacyWhitelistedParams = map[legacyParamChangeKey]struct{}{

// add whitelisted module param update messages [cosmos-sdk >= 0.47]
var WhiteListModule = map[string]struct{}{
"/cosmos.gov.v1.MsgUpdateParams": {},
"/cosmos.bank.v1beta1.MsgUpdateParams": {},
"/cosmos.staking.v1beta1.MsgUpdateParams": {},
"/cosmos.distribution.v1beta1.MsgUpdateParams": {},
"/cosmos.mint.v1beta1.MsgUpdateParams": {},
"/cosmos.gov.v1beta1.TextProposal": {},
"/ibc.applications.transfer.v1.MsgUpdateParams": {},
"/cosmos.gov.v1.MsgUpdateParams": {},
"/cosmos.bank.v1beta1.MsgUpdateParams": {},
"/cosmos.staking.v1beta1.MsgUpdateParams": {},
"/cosmos.distribution.v1beta1.MsgUpdateParams": {},
"/cosmos.mint.v1beta1.MsgUpdateParams": {},
"/cosmos.gov.v1beta1.TextProposal": {},
"/ibc.applications.transfer.v1.MsgUpdateParams": {},
"/interchain_security.ccv.consumer.v1.MsgUpdateParams": {},
}

func IsModuleWhiteList(typeUrl string) bool {
Expand Down
29 changes: 29 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package interchain_security.ccv.consumer.v1;
option go_package = "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types";

import "amino/amino.proto";
import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "interchain_security/ccv/v1/shared_consumer.proto";

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

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

// signer is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/provider parameters to update.
interchain_security.ccv.v1.ConsumerParams params = 2 [(gogoproto.nullable) = false];
}

message MsgUpdateParamsResponse {}
48 changes: 48 additions & 0 deletions tests/integration/democracy.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,54 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() {
s.Assert().Equal(votersOldBalances, getAccountsBalances(s.consumerCtx(), bankKeeper, bondDenom, votingAccounts))
}

func (s *ConsumerDemocracyTestSuite) TestDemocracyMsgUpdateParams() {
govKeeper := s.consumerApp.GetTestGovKeeper()
params, err := govKeeper.Params.Get(s.consumerCtx())
s.Require().NoError(err)

stakingKeeper := s.consumerApp.GetTestStakingKeeper()
bankKeeper := s.consumerApp.GetTestBankKeeper()
votingAccounts := s.consumerChain.SenderAccounts
bondDenom, err := stakingKeeper.BondDenom(s.consumerCtx())
s.Require().NoError(err)
depositAmount := params.MinDeposit
duration := (3 * time.Second)
params.VotingPeriod = &duration
err = govKeeper.Params.Set(s.consumerCtx(), params)
s.Assert().NoError(err)
proposer := s.consumerChain.SenderAccount
s.consumerChain.NextBlock()
votersOldBalances := getAccountsBalances(s.consumerCtx(), bankKeeper, bondDenom, votingAccounts)

oldParams := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
modifiedParams := oldParams
modifiedParams.RetryDelayPeriod = 7200 * time.Second
s.Require().NotEqual(oldParams.RetryDelayPeriod, modifiedParams.RetryDelayPeriod)

msg := &consumertypes.MsgUpdateParams{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Params: modifiedParams,
}

err = submitProposalWithDepositAndVote(govKeeper, s.consumerCtx(), []sdk.Msg{msg}, votingAccounts, proposer.GetAddress(), depositAmount)
s.Assert().NoError(err)
// set current header time to be equal or later than voting end time in order to process proposal from active queue,
// once the proposal is added to the chain
s.consumerChain.CurrentHeader.Time = s.consumerChain.CurrentHeader.Time.Add(*params.VotingPeriod)

s.consumerChain.NextBlock()

newParams := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
s.Assert().NotEqual(oldParams, newParams)
s.Assert().Equal(modifiedParams, newParams)
s.Assert().NotEqual(oldParams.RetryDelayPeriod, newParams.RetryDelayPeriod)
s.Assert().Equal(modifiedParams.RetryDelayPeriod, newParams.RetryDelayPeriod)

// deposit is refunded
s.Assert().Equal(votersOldBalances, getAccountsBalances(s.consumerCtx(), bankKeeper, bondDenom, votingAccounts))

}

func submitProposalWithDepositAndVote(govKeeper govkeeper.Keeper, ctx sdk.Context, msgs []sdk.Msg,
accounts []ibctesting.SenderAccount, proposer sdk.AccAddress, depositAmount sdk.Coins,
) error {
Expand Down
4 changes: 4 additions & 0 deletions testutil/integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func TestDemocracyGovernanceWhitelisting(t *testing.T) {
runConsumerDemocracyTestByName(t, "TestDemocracyGovernanceWhitelisting")
}

func TestDemocracyMsgUpdateParams(t *testing.T) {
runConsumerDemocracyTestByName(t, "TestDemocracyMsgUpdateParams")
}

//
// Distribution tests
//
Expand Down
28 changes: 28 additions & 0 deletions x/ccv/consumer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewQueryCmd() *cobra.Command {
CmdNextFeeDistribution(),
CmdProviderInfo(),
CmdThrottleState(),
CmdParams(),
)

return cmd
Expand Down Expand Up @@ -108,3 +109,30 @@ func CmdThrottleState() *cobra.Command {

return cmd
}

func CmdParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query consumer module parameters",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryParamsRequest{}
res, err := queryClient.QueryParams(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
5 changes: 5 additions & 0 deletions x/ccv/consumer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func NewKeeper(
return k
}

// GetAuthority returns the x/ccv/provider module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}

// Returns a keeper with cdc, key and paramSpace set it does not raise any panics during registration (eg with IBCKeeper).
// Used only in testing.
func NewNonZeroKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace) Keeper {
Expand Down
36 changes: 36 additions & 0 deletions x/ccv/consumer/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package keeper

import (
"context"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/cosmos/interchain-security/v5/x/ccv/consumer/types"
)

type msgServer struct {
*Keeper
}

// NewMsgServerImpl returns an implementation of the bank MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper *Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}

var _ types.MsgServer = msgServer{}

// UpdateParams updates the params.
func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != msg.Authority {
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
k.Keeper.SetParams(ctx, msg.Params)

return &types.MsgUpdateParamsResponse{}, nil
}
3 changes: 2 additions & 1 deletion x/ccv/consumer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

// RegisterInterfaces registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// ccv.RegisterInterfaces(registry)
consumertypes.RegisterInterfaces(registry)
}

// IsAppModule implements the appmodule.AppModule interface.
Expand Down Expand Up @@ -120,6 +120,7 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
consumertypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper))
consumertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper)

m := keeper.NewMigrator(am.keeper, am.paramSpace)
Expand Down
18 changes: 18 additions & 0 deletions x/ccv/consumer/types/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package types

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

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

// RegisterInterfaces registers the consumer Tx message types to the interface registry
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {

registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgUpdateParams{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
Loading
Loading