diff --git a/x/ibc/02-client/client/cli/query.go b/x/ibc/02-client/client/cli/query.go index 34c5e58093de..e77f82f4a0c3 100644 --- a/x/ibc/02-client/client/cli/query.go +++ b/x/ibc/02-client/client/cli/query.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) // GetCmdQueryClientStates defines the command to query all the light clients @@ -173,7 +173,7 @@ func GetCmdQueryPath(storeName string, cdc *codec.Codec) *cobra.Command { Short: "Query the commitment path of the running chain", RunE: func(cmd *cobra.Command, args []string) error { ctx := context.NewCLIContext().WithCodec(cdc) - path := commitment.NewPrefix([]byte("ibc")) + path := commitmenttypes.NewMerklePrefix([]byte("ibc")) return ctx.PrintOutput(path) }, } diff --git a/x/ibc/02-client/client/rest/swagger.go b/x/ibc/02-client/client/rest/swagger.go index 7c78a9f4808b..29b8b164eb03 100644 --- a/x/ibc/02-client/client/rest/swagger.go +++ b/x/ibc/02-client/client/rest/swagger.go @@ -3,7 +3,7 @@ package rest import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // nolint @@ -29,7 +29,7 @@ type ( } QueryPath struct { - Height int64 `json:"height"` - Result commitment.Prefix `json:"result"` + Height int64 `json:"height"` + Result commitmentexported.Prefix `json:"result"` } ) diff --git a/x/ibc/02-client/client/utils/utils.go b/x/ibc/02-client/client/utils/utils.go index eb83f1bc9df8..c267978ddd83 100644 --- a/x/ibc/02-client/client/utils/utils.go +++ b/x/ibc/02-client/client/utils/utils.go @@ -10,7 +10,7 @@ import ( "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" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -149,7 +149,7 @@ func QueryNodeConsensusState(cliCtx context.CLIContext) (ibctmtypes.ConsensusSta state := ibctmtypes.ConsensusState{ Timestamp: commit.Time, - Root: commitment.NewRoot(commit.AppHash), + Root: commitmenttypes.NewMerkleRoot(commit.AppHash), ValidatorSet: tmtypes.NewValidatorSet(validators.Validators), } diff --git a/x/ibc/02-client/exported/exported.go b/x/ibc/02-client/exported/exported.go index e5623ed8ddca..996a5343c797 100644 --- a/x/ibc/02-client/exported/exported.go +++ b/x/ibc/02-client/exported/exported.go @@ -10,7 +10,7 @@ import ( evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // ClientState defines the required common functions for light clients. @@ -25,15 +25,15 @@ type ClientState interface { VerifyClientConsensusState( cdc *codec.Codec, height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, consensusState ConsensusState, ) error VerifyConnectionState( cdc *codec.Codec, height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, connectionID string, connectionEnd connectionexported.ConnectionI, consensusState ConsensusState, @@ -41,8 +41,8 @@ type ClientState interface { VerifyChannelState( cdc *codec.Codec, height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, channel channelexported.ChannelI, @@ -50,8 +50,8 @@ type ClientState interface { ) error VerifyPacketCommitment( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -60,8 +60,8 @@ type ClientState interface { ) error VerifyPacketAcknowledgement( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -70,8 +70,8 @@ type ClientState interface { ) error VerifyPacketAcknowledgementAbsence( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -79,8 +79,8 @@ type ClientState interface { ) error VerifyNextSequenceRecv( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, nextSequenceRecv uint64, @@ -97,7 +97,7 @@ type ConsensusState interface { // GetRoot returns the commitment root of the consensus state, // which is used for key-value pair verification. - GetRoot() commitment.RootI + GetRoot() commitmentexported.Root ValidateBasic() error } diff --git a/x/ibc/02-client/keeper/client_test.go b/x/ibc/02-client/keeper/client_test.go index adde9062b7d3..31edfeec0f21 100644 --- a/x/ibc/02-client/keeper/client_test.go +++ b/x/ibc/02-client/keeper/client_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) const ( @@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestUpdateClient() { expConsensusState := ibctmtypes.ConsensusState{ Height: uint64(updateHeader.Height), Timestamp: updateHeader.Time, - Root: commitment.NewRoot(updateHeader.AppHash), + Root: commitmenttypes.NewMerkleRoot(updateHeader.AppHash), ValidatorSet: updateHeader.ValidatorSet, } diff --git a/x/ibc/02-client/keeper/keeper.go b/x/ibc/02-client/keeper/keeper.go index f9b1dbdcfdc9..ef5ab61bf87f 100644 --- a/x/ibc/02-client/keeper/keeper.go +++ b/x/ibc/02-client/keeper/keeper.go @@ -11,7 +11,7 @@ import ( "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" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -137,7 +137,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported. consensusState := ibctmtypes.ConsensusState{ Height: height, Timestamp: ctx.BlockTime(), - Root: commitment.NewRoot(histInfo.Header.AppHash), + Root: commitmenttypes.NewMerkleRoot(histInfo.Header.AppHash), ValidatorSet: tmtypes.NewValidatorSet(valSet.ToTmValidators()), } return consensusState, true diff --git a/x/ibc/02-client/keeper/keeper_test.go b/x/ibc/02-client/keeper/keeper_test.go index afeca9bdefa2..19a8d99f2f6b 100644 --- a/x/ibc/02-client/keeper/keeper_test.go +++ b/x/ibc/02-client/keeper/keeper_test.go @@ -16,7 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/keeper" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -60,7 +60,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.consensusState = ibctmtypes.ConsensusState{ Height: testClientHeight, Timestamp: suite.now, - Root: commitment.NewRoot([]byte("hash")), + Root: commitmenttypes.NewMerkleRoot([]byte("hash")), ValidatorSet: suite.valSet, } @@ -162,7 +162,7 @@ func (suite KeeperTestSuite) TestConsensusStateHelpers() { nextState := ibctmtypes.ConsensusState{ Height: testClientHeight + 5, Timestamp: suite.now, - Root: commitment.NewRoot([]byte("next")), + Root: commitmenttypes.NewMerkleRoot([]byte("next")), ValidatorSet: suite.valSet, } diff --git a/x/ibc/02-client/types/querier.go b/x/ibc/02-client/types/querier.go index 31a1b3586006..892349f7104b 100644 --- a/x/ibc/02-client/types/querier.go +++ b/x/ibc/02-client/types/querier.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -35,10 +35,10 @@ func NewQueryAllClientsParams(page, limit int) QueryAllClientsParams { // StateResponse defines the client response for a client state query. // It includes the commitment proof and the height of the proof. type StateResponse struct { - ClientState exported.ClientState `json:"client_state" yaml:"client_state"` - Proof commitment.Proof `json:"proof,omitempty" yaml:"proof,omitempty"` - ProofPath commitment.Path `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` - ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` + ClientState exported.ClientState `json:"client_state" yaml:"client_state"` + Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"` + ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` + ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` } // NewClientStateResponse creates a new StateResponse instance. @@ -47,8 +47,8 @@ func NewClientStateResponse( ) StateResponse { return StateResponse{ ClientState: clientState, - Proof: commitment.Proof{Proof: proof}, - ProofPath: commitment.NewPath(strings.Split(ibctypes.ClientStatePath(clientID), "/")), + Proof: commitmenttypes.MerkleProof{Proof: proof}, + ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ClientStatePath(clientID), "/")), ProofHeight: uint64(height), } } @@ -56,10 +56,10 @@ func NewClientStateResponse( // ConsensusStateResponse defines the client response for a Consensus state query. // It includes the commitment proof and the height of the proof. type ConsensusStateResponse struct { - ConsensusState exported.ConsensusState `json:"consensus_state" yaml:"consensus_state"` - Proof commitment.Proof `json:"proof,omitempty" yaml:"proof,omitempty"` - ProofPath commitment.Path `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` - ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` + ConsensusState exported.ConsensusState `json:"consensus_state" yaml:"consensus_state"` + Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"` + ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` + ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` } // NewConsensusStateResponse creates a new ConsensusStateResponse instance. @@ -68,8 +68,8 @@ func NewConsensusStateResponse( ) ConsensusStateResponse { return ConsensusStateResponse{ ConsensusState: cs, - Proof: commitment.Proof{Proof: proof}, - ProofPath: commitment.NewPath(strings.Split(ibctypes.ConsensusStatePath(clientID, uint64(height)), "/")), + Proof: commitmenttypes.MerkleProof{Proof: proof}, + ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ConsensusStatePath(clientID, uint64(height)), "/")), ProofHeight: uint64(height), } } diff --git a/x/ibc/03-connection/client/cli/tx.go b/x/ibc/03-connection/client/cli/tx.go index 9a02faa374a9..44caac4bf106 100644 --- a/x/ibc/03-connection/client/cli/tx.go +++ b/x/ibc/03-connection/client/cli/tx.go @@ -13,8 +13,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" ) diff --git a/x/ibc/03-connection/client/rest/rest.go b/x/ibc/03-connection/client/rest/rest.go index ed8e97b69280..a3d3c5613de1 100644 --- a/x/ibc/03-connection/client/rest/rest.go +++ b/x/ibc/03-connection/client/rest/rest.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) const ( @@ -21,42 +21,42 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) // ConnectionOpenInitReq defines the properties of a connection open init request's body. type ConnectionOpenInitReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - ConnectionID string `json:"connection_id" yaml:"connection_id"` - ClientID string `json:"client_id" yaml:"client_id"` - CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"` - CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"` - CounterpartyPrefix commitment.PrefixI `json:"counterparty_prefix" yaml:"counterparty_prefix"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + ConnectionID string `json:"connection_id" yaml:"connection_id"` + ClientID string `json:"client_id" yaml:"client_id"` + CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"` + CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"` + CounterpartyPrefix commitmentexported.Prefix `json:"counterparty_prefix" yaml:"counterparty_prefix"` } // ConnectionOpenTryReq defines the properties of a connection open try request's body. type ConnectionOpenTryReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - ConnectionID string `json:"connection_id" yaml:"connection_id"` - ClientID string `json:"client_id" yaml:"client_id"` - CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"` - CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"` - CounterpartyPrefix commitment.PrefixI `json:"counterparty_prefix" yaml:"counterparty_prefix"` - CounterpartyVersions []string `json:"counterparty_versions" yaml:"counterparty_versions"` - ProofInit commitment.ProofI `json:"proof_init" yaml:"proof_init"` - ProofConsensus commitment.ProofI `json:"proof_consensus" yaml:"proof_consensus"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` - ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + ConnectionID string `json:"connection_id" yaml:"connection_id"` + ClientID string `json:"client_id" yaml:"client_id"` + CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"` + CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"` + CounterpartyPrefix commitmentexported.Prefix `json:"counterparty_prefix" yaml:"counterparty_prefix"` + CounterpartyVersions []string `json:"counterparty_versions" yaml:"counterparty_versions"` + ProofInit commitmentexported.Proof `json:"proof_init" yaml:"proof_init"` + ProofConsensus commitmentexported.Proof `json:"proof_consensus" yaml:"proof_consensus"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"` } // ConnectionOpenAckReq defines the properties of a connection open ack request's body. type ConnectionOpenAckReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - ProofTry commitment.ProofI `json:"proof_try" yaml:"proof_try"` - ProofConsensus commitment.ProofI `json:"proof_consensus" yaml:"proof_consensus"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` - ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"` - Version string `json:"version" yaml:"version"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + ProofTry commitmentexported.Proof `json:"proof_try" yaml:"proof_try"` + ProofConsensus commitmentexported.Proof `json:"proof_consensus" yaml:"proof_consensus"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"` + Version string `json:"version" yaml:"version"` } // ConnectionOpenConfirmReq defines the properties of a connection open confirm request's body. type ConnectionOpenConfirmReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - ProofAck commitment.ProofI `json:"proof_ack" yaml:"proof_ack"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + ProofAck commitmentexported.Proof `json:"proof_ack" yaml:"proof_ack"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` } diff --git a/x/ibc/03-connection/client/rest/swagger.go b/x/ibc/03-connection/client/rest/swagger.go index bc12e73985d3..fd41f9449716 100644 --- a/x/ibc/03-connection/client/rest/swagger.go +++ b/x/ibc/03-connection/client/rest/swagger.go @@ -18,29 +18,29 @@ type ( PostConnectionOpenInit struct { Msgs []types.MsgConnectionOpenInit `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostConnectionOpenTry struct { Msgs []types.MsgConnectionOpenTry `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostConnectionOpenAck struct { Msgs []types.MsgConnectionOpenAck `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostConnectionOpenConfirm struct { Msgs []types.MsgConnectionOpenConfirm `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } ) diff --git a/x/ibc/03-connection/client/utils/utils.go b/x/ibc/03-connection/client/utils/utils.go index 29c52a33be9a..f2cb94beac96 100644 --- a/x/ibc/03-connection/client/utils/utils.go +++ b/x/ibc/03-connection/client/utils/utils.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -91,16 +91,16 @@ func QueryClientConnections( // ParsePrefix unmarshals an cmd input argument from a JSON string to a commitment // Prefix. If the input is not a JSON, it looks for a path to the JSON file. -func ParsePrefix(cdc *codec.Codec, arg string) (commitment.Prefix, error) { - var prefix commitment.Prefix +func ParsePrefix(cdc *codec.Codec, arg string) (commitmenttypes.MerklePrefix, error) { + var prefix commitmenttypes.MerklePrefix if err := cdc.UnmarshalJSON([]byte(arg), &prefix); err != nil { // check for file path if JSON input is not provided contents, err := ioutil.ReadFile(arg) if err != nil { - return commitment.Prefix{}, errors.New("neither JSON input nor path to .json file were provided") + return commitmenttypes.MerklePrefix{}, errors.New("neither JSON input nor path to .json file were provided") } if err := cdc.UnmarshalJSON(contents, &prefix); err != nil { - return commitment.Prefix{}, errors.Wrap(err, "error unmarshalling commitment prefix") + return commitmenttypes.MerklePrefix{}, errors.Wrap(err, "error unmarshalling commitment prefix") } } return prefix, nil @@ -108,16 +108,16 @@ func ParsePrefix(cdc *codec.Codec, arg string) (commitment.Prefix, error) { // ParseProof unmarshals an cmd input argument from a JSON string to a commitment // Proof. If the input is not a JSON, it looks for a path to the JSON file. -func ParseProof(cdc *codec.Codec, arg string) (commitment.Proof, error) { - var proof commitment.Proof +func ParseProof(cdc *codec.Codec, arg string) (commitmenttypes.MerkleProof, error) { + var proof commitmenttypes.MerkleProof if err := cdc.UnmarshalJSON([]byte(arg), &proof); err != nil { // check for file path if JSON input is not provided contents, err := ioutil.ReadFile(arg) if err != nil { - return commitment.Proof{}, errors.New("neither JSON input nor path to .json file were provided") + return commitmenttypes.MerkleProof{}, errors.New("neither JSON input nor path to .json file were provided") } if err := cdc.UnmarshalJSON(contents, &proof); err != nil { - return commitment.Proof{}, errors.Wrap(err, "error unmarshalling commitment proof") + return commitmenttypes.MerkleProof{}, errors.Wrap(err, "error unmarshalling commitment proof") } } return proof, nil diff --git a/x/ibc/03-connection/exported/exported.go b/x/ibc/03-connection/exported/exported.go index a45570c80130..8f1591f2f6e6 100644 --- a/x/ibc/03-connection/exported/exported.go +++ b/x/ibc/03-connection/exported/exported.go @@ -3,7 +3,7 @@ package exported import ( "encoding/json" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // ConnectionI describes the required methods for a connection. @@ -19,7 +19,7 @@ type ConnectionI interface { type CounterpartyI interface { GetClientID() string GetConnectionID() string - GetPrefix() commitment.PrefixI + GetPrefix() commitmentexported.Prefix ValidateBasic() error } diff --git a/x/ibc/03-connection/keeper/handshake.go b/x/ibc/03-connection/keeper/handshake.go index e8d0003c6159..5b8592f83daa 100644 --- a/x/ibc/03-connection/keeper/handshake.go +++ b/x/ibc/03-connection/keeper/handshake.go @@ -9,7 +9,7 @@ import ( clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -51,8 +51,8 @@ func (k Keeper) ConnOpenTry( counterparty types.Counterparty, // counterpartyConnectionIdentifier, counterpartyPrefix and counterpartyClientIdentifier clientID string, // clientID of chainA counterpartyVersions []string, // supported versions of chain A - proofInit commitment.ProofI, // proof that chainA stored connectionEnd in state (on ConnOpenInit) - proofConsensus commitment.ProofI, // proof that chainA stored chainB's consensus state at consensus height + proofInit commitmentexported.Proof, // proof that chainA stored connectionEnd in state (on ConnOpenInit) + proofConsensus commitmentexported.Proof, // proof that chainA stored chainB's consensus state at consensus height proofHeight uint64, // height at which relayer constructs proof of A storing connectionEnd in state consensusHeight uint64, // latest height of chain B which chain A has stored in its chain B client ) error { @@ -125,8 +125,8 @@ func (k Keeper) ConnOpenAck( ctx sdk.Context, connectionID string, version string, // version that ChainB chose in ConnOpenTry - proofTry commitment.ProofI, // proof that connectionEnd was added to ChainB state in ConnOpenTry - proofConsensus commitment.ProofI, // proof that chainB has stored ConsensusState of chainA on its client + proofTry commitmentexported.Proof, // proof that connectionEnd was added to ChainB state in ConnOpenTry + proofConsensus commitmentexported.Proof, // proof that chainB has stored ConsensusState of chainA on its client proofHeight uint64, // height that relayer constructed proofTry consensusHeight uint64, // latest height of chainA that chainB has stored on its chainA client ) error { @@ -197,7 +197,7 @@ func (k Keeper) ConnOpenAck( func (k Keeper) ConnOpenConfirm( ctx sdk.Context, connectionID string, - proofAck commitment.ProofI, // proof that connection opened on ChainA during ConnOpenAck + proofAck commitmentexported.Proof, // proof that connection opened on ChainA during ConnOpenAck proofHeight uint64, // height that relayer constructed proofAck ) error { // Retrieve connection diff --git a/x/ibc/03-connection/keeper/handshake_test.go b/x/ibc/03-connection/keeper/handshake_test.go index e3586b13b5b9..83a2ae0958ef 100644 --- a/x/ibc/03-connection/keeper/handshake_test.go +++ b/x/ibc/03-connection/keeper/handshake_test.go @@ -5,7 +5,7 @@ import ( connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -57,8 +57,8 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { ) testCases := []struct { msg string - proofInit commitment.ProofI - proofConsensus commitment.ProofI + proofInit commitmentexported.Proof + proofConsensus commitmentexported.Proof malleate func() expPass bool }{ @@ -151,8 +151,8 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { testCases := []struct { msg string version string - proofTry commitment.ProofI - proofConsensus commitment.ProofI + proofTry commitmentexported.Proof + proofConsensus commitmentexported.Proof malleate func() expPass bool }{ diff --git a/x/ibc/03-connection/keeper/keeper.go b/x/ibc/03-connection/keeper/keeper.go index 0ef8d8d77b2d..165e46e93823 100644 --- a/x/ibc/03-connection/keeper/keeper.go +++ b/x/ibc/03-connection/keeper/keeper.go @@ -10,7 +10,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -38,8 +39,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // GetCommitmentPrefix returns the IBC connection store prefix as a commitment // Prefix -func (k Keeper) GetCommitmentPrefix() commitment.PrefixI { - return commitment.NewPrefix([]byte(k.storeKey.Name())) +func (k Keeper) GetCommitmentPrefix() commitmentexported.Prefix { + return commitmenttypes.NewMerklePrefix([]byte(k.storeKey.Name())) } // GetConnection returns a connection with a particular identifier diff --git a/x/ibc/03-connection/keeper/keeper_test.go b/x/ibc/03-connection/keeper/keeper_test.go index 36bb2ea36472..2ed104744b71 100644 --- a/x/ibc/03-connection/keeper/keeper_test.go +++ b/x/ibc/03-connection/keeper/keeper_test.go @@ -18,7 +18,7 @@ import ( channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -61,7 +61,7 @@ func (suite *KeeperTestSuite) SetupTest() { } // nolint: unused -func (suite *KeeperTestSuite) queryProof(key []byte) (commitment.Proof, int64) { +func (suite *KeeperTestSuite) queryProof(key []byte) (commitmenttypes.MerkleProof, int64) { res := suite.chainA.App.Query(abci.RequestQuery{ Path: fmt.Sprintf("store/%s/key", storeKey), Height: suite.chainA.App.LastBlockHeight(), @@ -69,7 +69,7 @@ func (suite *KeeperTestSuite) queryProof(key []byte) (commitment.Proof, int64) { Prove: true, }) - proof := commitment.Proof{ + proof := commitmenttypes.MerkleProof{ Proof: res.Proof, } @@ -241,7 +241,7 @@ func (chain *TestChain) updateClient(client *TestChain) { consensusState := ibctmtypes.ConsensusState{ Height: uint64(client.Header.Height), Timestamp: client.Header.Time, - Root: commitment.NewRoot(commitID.Hash), + Root: commitmenttypes.NewMerkleRoot(commitID.Hash), ValidatorSet: client.Vals, } diff --git a/x/ibc/03-connection/keeper/verify.go b/x/ibc/03-connection/keeper/verify.go index 4741cb359c3a..aea829d922d5 100644 --- a/x/ibc/03-connection/keeper/verify.go +++ b/x/ibc/03-connection/keeper/verify.go @@ -7,7 +7,7 @@ import ( clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // VerifyClientConsensusState verifies a proof of the consensus state of the @@ -16,7 +16,7 @@ func (k Keeper) VerifyClientConsensusState( ctx sdk.Context, connection exported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, consensusState clientexported.ConsensusState, ) error { clientID := connection.GetClientID() @@ -36,7 +36,7 @@ func (k Keeper) VerifyConnectionState( ctx sdk.Context, connection exported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, connectionID string, connectionEnd exported.ConnectionI, // opposite connection ) error { @@ -67,7 +67,7 @@ func (k Keeper) VerifyChannelState( ctx sdk.Context, connection exported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, channel channelexported.ChannelI, @@ -100,7 +100,7 @@ func (k Keeper) VerifyPacketCommitment( ctx sdk.Context, connection exported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -134,7 +134,7 @@ func (k Keeper) VerifyPacketAcknowledgement( ctx sdk.Context, connection exported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -169,7 +169,7 @@ func (k Keeper) VerifyPacketAcknowledgementAbsence( ctx sdk.Context, connection exported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -202,7 +202,7 @@ func (k Keeper) VerifyNextSequenceRecv( ctx sdk.Context, connection exported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, nextSequenceRecv uint64, diff --git a/x/ibc/03-connection/keeper/verify_test.go b/x/ibc/03-connection/keeper/verify_test.go index 2e5f4f77b6db..39a817a13d49 100644 --- a/x/ibc/03-connection/keeper/verify_test.go +++ b/x/ibc/03-connection/keeper/verify_test.go @@ -6,7 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -32,7 +33,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() { cases := []struct { msg string connection types.ConnectionEnd - proof commitment.ProofI + proof commitmentexported.Proof malleate func() expPass bool }{ @@ -76,7 +77,7 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { // connectionKey := ibctypes.KeyConnection(testConnectionIDA) cases := []struct { msg string - proof commitment.ProofI + proof commitmentexported.Proof malleate func() expPass bool }{ @@ -113,7 +114,7 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { proofHeight := uint64(suite.chainA.Header.Height) // proof, proofHeight := suite.queryProof(connectionKey) - counterparty := types.NewCounterparty(testClientIDB, testConnectionIDA, commitment.NewPrefix([]byte("ibc"))) + counterparty := types.NewCounterparty(testClientIDB, testConnectionIDA, commitmenttypes.NewMerklePrefix([]byte("ibc"))) connection := types.NewConnectionEnd(exported.UNINITIALIZED, testClientIDA, counterparty, []string{"1.0.0"}) // Ensure chain B can verify connection exists in chain A err := suite.chainB.App.IBCKeeper.ConnectionKeeper.VerifyConnectionState( @@ -133,7 +134,7 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { // channelKey := ibctypes.KeyChannel(testPort1, testChannel1) cases := []struct { msg string - proof commitment.ProofI + proof commitmentexported.Proof proofHeight uint64 malleate func() expPass bool @@ -190,7 +191,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { cases := []struct { msg string - proof commitment.ProofI + proof commitmentexported.Proof proofHeight uint64 malleate func() expPass bool @@ -245,7 +246,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { cases := []struct { msg string - proof commitment.ProofI + proof commitmentexported.Proof proofHeight uint64 malleate func() expPass bool @@ -292,7 +293,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgementAbsence() { cases := []struct { msg string - proof commitment.ProofI + proof commitmentexported.Proof proofHeight uint64 malleate func() expPass bool @@ -339,7 +340,7 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { cases := []struct { msg string - proof commitment.ProofI + proof commitmentexported.Proof proofHeight uint64 malleate func() expPass bool diff --git a/x/ibc/03-connection/types/connection.go b/x/ibc/03-connection/types/connection.go index 9f0678310dd7..27b5d0d9021b 100644 --- a/x/ibc/03-connection/types/connection.go +++ b/x/ibc/03-connection/types/connection.go @@ -5,7 +5,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -79,13 +79,13 @@ var _ exported.CounterpartyI = Counterparty{} // Counterparty defines the counterparty chain associated with a connection end. type Counterparty struct { - ClientID string `json:"client_id" yaml:"client_id"` - ConnectionID string `json:"connection_id" yaml:"connection_id"` - Prefix commitment.PrefixI `json:"prefix" yaml:"prefix"` + ClientID string `json:"client_id" yaml:"client_id"` + ConnectionID string `json:"connection_id" yaml:"connection_id"` + Prefix commitmentexported.Prefix `json:"prefix" yaml:"prefix"` } // NewCounterparty creates a new Counterparty instance. -func NewCounterparty(clientID, connectionID string, prefix commitment.PrefixI) Counterparty { +func NewCounterparty(clientID, connectionID string, prefix commitmentexported.Prefix) Counterparty { return Counterparty{ ClientID: clientID, ConnectionID: connectionID, @@ -104,7 +104,7 @@ func (c Counterparty) GetConnectionID() string { } // GetPrefix implements the CounterpartyI interface -func (c Counterparty) GetPrefix() commitment.PrefixI { +func (c Counterparty) GetPrefix() commitmentexported.Prefix { return c.Prefix } diff --git a/x/ibc/03-connection/types/connection_test.go b/x/ibc/03-connection/types/connection_test.go index 895eaf45afdb..92605a7ea61e 100644 --- a/x/ibc/03-connection/types/connection_test.go +++ b/x/ibc/03-connection/types/connection_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) func TestConnectionValidateBasic(t *testing.T) { @@ -17,22 +17,22 @@ func TestConnectionValidateBasic(t *testing.T) { }{ { "valid connection", - ConnectionEnd{exported.INIT, "clientidone", Counterparty{"clientidtwo", "connectionidone", commitment.NewPrefix([]byte("prefix"))}, []string{"1.0.0"}}, + ConnectionEnd{exported.INIT, "clientidone", Counterparty{"clientidtwo", "connectionidone", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}}, true, }, { "invalid client id", - ConnectionEnd{exported.INIT, "ClientIDTwo", Counterparty{"clientidtwo", "connectionidone", commitment.NewPrefix([]byte("prefix"))}, []string{"1.0.0"}}, + ConnectionEnd{exported.INIT, "ClientIDTwo", Counterparty{"clientidtwo", "connectionidone", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}}, false, }, { "empty versions", - ConnectionEnd{exported.INIT, "clientidone", Counterparty{"clientidtwo", "connectionidone", commitment.NewPrefix([]byte("prefix"))}, nil}, + ConnectionEnd{exported.INIT, "clientidone", Counterparty{"clientidtwo", "connectionidone", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, nil}, false, }, { "invalid version", - ConnectionEnd{exported.INIT, "clientidone", Counterparty{"clientidtwo", "connectionidone", commitment.NewPrefix([]byte("prefix"))}, []string{""}}, + ConnectionEnd{exported.INIT, "clientidone", Counterparty{"clientidtwo", "connectionidone", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{""}}, false, }, { @@ -60,9 +60,9 @@ func TestCounterpartyValidateBasic(t *testing.T) { counterparty Counterparty expPass bool }{ - {"valid counterparty", Counterparty{"clientidone", "connectionidone", commitment.NewPrefix([]byte("prefix"))}, true}, - {"invalid client id", Counterparty{"InvalidClient", "channelidone", commitment.NewPrefix([]byte("prefix"))}, false}, - {"invalid connection id", Counterparty{"clientidone", "InvalidConnection", commitment.NewPrefix([]byte("prefix"))}, false}, + {"valid counterparty", Counterparty{"clientidone", "connectionidone", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, true}, + {"invalid client id", Counterparty{"InvalidClient", "channelidone", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false}, + {"invalid connection id", Counterparty{"clientidone", "InvalidConnection", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false}, {"invalid prefix", Counterparty{"clientidone", "connectionidone", nil}, false}, } diff --git a/x/ibc/03-connection/types/msgs.go b/x/ibc/03-connection/types/msgs.go index 673d42080490..9fb96cc3734e 100644 --- a/x/ibc/03-connection/types/msgs.go +++ b/x/ibc/03-connection/types/msgs.go @@ -5,7 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -24,7 +25,7 @@ type MsgConnectionOpenInit struct { // NewMsgConnectionOpenInit creates a new MsgConnectionOpenInit instance func NewMsgConnectionOpenInit( connectionID, clientID, counterpartyConnectionID, - counterpartyClientID string, counterpartyPrefix commitment.PrefixI, + counterpartyClientID string, counterpartyPrefix commitmentexported.Prefix, signer sdk.AccAddress, ) MsgConnectionOpenInit { counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix) @@ -75,22 +76,22 @@ var _ sdk.Msg = MsgConnectionOpenTry{} // MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a connection // on Chain B. type MsgConnectionOpenTry struct { - ConnectionID string `json:"connection_id"` - ClientID string `json:"client_id"` - Counterparty Counterparty `json:"counterparty"` - CounterpartyVersions []string `json:"counterparty_versions"` - ProofInit commitment.ProofI `json:"proof_init"` // proof of the initialization the connection on Chain A: `none -> INIT` - ProofConsensus commitment.ProofI `json:"proof_consensus"` // proof of client consensus state - ProofHeight uint64 `json:"proof_height"` - ConsensusHeight uint64 `json:"consensus_height"` - Signer sdk.AccAddress `json:"signer"` + ConnectionID string `json:"connection_id"` + ClientID string `json:"client_id"` + Counterparty Counterparty `json:"counterparty"` + CounterpartyVersions []string `json:"counterparty_versions"` + ProofInit commitmentexported.Proof `json:"proof_init"` // proof of the initialization the connection on Chain A: `none -> INIT` + ProofConsensus commitmentexported.Proof `json:"proof_consensus"` // proof of client consensus state + ProofHeight uint64 `json:"proof_height"` + ConsensusHeight uint64 `json:"consensus_height"` + Signer sdk.AccAddress `json:"signer"` } // NewMsgConnectionOpenTry creates a new MsgConnectionOpenTry instance func NewMsgConnectionOpenTry( connectionID, clientID, counterpartyConnectionID, - counterpartyClientID string, counterpartyPrefix commitment.PrefixI, - counterpartyVersions []string, proofInit, proofConsensus commitment.ProofI, + counterpartyClientID string, counterpartyPrefix commitmentexported.Prefix, + counterpartyVersions []string, proofInit, proofConsensus commitmentexported.Proof, proofHeight, consensusHeight uint64, signer sdk.AccAddress, ) MsgConnectionOpenTry { counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix) @@ -134,7 +135,7 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error { } } if msg.ProofInit == nil || msg.ProofConsensus == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofInit.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof init cannot be nil") @@ -169,18 +170,18 @@ var _ sdk.Msg = MsgConnectionOpenAck{} // MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to acknowledge // the change of connection state to TRYOPEN on Chain B. type MsgConnectionOpenAck struct { - ConnectionID string `json:"connection_id"` - ProofTry commitment.ProofI `json:"proof_try"` // proof for the change of the connection state on Chain B: `none -> TRYOPEN` - ProofConsensus commitment.ProofI `json:"proof_consensus"` // proof of client consensus state - ProofHeight uint64 `json:"proof_height"` - ConsensusHeight uint64 `json:"consensus_height"` - Version string `json:"version"` - Signer sdk.AccAddress `json:"signer"` + ConnectionID string `json:"connection_id"` + ProofTry commitmentexported.Proof `json:"proof_try"` // proof for the change of the connection state on Chain B: `none -> TRYOPEN` + ProofConsensus commitmentexported.Proof `json:"proof_consensus"` // proof of client consensus state + ProofHeight uint64 `json:"proof_height"` + ConsensusHeight uint64 `json:"consensus_height"` + Version string `json:"version"` + Signer sdk.AccAddress `json:"signer"` } // NewMsgConnectionOpenAck creates a new MsgConnectionOpenAck instance func NewMsgConnectionOpenAck( - connectionID string, proofTry, proofConsensus commitment.ProofI, + connectionID string, proofTry, proofConsensus commitmentexported.Proof, proofHeight, consensusHeight uint64, version string, signer sdk.AccAddress, ) MsgConnectionOpenAck { @@ -214,7 +215,7 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "version can't be blank") } if msg.ProofTry == nil || msg.ProofConsensus == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofTry.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof try cannot be nil") @@ -249,15 +250,15 @@ var _ sdk.Msg = MsgConnectionOpenConfirm{} // MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to acknowledge // the change of connection state to OPEN on Chain A. type MsgConnectionOpenConfirm struct { - ConnectionID string `json:"connection_id"` - ProofAck commitment.ProofI `json:"proof_ack"` // proof for the change of the connection state on Chain A: `INIT -> OPEN` - ProofHeight uint64 `json:"proof_height"` - Signer sdk.AccAddress `json:"signer"` + ConnectionID string `json:"connection_id"` + ProofAck commitmentexported.Proof `json:"proof_ack"` // proof for the change of the connection state on Chain A: `INIT -> OPEN` + ProofHeight uint64 `json:"proof_height"` + Signer sdk.AccAddress `json:"signer"` } // NewMsgConnectionOpenConfirm creates a new MsgConnectionOpenConfirm instance func NewMsgConnectionOpenConfirm( - connectionID string, proofAck commitment.ProofI, proofHeight uint64, + connectionID string, proofAck commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress, ) MsgConnectionOpenConfirm { return MsgConnectionOpenConfirm{ @@ -284,7 +285,7 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error { return sdkerrors.Wrap(err, "invalid connection ID") } if msg.ProofAck == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofAck.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof ack cannot be nil") diff --git a/x/ibc/03-connection/types/msgs_test.go b/x/ibc/03-connection/types/msgs_test.go index 8bca120769ba..26c88868837f 100644 --- a/x/ibc/03-connection/types/msgs_test.go +++ b/x/ibc/03-connection/types/msgs_test.go @@ -13,13 +13,13 @@ import ( "github.com/cosmos/cosmos-sdk/store/rootmulti" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) type MsgTestSuite struct { suite.Suite - proof commitment.Proof + proof commitmenttypes.MerkleProof } func (suite *MsgTestSuite) SetupTest() { @@ -40,7 +40,7 @@ func (suite *MsgTestSuite) SetupTest() { Prove: true, }) - suite.proof = commitment.Proof{Proof: res.Proof} + suite.proof = commitmenttypes.MerkleProof{Proof: res.Proof} } func TestMsgTestSuite(t *testing.T) { @@ -48,7 +48,7 @@ func TestMsgTestSuite(t *testing.T) { } func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { - prefix := commitment.NewPrefix([]byte("storePrefixKey")) + prefix := commitmenttypes.NewMerklePrefix([]byte("storePrefixKey")) signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") testMsgs := []MsgConnectionOpenInit{ @@ -86,7 +86,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { } func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { - prefix := commitment.NewPrefix([]byte("storePrefixKey")) + prefix := commitmenttypes.NewMerklePrefix([]byte("storePrefixKey")) signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") testMsgs := []MsgConnectionOpenTry{ @@ -97,9 +97,9 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", nil, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{}, suite.proof, suite.proof, 10, 10, signer), NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, nil, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, commitment.Proof{Proof: nil}, suite.proof, 10, 10, signer), + NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, commitmenttypes.MerkleProof{Proof: nil}, suite.proof, 10, 10, signer), NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, nil, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, commitment.Proof{Proof: nil}, 10, 10, signer), + NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, commitmenttypes.MerkleProof{Proof: nil}, 10, 10, signer), NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 0, 10, signer), NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 0, signer), NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, nil), @@ -143,9 +143,9 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { testMsgs := []MsgConnectionOpenAck{ NewMsgConnectionOpenAck("test/conn1", suite.proof, suite.proof, 10, 10, "1.0.0", signer), NewMsgConnectionOpenAck("ibcconntest", nil, suite.proof, 10, 10, "1.0.0", signer), - NewMsgConnectionOpenAck("ibcconntest", commitment.Proof{Proof: nil}, suite.proof, 10, 10, "1.0.0", signer), + NewMsgConnectionOpenAck("ibcconntest", commitmenttypes.MerkleProof{Proof: nil}, suite.proof, 10, 10, "1.0.0", signer), NewMsgConnectionOpenAck("ibcconntest", suite.proof, nil, 10, 10, "1.0.0", signer), - NewMsgConnectionOpenAck("ibcconntest", suite.proof, commitment.Proof{Proof: nil}, 10, 10, "1.0.0", signer), + NewMsgConnectionOpenAck("ibcconntest", suite.proof, commitmenttypes.MerkleProof{Proof: nil}, 10, 10, "1.0.0", signer), NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 0, 10, "1.0.0", signer), NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 0, "1.0.0", signer), NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "", signer), @@ -185,7 +185,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() { testMsgs := []MsgConnectionOpenConfirm{ NewMsgConnectionOpenConfirm("test/conn1", suite.proof, 10, signer), NewMsgConnectionOpenConfirm("ibcconntest", nil, 10, signer), - NewMsgConnectionOpenConfirm("ibcconntest", commitment.Proof{Proof: nil}, 10, signer), + NewMsgConnectionOpenConfirm("ibcconntest", commitmenttypes.MerkleProof{Proof: nil}, 10, signer), NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 0, signer), NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, nil), NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, signer), diff --git a/x/ibc/03-connection/types/querier.go b/x/ibc/03-connection/types/querier.go index 459082a7f0c0..48db30da8f95 100644 --- a/x/ibc/03-connection/types/querier.go +++ b/x/ibc/03-connection/types/querier.go @@ -5,7 +5,7 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -18,10 +18,10 @@ const ( // ConnectionResponse defines the client query response for a connection which // also includes a proof and the height from which the proof was retrieved. type ConnectionResponse struct { - Connection ConnectionEnd `json:"connection" yaml:"connection"` - Proof commitment.Proof `json:"proof,omitempty" yaml:"proof,omitempty"` - ProofPath commitment.Path `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` - ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` + Connection ConnectionEnd `json:"connection" yaml:"connection"` + Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"` + ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` + ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` } // NewConnectionResponse creates a new ConnectionResponse instance @@ -30,8 +30,8 @@ func NewConnectionResponse( ) ConnectionResponse { return ConnectionResponse{ Connection: connection, - Proof: commitment.Proof{Proof: proof}, - ProofPath: commitment.NewPath(strings.Split(ibctypes.ConnectionPath(connectionID), "/")), + Proof: commitmenttypes.MerkleProof{Proof: proof}, + ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ConnectionPath(connectionID), "/")), ProofHeight: uint64(height), } } @@ -55,10 +55,10 @@ func NewQueryAllConnectionsParams(page, limit int) QueryAllConnectionsParams { // connection paths which also includes a proof and the height from which the // proof was retrieved. type ClientConnectionsResponse struct { - ConnectionPaths []string `json:"connection_paths" yaml:"connection_paths"` - Proof commitment.Proof `json:"proof,omitempty" yaml:"proof,omitempty"` - ProofPath commitment.Path `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` - ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` + ConnectionPaths []string `json:"connection_paths" yaml:"connection_paths"` + Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"` + ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` + ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` } // NewClientConnectionsResponse creates a new ConnectionPaths instance @@ -67,8 +67,8 @@ func NewClientConnectionsResponse( ) ClientConnectionsResponse { return ClientConnectionsResponse{ ConnectionPaths: connectionPaths, - Proof: commitment.Proof{Proof: proof}, - ProofPath: commitment.NewPath(strings.Split(ibctypes.ClientConnectionsPath(clientID), "/")), + Proof: commitmenttypes.MerkleProof{Proof: proof}, + ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ClientConnectionsPath(clientID), "/")), ProofHeight: uint64(height), } } diff --git a/x/ibc/04-channel/alias.go b/x/ibc/04-channel/alias.go index c24c077d9c60..dc4073212266 100644 --- a/x/ibc/04-channel/alias.go +++ b/x/ibc/04-channel/alias.go @@ -12,12 +12,12 @@ import ( ) const ( - SubModuleName = types.SubModuleName - StoreKey = types.StoreKey - RouterKey = types.RouterKey - QuerierRoute = types.QuerierRoute - QueryAllChannels = types.QueryAllChannels - QueryChannel = types.QueryChannel + SubModuleName = types.SubModuleName + StoreKey = types.StoreKey + RouterKey = types.RouterKey + QuerierRoute = types.QuerierRoute + QueryAllChannels = types.QueryAllChannels + QueryChannel = types.QueryChannel ) var ( diff --git a/x/ibc/04-channel/client/cli/tx.go b/x/ibc/04-channel/client/cli/tx.go index 3241eb780f39..16183ae2ec04 100644 --- a/x/ibc/04-channel/client/cli/tx.go +++ b/x/ibc/04-channel/client/cli/tx.go @@ -11,8 +11,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" connectionutils "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" diff --git a/x/ibc/04-channel/client/rest/rest.go b/x/ibc/04-channel/client/rest/rest.go index 7ee17790ea88..2d65fc2d5817 100644 --- a/x/ibc/04-channel/client/rest/rest.go +++ b/x/ibc/04-channel/client/rest/rest.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) const ( @@ -35,32 +35,32 @@ type ChannelOpenInitReq struct { // ChannelOpenTryReq defines the properties of a channel open try request's body. type ChannelOpenTryReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - PortID string `json:"port_id" yaml:"port_id"` - ChannelID string `json:"channel_id" yaml:"channel_id"` - Version string `json:"version" yaml:"version"` - ChannelOrder exported.Order `json:"channel_order" yaml:"channel_order"` - ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"` - CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"` - CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"` - CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"` - ProofInit commitment.ProofI `json:"proof_init" yaml:"proof_init"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + PortID string `json:"port_id" yaml:"port_id"` + ChannelID string `json:"channel_id" yaml:"channel_id"` + Version string `json:"version" yaml:"version"` + ChannelOrder exported.Order `json:"channel_order" yaml:"channel_order"` + ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"` + CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"` + CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"` + CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"` + ProofInit commitmentexported.Proof `json:"proof_init" yaml:"proof_init"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` } // ChannelOpenAckReq defines the properties of a channel open ack request's body. type ChannelOpenAckReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"` - ProofTry commitment.ProofI `json:"proof_try" yaml:"proof_try"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"` + ProofTry commitmentexported.Proof `json:"proof_try" yaml:"proof_try"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` } // ChannelOpenConfirmReq defines the properties of a channel open confirm request's body. type ChannelOpenConfirmReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - ProofAck commitment.ProofI `json:"proof_ack" yaml:"proof_ack"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + ProofAck commitmentexported.Proof `json:"proof_ack" yaml:"proof_ack"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` } // ConnectionOpenInitReq defines the properties of a channel close init request's body. @@ -70,15 +70,15 @@ type ChannelCloseInitReq struct { // ChannelCloseConfirmReq defines the properties of a channel close confirm request's body. type ChannelCloseConfirmReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - ProofInit commitment.ProofI `json:"proof_init" yaml:"proof_init"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + ProofInit commitmentexported.Proof `json:"proof_init" yaml:"proof_init"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` } // RecvPacketReq defines the properties of a receive packet request's body. type RecvPacketReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - Packet types.Packet `json:"packet" yaml:"packet"` - Proofs commitment.ProofI `json:"proofs" yaml:"proofs"` - Height uint64 `json:"height" yaml:"height"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + Packet types.Packet `json:"packet" yaml:"packet"` + Proofs commitmentexported.Proof `json:"proofs" yaml:"proofs"` + Height uint64 `json:"height" yaml:"height"` } diff --git a/x/ibc/04-channel/client/rest/swagger.go b/x/ibc/04-channel/client/rest/swagger.go index 5f6dc5821468..04d011f2cb63 100644 --- a/x/ibc/04-channel/client/rest/swagger.go +++ b/x/ibc/04-channel/client/rest/swagger.go @@ -13,43 +13,43 @@ type ( PostChannelOpenInit struct { Msgs []types.MsgChannelOpenInit `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostChannelOpenTry struct { Msgs []types.MsgChannelOpenTry `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostChannelOpenAck struct { Msgs []types.MsgChannelOpenAck `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostChannelOpenConfirm struct { Msgs []types.MsgChannelOpenConfirm `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostChannelCloseInit struct { Msgs []types.MsgChannelCloseInit `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostChannelCloseConfirm struct { Msgs []types.MsgChannelCloseConfirm `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } ) diff --git a/x/ibc/04-channel/keeper/handshake.go b/x/ibc/04-channel/keeper/handshake.go index 40bfb79e90d1..0b434d2ea650 100644 --- a/x/ibc/04-channel/keeper/handshake.go +++ b/x/ibc/04-channel/keeper/handshake.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // CounterpartyHops returns the connection hops of the counterparty channel. @@ -78,7 +78,7 @@ func (k Keeper) ChanOpenTry( counterparty types.Counterparty, version, counterpartyVersion string, - proofInit commitment.ProofI, + proofInit commitmentexported.Proof, proofHeight uint64, ) error { // channel identifier and connection hop length checked on msg.ValidateBasic() @@ -154,7 +154,7 @@ func (k Keeper) ChanOpenAck( portID, channelID, counterpartyVersion string, - proofTry commitment.ProofI, + proofTry commitmentexported.Proof, proofHeight uint64, ) error { channel, found := k.GetChannel(ctx, portID, channelID) @@ -221,7 +221,7 @@ func (k Keeper) ChanOpenConfirm( ctx sdk.Context, portID, channelID string, - proofAck commitment.ProofI, + proofAck commitmentexported.Proof, proofHeight uint64, ) error { channel, found := k.GetChannel(ctx, portID, channelID) @@ -341,7 +341,7 @@ func (k Keeper) ChanCloseConfirm( ctx sdk.Context, portID, channelID string, - proofInit commitment.ProofI, + proofInit commitmentexported.Proof, proofHeight uint64, ) error { // TODO: blocked by #5542 diff --git a/x/ibc/04-channel/keeper/keeper_test.go b/x/ibc/04-channel/keeper/keeper_test.go index e3c42527f015..c65d32dab4c4 100644 --- a/x/ibc/04-channel/keeper/keeper_test.go +++ b/x/ibc/04-channel/keeper/keeper_test.go @@ -19,10 +19,10 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - "github.com/cosmos/cosmos-sdk/x/staking" - - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + "github.com/cosmos/cosmos-sdk/x/staking" ) // define constants used for testing @@ -207,7 +207,7 @@ func commitNBlocks(chain *TestChain, n int) { } // nolint: unused -func (suite *KeeperTestSuite) queryProof(key []byte) (commitment.Proof, int64) { +func (suite *KeeperTestSuite) queryProof(key []byte) (commitmenttypes.MerkleProof, int64) { res := suite.chainB.App.Query(abci.RequestQuery{ Path: fmt.Sprintf("store/%s/key", ibctypes.StoreKey), Height: suite.chainB.App.LastBlockHeight(), @@ -215,7 +215,7 @@ func (suite *KeeperTestSuite) queryProof(key []byte) (commitment.Proof, int64) { Prove: true, }) - proof := commitment.Proof{ + proof := commitmenttypes.MerkleProof{ Proof: res.Proof, } @@ -341,7 +341,7 @@ func (chain *TestChain) updateClient(client *TestChain) { consensusState := ibctmtypes.ConsensusState{ Height: uint64(client.Header.Height), Timestamp: client.Header.Time, - Root: commitment.NewRoot(commitID.Hash), + Root: commitmenttypes.NewMerkleRoot(commitID.Hash), ValidatorSet: client.Vals, } @@ -403,8 +403,8 @@ func nextHeader(chain *TestChain) ibctmtypes.Header { // TODO: fix tests and replace for real proofs var ( - _ commitment.ProofI = validProof{} - _ commitment.ProofI = invalidProof{} + _ commitmentexported.Proof = validProof{} + _ commitmentexported.Proof = invalidProof{} ) type ( @@ -412,16 +412,16 @@ type ( invalidProof struct{} ) -func (validProof) GetCommitmentType() commitment.Type { - return commitment.Merkle +func (validProof) GetCommitmentType() commitmentexported.Type { + return commitmentexported.Merkle } func (validProof) VerifyMembership( - root commitment.RootI, path commitment.PathI, value []byte) error { + root commitmentexported.Root, path commitmentexported.Path, value []byte) error { return nil } -func (validProof) VerifyNonMembership(root commitment.RootI, path commitment.PathI) error { +func (validProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { return nil } @@ -433,16 +433,16 @@ func (validProof) IsEmpty() bool { return false } -func (invalidProof) GetCommitmentType() commitment.Type { - return commitment.Merkle +func (invalidProof) GetCommitmentType() commitmentexported.Type { + return commitmentexported.Merkle } func (invalidProof) VerifyMembership( - root commitment.RootI, path commitment.PathI, value []byte) error { + root commitmentexported.Root, path commitmentexported.Path, value []byte) error { return errors.New("proof failed") } -func (invalidProof) VerifyNonMembership(root commitment.RootI, path commitment.PathI) error { +func (invalidProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { return errors.New("proof failed") } diff --git a/x/ibc/04-channel/keeper/packet.go b/x/ibc/04-channel/keeper/packet.go index 614da9d0ebcf..9630cedfd09f 100644 --- a/x/ibc/04-channel/keeper/packet.go +++ b/x/ibc/04-channel/keeper/packet.go @@ -11,7 +11,7 @@ import ( connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // SendPacket is called by a module in order to send an IBC packet on a channel @@ -111,7 +111,7 @@ func (k Keeper) SendPacket( func (k Keeper) RecvPacket( ctx sdk.Context, packet exported.PacketI, - proof commitment.ProofI, + proof commitmentexported.Proof, proofHeight uint64, ) (exported.PacketI, error) { channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel()) @@ -232,7 +232,7 @@ func (k Keeper) AcknowledgePacket( ctx sdk.Context, packet exported.PacketI, acknowledgement exported.PacketAcknowledgementI, - proof commitment.ProofI, + proof commitmentexported.Proof, proofHeight uint64, ) (exported.PacketI, error) { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) @@ -307,7 +307,7 @@ func (k Keeper) AcknowledgePacket( func (k Keeper) CleanupPacket( ctx sdk.Context, packet exported.PacketI, - proof commitment.ProofI, + proof commitmentexported.Proof, proofHeight, nextSequenceRecv uint64, acknowledgement []byte, diff --git a/x/ibc/04-channel/keeper/timeout.go b/x/ibc/04-channel/keeper/timeout.go index 1989722130b2..ff2111675024 100644 --- a/x/ibc/04-channel/keeper/timeout.go +++ b/x/ibc/04-channel/keeper/timeout.go @@ -8,7 +8,7 @@ import ( connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // TimeoutPacket is called by a module which originally attempted to send a @@ -19,7 +19,7 @@ import ( func (k Keeper) TimeoutPacket( ctx sdk.Context, packet exported.PacketI, - proof commitment.ProofI, + proof commitmentexported.Proof, proofHeight, nextSequenceRecv uint64, ) (exported.PacketI, error) { @@ -135,7 +135,7 @@ func (k Keeper) TimeoutOnClose( ctx sdk.Context, packet types.Packet, proof, - proofClosed commitment.ProofI, + proofClosed commitmentexported.Proof, proofHeight, nextSequenceRecv uint64, ) (exported.PacketI, error) { diff --git a/x/ibc/04-channel/keeper/timeout_test.go b/x/ibc/04-channel/keeper/timeout_test.go index 8991b7a5952f..917b80adbb6a 100644 --- a/x/ibc/04-channel/keeper/timeout_test.go +++ b/x/ibc/04-channel/keeper/timeout_test.go @@ -6,7 +6,7 @@ import ( connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -135,9 +135,9 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { var ( packet types.Packet nextSeqRecv uint64 - proofHeight uint64 = 1 - proof commitment.ProofI = ibctypes.InvalidProof{} - proofClosed commitment.ProofI = ibctypes.InvalidProof{} + proofHeight uint64 = 1 + proof commitmentexported.Proof = ibctypes.InvalidProof{} + proofClosed commitmentexported.Proof = ibctypes.InvalidProof{} ) testCases := []testCase{ diff --git a/x/ibc/04-channel/types/codec.go b/x/ibc/04-channel/types/codec.go index e8bb91bf33be..ca64d49d2851 100644 --- a/x/ibc/04-channel/types/codec.go +++ b/x/ibc/04-channel/types/codec.go @@ -4,7 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" client "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) // SubModuleCdc defines the IBC channel codec. @@ -12,7 +12,7 @@ var SubModuleCdc *codec.Codec func init() { SubModuleCdc = codec.New() - commitment.RegisterCodec(SubModuleCdc) + commitmenttypes.RegisterCodec(SubModuleCdc) client.RegisterCodec(SubModuleCdc) RegisterCodec(SubModuleCdc) } diff --git a/x/ibc/04-channel/types/expected_keepers.go b/x/ibc/04-channel/types/expected_keepers.go index c63fa9a9fe80..26c6ad1547a4 100644 --- a/x/ibc/04-channel/types/expected_keepers.go +++ b/x/ibc/04-channel/types/expected_keepers.go @@ -6,7 +6,7 @@ import ( connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // ClientKeeper expected account IBC client keeper @@ -21,7 +21,7 @@ type ConnectionKeeper interface { ctx sdk.Context, connection connectionexported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, channel exported.ChannelI, @@ -30,7 +30,7 @@ type ConnectionKeeper interface { ctx sdk.Context, connection connectionexported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -40,7 +40,7 @@ type ConnectionKeeper interface { ctx sdk.Context, connection connectionexported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -50,7 +50,7 @@ type ConnectionKeeper interface { ctx sdk.Context, connection connectionexported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, @@ -59,7 +59,7 @@ type ConnectionKeeper interface { ctx sdk.Context, connection connectionexported.ConnectionI, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, portID, channelID string, nextSequenceRecv uint64, diff --git a/x/ibc/04-channel/types/msgs.go b/x/ibc/04-channel/types/msgs.go index 3f52db670f97..6797e942f57b 100644 --- a/x/ibc/04-channel/types/msgs.go +++ b/x/ibc/04-channel/types/msgs.go @@ -6,7 +6,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -70,20 +71,20 @@ func (msg MsgChannelOpenInit) GetSigners() []sdk.AccAddress { var _ sdk.Msg = MsgChannelOpenTry{} type MsgChannelOpenTry struct { - PortID string `json:"port_id"` - ChannelID string `json:"channel_id"` - Channel Channel `json:"channel"` - CounterpartyVersion string `json:"counterparty_version"` - ProofInit commitment.ProofI `json:"proof_init"` - ProofHeight uint64 `json:"proof_height"` - Signer sdk.AccAddress `json:"signer"` + PortID string `json:"port_id"` + ChannelID string `json:"channel_id"` + Channel Channel `json:"channel"` + CounterpartyVersion string `json:"counterparty_version"` + ProofInit commitmentexported.Proof `json:"proof_init"` + ProofHeight uint64 `json:"proof_height"` + Signer sdk.AccAddress `json:"signer"` } // NewMsgChannelOpenTry creates a new MsgChannelOpenTry instance func NewMsgChannelOpenTry( portID, channelID, version string, channelOrder exported.Order, connectionHops []string, counterpartyPortID, counterpartyChannelID, counterpartyVersion string, - proofInit commitment.ProofI, proofHeight uint64, signer sdk.AccAddress, + proofInit commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress, ) MsgChannelOpenTry { counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := NewChannel(exported.INIT, channelOrder, counterparty, connectionHops, version) @@ -120,7 +121,7 @@ func (msg MsgChannelOpenTry) ValidateBasic() error { return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty version cannot be blank") } if msg.ProofInit == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofInit.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof init cannot be nil") @@ -145,17 +146,17 @@ func (msg MsgChannelOpenTry) GetSigners() []sdk.AccAddress { var _ sdk.Msg = MsgChannelOpenAck{} type MsgChannelOpenAck struct { - PortID string `json:"port_id"` - ChannelID string `json:"channel_id"` - CounterpartyVersion string `json:"counterparty_version"` - ProofTry commitment.ProofI `json:"proof_try"` - ProofHeight uint64 `json:"proof_height"` - Signer sdk.AccAddress `json:"signer"` + PortID string `json:"port_id"` + ChannelID string `json:"channel_id"` + CounterpartyVersion string `json:"counterparty_version"` + ProofTry commitmentexported.Proof `json:"proof_try"` + ProofHeight uint64 `json:"proof_height"` + Signer sdk.AccAddress `json:"signer"` } // NewMsgChannelOpenAck creates a new MsgChannelOpenAck instance func NewMsgChannelOpenAck( - portID, channelID string, cpv string, proofTry commitment.ProofI, proofHeight uint64, + portID, channelID string, cpv string, proofTry commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress, ) MsgChannelOpenAck { return MsgChannelOpenAck{ @@ -190,7 +191,7 @@ func (msg MsgChannelOpenAck) ValidateBasic() error { return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty version cannot be blank") } if msg.ProofTry == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofTry.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof try cannot be nil") @@ -215,16 +216,16 @@ func (msg MsgChannelOpenAck) GetSigners() []sdk.AccAddress { var _ sdk.Msg = MsgChannelOpenConfirm{} type MsgChannelOpenConfirm struct { - PortID string `json:"port_id"` - ChannelID string `json:"channel_id"` - ProofAck commitment.ProofI `json:"proof_ack"` - ProofHeight uint64 `json:"proof_height"` - Signer sdk.AccAddress `json:"signer"` + PortID string `json:"port_id"` + ChannelID string `json:"channel_id"` + ProofAck commitmentexported.Proof `json:"proof_ack"` + ProofHeight uint64 `json:"proof_height"` + Signer sdk.AccAddress `json:"signer"` } // NewMsgChannelOpenConfirm creates a new MsgChannelOpenConfirm instance func NewMsgChannelOpenConfirm( - portID, channelID string, proofAck commitment.ProofI, proofHeight uint64, + portID, channelID string, proofAck commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress, ) MsgChannelOpenConfirm { return MsgChannelOpenConfirm{ @@ -255,7 +256,7 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error { return sdkerrors.Wrap(err, "invalid channel ID") } if msg.ProofAck == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofAck.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof ack cannot be nil") @@ -329,16 +330,16 @@ func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress { var _ sdk.Msg = MsgChannelCloseConfirm{} type MsgChannelCloseConfirm struct { - PortID string `json:"port_id"` - ChannelID string `json:"channel_id"` - ProofInit commitment.ProofI `json:"proof_init"` - ProofHeight uint64 `json:"proof_height"` - Signer sdk.AccAddress `json:"signer"` + PortID string `json:"port_id"` + ChannelID string `json:"channel_id"` + ProofInit commitmentexported.Proof `json:"proof_init"` + ProofHeight uint64 `json:"proof_height"` + Signer sdk.AccAddress `json:"signer"` } // NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance func NewMsgChannelCloseConfirm( - portID, channelID string, proofInit commitment.ProofI, proofHeight uint64, + portID, channelID string, proofInit commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress, ) MsgChannelCloseConfirm { return MsgChannelCloseConfirm{ @@ -369,7 +370,7 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error { return sdkerrors.Wrap(err, "invalid channel ID") } if msg.ProofInit == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofInit.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof init cannot be nil") @@ -394,15 +395,15 @@ func (msg MsgChannelCloseConfirm) GetSigners() []sdk.AccAddress { // MsgPacket receives incoming IBC packet type MsgPacket struct { Packet `json:"packet" yaml:"packet"` - Proof commitment.ProofI `json:"proof" yaml:"proof"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` - Signer sdk.AccAddress `json:"signer" yaml:"signer"` + Proof commitmentexported.Proof `json:"proof" yaml:"proof"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + Signer sdk.AccAddress `json:"signer" yaml:"signer"` } var _ sdk.Msg = MsgPacket{} // NewMsgPacket constructs new MsgPacket -func NewMsgPacket(packet Packet, proof commitment.ProofI, proofHeight uint64, signer sdk.AccAddress) MsgPacket { +func NewMsgPacket(packet Packet, proof commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress) MsgPacket { return MsgPacket{ Packet: packet, Proof: proof, @@ -419,7 +420,7 @@ func (msg MsgPacket) Route() string { // ValidateBasic implements sdk.Msg func (msg MsgPacket) ValidateBasic() error { if msg.Proof == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.Proof.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof ack cannot be nil") @@ -449,14 +450,14 @@ var _ sdk.Msg = MsgTimeout{} // MsgTimeout receives timed-out packet type MsgTimeout struct { Packet `json:"packet" yaml:"packet"` - NextSequenceRecv uint64 `json:"next_sequence_recv" yaml:"next_sequence_recv"` - Proof commitment.ProofI `json:"proof" yaml:"proof"` - ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` - Signer sdk.AccAddress `json:"signer" yaml:"signer"` + NextSequenceRecv uint64 `json:"next_sequence_recv" yaml:"next_sequence_recv"` + Proof commitmentexported.Proof `json:"proof" yaml:"proof"` + ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` + Signer sdk.AccAddress `json:"signer" yaml:"signer"` } // NewMsgTimeout constructs new MsgTimeout -func NewMsgTimeout(packet Packet, nextSequenceRecv uint64, proof commitment.ProofI, proofHeight uint64, signer sdk.AccAddress) MsgTimeout { +func NewMsgTimeout(packet Packet, nextSequenceRecv uint64, proof commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress) MsgTimeout { return MsgTimeout{ Packet: packet, NextSequenceRecv: nextSequenceRecv, @@ -474,7 +475,7 @@ func (msg MsgTimeout) Route() string { // ValidateBasic implements sdk.Msg func (msg MsgTimeout) ValidateBasic() error { if msg.Proof == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.Proof.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof ack cannot be nil") @@ -505,13 +506,13 @@ var _ sdk.Msg = MsgAcknowledgement{} type MsgAcknowledgement struct { Packet `json:"packet" yaml:"packet"` Acknowledgement exported.PacketAcknowledgementI `json:"acknowledgement" yaml:"acknowledgement"` - Proof commitment.ProofI `json:"proof" yaml:"proof"` + Proof commitmentexported.Proof `json:"proof" yaml:"proof"` ProofHeight uint64 `json:"proof_height" yaml:"proof_height"` Signer sdk.AccAddress `json:"signer" yaml:"signer"` } // NewMsgAcknowledgement constructs a new MsgAcknowledgement -func NewMsgAcknowledgement(packet Packet, ack exported.PacketAcknowledgementI, proof commitment.ProofI, proofHeight uint64, signer sdk.AccAddress) MsgAcknowledgement { +func NewMsgAcknowledgement(packet Packet, ack exported.PacketAcknowledgementI, proof commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress) MsgAcknowledgement { return MsgAcknowledgement{ Packet: packet, Acknowledgement: ack, @@ -529,7 +530,7 @@ func (msg MsgAcknowledgement) Route() string { // ValidateBasic implements sdk.Msg func (msg MsgAcknowledgement) ValidateBasic() error { if msg.Proof == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.Proof.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "proof ack cannot be nil") diff --git a/x/ibc/04-channel/types/msgs_test.go b/x/ibc/04-channel/types/msgs_test.go index f071b7a17fcb..197d5231cac3 100644 --- a/x/ibc/04-channel/types/msgs_test.go +++ b/x/ibc/04-channel/types/msgs_test.go @@ -17,7 +17,8 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) // define constants used for testing @@ -42,7 +43,7 @@ var ( invalidShortConnHops = []string{invalidShortConnection} invalidLongConnHops = []string{invalidLongConnection} - proof = commitment.Proof{Proof: &merkle.Proof{}} + proof = commitmenttypes.MerkleProof{Proof: &merkle.Proof{}} addr = sdk.AccAddress("testaddr") ) @@ -50,7 +51,7 @@ var ( type MsgTestSuite struct { suite.Suite - proof commitment.Proof + proof commitmenttypes.MerkleProof } func (suite *MsgTestSuite) SetupTest() { @@ -71,7 +72,7 @@ func (suite *MsgTestSuite) SetupTest() { Prove: true, }) - suite.proof = commitment.Proof{Proof: res.Proof} + suite.proof = commitmenttypes.MerkleProof{Proof: res.Proof} } func TestMsgTestSuite(t *testing.T) { @@ -191,17 +192,17 @@ func (suite *MsgTestSuite) TestMsgChannelOpenTry() { // TestMsgChannelOpenAck tests ValidateBasic for MsgChannelOpenAck func (suite *MsgTestSuite) TestMsgChannelOpenAck() { testMsgs := []MsgChannelOpenAck{ - NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 1, addr), // valid msg - NewMsgChannelOpenAck(invalidShortPort, "testchannel", "1.0", suite.proof, 1, addr), // too short port id - NewMsgChannelOpenAck(invalidLongPort, "testchannel", "1.0", suite.proof, 1, addr), // too long port id - NewMsgChannelOpenAck(invalidPort, "testchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelOpenAck("testportid", invalidShortChannel, "1.0", suite.proof, 1, addr), // too short channel id - NewMsgChannelOpenAck("testportid", invalidLongChannel, "1.0", suite.proof, 1, addr), // too long channel id - NewMsgChannelOpenAck("testportid", invalidChannel, "1.0", suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelOpenAck("testportid", "testchannel", "", suite.proof, 1, addr), // empty counterparty version - NewMsgChannelOpenAck("testportid", "testchannel", "1.0", nil, 1, addr), // empty proof - NewMsgChannelOpenAck("testportid", "testchannel", "1.0", commitment.Proof{Proof: nil}, 1, addr), // empty proof - NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 0, addr), // proof height is zero + NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 1, addr), // valid msg + NewMsgChannelOpenAck(invalidShortPort, "testchannel", "1.0", suite.proof, 1, addr), // too short port id + NewMsgChannelOpenAck(invalidLongPort, "testchannel", "1.0", suite.proof, 1, addr), // too long port id + NewMsgChannelOpenAck(invalidPort, "testchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha + NewMsgChannelOpenAck("testportid", invalidShortChannel, "1.0", suite.proof, 1, addr), // too short channel id + NewMsgChannelOpenAck("testportid", invalidLongChannel, "1.0", suite.proof, 1, addr), // too long channel id + NewMsgChannelOpenAck("testportid", invalidChannel, "1.0", suite.proof, 1, addr), // channel id contains non-alpha + NewMsgChannelOpenAck("testportid", "testchannel", "", suite.proof, 1, addr), // empty counterparty version + NewMsgChannelOpenAck("testportid", "testchannel", "1.0", nil, 1, addr), // empty proof + NewMsgChannelOpenAck("testportid", "testchannel", "1.0", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof + NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 0, addr), // proof height is zero } testCases := []struct { @@ -235,16 +236,16 @@ func (suite *MsgTestSuite) TestMsgChannelOpenAck() { // TestMsgChannelOpenConfirm tests ValidateBasic for MsgChannelOpenConfirm func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() { testMsgs := []MsgChannelOpenConfirm{ - NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg - NewMsgChannelOpenConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id - NewMsgChannelOpenConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id - NewMsgChannelOpenConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelOpenConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id - NewMsgChannelOpenConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id - NewMsgChannelOpenConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelOpenConfirm("testportid", "testchannel", nil, 1, addr), // empty proof - NewMsgChannelOpenConfirm("testportid", "testchannel", commitment.Proof{Proof: nil}, 1, addr), // empty proof - NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero + NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg + NewMsgChannelOpenConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id + NewMsgChannelOpenConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id + NewMsgChannelOpenConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha + NewMsgChannelOpenConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id + NewMsgChannelOpenConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id + NewMsgChannelOpenConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha + NewMsgChannelOpenConfirm("testportid", "testchannel", nil, 1, addr), // empty proof + NewMsgChannelOpenConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof + NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero } testCases := []struct { @@ -313,16 +314,16 @@ func (suite *MsgTestSuite) TestMsgChannelCloseInit() { // TestMsgChannelCloseConfirm tests ValidateBasic for MsgChannelCloseConfirm func (suite *MsgTestSuite) TestMsgChannelCloseConfirm() { testMsgs := []MsgChannelCloseConfirm{ - NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg - NewMsgChannelCloseConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id - NewMsgChannelCloseConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id - NewMsgChannelCloseConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelCloseConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id - NewMsgChannelCloseConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id - NewMsgChannelCloseConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelCloseConfirm("testportid", "testchannel", nil, 1, addr), // empty proof - NewMsgChannelCloseConfirm("testportid", "testchannel", commitment.Proof{Proof: nil}, 1, addr), // empty proof - NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero + NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg + NewMsgChannelCloseConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id + NewMsgChannelCloseConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id + NewMsgChannelCloseConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha + NewMsgChannelCloseConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id + NewMsgChannelCloseConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id + NewMsgChannelCloseConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha + NewMsgChannelCloseConfirm("testportid", "testchannel", nil, 1, addr), // empty proof + NewMsgChannelCloseConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof + NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero } testCases := []struct { @@ -406,8 +407,8 @@ var ( invalidPacket = NewPacket(invalidPacketT{}, 0, portid, chanid, cpportid, cpchanid) invalidAck = invalidAckT{} - emptyProof = commitment.Proof{Proof: nil} - invalidProofs1 = commitment.ProofI(nil) + emptyProof = commitmenttypes.MerkleProof{Proof: nil} + invalidProofs1 = commitmentexported.Proof(nil) invalidProofs2 = emptyProof addr1 = sdk.AccAddress("testaddr1") @@ -475,7 +476,7 @@ func TestMsgPacketGetSignBytes(t *testing.T) { SubModuleCdc.RegisterConcrete(validPacketT{}, "test/validPacketT", nil) res := msg.GetSignBytes() - expected := `{"packet":{"data":{"type":"test/validPacketT","value":{}},"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid"},"proof":{"type":"ibc/commitment/merkle/Proof","value":{"proof":{"ops":[]}}},"proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}` + expected := `{"packet":{"data":{"type":"test/validPacketT","value":{}},"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid"},"proof":{"type":"ibc/commitment/MerkleProof","value":{"proof":{"ops":[]}}},"proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}` require.Equal(t, expected, string(res)) } diff --git a/x/ibc/04-channel/types/querier.go b/x/ibc/04-channel/types/querier.go index 37b24559ba20..fdedeca408b6 100644 --- a/x/ibc/04-channel/types/querier.go +++ b/x/ibc/04-channel/types/querier.go @@ -5,7 +5,7 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -18,10 +18,10 @@ const ( // ChannelResponse defines the client query response for a channel which also // includes a proof,its path and the height from which the proof was retrieved. type ChannelResponse struct { - Channel Channel `json:"channel" yaml:"channel"` - Proof commitment.Proof `json:"proof,omitempty" yaml:"proof,omitempty"` - ProofPath commitment.Path `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` - ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` + Channel Channel `json:"channel" yaml:"channel"` + Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"` + ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` + ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` } // NewChannelResponse creates a new ChannelResponse instance @@ -30,8 +30,8 @@ func NewChannelResponse( ) ChannelResponse { return ChannelResponse{ Channel: channel, - Proof: commitment.Proof{Proof: proof}, - ProofPath: commitment.NewPath(strings.Split(ibctypes.ChannelPath(portID, channelID), "/")), + Proof: commitmenttypes.MerkleProof{Proof: proof}, + ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ChannelPath(portID, channelID), "/")), ProofHeight: uint64(height), } } @@ -54,10 +54,10 @@ func NewQueryAllChannelsParams(page, limit int) QueryAllChannelsParams { // PacketResponse defines the client query response for a packet which also // includes a proof, its path and the height form which the proof was retrieved type PacketResponse struct { - Packet Packet `json:"packet" yaml:"packet"` - Proof commitment.Proof `json:"proof,omitempty" yaml:"proof,omitempty"` - ProofPath commitment.Path `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` - ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` + Packet Packet `json:"packet" yaml:"packet"` + Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"` + ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` + ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` } // NewPacketResponse creates a new PacketResponswe instance @@ -66,8 +66,8 @@ func NewPacketResponse( ) PacketResponse { return PacketResponse{ Packet: packet, - Proof: commitment.Proof{Proof: proof}, - ProofPath: commitment.NewPath(strings.Split(ibctypes.PacketCommitmentPath(portID, channelID, sequence), "/")), + Proof: commitmenttypes.MerkleProof{Proof: proof}, + ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.PacketCommitmentPath(portID, channelID, sequence), "/")), ProofHeight: uint64(height), } } @@ -76,10 +76,10 @@ func NewPacketResponse( // number which also includes a proof, its path and the height form which the // proof was retrieved type RecvResponse struct { - NextSequenceRecv uint64 `json:"next_sequence_recv" yaml:"next_sequence_recv"` - Proof commitment.Proof `json:"proof,omitempty" yaml:"proof,omitempty"` - ProofPath commitment.Path `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` - ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` + NextSequenceRecv uint64 `json:"next_sequence_recv" yaml:"next_sequence_recv"` + Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"` + ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"` + ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"` } // NewRecvResponse creates a new RecvResponse instance @@ -88,8 +88,8 @@ func NewRecvResponse( ) RecvResponse { return RecvResponse{ NextSequenceRecv: sequenceRecv, - Proof: commitment.Proof{Proof: proof}, - ProofPath: commitment.NewPath(strings.Split(ibctypes.NextSequenceRecvPath(portID, channelID), "/")), + Proof: commitmenttypes.MerkleProof{Proof: proof}, + ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.NextSequenceRecvPath(portID, channelID), "/")), ProofHeight: uint64(height), } } diff --git a/x/ibc/07-tendermint/client/rest/swagger.go b/x/ibc/07-tendermint/client/rest/swagger.go index 32bb8761f3de..884ab3c2dd56 100644 --- a/x/ibc/07-tendermint/client/rest/swagger.go +++ b/x/ibc/07-tendermint/client/rest/swagger.go @@ -9,22 +9,22 @@ import ( type ( PostCreateClient struct { Msgs []ibctmtypes.MsgCreateClient `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostUpdateClient struct { Msgs []ibctmtypes.MsgUpdateClient `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` Memo string `json:"memo" yaml:"memo"` } PostSubmitMisbehaviour struct { Msgs []ibctmtypes.MsgSubmitClientMisbehaviour `json:"msg" yaml:"msg"` - Fee authtypes.StdFee `json:"fee" yaml:"fee"` - Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` - Memo string `json:"memo" yaml:"memo"` + Fee authtypes.StdFee `json:"fee" yaml:"fee"` + Signatures []authtypes.StdSignature `json:"signatures" yaml:"signatures"` + Memo string `json:"memo" yaml:"memo"` } ) diff --git a/x/ibc/07-tendermint/misbehaviour.go b/x/ibc/07-tendermint/misbehaviour.go index df6009a14164..d373e2e5afd1 100644 --- a/x/ibc/07-tendermint/misbehaviour.go +++ b/x/ibc/07-tendermint/misbehaviour.go @@ -5,12 +5,13 @@ import ( "fmt" "time" + lite "github.com/tendermint/tendermint/lite2" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" - lite "github.com/tendermint/tendermint/lite2" ) // CheckMisbehaviourAndUpdateState determines whether or not two conflicting diff --git a/x/ibc/07-tendermint/misbehaviour_test.go b/x/ibc/07-tendermint/misbehaviour_test.go index 4387af1cf7b1..8796b4af755d 100644 --- a/x/ibc/07-tendermint/misbehaviour_test.go +++ b/x/ibc/07-tendermint/misbehaviour_test.go @@ -8,7 +8,7 @@ import ( 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" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) func (suite *TendermintTestSuite) TestCheckMisbehaviour() { @@ -41,7 +41,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { { "valid misbehavior evidence", ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), - ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitment.NewRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, + ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, suite.valSet, bothSigners), Header2: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothValSet, bothSigners), @@ -54,7 +54,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { { "valid misbehavior at height greater than last consensusState", ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), - ibctmtypes.ConsensusState{Timestamp: suite.now, Height: height - 1, Root: commitment.NewRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, + ibctmtypes.ConsensusState{Timestamp: suite.now, Height: height - 1, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, suite.valSet, bothSigners), Header2: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothValSet, bothSigners), @@ -67,7 +67,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { { "consensus state's valset hash different from evidence should still pass", ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), - ibctmtypes.ConsensusState{Timestamp: suite.now, Height: height - 1, Root: commitment.NewRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: suite.valSet}, + ibctmtypes.ConsensusState{Timestamp: suite.now, Height: height - 1, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: suite.valSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, suite.valSet, bothSigners), Header2: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothValSet, bothSigners), @@ -80,7 +80,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { { "first valset has too much change", ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), - ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitment.NewRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, + ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, altValSet, bothValSet, altSigners), Header2: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothValSet, bothSigners), @@ -93,7 +93,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { { "second valset has too much change", ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), - ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitment.NewRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, + ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothValSet, bothSigners), Header2: ibctmtypes.CreateTestHeader(chainID, height, suite.now, altValSet, bothValSet, altSigners), @@ -106,7 +106,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { { "both valsets have too much change", ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), - ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitment.NewRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, + ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, altValSet, altValSet, altSigners), Header2: ibctmtypes.CreateTestHeader(chainID, height, suite.now, altValSet, bothValSet, altSigners), diff --git a/x/ibc/07-tendermint/tendermint_test.go b/x/ibc/07-tendermint/tendermint_test.go index c8c465cdc7f8..6339812a8b97 100644 --- a/x/ibc/07-tendermint/tendermint_test.go +++ b/x/ibc/07-tendermint/tendermint_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) const ( @@ -36,7 +36,7 @@ func (suite *TendermintTestSuite) SetupTest() { suite.cdc = codec.New() codec.RegisterCrypto(suite.cdc) ibctmtypes.RegisterCodec(suite.cdc) - commitment.RegisterCodec(suite.cdc) + commitmenttypes.RegisterCodec(suite.cdc) // now is the time of the current chain, must be after the updating header // mocks ctx.BlockTime() diff --git a/x/ibc/07-tendermint/types/client_state.go b/x/ibc/07-tendermint/types/client_state.go index 2081a96333e9..94cb54250942 100644 --- a/x/ibc/07-tendermint/types/client_state.go +++ b/x/ibc/07-tendermint/types/client_state.go @@ -12,7 +12,8 @@ import ( clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -106,11 +107,11 @@ func (cs ClientState) IsFrozen() bool { func (cs ClientState) VerifyClientConsensusState( cdc *codec.Codec, height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, consensusState clientexported.ConsensusState, ) error { - path, err := commitment.ApplyPrefix(prefix, ibctypes.ConsensusStatePath(cs.GetID(), height)) + path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ConsensusStatePath(cs.GetID(), height)) if err != nil { return err } @@ -136,13 +137,13 @@ func (cs ClientState) VerifyClientConsensusState( func (cs ClientState) VerifyConnectionState( cdc *codec.Codec, height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, connectionID string, connectionEnd connectionexported.ConnectionI, consensusState clientexported.ConsensusState, ) error { - path, err := commitment.ApplyPrefix(prefix, ibctypes.ConnectionPath(connectionID)) + path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ConnectionPath(connectionID)) if err != nil { return err } @@ -168,14 +169,14 @@ func (cs ClientState) VerifyConnectionState( func (cs ClientState) VerifyChannelState( cdc *codec.Codec, height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, channel channelexported.ChannelI, consensusState clientexported.ConsensusState, ) error { - path, err := commitment.ApplyPrefix(prefix, ibctypes.ChannelPath(portID, channelID)) + path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ChannelPath(portID, channelID)) if err != nil { return err } @@ -200,15 +201,15 @@ func (cs ClientState) VerifyChannelState( // the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketCommitment( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, commitmentBytes []byte, consensusState clientexported.ConsensusState, ) error { - path, err := commitment.ApplyPrefix(prefix, ibctypes.PacketCommitmentPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketCommitmentPath(portID, channelID, sequence)) if err != nil { return err } @@ -228,15 +229,15 @@ func (cs ClientState) VerifyPacketCommitment( // acknowledgement at the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketAcknowledgement( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, acknowledgement []byte, consensusState clientexported.ConsensusState, ) error { - path, err := commitment.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) if err != nil { return err } @@ -257,14 +258,14 @@ func (cs ClientState) VerifyPacketAcknowledgement( // specified sequence. func (cs ClientState) VerifyPacketAcknowledgementAbsence( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, sequence uint64, consensusState clientexported.ConsensusState, ) error { - path, err := commitment.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) if err != nil { return err } @@ -284,14 +285,14 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence( // received of the specified channel at the specified port. func (cs ClientState) VerifyNextSequenceRecv( height uint64, - prefix commitment.PrefixI, - proof commitment.ProofI, + prefix commitmentexported.Prefix, + proof commitmentexported.Proof, portID, channelID string, nextSequenceRecv uint64, consensusState clientexported.ConsensusState, ) error { - path, err := commitment.ApplyPrefix(prefix, ibctypes.NextSequenceRecvPath(portID, channelID)) + path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.NextSequenceRecvPath(portID, channelID)) if err != nil { return err } @@ -314,7 +315,7 @@ func (cs ClientState) VerifyNextSequenceRecv( func validateVerificationArgs( cs ClientState, height uint64, - proof commitment.ProofI, + proof commitmentexported.Proof, consensusState clientexported.ConsensusState, ) error { if cs.GetLatestHeight() < height { @@ -329,7 +330,7 @@ func validateVerificationArgs( } if proof == nil { - return sdkerrors.Wrap(commitment.ErrInvalidProof, "proof cannot be empty") + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "proof cannot be empty") } if consensusState == nil { diff --git a/x/ibc/07-tendermint/types/client_state_test.go b/x/ibc/07-tendermint/types/client_state_test.go index 5f392be235e5..5eb2705b6cb7 100644 --- a/x/ibc/07-tendermint/types/client_state_test.go +++ b/x/ibc/07-tendermint/types/client_state_test.go @@ -6,7 +6,7 @@ import ( channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) const ( @@ -21,55 +21,55 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() { name string clientState ibctmtypes.ClientState consensusState ibctmtypes.ConsensusState - prefix commitment.Prefix - proof commitment.Proof + prefix commitmenttypes.MerklePrefix + proof commitmenttypes.MerkleProof expPass bool }{ // { // name: "successful verification", // clientState: ibctmtypes.NewClientState(chainID, chainID, height), // consensusState: ibctmtypes.ConsensusState{ - // Root: commitment.NewRoot(suite.header.AppHash), + // Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), // }, - // prefix: commitment.NewPrefix([]byte("ibc")), + // prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), // expPass: true, // }, { name: "ApplyPrefix failed", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.Prefix{}, + prefix: commitmenttypes.MerklePrefix{}, expPass: false, }, { name: "latest client height < height", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { name: "client is frozen", clientState: ibctmtypes.ClientState{ID: chainID, LastHeader: suite.header, FrozenHeight: height - 1}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { name: "proof verification failed", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, }, - prefix: commitment.NewPrefix([]byte("ibc")), - proof: commitment.Proof{}, + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), + proof: commitmenttypes.MerkleProof{}, expPass: false, }, } @@ -90,7 +90,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() { } func (suite *TendermintTestSuite) TestVerifyConnectionState() { - counterparty := connection.NewCounterparty("clientB", testConnectionID, commitment.NewPrefix([]byte("ibc"))) + counterparty := connection.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc"))) conn := connection.NewConnectionEnd(connectionexported.OPEN, "clientA", counterparty, []string{"1.0.0"}) testCases := []struct { @@ -98,8 +98,8 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { clientState ibctmtypes.ClientState connection connection.ConnectionEnd consensusState ibctmtypes.ConsensusState - prefix commitment.Prefix - proof commitment.Proof + prefix commitmenttypes.MerklePrefix + proof commitmenttypes.MerkleProof expPass bool }{ // { @@ -107,9 +107,9 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { // clientState: ibctmtypes.NewClientState(chainID, chainID, height), // connection: conn, // consensusState: ibctmtypes.ConsensusState{ - // Root: commitment.NewRoot(suite.header.AppHash), + // Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), // }, - // prefix: commitment.NewPrefix([]byte("ibc")), + // prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), // expPass: true, // }, { @@ -117,9 +117,9 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), connection: conn, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.Prefix{}, + prefix: commitmenttypes.MerklePrefix{}, expPass: false, }, { @@ -127,9 +127,9 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), connection: conn, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -137,9 +137,9 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { clientState: ibctmtypes.ClientState{ID: chainID, LastHeader: suite.header, FrozenHeight: height - 1}, connection: conn, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -147,11 +147,11 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), connection: conn, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, }, - prefix: commitment.NewPrefix([]byte("ibc")), - proof: commitment.Proof{}, + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), + proof: commitmenttypes.MerkleProof{}, expPass: false, }, } @@ -180,8 +180,8 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { clientState ibctmtypes.ClientState channel channel.Channel consensusState ibctmtypes.ConsensusState - prefix commitment.Prefix - proof commitment.Proof + prefix commitmenttypes.MerklePrefix + proof commitmenttypes.MerkleProof expPass bool }{ // { @@ -189,9 +189,9 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { // clientState: ibctmtypes.NewClientState(chainID, height), // connection: conn, // consensusState: ibctmtypes.ConsensusState{ - // Root: commitment.NewRoot(suite.header.AppHash), + // Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), // }, - // prefix: commitment.NewPrefix([]byte("ibc")), + // prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), // expPass: true, // }, { @@ -199,9 +199,9 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), channel: ch, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.Prefix{}, + prefix: commitmenttypes.MerklePrefix{}, expPass: false, }, { @@ -209,9 +209,9 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), channel: ch, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -219,9 +219,9 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { clientState: ibctmtypes.ClientState{ID: chainID, LastHeader: suite.header, FrozenHeight: height - 1}, channel: ch, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -229,11 +229,11 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), channel: ch, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, }, - prefix: commitment.NewPrefix([]byte("ibc")), - proof: commitment.Proof{}, + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), + proof: commitmenttypes.MerkleProof{}, expPass: false, }, } @@ -259,8 +259,8 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { clientState ibctmtypes.ClientState commitment []byte consensusState ibctmtypes.ConsensusState - prefix commitment.Prefix - proof commitment.Proof + prefix commitmenttypes.MerklePrefix + proof commitmenttypes.MerkleProof expPass bool }{ // { @@ -268,9 +268,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { // clientState: ibctmtypes.NewClientState(chainID, height), // connection: conn, // consensusState: ibctmtypes.ConsensusState{ - // Root: commitment.NewRoot(suite.header.AppHash), + // Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), // }, - // prefix: commitment.NewPrefix([]byte("ibc")), + // prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), // expPass: true, // }, { @@ -278,9 +278,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), commitment: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.Prefix{}, + prefix: commitmenttypes.MerklePrefix{}, expPass: false, }, { @@ -288,9 +288,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), commitment: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -298,9 +298,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { clientState: ibctmtypes.ClientState{ID: chainID, LastHeader: suite.header, FrozenHeight: height - 1}, commitment: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -308,11 +308,11 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), commitment: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, }, - prefix: commitment.NewPrefix([]byte("ibc")), - proof: commitment.Proof{}, + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), + proof: commitmenttypes.MerkleProof{}, expPass: false, }, } @@ -338,8 +338,8 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { clientState ibctmtypes.ClientState ack []byte consensusState ibctmtypes.ConsensusState - prefix commitment.Prefix - proof commitment.Proof + prefix commitmenttypes.MerklePrefix + proof commitmenttypes.MerkleProof expPass bool }{ // { @@ -347,9 +347,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { // clientState: ibctmtypes.NewClientState(chainID, chainID, height), // connection: conn, // consensusState: ibctmtypes.ConsensusState{ - // Root: commitment.NewRoot(suite.header.AppHash), + // Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), // }, - // prefix: commitment.NewPrefix([]byte("ibc")), + // prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), // expPass: true, // }, { @@ -357,9 +357,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), ack: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.Prefix{}, + prefix: commitmenttypes.MerklePrefix{}, expPass: false, }, { @@ -367,9 +367,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), ack: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -377,9 +377,9 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { clientState: ibctmtypes.ClientState{ID: chainID, LastHeader: suite.header, FrozenHeight: height - 1}, ack: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { @@ -387,11 +387,11 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), ack: []byte{}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, }, - prefix: commitment.NewPrefix([]byte("ibc")), - proof: commitment.Proof{}, + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), + proof: commitmenttypes.MerkleProof{}, expPass: false, }, } @@ -416,8 +416,8 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() { name string clientState ibctmtypes.ClientState consensusState ibctmtypes.ConsensusState - prefix commitment.Prefix - proof commitment.Proof + prefix commitmenttypes.MerklePrefix + proof commitmenttypes.MerkleProof expPass bool }{ // { @@ -425,47 +425,47 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() { // clientState: ibctmtypes.NewClientState(chainID, chainID, height), // connection: conn, // consensusState: ibctmtypes.ConsensusState{ - // Root: commitment.NewRoot(suite.header.AppHash), + // Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), // }, - // prefix: commitment.NewPrefix([]byte("ibc")), + // prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), // expPass: true, // }, { name: "ApplyPrefix failed", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.Prefix{}, + prefix: commitmenttypes.MerklePrefix{}, expPass: false, }, { name: "latest client height < height", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { name: "client is frozen", clientState: ibctmtypes.ClientState{ID: chainID, LastHeader: suite.header, FrozenHeight: height - 1}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { name: "proof verification failed", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, }, - prefix: commitment.NewPrefix([]byte("ibc")), - proof: commitment.Proof{}, + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), + proof: commitmenttypes.MerkleProof{}, expPass: false, }, } @@ -490,8 +490,8 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { name string clientState ibctmtypes.ClientState consensusState ibctmtypes.ConsensusState - prefix commitment.Prefix - proof commitment.Proof + prefix commitmenttypes.MerklePrefix + proof commitmenttypes.MerkleProof expPass bool }{ // { @@ -499,47 +499,47 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { // clientState: ibctmtypes.NewClientState(chainID, chainID, height), // connection: conn, // consensusState: ibctmtypes.ConsensusState{ - // Root: commitment.NewRoot(suite.header.AppHash), + // Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), // }, - // prefix: commitment.NewPrefix([]byte("ibc")), + // prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), // expPass: true, // }, { name: "ApplyPrefix failed", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.Prefix{}, + prefix: commitmenttypes.MerklePrefix{}, expPass: false, }, { name: "latest client height < height", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { name: "client is frozen", clientState: ibctmtypes.ClientState{ID: chainID, LastHeader: suite.header, FrozenHeight: height - 1}, consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, - prefix: commitment.NewPrefix([]byte("ibc")), + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), expPass: false, }, { name: "proof verification failed", clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, suite.header), consensusState: ibctmtypes.ConsensusState{ - Root: commitment.NewRoot(suite.header.AppHash), + Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, }, - prefix: commitment.NewPrefix([]byte("ibc")), - proof: commitment.Proof{}, + prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")), + proof: commitmenttypes.MerkleProof{}, expPass: false, }, } diff --git a/x/ibc/07-tendermint/types/consensus_state.go b/x/ibc/07-tendermint/types/consensus_state.go index cba067f9a918..801fc768f181 100644 --- a/x/ibc/07-tendermint/types/consensus_state.go +++ b/x/ibc/07-tendermint/types/consensus_state.go @@ -3,19 +3,20 @@ package types import ( "time" + tmtypes "github.com/tendermint/tendermint/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" - tmtypes "github.com/tendermint/tendermint/types" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // ConsensusState defines a Tendermint consensus state type ConsensusState struct { - Timestamp time.Time `json:"timestamp" yaml:"timestamp"` - Root commitment.RootI `json:"root" yaml:"root"` - Height uint64 `json:"height" yaml:"height"` - ValidatorSet *tmtypes.ValidatorSet `json:"validator_set" yaml:"validator_set"` + Timestamp time.Time `json:"timestamp" yaml:"timestamp"` + Root commitmentexported.Root `json:"root" yaml:"root"` + Height uint64 `json:"height" yaml:"height"` + ValidatorSet *tmtypes.ValidatorSet `json:"validator_set" yaml:"validator_set"` } // ClientType returns Tendermint @@ -24,7 +25,7 @@ func (ConsensusState) ClientType() clientexported.ClientType { } // GetRoot returns the commitment Root for the specific -func (cs ConsensusState) GetRoot() commitment.RootI { +func (cs ConsensusState) GetRoot() commitmentexported.Root { return cs.Root } diff --git a/x/ibc/07-tendermint/types/consensus_state_test.go b/x/ibc/07-tendermint/types/consensus_state_test.go index c50be3483e5f..ac1229b40568 100644 --- a/x/ibc/07-tendermint/types/consensus_state_test.go +++ b/x/ibc/07-tendermint/types/consensus_state_test.go @@ -5,7 +5,7 @@ import ( clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() { @@ -18,7 +18,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() { ibctmtypes.ConsensusState{ Timestamp: suite.now, Height: height, - Root: commitment.NewRoot([]byte("app_hash")), + Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")), ValidatorSet: suite.valSet, }, true}, @@ -34,7 +34,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() { ibctmtypes.ConsensusState{ Timestamp: suite.now, Height: height, - Root: commitment.Root{}, + Root: commitmenttypes.MerkleRoot{}, ValidatorSet: suite.valSet, }, false}, @@ -42,7 +42,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() { ibctmtypes.ConsensusState{ Timestamp: suite.now, Height: height, - Root: commitment.NewRoot([]byte("app_hash")), + Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")), ValidatorSet: nil, }, false}, @@ -50,7 +50,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() { ibctmtypes.ConsensusState{ Timestamp: suite.now, Height: 0, - Root: commitment.NewRoot([]byte("app_hash")), + Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")), ValidatorSet: suite.valSet, }, false}, @@ -58,7 +58,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() { ibctmtypes.ConsensusState{ Timestamp: time.Time{}, Height: height, - Root: commitment.NewRoot([]byte("app_hash")), + Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")), ValidatorSet: suite.valSet, }, false}, diff --git a/x/ibc/07-tendermint/types/header.go b/x/ibc/07-tendermint/types/header.go index ddc5e01f458a..7b5d6e047979 100644 --- a/x/ibc/07-tendermint/types/header.go +++ b/x/ibc/07-tendermint/types/header.go @@ -9,7 +9,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) var _ clientexported.Header = Header{} @@ -31,7 +31,7 @@ func (h Header) ConsensusState() ConsensusState { return ConsensusState{ Height: uint64(h.Height), Timestamp: h.Time, - Root: commitment.NewRoot(h.AppHash), + Root: commitmenttypes.NewMerkleRoot(h.AppHash), ValidatorSet: h.ValidatorSet, } } diff --git a/x/ibc/07-tendermint/types/msgs.go b/x/ibc/07-tendermint/types/msgs.go index aec1d3a0b9a0..955d1342ab3f 100644 --- a/x/ibc/07-tendermint/types/msgs.go +++ b/x/ibc/07-tendermint/types/msgs.go @@ -8,21 +8,21 @@ import ( evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // Message types for the IBC client const ( - TypeMsgCreateClient string = "create_client" - TypeMsgUpdateClient string = "update_client" + TypeMsgCreateClient string = "create_client" + TypeMsgUpdateClient string = "update_client" TypeMsgSubmitClientMisbehaviour string = "submit_client_misbehaviour" ) var ( - _ clientexported.MsgCreateClient = MsgCreateClient{} - _ clientexported.MsgUpdateClient = MsgUpdateClient{} + _ clientexported.MsgCreateClient = MsgCreateClient{} + _ clientexported.MsgUpdateClient = MsgUpdateClient{} _ evidenceexported.MsgSubmitEvidence = MsgSubmitClientMisbehaviour{} ) @@ -100,7 +100,7 @@ func (msg MsgCreateClient) GetClientType() string { // GetConsensusState implements clientexported.MsgCreateClient func (msg MsgCreateClient) GetConsensusState() clientexported.ConsensusState { // Construct initial consensus state from provided Header - root := commitment.NewRoot(msg.Header.AppHash) + root := commitmenttypes.NewMerkleRoot(msg.Header.AppHash) return ConsensusState{ Timestamp: msg.Header.Time, Root: root, @@ -163,49 +163,49 @@ func (msg MsgUpdateClient) GetHeader() clientexported.Header { return msg.Header } -// MsgSubmitClientMisbehaviour defines an sdk.Msg type that supports submitting -// Evidence for client misbehaviour. -type MsgSubmitClientMisbehaviour struct { - Evidence evidenceexported.Evidence `json:"evidence" yaml:"evidence"` - Submitter sdk.AccAddress `json:"submitter" yaml:"submitter"` +// MsgSubmitClientMisbehaviour defines an sdk.Msg type that supports submitting +// Evidence for client misbehaviour. +type MsgSubmitClientMisbehaviour struct { + Evidence evidenceexported.Evidence `json:"evidence" yaml:"evidence"` + Submitter sdk.AccAddress `json:"submitter" yaml:"submitter"` } // NewMsgSubmitClientMisbehaviour creates a new MsgSubmitClientMisbehaviour // instance. -func NewMsgSubmitClientMisbehaviour(e evidenceexported.Evidence, s sdk.AccAddress) MsgSubmitClientMisbehaviour { - return MsgSubmitClientMisbehaviour{Evidence: e, Submitter: s} -} - -// Route returns the MsgSubmitClientMisbehaviour's route. -func (msg MsgSubmitClientMisbehaviour) Route() string { return ibctypes.RouterKey } - -// Type returns the MsgSubmitClientMisbehaviour's type. -func (msg MsgSubmitClientMisbehaviour) Type() string { return TypeMsgSubmitClientMisbehaviour } - -// ValidateBasic performs basic (non-state-dependant) validation on a MsgSubmitClientMisbehaviour. -func (msg MsgSubmitClientMisbehaviour) ValidateBasic() error { - if msg.Evidence == nil { - return sdkerrors.Wrap(evidencetypes.ErrInvalidEvidence, "missing evidence") - } - if err := msg.Evidence.ValidateBasic(); err != nil { - return err - } - if msg.Submitter.Empty() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Submitter.String()) - } - - return nil -} - -// GetSignBytes returns the raw bytes a signer is expected to sign when submitting -// a MsgSubmitClientMisbehaviour message. -func (msg MsgSubmitClientMisbehaviour) GetSignBytes() []byte { +func NewMsgSubmitClientMisbehaviour(e evidenceexported.Evidence, s sdk.AccAddress) MsgSubmitClientMisbehaviour { + return MsgSubmitClientMisbehaviour{Evidence: e, Submitter: s} +} + +// Route returns the MsgSubmitClientMisbehaviour's route. +func (msg MsgSubmitClientMisbehaviour) Route() string { return ibctypes.RouterKey } + +// Type returns the MsgSubmitClientMisbehaviour's type. +func (msg MsgSubmitClientMisbehaviour) Type() string { return TypeMsgSubmitClientMisbehaviour } + +// ValidateBasic performs basic (non-state-dependant) validation on a MsgSubmitClientMisbehaviour. +func (msg MsgSubmitClientMisbehaviour) ValidateBasic() error { + if msg.Evidence == nil { + return sdkerrors.Wrap(evidencetypes.ErrInvalidEvidence, "missing evidence") + } + if err := msg.Evidence.ValidateBasic(); err != nil { + return err + } + if msg.Submitter.Empty() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Submitter.String()) + } + + return nil +} + +// GetSignBytes returns the raw bytes a signer is expected to sign when submitting +// a MsgSubmitClientMisbehaviour message. +func (msg MsgSubmitClientMisbehaviour) GetSignBytes() []byte { return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) -} +} -// GetSigners returns the single expected signer for a MsgSubmitClientMisbehaviour. -func (msg MsgSubmitClientMisbehaviour) GetSigners() []sdk.AccAddress { - return []sdk.AccAddress{msg.Submitter} +// GetSigners returns the single expected signer for a MsgSubmitClientMisbehaviour. +func (msg MsgSubmitClientMisbehaviour) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{msg.Submitter} } func (msg MsgSubmitClientMisbehaviour) GetEvidence() evidenceexported.Evidence { @@ -214,4 +214,4 @@ func (msg MsgSubmitClientMisbehaviour) GetEvidence() evidenceexported.Evidence { func (msg MsgSubmitClientMisbehaviour) GetSubmitter() sdk.AccAddress { return msg.Submitter -} \ No newline at end of file +} diff --git a/x/ibc/07-tendermint/types/tendermint_test.go b/x/ibc/07-tendermint/types/tendermint_test.go index d4d71cc91ce2..5b4ecb9338ab 100644 --- a/x/ibc/07-tendermint/types/tendermint_test.go +++ b/x/ibc/07-tendermint/types/tendermint_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) const ( @@ -34,7 +34,7 @@ func (suite *TendermintTestSuite) SetupTest() { suite.cdc = codec.New() codec.RegisterCrypto(suite.cdc) ibctmtypes.RegisterCodec(suite.cdc) - commitment.RegisterCodec(suite.cdc) + commitmenttypes.RegisterCodec(suite.cdc) suite.now = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC) suite.privVal = tmtypes.NewMockPV() diff --git a/x/ibc/07-tendermint/update.go b/x/ibc/07-tendermint/update.go index 9f21eb7d8ce2..efc85eb81de8 100644 --- a/x/ibc/07-tendermint/update.go +++ b/x/ibc/07-tendermint/update.go @@ -4,12 +4,13 @@ import ( "errors" "time" + lite "github.com/tendermint/tendermint/lite2" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" - lite "github.com/tendermint/tendermint/lite2" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) // CheckValidityAndUpdateState checks if the provided header is valid and updates @@ -93,7 +94,7 @@ func update(clientState types.ClientState, header types.Header) (types.ClientSta consensusState := types.ConsensusState{ Height: uint64(header.Height), Timestamp: header.Time, - Root: commitment.NewRoot(header.AppHash), + Root: commitmenttypes.NewMerkleRoot(header.AppHash), ValidatorSet: header.ValidatorSet, } diff --git a/x/ibc/07-tendermint/update_test.go b/x/ibc/07-tendermint/update_test.go index 025c480aa4f0..3f293e882126 100644 --- a/x/ibc/07-tendermint/update_test.go +++ b/x/ibc/07-tendermint/update_test.go @@ -4,10 +4,11 @@ import ( "bytes" "time" + tmtypes "github.com/tendermint/tendermint/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" - tmtypes "github.com/tendermint/tendermint/types" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) func (suite *TendermintTestSuite) TestCheckValidity() { @@ -148,7 +149,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { expectedConsensus := ibctmtypes.ConsensusState{ Height: uint64(newHeader.Height), Timestamp: newHeader.Time, - Root: commitment.NewRoot(newHeader.AppHash), + Root: commitmenttypes.NewMerkleRoot(newHeader.AppHash), ValidatorSet: newHeader.ValidatorSet, } diff --git a/x/ibc/20-transfer/handler_test.go b/x/ibc/20-transfer/handler_test.go index 98f9c8a1acc8..d53905bb5c89 100644 --- a/x/ibc/20-transfer/handler_test.go +++ b/x/ibc/20-transfer/handler_test.go @@ -21,7 +21,7 @@ import ( ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" transfer "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" @@ -73,7 +73,7 @@ func (suite *HandlerTestSuite) SetupTest() { suite.cdc = suite.chainA.App.Codec() } -func (suite *HandlerTestSuite) queryProof(key []byte) (proof commitment.Proof, height int64) { +func (suite *HandlerTestSuite) queryProof(key []byte) (proof commitmenttypes.MerkleProof, height int64) { res := suite.chainA.App.Query(abci.RequestQuery{ Path: fmt.Sprintf("store/%s/key", ibctypes.StoreKey), Data: key, @@ -81,7 +81,7 @@ func (suite *HandlerTestSuite) queryProof(key []byte) (proof commitment.Proof, h }) height = res.Height - proof = commitment.Proof{ + proof = commitmenttypes.MerkleProof{ Proof: res.Proof, } @@ -261,7 +261,7 @@ func (chain *TestChain) updateClient(client *TestChain) { consensusState := ibctmtypes.ConsensusState{ Height: uint64(client.Header.Height), Timestamp: client.Header.Time, - Root: commitment.NewRoot(commitID.Hash), + Root: commitmenttypes.NewMerkleRoot(commitID.Hash), ValidatorSet: client.Vals, } diff --git a/x/ibc/20-transfer/keeper/keeper_test.go b/x/ibc/20-transfer/keeper/keeper_test.go index dfb75aa17438..5f509169cbbe 100644 --- a/x/ibc/20-transfer/keeper/keeper_test.go +++ b/x/ibc/20-transfer/keeper/keeper_test.go @@ -21,7 +21,7 @@ import ( channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) SetupTest() { } // nolint: unused -func (suite *KeeperTestSuite) queryProof(key []byte) (proof commitment.Proof, height int64) { +func (suite *KeeperTestSuite) queryProof(key []byte) (proof commitmenttypes.MerkleProof, height int64) { res := suite.chainA.App.Query(abci.RequestQuery{ Path: fmt.Sprintf("store/%s/key", ibctypes.StoreKey), Data: key, @@ -81,7 +81,7 @@ func (suite *KeeperTestSuite) queryProof(key []byte) (proof commitment.Proof, he }) height = res.Height - proof = commitment.Proof{ + proof = commitmenttypes.MerkleProof{ Proof: res.Proof, } @@ -223,7 +223,7 @@ func (chain *TestChain) updateClient(client *TestChain) { consensusState := ibctmtypes.ConsensusState{ Height: uint64(client.Header.Height), Timestamp: client.Header.Time, - Root: commitment.NewRoot(commitID.Hash), + Root: commitmenttypes.NewMerkleRoot(commitID.Hash), ValidatorSet: client.Vals, } diff --git a/x/ibc/20-transfer/types/codec.go b/x/ibc/20-transfer/types/codec.go index 489bd6cd9dce..80c1c767b978 100644 --- a/x/ibc/20-transfer/types/codec.go +++ b/x/ibc/20-transfer/types/codec.go @@ -3,7 +3,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) // ModuleCdc defines the IBC transfer codec. @@ -18,5 +18,5 @@ func RegisterCodec(cdc *codec.Codec) { func init() { RegisterCodec(ModuleCdc) channel.RegisterCodec(ModuleCdc) - commitment.RegisterCodec(ModuleCdc) + commitmenttypes.RegisterCodec(ModuleCdc) } diff --git a/x/ibc/23-commitment/codec.go b/x/ibc/23-commitment/codec.go deleted file mode 100644 index 1fc535cfc0ca..000000000000 --- a/x/ibc/23-commitment/codec.go +++ /dev/null @@ -1,26 +0,0 @@ -package commitment - -import ( - "github.com/cosmos/cosmos-sdk/codec" -) - -var SubModuleCdc *codec.Codec - -// RegisterCodec registers types declared in this package -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*RootI)(nil), nil) - cdc.RegisterInterface((*PrefixI)(nil), nil) - cdc.RegisterInterface((*PathI)(nil), nil) - cdc.RegisterInterface((*ProofI)(nil), nil) - - cdc.RegisterConcrete(Root{}, "ibc/commitment/merkle/Root", nil) - cdc.RegisterConcrete(Prefix{}, "ibc/commitment/merkle/Prefix", nil) - cdc.RegisterConcrete(Path{}, "ibc/commitment/merkle/Path", nil) - cdc.RegisterConcrete(Proof{}, "ibc/commitment/merkle/Proof", nil) - - SetSubModuleCodec(cdc) -} - -func SetSubModuleCodec(cdc *codec.Codec) { - SubModuleCdc = cdc -} diff --git a/x/ibc/23-commitment/types.go b/x/ibc/23-commitment/exported/exported.go similarity index 78% rename from x/ibc/23-commitment/types.go rename to x/ibc/23-commitment/exported/exported.go index aaab6f9d656b..c6fbbce3ada1 100644 --- a/x/ibc/23-commitment/types.go +++ b/x/ibc/23-commitment/exported/exported.go @@ -1,4 +1,4 @@ -package commitment +package exported // ICS 023 Types Implementation // @@ -7,40 +7,40 @@ package commitment // spec:Path and spec:Value are defined as bytestring -// RootI implements spec:CommitmentRoot. +// Root implements spec:CommitmentRoot. // A root is constructed from a set of key-value pairs, // and the inclusion or non-inclusion of an arbitrary key-value pair // can be proven with the proof. -type RootI interface { +type Root interface { GetCommitmentType() Type GetHash() []byte IsEmpty() bool } -// PrefixI implements spec:CommitmentPrefix. +// Prefix implements spec:CommitmentPrefix. // Prefix represents the common "prefix" that a set of keys shares. -type PrefixI interface { +type Prefix interface { GetCommitmentType() Type Bytes() []byte IsEmpty() bool } -// PathI implements spec:CommitmentPath. +// Path implements spec:CommitmentPath. // A path is the additional information provided to the verification function. -type PathI interface { +type Path interface { GetCommitmentType() Type String() string IsEmpty() bool } -// ProofI implements spec:CommitmentProof. +// Proof implements spec:CommitmentProof. // Proof can prove whether the key-value pair is a part of the Root or not. // Each proof has designated key-value pair it is able to prove. // Proofs includes key but value is provided dynamically at the verification time. -type ProofI interface { +type Proof interface { GetCommitmentType() Type - VerifyMembership(RootI, PathI, []byte) error - VerifyNonMembership(RootI, PathI) error + VerifyMembership(Root, Path, []byte) error + VerifyNonMembership(Root, Path) error IsEmpty() bool ValidateBasic() error diff --git a/x/ibc/23-commitment/types/codec.go b/x/ibc/23-commitment/types/codec.go new file mode 100644 index 000000000000..e7e761867fc8 --- /dev/null +++ b/x/ibc/23-commitment/types/codec.go @@ -0,0 +1,27 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" +) + +var SubModuleCdc *codec.Codec + +// RegisterCodec registers types declared in this package +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterInterface((*exported.Root)(nil), nil) + cdc.RegisterInterface((*exported.Prefix)(nil), nil) + cdc.RegisterInterface((*exported.Path)(nil), nil) + cdc.RegisterInterface((*exported.Proof)(nil), nil) + + cdc.RegisterConcrete(MerkleRoot{}, "ibc/commitment/MerkleRoot", nil) + cdc.RegisterConcrete(MerklePrefix{}, "ibc/commitment/MerklePrefix", nil) + cdc.RegisterConcrete(MerklePath{}, "ibc/commitment/MerklePath", nil) + cdc.RegisterConcrete(MerkleProof{}, "ibc/commitment/MerkleProof", nil) + + SetSubModuleCodec(cdc) +} + +func SetSubModuleCodec(cdc *codec.Codec) { + SubModuleCdc = cdc +} diff --git a/x/ibc/23-commitment/commitment_test.go b/x/ibc/23-commitment/types/commitment_test.go similarity index 97% rename from x/ibc/23-commitment/commitment_test.go rename to x/ibc/23-commitment/types/commitment_test.go index 2535f5705e29..932599e539cd 100644 --- a/x/ibc/23-commitment/commitment_test.go +++ b/x/ibc/23-commitment/types/commitment_test.go @@ -1,4 +1,4 @@ -package commitment_test +package types_test import ( "testing" diff --git a/x/ibc/23-commitment/errors.go b/x/ibc/23-commitment/types/errors.go similarity index 82% rename from x/ibc/23-commitment/errors.go rename to x/ibc/23-commitment/types/errors.go index 89b2bf0b0ad7..3b32f24643c0 100644 --- a/x/ibc/23-commitment/errors.go +++ b/x/ibc/23-commitment/types/errors.go @@ -1,11 +1,11 @@ -package commitment +package types import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // SubModuleName is the error codespace -const SubModuleName string = "ibc/commitment" +const SubModuleName string = "commitment" // IBC connection sentinel errors var ( diff --git a/x/ibc/23-commitment/merkle.go b/x/ibc/23-commitment/types/merkle.go similarity index 56% rename from x/ibc/23-commitment/merkle.go rename to x/ibc/23-commitment/types/merkle.go index d3649e7313f9..74f6353f339a 100644 --- a/x/ibc/23-commitment/merkle.go +++ b/x/ibc/23-commitment/types/merkle.go @@ -1,4 +1,4 @@ -package commitment +package types import ( "errors" @@ -7,6 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" "github.com/cosmos/cosmos-sdk/store/rootmulti" + "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) @@ -16,99 +17,99 @@ import ( // Merkle proof implementation of the Proof interface // Applied on SDK-based IBC implementation -var _ RootI = Root{} +var _ exported.Root = MerkleRoot{} -// Root defines a merkle root hash. -// In the Cosmos SDK, the AppHash of a block header becomes the Root. -type Root struct { +// MerkleRoot defines a merkle root hash. +// In the Cosmos SDK, the AppHash of a block header becomes the root. +type MerkleRoot struct { Hash []byte `json:"hash" yaml:"hash"` } -// NewRoot constructs a new Root -func NewRoot(hash []byte) Root { - return Root{ +// NewMerkleRoot constructs a new MerkleRoot +func NewMerkleRoot(hash []byte) MerkleRoot { + return MerkleRoot{ Hash: hash, } } // GetCommitmentType implements RootI interface -func (Root) GetCommitmentType() Type { - return Merkle +func (MerkleRoot) GetCommitmentType() exported.Type { + return exported.Merkle } // GetHash implements RootI interface -func (r Root) GetHash() []byte { - return r.Hash +func (mr MerkleRoot) GetHash() []byte { + return mr.Hash } // IsEmpty returns true if the root is empty -func (r Root) IsEmpty() bool { - return len(r.GetHash()) == 0 +func (mr MerkleRoot) IsEmpty() bool { + return len(mr.GetHash()) == 0 } -var _ PrefixI = Prefix{} +var _ exported.Prefix = MerklePrefix{} -// Prefix is merkle path prefixed to the key. +// MerklePrefix is merkle path prefixed to the key. // The constructed key from the Path and the key will be append(Path.KeyPath, append(Path.KeyPrefix, key...)) -type Prefix struct { +type MerklePrefix struct { KeyPrefix []byte `json:"key_prefix" yaml:"key_prefix"` // byte slice prefixed before the key } -// NewPrefix constructs new Prefix instance -func NewPrefix(keyPrefix []byte) Prefix { - return Prefix{ +// NewMerklePrefix constructs new MerklePrefix instance +func NewMerklePrefix(keyPrefix []byte) MerklePrefix { + return MerklePrefix{ KeyPrefix: keyPrefix, } } -// GetCommitmentType implements PrefixI -func (Prefix) GetCommitmentType() Type { - return Merkle +// GetCommitmentType implements Prefix interface +func (MerklePrefix) GetCommitmentType() exported.Type { + return exported.Merkle } // Bytes returns the key prefix bytes -func (p Prefix) Bytes() []byte { - return p.KeyPrefix +func (mp MerklePrefix) Bytes() []byte { + return mp.KeyPrefix } // IsEmpty returns true if the prefix is empty -func (p Prefix) IsEmpty() bool { - return len(p.Bytes()) == 0 +func (mp MerklePrefix) IsEmpty() bool { + return len(mp.Bytes()) == 0 } -var _ PathI = Path{} +var _ exported.Path = MerklePath{} -// Path is the path used to verify commitment proofs, which can be an arbitrary +// MerklePath is the path used to verify commitment proofs, which can be an arbitrary // structured object (defined by a commitment type). -type Path struct { +type MerklePath struct { KeyPath merkle.KeyPath `json:"key_path" yaml:"key_path"` // byte slice prefixed before the key } -// NewPath creates a new CommitmentPath instance -func NewPath(keyPathStr []string) Path { +// NewMerklePath creates a new MerklePath instance +func NewMerklePath(keyPathStr []string) MerklePath { merkleKeyPath := merkle.KeyPath{} for _, keyStr := range keyPathStr { merkleKeyPath = merkleKeyPath.AppendKey([]byte(keyStr), merkle.KeyEncodingURL) } - return Path{ + return MerklePath{ KeyPath: merkleKeyPath, } } // GetCommitmentType implements PathI -func (Path) GetCommitmentType() Type { - return Merkle +func (MerklePath) GetCommitmentType() exported.Type { + return exported.Merkle } // String implements fmt.Stringer. -func (p Path) String() string { - return p.KeyPath.String() +func (mp MerklePath) String() string { + return mp.KeyPath.String() } // Pretty returns the unescaped path of the URL string. -func (p Path) Pretty() string { - path, err := url.PathUnescape(p.KeyPath.String()) +func (mp MerklePath) Pretty() string { + path, err := url.PathUnescape(mp.KeyPath.String()) if err != nil { panic(err) } @@ -116,8 +117,8 @@ func (p Path) Pretty() string { } // IsEmpty returns true if the path is empty -func (p Path) IsEmpty() bool { - return len(p.KeyPath) == 0 +func (mp MerklePath) IsEmpty() bool { + return len(mp.KeyPath) == 0 } // ApplyPrefix constructs a new commitment path from the arguments. It interprets @@ -125,35 +126,35 @@ func (p Path) IsEmpty() bool { // // CONTRACT: provided path string MUST be a well formated path. See ICS24 for // reference. -func ApplyPrefix(prefix PrefixI, path string) (Path, error) { +func ApplyPrefix(prefix exported.Prefix, path string) (MerklePath, error) { err := host.DefaultPathValidator(path) if err != nil { - return Path{}, err + return MerklePath{}, err } if prefix == nil || prefix.IsEmpty() { - return Path{}, errors.New("prefix can't be empty") + return MerklePath{}, errors.New("prefix can't be empty") } - return NewPath([]string{string(prefix.Bytes()), path}), nil + return NewMerklePath([]string{string(prefix.Bytes()), path}), nil } -var _ ProofI = Proof{} +var _ exported.Proof = MerkleProof{} -// Proof is a wrapper type that contains a merkle proof. +// MerkleProof is a wrapper type that contains a merkle proof. // It demonstrates membership or non-membership for an element or set of elements, // verifiable in conjunction with a known commitment root. Proofs should be // succinct. -type Proof struct { +type MerkleProof struct { Proof *merkle.Proof `json:"proof" yaml:"proof"` } // GetCommitmentType implements ProofI -func (Proof) GetCommitmentType() Type { - return Merkle +func (MerkleProof) GetCommitmentType() exported.Type { + return exported.Merkle } // VerifyMembership verifies the membership pf a merkle proof against the given root, path, and value. -func (proof Proof) VerifyMembership(root RootI, path PathI, value []byte) error { +func (proof MerkleProof) VerifyMembership(root exported.Root, path exported.Path, value []byte) error { if proof.IsEmpty() || root == nil || root.IsEmpty() || path == nil || path.IsEmpty() || len(value) == 0 { return errors.New("empty params or proof") } @@ -163,7 +164,7 @@ func (proof Proof) VerifyMembership(root RootI, path PathI, value []byte) error } // VerifyNonMembership verifies the absence of a merkle proof against the given root and path. -func (proof Proof) VerifyNonMembership(root RootI, path PathI) error { +func (proof MerkleProof) VerifyNonMembership(root exported.Root, path exported.Path) error { if proof.IsEmpty() || root == nil || root.IsEmpty() || path == nil || path.IsEmpty() { return errors.New("empty params or proof") } @@ -173,12 +174,12 @@ func (proof Proof) VerifyNonMembership(root RootI, path PathI) error { } // IsEmpty returns true if the root is empty -func (proof Proof) IsEmpty() bool { - return (proof == Proof{}) || proof.Proof == nil +func (proof MerkleProof) IsEmpty() bool { + return (proof == MerkleProof{}) || proof.Proof == nil } // ValidateBasic checks if the proof is empty. -func (proof Proof) ValidateBasic() error { +func (proof MerkleProof) ValidateBasic() error { if proof.IsEmpty() { return ErrInvalidProof } diff --git a/x/ibc/23-commitment/merkle_test.go b/x/ibc/23-commitment/types/merkle_test.go similarity index 88% rename from x/ibc/23-commitment/merkle_test.go rename to x/ibc/23-commitment/types/merkle_test.go index 4ce2c697df4d..bb287ecde634 100644 --- a/x/ibc/23-commitment/merkle_test.go +++ b/x/ibc/23-commitment/types/merkle_test.go @@ -1,4 +1,4 @@ -package commitment_test +package types_test import ( "fmt" @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" abci "github.com/tendermint/tendermint/abci/types" ) @@ -22,11 +22,11 @@ func (suite *MerkleTestSuite) TestVerifyMembership() { }) require.NotNil(suite.T(), res.Proof) - proof := commitment.Proof{ + proof := types.MerkleProof{ Proof: res.Proof, } suite.Require().NoError(proof.ValidateBasic()) - suite.Require().Error(commitment.Proof{}.ValidateBasic()) + suite.Require().Error(types.MerkleProof{}.ValidateBasic()) cases := []struct { name string @@ -50,8 +50,8 @@ func (suite *MerkleTestSuite) TestVerifyMembership() { for i, tc := range cases { tc := tc suite.Run(tc.name, func() { - root := commitment.NewRoot(tc.root) - path := commitment.NewPath(tc.pathArr) + root := types.NewMerkleRoot(tc.root) + path := types.NewMerklePath(tc.pathArr) err := proof.VerifyMembership(root, path, tc.value) @@ -77,7 +77,7 @@ func (suite *MerkleTestSuite) TestVerifyNonMembership() { }) require.NotNil(suite.T(), res.Proof) - proof := commitment.Proof{ + proof := types.MerkleProof{ Proof: res.Proof, } suite.Require().NoError(proof.ValidateBasic()) @@ -103,8 +103,8 @@ func (suite *MerkleTestSuite) TestVerifyNonMembership() { tc := tc suite.Run(tc.name, func() { - root := commitment.NewRoot(tc.root) - path := commitment.NewPath(tc.pathArr) + root := types.NewMerkleRoot(tc.root) + path := types.NewMerklePath(tc.pathArr) err := proof.VerifyNonMembership(root, path) @@ -119,11 +119,11 @@ func (suite *MerkleTestSuite) TestVerifyNonMembership() { } func TestApplyPrefix(t *testing.T) { - prefix := commitment.NewPrefix([]byte("storePrefixKey")) + prefix := types.NewMerklePrefix([]byte("storePrefixKey")) pathStr := "path1/path2/path3/key" - prefixedPath, err := commitment.ApplyPrefix(prefix, pathStr) + prefixedPath, err := types.ApplyPrefix(prefix, pathStr) require.Nil(t, err, "valid prefix returns error") require.Equal(t, "/storePrefixKey/path1/path2/path3/key", prefixedPath.Pretty(), "Prefixed path incorrect") @@ -131,7 +131,7 @@ func TestApplyPrefix(t *testing.T) { // invalid prefix contains non-alphanumeric character invalidPathStr := "invalid-path/doesitfail?/hopefully" - invalidPath, err := commitment.ApplyPrefix(prefix, invalidPathStr) + invalidPath, err := types.ApplyPrefix(prefix, invalidPathStr) require.NotNil(t, err, "invalid prefix does not returns error") - require.Equal(t, commitment.Path{}, invalidPath, "invalid prefix returns valid Path on ApplyPrefix") + require.Equal(t, types.MerklePath{}, invalidPath, "invalid prefix returns valid Path on ApplyPrefix") } diff --git a/x/ibc/23-commitment/verify.go b/x/ibc/23-commitment/verify.go index 8e070595949f..4690fe9e1567 100644 --- a/x/ibc/23-commitment/verify.go +++ b/x/ibc/23-commitment/verify.go @@ -2,12 +2,14 @@ package commitment import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" + "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) // CalculateRoot returns the application Hash at the curretn block height as a commitment // root for proof verification. -func CalculateRoot(ctx sdk.Context) RootI { - return NewRoot(ctx.BlockHeader().AppHash) +func CalculateRoot(ctx sdk.Context) exported.Root { + return types.NewMerkleRoot(ctx.BlockHeader().AppHash) } // BatchVerifyMembership verifies a proof that many paths have been set to @@ -16,14 +18,14 @@ func CalculateRoot(ctx sdk.Context) RootI { // Returns false on the first failed membership verification. func BatchVerifyMembership( ctx sdk.Context, - proof ProofI, - prefix PrefixI, + proof exported.Proof, + prefix exported.Prefix, items map[string][]byte, ) error { root := CalculateRoot(ctx) for pathStr, value := range items { - path, err := ApplyPrefix(prefix, pathStr) + path, err := types.ApplyPrefix(prefix, pathStr) if err != nil { return err } @@ -42,13 +44,13 @@ func BatchVerifyMembership( // Returns false on the first failed non-membership verification. func BatchVerifyNonMembership( ctx sdk.Context, - proof ProofI, - prefix PrefixI, + proof exported.Proof, + prefix exported.Prefix, paths []string, ) error { root := CalculateRoot(ctx) for _, pathStr := range paths { - path, err := ApplyPrefix(prefix, pathStr) + path, err := types.ApplyPrefix(prefix, pathStr) if err != nil { return err } diff --git a/x/ibc/ante/ante_test.go b/x/ibc/ante/ante_test.go index 535157c7ad6c..57f5b7c2e608 100644 --- a/x/ibc/ante/ante_test.go +++ b/x/ibc/ante/ante_test.go @@ -23,7 +23,7 @@ import ( ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" "github.com/cosmos/cosmos-sdk/x/staking" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" "github.com/cosmos/cosmos-sdk/x/ibc/ante" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) @@ -68,7 +68,7 @@ func (suite *HandlerTestSuite) SetupTest() { suite.chainB.createConnection(testConnection, testConnection, testClientIDA, testClientIDB, connectionexported.OPEN) } -func queryProof(chain *TestChain, key string) (proof commitment.Proof, height int64) { +func queryProof(chain *TestChain, key string) (proof commitmenttypes.MerkleProof, height int64) { res := chain.App.Query(abci.RequestQuery{ Path: fmt.Sprintf("store/%s/key", ibctypes.StoreKey), Data: []byte(key), @@ -76,7 +76,7 @@ func queryProof(chain *TestChain, key string) (proof commitment.Proof, height in }) height = res.Height - proof = commitment.Proof{ + proof = commitmenttypes.MerkleProof{ Proof: res.Proof, } @@ -298,7 +298,7 @@ func (chain *TestChain) updateClient(client *TestChain) { consensusState := ibctmtypes.ConsensusState{ Height: uint64(client.Header.Height) - 1, Timestamp: client.Header.Time, - Root: commitment.NewRoot(commitID.Hash), + Root: commitmenttypes.NewMerkleRoot(commitID.Hash), ValidatorSet: client.Vals, } diff --git a/x/ibc/module.go b/x/ibc/module.go index 904820f52c06..acb96a3bfedf 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -16,7 +16,7 @@ import ( connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" "github.com/cosmos/cosmos-sdk/x/ibc/client/cli" "github.com/cosmos/cosmos-sdk/x/ibc/client/rest" "github.com/cosmos/cosmos-sdk/x/ibc/types" @@ -44,7 +44,7 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { connection.RegisterCodec(cdc) channel.RegisterCodec(cdc) ibctmtypes.RegisterCodec(cdc) - commitment.RegisterCodec(cdc) + commitmenttypes.RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the ibc diff --git a/x/ibc/types/mock.go b/x/ibc/types/mock.go index ebc307a3129a..43fcd3beadb1 100644 --- a/x/ibc/types/mock.go +++ b/x/ibc/types/mock.go @@ -3,15 +3,15 @@ package types import ( "errors" - commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" + commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" ) // Mocked types // TODO: fix tests and replace for real proofs var ( - _ commitment.ProofI = ValidProof{} - _ commitment.ProofI = InvalidProof{} + _ commitmentexported.Proof = ValidProof{} + _ commitmentexported.Proof = InvalidProof{} ) type ( @@ -19,16 +19,16 @@ type ( InvalidProof struct{} ) -func (ValidProof) GetCommitmentType() commitment.Type { - return commitment.Merkle +func (ValidProof) GetCommitmentType() commitmentexported.Type { + return commitmentexported.Merkle } func (ValidProof) VerifyMembership( - root commitment.RootI, path commitment.PathI, value []byte) error { + root commitmentexported.Root, path commitmentexported.Path, value []byte) error { return nil } -func (ValidProof) VerifyNonMembership(root commitment.RootI, path commitment.PathI) error { +func (ValidProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { return nil } @@ -40,16 +40,16 @@ func (ValidProof) IsEmpty() bool { return false } -func (InvalidProof) GetCommitmentType() commitment.Type { - return commitment.Merkle +func (InvalidProof) GetCommitmentType() commitmentexported.Type { + return commitmentexported.Merkle } func (InvalidProof) VerifyMembership( - root commitment.RootI, path commitment.PathI, value []byte) error { + root commitmentexported.Root, path commitmentexported.Path, value []byte) error { return errors.New("proof failed") } -func (InvalidProof) VerifyNonMembership(root commitment.RootI, path commitment.PathI) error { +func (InvalidProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { return errors.New("proof failed") }