Skip to content

Commit

Permalink
Added proposal message MsgChangeRewardDenoms
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Nov 1, 2023
1 parent a02e9f0 commit 5f145bf
Show file tree
Hide file tree
Showing 7 changed files with 735 additions and 185 deletions.
3 changes: 2 additions & 1 deletion proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ message ConsumerRemovalProposal {

// ChangeRewardDenomsProposal is a governance proposal on the provider chain to
// mutate the set of denoms accepted by the provider as rewards.

// Deprecated: Use MsgChangeRewardDenoms instead
message ChangeRewardDenomsProposal {
option deprecated = true;
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";

// the title of the proposal
Expand Down
48 changes: 39 additions & 9 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ service Msg {
option (cosmos.msg.v1.service) = true;

rpc AssignConsumerKey(MsgAssignConsumerKey)
returns (MsgAssignConsumerKeyResponse);
returns (MsgAssignConsumerKeyResponse);

rpc ConsumerAddition(MsgConsumerAddition)
returns (MsgConsumerAdditionResponse);
returns (MsgConsumerAdditionResponse);

rpc ConsumerRemoval(MsgConsumerRemoval)
returns (MsgConsumerRemovalResponse);
rpc ConsumerRemoval(MsgConsumerRemoval)
returns (MsgConsumerRemovalResponse);

rpc ChangeRewardDenoms(MsgChangeRewardDenoms)
returns (MsgChangeRewardDenomsResponse);
}

message MsgAssignConsumerKey {
Expand Down Expand Up @@ -107,21 +110,48 @@ message MsgConsumerAddition {
string signer = 13 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgConsumerAdditionResponse defines the Msg/MsgIBCSoftwareUpgrade response type
// MsgConsumerAdditionResponse defines response type for MsgConsumerAddition messages
message MsgConsumerAdditionResponse {}


// MsgConsumerRemoval message contains a governance proposal on the provider chain to
// remove (and stop) a consumer chain. If it passes, all the consumer chain's
// state is removed from the provider chain. The outstanding unbonding operation
// funds are released.
//
// Note: this replaces ConsumerRemovalProposal which is deprecated and will be removed soon
message MsgConsumerRemoval {
option (cosmos.msg.v1.signer) = "signer";

// the chain-id of the consumer chain to be stopped
string chain_id = 3;
string chain_id = 1;
// the time on the provider chain at which all validators are responsible to
// stop their consumer chain validator node
google.protobuf.Timestamp stop_time = 4
google.protobuf.Timestamp stop_time = 2
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];

// signer address
string signer = 13 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string signer = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgConsumerRemovalResponse defines response type for MsgConsumerRemoval messages
message MsgConsumerRemovalResponse {}

// ChangeRewardDenomsProposal is a governance proposal on the provider chain to
// mutate the set of denoms accepted by the provider as rewards.
//
// Note: this replaces ChangeRewardDenomsProposal which is deprecated and will be removed soon
message MsgChangeRewardDenoms {
option (cosmos.msg.v1.signer) = "signer";

// the list of consumer reward denoms to add
repeated string denoms_to_add = 1;
// the list of consumer reward denoms to remove
repeated string denoms_to_remove = 2;
// signer address
string signer = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];

}

message MsgConsumerRemovalResponse {}
// MsgChangeRewardDenomsResponse defines response type for MsgChangeRewardDenoms messages
message MsgChangeRewardDenomsResponse {}
13 changes: 13 additions & 0 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,16 @@ func (k msgServer) ConsumerRemoval(

return &types.MsgConsumerRemovalResponse{}, nil
}

// ConsumerRemoval defines a rpc handler method for MsgConsumerRemoval
func (k msgServer) ChangeRewardDenoms(
goCtx context.Context,
msg *types.MsgChangeRewardDenoms) (*types.MsgChangeRewardDenomsResponse, error) {
if k.GetAuthority() != msg.Signer {
return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer)
}

// TODO: Call keeper implementation !

return &types.MsgChangeRewardDenomsResponse{}, nil
}
1 change: 1 addition & 0 deletions x/ccv/provider/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&MsgAssignConsumerKey{},
&MsgConsumerAddition{},
&MsgConsumerRemoval{},
&MsgChangeRewardDenoms{},
)
registry.RegisterImplementations(
(*govv1beta1.Content)(nil),
Expand Down
44 changes: 44 additions & 0 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package types

import (
"encoding/json"
"fmt"
"strings"
"time"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
Expand All @@ -20,10 +22,12 @@ var (
_ sdk.Msg = (*MsgAssignConsumerKey)(nil)
_ sdk.Msg = (*MsgConsumerAddition)(nil)
_ sdk.Msg = (*MsgConsumerRemoval)(nil)
_ sdk.Msg = (*MsgChangeRewardDenoms)(nil)

_ sdk.HasValidateBasic = (*MsgAssignConsumerKey)(nil)
_ sdk.HasValidateBasic = (*MsgConsumerAddition)(nil)
_ sdk.HasValidateBasic = (*MsgConsumerRemoval)(nil)
_ sdk.HasValidateBasic = (*MsgChangeRewardDenoms)(nil)
)

// NewMsgAssignConsumerKey creates a new MsgAssignConsumerKey instance.
Expand Down Expand Up @@ -220,3 +224,43 @@ func (msg *MsgConsumerRemoval) ValidateBasic() error {
}
return nil
}

// MsgChangeRewardDenoms creates a new MsgChangeRewardDenoms instance
func NewMsgChangeRewardDenoms(signer string) *MsgChangeRewardDenoms {
//@bermuell: TODO finsh implementation!
return &MsgChangeRewardDenoms{}
}

func (msg *MsgChangeRewardDenoms) ValidateBasic() error {
emptyDenomsToAdd := len(msg.DenomsToAdd) == 0
emptyDenomsToRemove := len(msg.DenomsToRemove) == 0
// Return error if both sets are empty or nil
if emptyDenomsToAdd && emptyDenomsToRemove {
return fmt.Errorf(
"invalid change reward denoms proposal: both denoms to add and denoms to remove are empty")
}

// Return error if a denom is in both sets
for _, denomToAdd := range msg.DenomsToAdd {
for _, denomToRemove := range msg.DenomsToRemove {
if denomToAdd == denomToRemove {
return fmt.Errorf(
"invalid change reward denoms proposal: %s cannot be both added and removed", denomToAdd)
}
}
}

// Return error if any denom is "invalid"
for _, denom := range msg.DenomsToAdd {
if !sdk.NewCoin(denom, math.NewInt(1)).IsValid() {
return fmt.Errorf("invalid change reward denoms proposal: %s is not a valid denom", denom)
}
}
for _, denom := range msg.DenomsToRemove {
if !sdk.NewCoin(denom, math.NewInt(1)).IsValid() {
return fmt.Errorf("invalid change reward denoms proposal: %s is not a valid denom", denom)
}
}

return nil
}
Loading

0 comments on commit 5f145bf

Please sign in to comment.