Skip to content

Commit

Permalink
Added ConsumerAddition message
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Oct 31, 2023
1 parent f96f1a6 commit 269a081
Show file tree
Hide file tree
Showing 10 changed files with 1,299 additions and 396 deletions.
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.1.3-rc.1
github.com/cometbft/cometbft v0.38.0
github.com/cometbft/cometbft-db v0.8.0
github.com/cometbft/cometbft-db v0.8.0 // indirect
github.com/cosmos/cosmos-sdk v0.50.0-rc.1
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ics23/go v0.10.0
Expand Down Expand Up @@ -41,7 +41,6 @@ require (
cosmossdk.io/api v0.7.1
cosmossdk.io/core v0.11.0
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/tools/rosetta v0.2.1
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand All @@ -55,14 +54,12 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.0.0-rc.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand Down Expand Up @@ -158,6 +155,7 @@ require (

require (
cosmossdk.io/client/v2 v2.0.0-20230818115413-c402c51a1508
cosmossdk.io/collections v0.4.0
cosmossdk.io/log v1.2.1
cosmossdk.io/store v1.0.0-rc.0
cosmossdk.io/tools/confix v0.0.0-20231011130440-f28a93a063c5
Expand All @@ -173,7 +171,6 @@ require (
)

require (
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/x/circuit v0.0.0-20230818115413-c402c51a1508 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/bits-and-blooms/bitset v1.8.0 // indirect
Expand Down
254 changes: 0 additions & 254 deletions go.sum

Large diffs are not rendered by default.

8 changes: 5 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 @@ -182,7 +184,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
77 changes: 76 additions & 1 deletion proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ package interchain_security.ccv.provider.v1;
option go_package = "github.com/cosmos/interchain-security/v3/x/ccv/provider/types";

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);

rpc ConsumerAddition(MsgConsumerAddition)
returns (MsgConsumerAdditionResponse);
}

message MsgAssignConsumerKey {
Expand All @@ -31,3 +37,72 @@ 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 the Msg/MsgIBCSoftwareUpgrade response type
message MsgConsumerAdditionResponse {}
11 changes: 11 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,14 @@ 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)
}

// TODO: Call keeper implementation !

return &types.MsgConsumerAdditionResponse{}, 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 @@ -26,6 +26,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgAssignConsumerKey{},
&MsgConsumerAddition{},
)
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 @@ -22,4 +22,5 @@ var (
ErrInvalidConsumerRewardDenom = errorsmod.Register(ModuleName, 14, "invalid consumer reward denom")
ErrInvalidDepositorAddress = errorsmod.Register(ModuleName, 15, "invalid depositor address")
ErrNoUnbondingTime = errorsmod.Register(ModuleName, 16, "provider unbonding time not found")
ErrUnauthorized = errorsmod.Register(ModuleName, 17, "unauthorized")
)
83 changes: 82 additions & 1 deletion x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ package types
import (
"encoding/json"
"strings"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
)

// provider message types
const (
TypeMsgAssignConsumerKey = "assign_consumer_key"
)

var _ sdk.Msg = &MsgAssignConsumerKey{}
var (
_ sdk.Msg = &MsgAssignConsumerKey{}
_ sdk.Msg = &MsgConsumerAddition{}

_ sdk.HasValidateBasic = &MsgAssignConsumerKey{}
_ sdk.HasValidateBasic = &MsgConsumerAddition{}
)

// NewMsgAssignConsumerKey creates a new MsgAssignConsumerKey instance.
// Delegator address and validator address are the same.
Expand Down Expand Up @@ -93,3 +101,76 @@ func ParseConsumerKeyFromJson(jsonStr string) (pkType, key string, err error) {
}
return pubKey.Type, pubKey.Key, nil
}

// 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,
consumerRedistributionFraction string,
blocksPerDistributionTransmission int64,
distributionTransmissionChannel string,
historicalEntries int64,
ccvTimeoutPeriod time.Duration,
transferTimeoutPeriod time.Duration,
unbondingPeriod time.Duration) *MsgConsumerAddition {
return &MsgConsumerAddition{
ChainId: chainID,
InitialHeight: initialHeight,
GenesisHash: genesisHash,
BinaryHash: binaryHash,
SpawnTime: spawnTime,
ConsumerRedistributionFraction: consumerRedistributionFraction,
BlocksPerDistributionTransmission: blocksPerDistributionTransmission,
DistributionTransmissionChannel: distributionTransmissionChannel,
HistoricalEntries: historicalEntries,
CcvTimeoutPeriod: ccvTimeoutPeriod,
TransferTimeoutPeriod: transferTimeoutPeriod,
UnbondingPeriod: unbondingPeriod,
}
}

// 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
// sign the msg as well.
func (msg *MsgConsumerAddition) GetSigners() []sdk.AccAddress {
valAddr, err := sdk.ValAddressFromBech32(msg.Signer)
if err != nil {
// same behavior as in cosmos-sdk
panic(err)
}
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
return nil
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
/* func (msg *MsgConsumerAddition) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
//return unpacker.UnpackAny(msg., new(exported.ClientState))
return nil
}
*/
Loading

0 comments on commit 269a081

Please sign in to comment.