Skip to content

Commit

Permalink
Added ConsumerRemoval message
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Nov 1, 2023
1 parent 269a081 commit a02e9f0
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 169 deletions.
3 changes: 3 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ message ConsumerAdditionProposal {
// 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.
// Deprecated: Use MsgConsumerRemoval instead
message ConsumerRemovalProposal {
option deprecated = true;
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";

// the title of the proposal
Expand All @@ -111,6 +113,7 @@ message ConsumerRemovalProposal {

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

message ChangeRewardDenomsProposal {
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";

Expand Down
23 changes: 21 additions & 2 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ service Msg {

rpc ConsumerAddition(MsgConsumerAddition)
returns (MsgConsumerAdditionResponse);

rpc ConsumerRemoval(MsgConsumerRemoval)
returns (MsgConsumerRemovalResponse);
}

message MsgAssignConsumerKey {
Expand Down Expand Up @@ -101,8 +104,24 @@ message MsgConsumerAddition {
string distribution_transmission_channel = 12;

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

// MsgConsumerAdditionResponse defines the Msg/MsgIBCSoftwareUpgrade response type
message MsgConsumerAdditionResponse {}
message MsgConsumerAdditionResponse {}

message MsgConsumerRemoval {
option (cosmos.msg.v1.signer) = "signer";

// the chain-id of the consumer chain to be stopped
string chain_id = 3;
// 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
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];

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

message MsgConsumerRemovalResponse {}
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 @@ -121,3 +121,16 @@ func (k msgServer) ConsumerAddition(goCtx context.Context, msg *types.MsgConsume

return &types.MsgConsumerAdditionResponse{}, nil
}

// ConsumerRemoval defines a rpc handler method for MsgConsumerRemoval
func (k msgServer) ConsumerRemoval(
goCtx context.Context,
msg *types.MsgConsumerRemoval) (*types.MsgConsumerRemovalResponse, 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.MsgConsumerRemovalResponse{}, 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 @@ -27,6 +27,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*sdk.Msg)(nil),
&MsgAssignConsumerKey{},
&MsgConsumerAddition{},
&MsgConsumerRemoval{},
)
registry.RegisterImplementations(
(*govv1beta1.Content)(nil),
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/types/legacy_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (sccp *ConsumerRemovalProposal) ValidateBasic() error {
}

if sccp.StopTime.IsZero() {
return errorsmod.Wrap(ErrInvalidConsumerRemovalProp, "spawn time cannot be zero")
return errorsmod.Wrap(ErrInvalidConsumerRemovalProp, "stop time cannot be zero")
}
return nil
}
Expand Down
98 changes: 72 additions & 26 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"strings"
"time"

errorsmod "cosmossdk.io/errors"
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"
)

// provider message types
Expand All @@ -15,11 +17,13 @@ const (
)

var (
_ sdk.Msg = &MsgAssignConsumerKey{}
_ sdk.Msg = &MsgConsumerAddition{}
_ sdk.Msg = (*MsgAssignConsumerKey)(nil)
_ sdk.Msg = (*MsgConsumerAddition)(nil)
_ sdk.Msg = (*MsgConsumerRemoval)(nil)

_ sdk.HasValidateBasic = &MsgAssignConsumerKey{}
_ sdk.HasValidateBasic = &MsgConsumerAddition{}
_ sdk.HasValidateBasic = (*MsgAssignConsumerKey)(nil)
_ sdk.HasValidateBasic = (*MsgConsumerAddition)(nil)
_ sdk.HasValidateBasic = (*MsgConsumerRemoval)(nil)
)

// NewMsgAssignConsumerKey creates a new MsgAssignConsumerKey instance.
Expand Down Expand Up @@ -103,7 +107,6 @@ func ParseConsumerKeyFromJson(jsonStr string) (pkType, key string, err error) {
}

// NewMsgConsumerAddition creates a new MsgConsumerAddition instance.
// Delegator address and validator address are the same.
func NewMsgConsumerAddition(signer, chainID string,
initialHeight clienttypes.Height, genesisHash, binaryHash []byte,
spawnTime time.Time,
Expand All @@ -127,19 +130,10 @@ func NewMsgConsumerAddition(signer, chainID string,
CcvTimeoutPeriod: ccvTimeoutPeriod,
TransferTimeoutPeriod: transferTimeoutPeriod,
UnbondingPeriod: unbondingPeriod,
Signer: signer,
}
}

// TODO: remove if not needed
/* // Route implements the sdk.Msg interface.
func (msg MsgConsumerAddition) Route() string { return RouterKey }
// Type implements the sdk.Msg interface.
func (msg MsgConsumerAddition) Type() string {
return TypeMsgConsumerAdditionKey
}
*/

// GetSigners implements the sdk.Msg interface. It returns the address(es) that
// must sign over msg.GetSignBytes().
// If the validator address is not same as delegator's, then the validator must
Expand All @@ -153,24 +147,76 @@ func (msg *MsgConsumerAddition) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{valAddr.Bytes()}
}

// GetSignBytes returns the message bytes to sign over.
func (msg *MsgConsumerAddition) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

// ValidateBasic implements the sdk.Msg interface.
func (msg *MsgConsumerAddition) ValidateBasic() error {
if strings.TrimSpace(msg.ChainId) == "" {
return ErrBlankConsumerChainID
}
//TODO

if strings.TrimSpace(msg.ChainId) == "" {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "consumer chain id must not be blank")
}

if msg.InitialHeight.IsZero() {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "initial height cannot be zero")
}

if len(msg.GenesisHash) == 0 {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "genesis hash cannot be empty")
}
if len(msg.BinaryHash) == 0 {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "binary hash cannot be empty")
}

if msg.SpawnTime.IsZero() {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "spawn time cannot be zero")
}

if err := ccvtypes.ValidateStringFraction(msg.ConsumerRedistributionFraction); err != nil {
return errorsmod.Wrapf(ErrInvalidConsumerAdditionProposal, "consumer redistribution fraction is invalid: %s", err)
}

if err := ccvtypes.ValidatePositiveInt64(msg.BlocksPerDistributionTransmission); err != nil {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "blocks per distribution transmission cannot be < 1")
}

if err := ccvtypes.ValidateDistributionTransmissionChannel(msg.DistributionTransmissionChannel); err != nil {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "distribution transmission channel")
}

if err := ccvtypes.ValidatePositiveInt64(msg.HistoricalEntries); err != nil {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "historical entries cannot be < 1")
}

if err := ccvtypes.ValidateDuration(msg.CcvTimeoutPeriod); err != nil {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "ccv timeout period cannot be zero")
}

if err := ccvtypes.ValidateDuration(msg.TransferTimeoutPeriod); err != nil {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "transfer timeout period cannot be zero")
}

if err := ccvtypes.ValidateDuration(msg.UnbondingPeriod); err != nil {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "unbonding period cannot be zero")
}

return nil
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
/* func (msg *MsgConsumerAddition) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
//return unpacker.UnpackAny(msg., new(exported.ClientState))
// NewMsgConsumerRemoval creates a new MsgConsumerRemoval instance
func NewMsgConsumerRemoval(signer string) *MsgConsumerRemoval {
//@bermuell: TODO finsh implementation!
return &MsgConsumerRemoval{}
}

func (msg *MsgConsumerRemoval) ValidateBasic() error {

if strings.TrimSpace(msg.ChainId) == "" {
return errorsmod.Wrap(ErrInvalidConsumerRemovalProp, "consumer chain id must not be blank")
}

if msg.StopTime.IsZero() {
return errorsmod.Wrap(ErrInvalidConsumerRemovalProp, "spawn time cannot be zero")
}
return nil
}
*/
Loading

0 comments on commit a02e9f0

Please sign in to comment.