Skip to content

Commit

Permalink
feat: Migrate submit proposal commands to sdk v50 (#1379)
Browse files Browse the repository at this point in the history
* Moved to legacy

* Moved proposal to legacy

* Added ConsumerAddition message

* Added ConsumerRemoval message

* Added proposal message MsgChangeRewardDenoms

* move client/proposals to client/legacy_proposals

* Testing: renaming

* Register amino message

* Fix e2e tests

* Remove amino tag on new message

* Added message handlers for new proposals

* Added handler + commands + minor fixes

* Revert "Fix e2e tests"

This reverts commit c264d4f.

* Remove cli commands for proposals attached to provider cli

* Revert "Testing: renaming"

This reverts commit cc6639a.

* Cleanup: remove dead code

* Addressed review comments
  • Loading branch information
bermuell authored Nov 8, 2023
1 parent a356b4f commit ca97abb
Show file tree
Hide file tree
Showing 16 changed files with 2,428 additions and 189 deletions.
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
File renamed without changes.
File renamed without changes.
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.HandleConsumerAdditionProposal(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.HandleConsumerRemovalProposal(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.HandleConsumerRewardDenomProposal(sdkCtx, msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed handling Change Reward Denoms proposal")
}

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

// HandleConsumerAdditionProposal will receive the consumer chain's client state from the proposal.
// Wrapper for the new proposal message MsgConsumerAddition
// Will replace legacy handler HandleLegacyConsumerAdditionProposal
func (k Keeper) HandleConsumerAdditionProposal(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.HandleLegacyConsumerAdditionProposal(ctx, &p)

}

// Wrapper for the new proposal message MsgConsumerRemoval
// Will replace legacy handler HandleLegacyConsumerRemovalProposal
func (k Keeper) HandleConsumerRemovalProposal(ctx sdk.Context, proposal *types.MsgConsumerRemoval) error {
p := types.ConsumerRemovalProposal{
ChainId: proposal.ChainId,
StopTime: proposal.StopTime,
}
return k.HandleLegacyConsumerRemovalProposal(ctx, &p)

}

// Wrapper for the new proposal message MsgChangeRewardDenoms
// Will replace legacy handler HandleLegacyConsumerRewardDenomProposal
func (k Keeper) HandleConsumerRewardDenomProposal(ctx sdk.Context, proposal *types.MsgChangeRewardDenoms) error {
p := types.ChangeRewardDenomsProposal{
Title: "New ChangeRewardDenomsProposal",
DenomsToAdd: proposal.DenomsToAdd,
DenomsToRemove: proposal.DenomsToRemove,
}
return k.HandleLegacyConsumerRewardDenomProposal(ctx, &p)
}

// HandleLegacyConsumerAdditionProposal 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.
//
// Note: This method implements SpawnConsumerChainProposalHandler in spec.
// See: https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/methods.md#ccv-pcf-hcaprop1
// Spec tag: [CCV-PCF-HCAPROP.1]
func (k Keeper) HandleConsumerAdditionProposal(ctx sdk.Context, p *types.ConsumerAdditionProposal) error {
func (k Keeper) HandleLegacyConsumerAdditionProposal(ctx sdk.Context, p *types.ConsumerAdditionProposal) error {
// verify the consumer addition proposal execution
// in cached context and discard the cached writes
if _, _, err := k.CreateConsumerClientInCachedCtx(ctx, *p); err != nil {
Expand Down Expand Up @@ -123,13 +167,13 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, prop *types.ConsumerAdditi
return nil
}

// HandleConsumerRemovalProposal stops a consumer chain and released the outstanding unbonding operations.
// HandleLegacyConsumerRemovalProposal stops a consumer chain and released the outstanding unbonding operations.
// If the consumer can be successfully stopped in a cached context, it stores the proposal as a pending proposal.
//
// This method implements StopConsumerChainProposalHandler from spec.
// See: https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/methods.md#ccv-pcf-hcrprop1
// Spec tag: [CCV-PCF-HCRPROP.1]
func (k Keeper) HandleConsumerRemovalProposal(ctx sdk.Context, p *types.ConsumerRemovalProposal) error {
func (k Keeper) HandleLegacyConsumerRemovalProposal(ctx sdk.Context, p *types.ConsumerRemovalProposal) error {
// verify the consumer removal proposal execution
// in cached context and discard the cached writes
if _, _, err := k.StopConsumerChainInCachedCtx(ctx, *p); err != nil {
Expand Down Expand Up @@ -611,7 +655,7 @@ func (k Keeper) StopConsumerChainInCachedCtx(ctx sdk.Context, p types.ConsumerRe
return
}

func (k Keeper) HandleConsumerRewardDenomProposal(ctx sdk.Context, p *types.ChangeRewardDenomsProposal) error {
func (k Keeper) HandleLegacyConsumerRewardDenomProposal(ctx sdk.Context, p *types.ChangeRewardDenomsProposal) error {
for _, denomToAdd := range p.DenomsToAdd {
// Log error and move on if one of the denoms is already registered
if k.ConsumerRewardDenomExists(ctx, denomToAdd) {
Expand Down
Loading

0 comments on commit ca97abb

Please sign in to comment.