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

ICS07 follow ups #5631

Merged
merged 16 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 2 additions & 6 deletions x/ibc/02-client/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ var (
ErrRootNotFound = types.ErrRootNotFound
ErrInvalidHeader = types.ErrInvalidHeader
ErrInvalidEvidence = types.ErrInvalidEvidence
NewMsgCreateClient = types.NewMsgCreateClient
NewMsgUpdateClient = types.NewMsgUpdateClient

// variable aliases
SubModuleCdc = types.SubModuleCdc
Expand All @@ -48,8 +46,6 @@ var (
)

type (
Keeper = keeper.Keeper
StakingKeeper = types.StakingKeeper
MsgCreateClient = types.MsgCreateClient
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
MsgUpdateClient = types.MsgUpdateClient
Keeper = keeper.Keeper
StakingKeeper = types.StakingKeeper
)
18 changes: 0 additions & 18 deletions x/ibc/02-client/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,3 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
)...)
return ics02ClientQueryCmd
}

// GetTxCmd returns the transaction commands for IBC clients
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
ics02ClientTxCmd := &cobra.Command{
Use: "client",
Short: "Client transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}

ics02ClientTxCmd.AddCommand(flags.PostCommands(
GetCmdCreateClient(cdc),
GetCmdUpdateClient(cdc),
GetCmdSubmitMisbehaviour(cdc),
)...)

return ics02ClientTxCmd
}
27 changes: 0 additions & 27 deletions x/ibc/02-client/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package rest

import (
"time"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
)

// REST client flags
Expand All @@ -20,26 +15,4 @@ const (
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) {
registerQueryRoutes(cliCtx, r)
registerTxRoutes(cliCtx, r)
}

// CreateClientReq defines the properties of a create client request's body.
type CreateClientReq struct {
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ClientID string `json:"client_id" yaml:"client_id"`
ConsensusState exported.ConsensusState `json:"consensus_state" yaml:"consensus_state"`
TrustingPeriod time.Duration `json:"trusting_period" yaml:"trusting_period"`
UnbondingPeriod time.Duration `json:"unbonding_period" yaml:"unbonding_period"`
}

// UpdateClientReq defines the properties of a update client request's body.
type UpdateClientReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Header exported.Header `json:"header" yaml:"header"`
}

// SubmitMisbehaviourReq defines the properties of a submit misbehaviour request's body.
type SubmitMisbehaviourReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Evidence evidenceexported.Evidence `json:"evidence" yaml:"evidence"`
}
29 changes: 3 additions & 26 deletions x/ibc/02-client/client/rest/swagger.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package rest

import (
auth "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
tendermint "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment"
)

Expand All @@ -17,7 +15,7 @@ type (

QueryHeader struct {
Height int64 `json:"height"`
Result tendermint.Header `json:"result"`
Result ibctmtypes.Header `json:"result"`
}

QueryClientState struct {
Expand All @@ -27,32 +25,11 @@ type (

QueryNodeConsensusState struct {
Height int64 `json:"height"`
Result tendermint.ConsensusState `json:"result"`
Result ibctmtypes.ConsensusState `json:"result"`
}

QueryPath struct {
Height int64 `json:"height"`
Result commitment.Prefix `json:"result"`
}

PostCreateClient struct {
Msgs []types.MsgCreateClient `json:"msg" yaml:"msg"`
Fee auth.StdFee `json:"fee" yaml:"fee"`
Signatures []auth.StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}

PostUpdateClient struct {
Msgs []types.MsgUpdateClient `json:"msg" yaml:"msg"`
Fee auth.StdFee `json:"fee" yaml:"fee"`
Signatures []auth.StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}

PostSubmitMisbehaviour struct {
Msgs []evidence.MsgSubmitEvidence `json:"msg" yaml:"msg"`
Fee auth.StdFee `json:"fee" yaml:"fee"`
Signatures []auth.StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}
)
26 changes: 13 additions & 13 deletions x/ibc/02-client/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
tendermint "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
Expand Down Expand Up @@ -91,30 +91,30 @@ func QueryConsensusState(

// QueryTendermintHeader takes a client context and returns the appropriate
// tendermint header
func QueryTendermintHeader(cliCtx context.CLIContext) (tendermint.Header, int64, error) {
func QueryTendermintHeader(cliCtx context.CLIContext) (ibctmtypes.Header, int64, error) {
node, err := cliCtx.GetNode()
if err != nil {
return tendermint.Header{}, 0, err
return ibctmtypes.Header{}, 0, err
}

info, err := node.ABCIInfo()
if err != nil {
return tendermint.Header{}, 0, err
return ibctmtypes.Header{}, 0, err
}

height := info.Response.LastBlockHeight

commit, err := node.Commit(&height)
if err != nil {
return tendermint.Header{}, 0, err
return ibctmtypes.Header{}, 0, err
}

validators, err := node.Validators(&height, 0, 10000)
if err != nil {
return tendermint.Header{}, 0, err
return ibctmtypes.Header{}, 0, err
}

header := tendermint.Header{
header := ibctmtypes.Header{
SignedHeader: commit.SignedHeader,
ValidatorSet: tmtypes.NewValidatorSet(validators.Validators),
}
Expand All @@ -124,30 +124,30 @@ func QueryTendermintHeader(cliCtx context.CLIContext) (tendermint.Header, int64,

// QueryNodeConsensusState takes a client context and returns the appropriate
// tendermint consensus state
func QueryNodeConsensusState(cliCtx context.CLIContext) (tendermint.ConsensusState, int64, error) {
func QueryNodeConsensusState(cliCtx context.CLIContext) (ibctmtypes.ConsensusState, int64, error) {
node, err := cliCtx.GetNode()
if err != nil {
return tendermint.ConsensusState{}, 0, err
return ibctmtypes.ConsensusState{}, 0, err
}

info, err := node.ABCIInfo()
if err != nil {
return tendermint.ConsensusState{}, 0, err
return ibctmtypes.ConsensusState{}, 0, err
}

height := info.Response.LastBlockHeight

commit, err := node.Commit(&height)
if err != nil {
return tendermint.ConsensusState{}, 0, err
return ibctmtypes.ConsensusState{}, 0, err
}

validators, err := node.Validators(&height, 0, 10000)
if err != nil {
return tendermint.ConsensusState{}, 0, err
return ibctmtypes.ConsensusState{}, 0, err
}

state := tendermint.ConsensusState{
state := ibctmtypes.ConsensusState{
Timestamp: commit.Time,
Root: commitment.NewRoot(commit.AppHash),
ValidatorSet: tmtypes.NewValidatorSet(validators.Validators),
Expand Down
22 changes: 22 additions & 0 deletions x/ibc/02-client/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/codec"
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
Expand Down Expand Up @@ -90,6 +92,9 @@ type ClientState interface {
type ConsensusState interface {
ClientType() ClientType // Consensus kind

// GetHeight returns the height of the consensus state
GetHeight() uint64

// GetRoot returns the commitment root of the consensus state,
// which is used for key-value pair verification.
GetRoot() commitment.RootI
Expand All @@ -110,6 +115,23 @@ type Header interface {
GetHeight() uint64
}

// MsgCreateClient defines the msg interface that the
// CreateClient Handler expects
type MsgCreateClient interface {
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
sdk.Msg
GetClientID() string
GetClientType() string
GetConsensusState() ConsensusState
}

// MsgUpdateClient defines the msg interface that the
// UpdateClient Handler expects
type MsgUpdateClient interface {
sdk.Msg
GetClientID() string
GetHeader() Header
}

// ClientType defines the type of the consensus algorithm
type ClientType byte

Expand Down
60 changes: 41 additions & 19 deletions x/ibc/02-client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,49 @@ import (
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
)

// HandleMsgCreateClient defines the sdk.Handler for MsgCreateClient
func HandleMsgCreateClient(ctx sdk.Context, k Keeper, msg MsgCreateClient) (*sdk.Result, error) {
clientType := exported.ClientTypeFromString(msg.ClientType)
if clientType == 0 {
return nil, sdkerrors.Wrap(ErrInvalidClientType, msg.ClientType)
func HandleMsgCreateClient(ctx sdk.Context, k Keeper, msg exported.MsgCreateClient) (*sdk.Result, error) {
clientType := exported.ClientTypeFromString(msg.GetClientType())
switch clientType {
case 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need it in case the string in msg does not match any of the expected values

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will fall under the default case

return nil, sdkerrors.Wrap(ErrInvalidClientType, msg.GetClientType())
case 1:
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
tmMsg, ok := msg.(ibctmtypes.MsgCreateClient)
if !ok {
return nil, sdkerrors.Wrap(ErrInvalidClientType, "Msg is not a Tendermint CreateClient msg")
}
clientState, err := ibctmtypes.InitializeFromMsg(tmMsg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move out of the switch statement

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, you can just use Initialize here

if err != nil {
return nil, err
}
_, err = k.CreateClient(
ctx, clientState, msg.GetConsensusState(),
)
if err != nil {
return nil, err
}
default:
return nil, sdkerrors.Wrap(ErrInvalidClientType, msg.GetClientType())
}

_, err := k.CreateClient(
ctx, msg.ClientID, clientType, msg.ConsensusState, msg.TrustingPeriod, msg.UnbondingPeriod,
)
if err != nil {
return nil, err
attributes := make([]sdk.Attribute, len(msg.GetSigners())+1)
attributes[0] = sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory)
for i, signer := range msg.GetSigners() {
cwgoes marked this conversation as resolved.
Show resolved Hide resolved
attributes[i+1] = sdk.NewAttribute(sdk.AttributeKeySender, signer.String())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a signer is not necessary the sender

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand what you mean here, addressed similar concern from Chris here:

#5631 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sender is the one who submits the transaction, so there will be only one sender. There will be multiple signers tho

}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
EventTypeCreateClient,
sdk.NewAttribute(AttributeKeyClientID, msg.ClientID),
sdk.NewAttribute(AttrbuteKeyClientType, msg.ClientType),
sdk.NewAttribute(AttributeKeyClientID, msg.GetClientID()),
sdk.NewAttribute(AttrbuteKeyClientType, msg.GetClientType()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Signer.String()),
attributes...,
),
})

Expand All @@ -42,21 +59,26 @@ func HandleMsgCreateClient(ctx sdk.Context, k Keeper, msg MsgCreateClient) (*sdk
}

// HandleMsgUpdateClient defines the sdk.Handler for MsgUpdateClient
func HandleMsgUpdateClient(ctx sdk.Context, k Keeper, msg MsgUpdateClient) (*sdk.Result, error) {
if err := k.UpdateClient(ctx, msg.ClientID, msg.Header); err != nil {
func HandleMsgUpdateClient(ctx sdk.Context, k Keeper, msg exported.MsgUpdateClient) (*sdk.Result, error) {
if err := k.UpdateClient(ctx, msg.GetClientID(), msg.GetHeader()); err != nil {
return nil, err
}

attributes := make([]sdk.Attribute, len(msg.GetSigners())+1)
attributes[0] = sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory)
for i, signer := range msg.GetSigners() {
cwgoes marked this conversation as resolved.
Show resolved Hide resolved
attributes[i+1] = sdk.NewAttribute(sdk.AttributeKeySender, signer.String())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
EventTypeUpdateClient,
sdk.NewAttribute(AttributeKeyClientID, msg.ClientID),
sdk.NewAttribute(AttrbuteKeyClientType, msg.Header.ClientType().String()),
sdk.NewAttribute(AttributeKeyClientID, msg.GetClientID()),
sdk.NewAttribute(AttrbuteKeyClientType, msg.GetHeader().ClientType().String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Signer.String()),
attributes...,
),
})

Expand Down
Loading