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: Migrate submit proposal commands to sdk v50 #1379

Merged
merged 17 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 16 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
12 changes: 9 additions & 3 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import "cosmos_proto/cosmos.proto";

//
// Note any type defined in this file is ONLY used internally to the provider CCV module.
// These schemas can change with proper consideration of compatibility or migration.
//
// These schemas can change with proper consideration of compatibility or migration.
//

// ConsumerAdditionProposal is a governance proposal on the provider chain to
// spawn a new consumer chain. If it passes, then all validators on the provider
// chain are expected to validate the consumer chain at spawn time or get
// slashed. It is recommended that spawn time occurs after the proposal end
// time.
// Deprecated: Use MsgConsumerAddition instead
message ConsumerAdditionProposal {
option deprecated = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";
Expand Down Expand Up @@ -92,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 @@ -109,7 +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 Expand Up @@ -182,7 +188,7 @@ message Params {
}

// SlashAcks contains cons addresses of consumer chain validators
// successfully slashed on the provider chain.
// successfully slashed on the provider chain.
message SlashAcks { repeated string addresses = 1; }

// ConsumerAdditionProposals holds pending governance proposals on the provider
Expand Down
129 changes: 127 additions & 2 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@ package interchain_security.ccv.provider.v1;

option go_package = "github.com/cosmos/interchain-security/v3/x/ccv/provider/types";

import "amino/amino.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "google/protobuf/any.proto";
import "ibc/core/client/v1/client.proto";

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

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

rpc ConsumerAddition(MsgConsumerAddition)
returns (MsgConsumerAdditionResponse);

rpc ConsumerRemoval(MsgConsumerRemoval)
returns (MsgConsumerRemovalResponse);

rpc ChangeRewardDenoms(MsgChangeRewardDenoms)
returns (MsgChangeRewardDenomsResponse);
}

message MsgAssignConsumerKey {
Expand All @@ -36,3 +49,115 @@ message MsgAssignConsumerKey {
}

message MsgAssignConsumerKeyResponse {}


// MsgConsumerAddition defines the message used to spawn a new consumer chain using a v1 governance proposal.
// If it passes, then all validators on the provider chain are expected to validate
// the consumer chain at spawn time or get slashed.
// It is recommended that spawn time occurs after the proposal end time.
//
// Note: this replaces ConsumerAdditionProposal which is deprecated and will be removed soon
message MsgConsumerAddition {
option (cosmos.msg.v1.signer) = "signer";

// the proposed chain-id of the new consumer chain, must be different from all
// other consumer chain ids of the executing provider chain.
string chain_id = 1;
// the proposed initial height of new consumer chain.
// For a completely new chain, this will be {0,1}. However, it may be
// different if this is a chain that is converting to a consumer chain.
ibc.core.client.v1.Height initial_height = 2 [ (gogoproto.nullable) = false ];
// The hash of the consumer chain genesis state without the consumer CCV
// module genesis params. It is used for off-chain confirmation of
// genesis.json validity by validators and other parties.
bytes genesis_hash = 3;
// The hash of the consumer chain binary that should be run by validators on
// chain initialization. It is used for off-chain confirmation of binary
// validity by validators and other parties.
bytes binary_hash = 4;
// spawn time is the time on the provider chain at which the consumer chain
// genesis is finalized and all validators will be responsible for starting
// their consumer chain validator node.
google.protobuf.Timestamp spawn_time = 5
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];

// Unbonding period for the consumer,
// which should be smaller than that of the provider in general.
google.protobuf.Duration unbonding_period = 6
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
// Sent CCV related IBC packets will timeout after this duration
google.protobuf.Duration ccv_timeout_period = 7
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
// Sent transfer related IBC packets will timeout after this duration
google.protobuf.Duration transfer_timeout_period = 8
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
// 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%.
string consumer_redistribution_fraction = 9;
// BlocksPerDistributionTransmission is the number of blocks between
// ibc-token-transfers from the consumer chain to the provider chain. On
// sending transmission event, `consumer_redistribution_fraction` of the
// accumulated tokens are sent to the consumer redistribution address.
int64 blocks_per_distribution_transmission = 10;
// The number of historical info entries to persist in store.
// This param is a part of the cosmos sdk staking module. In the case of
// a ccv enabled consumer chain, the ccv module acts as the staking module.
int64 historical_entries = 11;
// The ID of a token transfer channel used for the Reward Distribution
// sub-protocol. If DistributionTransmissionChannel == "", a new transfer
// channel is created on top of the same connection as the CCV channel.
// Note that transfer_channel_id is the ID of the channel end on the consumer
// chain. it is most relevant for chains performing a sovereign to consumer
// changeover in order to maintan the existing ibc transfer channel
string distribution_transmission_channel = 12;

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

// 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 = 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 = 2
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];

// signer address
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"];

}

// MsgChangeRewardDenomsResponse defines response type for MsgChangeRewardDenoms messages
message MsgChangeRewardDenomsResponse {}
5 changes: 1 addition & 4 deletions x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package cli
import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
"github.com/spf13/cobra"
)

// GetTxCmd returns the transaction commands for this module
Expand All @@ -24,7 +22,6 @@ func GetTxCmd() *cobra.Command {
}

cmd.AddCommand(NewAssignConsumerKeyCmd())

return cmd
}

Expand Down
46 changes: 46 additions & 0 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,49 @@ func (k msgServer) AssignConsumerKey(goCtx context.Context, msg *types.MsgAssign

return &types.MsgAssignConsumerKeyResponse{}, nil
}

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

ctx := sdk.UnwrapSDKContext(goCtx)
err := k.Keeper.HandleNewConsumerAdditionProposal(ctx, msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed handling ConsumerAddition proposal")
}
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)
}

ctx := sdk.UnwrapSDKContext(goCtx)
err := k.Keeper.HandleNewConsumerRemovalProposal(ctx, msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed handling ConsumerAddition proposal")
}

return &types.MsgConsumerRemovalResponse{}, nil
}

// ChangeRewardDenoms defines a rpc handler method for MsgChangeRewardDenoms
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)
}

sdkCtx := sdk.UnwrapSDKContext(goCtx)
err := k.Keeper.HandleNewConsumerRewardDenomProposal(sdkCtx, msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed handling Change Reward Denoms proposal")
}

return &types.MsgChangeRewardDenomsResponse{}, nil
}
44 changes: 44 additions & 0 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@ import (
ccv "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

// Wrapper for the new proposal message MsgConsumerAddition
// Will replace legacy handler HandleConsumerAdditionProposal
func (k Keeper) HandleNewConsumerAdditionProposal(ctx sdk.Context, proposal *types.MsgConsumerAddition) error {
p := types.ConsumerAdditionProposal{
Title: "New ConsumerAddition Proposal",
ChainId: proposal.ChainId,
InitialHeight: proposal.InitialHeight,
GenesisHash: proposal.GenesisHash,
BinaryHash: proposal.BinaryHash,
SpawnTime: proposal.SpawnTime,
UnbondingPeriod: proposal.UnbondingPeriod,
CcvTimeoutPeriod: proposal.CcvTimeoutPeriod,
TransferTimeoutPeriod: proposal.TransferTimeoutPeriod,
ConsumerRedistributionFraction: proposal.ConsumerRedistributionFraction,
BlocksPerDistributionTransmission: proposal.BlocksPerDistributionTransmission,
HistoricalEntries: proposal.HistoricalEntries,
DistributionTransmissionChannel: proposal.DistributionTransmissionChannel,
}
return k.HandleConsumerAdditionProposal(ctx, &p)
bermuell marked this conversation as resolved.
Show resolved Hide resolved

}

// Wrapper for the new proposal message MsgConsumerRemoval
// Will replace legacy handler HandleConsumerRemovalProposal
func (k Keeper) HandleNewConsumerRemovalProposal(ctx sdk.Context, proposal *types.MsgConsumerRemoval) error {
bermuell marked this conversation as resolved.
Show resolved Hide resolved
p := types.ConsumerRemovalProposal{
ChainId: proposal.ChainId,
StopTime: proposal.StopTime,
}
return k.HandleConsumerRemovalProposal(ctx, &p)

}

// Wrapper for the new proposal message MsgChangeRewardDenoms
// Will replace legacy handler HandleConsumerRewardDenomProposal
func (k Keeper) HandleNewConsumerRewardDenomProposal(ctx sdk.Context, proposal *types.MsgChangeRewardDenoms) error {
bermuell marked this conversation as resolved.
Show resolved Hide resolved
p := types.ChangeRewardDenomsProposal{
Title: "New ChangeRewardDenomsProposal",
DenomsToAdd: proposal.DenomsToAdd,
DenomsToRemove: proposal.DenomsToRemove,
}
return k.HandleConsumerRewardDenomProposal(ctx, &p)
}

// HandleConsumerAdditionProposal will receive the consumer chain's client state from the proposal.
// If the client can be successfully created in a cached context, it stores the proposal as a pending proposal.
//
Expand Down
5 changes: 5 additions & 0 deletions x/ccv/provider/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
Expand All @@ -11,6 +12,7 @@ import (
// RegisterLegacyAminoCodec registers the necessary x/ibc transfer interfaces and concrete types
// on the provided LegacyAmino codec. These types are used for Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgConsumerAddition{}, "cosmos-sdk/MsgConsumerAddition")
}

// RegisterInterfaces registers the provider proposal structs to the interface registry
Expand All @@ -26,6 +28,9 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgAssignConsumerKey{},
&MsgConsumerAddition{},
&MsgConsumerRemoval{},
&MsgChangeRewardDenoms{},
)
registry.RegisterImplementations(
(*govv1beta1.Content)(nil),
Expand Down
1 change: 1 addition & 0 deletions x/ccv/provider/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ var (
ErrInvalidDepositorAddress = errorsmod.Register(ModuleName, 15, "invalid depositor address")
ErrNoUnbondingTime = errorsmod.Register(ModuleName, 16, "provider unbonding time not found")
ErrInvalidAddress = errorsmod.Register(ModuleName, 17, "invalid address")
ErrUnauthorized = errorsmod.Register(ModuleName, 18, "unauthorized")
)
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
Loading
Loading