From b996c6cad20ff7761897667f2a50480449c755c9 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 18 Jan 2023 20:20:34 +0100 Subject: [PATCH 01/52] add EnableLocalhost to 03-connection --- modules/core/03-connection/keeper/keeper.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 05ec016a119..9b9dd062c0b 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -41,6 +41,20 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramt } } +// EnableLocalhost is called by init genesis or an upgrade handler? +func (k Keeper) EnableLocalhost(ctx sdk.Context) { + connectionEnd := types.ConnectionEnd{ + State: types.OPEN, + ClientId: "09-localhost", // todo: replace strings with consts + Versions: types.ExportedVersionsToProto(types.GetCompatibleVersions()), + Counterparty: types.NewCounterparty("09-localhost", "connection-localhost", commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())), + } + + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&connectionEnd) + store.Set(host.ConnectionKey("connection-localhost"), bz) +} + // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) From b080ff93f634deacfe1b5367de77877ab3577746 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 18 Jan 2023 20:27:45 +0100 Subject: [PATCH 02/52] adding godoc and temp comment --- modules/core/03-connection/keeper/keeper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 9b9dd062c0b..b3da197dd9a 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -42,6 +42,8 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramt } // EnableLocalhost is called by init genesis or an upgrade handler? +// EnableLocalhost sets the localhost loopback connection end in store +// - channel handshake code can remain the same func (k Keeper) EnableLocalhost(ctx sdk.Context) { connectionEnd := types.ConnectionEnd{ State: types.OPEN, From ccfb9fbfaa639e45b115087ab457f20f86952e78 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 18 Jan 2023 21:25:57 +0100 Subject: [PATCH 03/52] dumping 09-localhost client state boilerplate --- modules/core/03-connection/keeper/keeper.go | 7 + modules/core/03-connection/types/msgs_test.go | 6 +- modules/core/03-connection/types/tx.pb.go | 216 +++++++--- modules/core/exported/client.go | 4 + .../09-localhost/client_state.go | 173 ++++++++ .../09-localhost/localhost.pb.go | 368 ++++++++++++++++++ modules/light-clients/09-localhost/module.go | 5 + proto/ibc/core/connection/v1/tx.proto | 4 +- .../lightclients/localhost/v1/localhost.proto | 18 + 9 files changed, 736 insertions(+), 65 deletions(-) create mode 100644 modules/light-clients/09-localhost/client_state.go create mode 100644 modules/light-clients/09-localhost/localhost.pb.go create mode 100644 modules/light-clients/09-localhost/module.go create mode 100644 proto/ibc/lightclients/localhost/v1/localhost.proto diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index b3da197dd9a..a8d6255316c 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -43,7 +43,14 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramt // EnableLocalhost is called by init genesis or an upgrade handler? // EnableLocalhost sets the localhost loopback connection end in store +// NOTES: // - channel handshake code can remain the same +// - packet handlers require access to a ClientState and use the following methods: +// - Status() +// - GetLatestHeight() +// - GetTimestampAtHeight() +// - VerifyMembership +// - VerifyNonMembership func (k Keeper) EnableLocalhost(ctx sdk.Context) { connectionEnd := types.ConnectionEnd{ State: types.OPEN, diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index 08ed2f3f657..ff1eb615b8e 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -133,12 +133,12 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { msg *types.MsgConnectionOpenTry expPass bool }{ - {"non empty connection ID", &types.MsgConnectionOpenTry{"connection-0", "clienttotesta", any, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer}, false}, + {"non empty connection ID", &types.MsgConnectionOpenTry{"connection-0", "clienttotesta", any, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, {"invalid client ID", types.NewMsgConnectionOpenTry("test/iris", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid counterparty connection ID", types.NewMsgConnectionOpenTry("clienttotesta", "ibc/test", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid counterparty client ID", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "test/conn1", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid nil counterparty client", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", nil, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid client unpacking", &types.MsgConnectionOpenTry{"", "clienttotesta", invalidAny, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer}, false}, + {"invalid client unpacking", &types.MsgConnectionOpenTry{"", "clienttotesta", invalidAny, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, {"counterparty failed validate", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", invalidClient, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"empty counterparty prefix", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, emptyPrefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"empty counterpartyVersions", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, @@ -186,7 +186,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { {"invalid connection ID", types.NewMsgConnectionOpenAck("test/conn1", connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, {"invalid counterparty connection ID", types.NewMsgConnectionOpenAck(connectionID, "test/conn1", clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, {"invalid nil counterparty client", types.NewMsgConnectionOpenAck(connectionID, connectionID, nil, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"invalid unpacking counterparty client", &types.MsgConnectionOpenAck{connectionID, connectionID, ibctesting.ConnectionVersion, invalidAny, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer}, false}, + {"invalid unpacking counterparty client", &types.MsgConnectionOpenAck{connectionID, connectionID, ibctesting.ConnectionVersion, invalidAny, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, {"counterparty client failed validate", types.NewMsgConnectionOpenAck(connectionID, connectionID, invalidClient, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, {"empty proofTry", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, emptyProof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, {"empty proofClient", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, emptyProof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, diff --git a/modules/core/03-connection/types/tx.pb.go b/modules/core/03-connection/types/tx.pb.go index 16db8d34b15..b87f8f1efc9 100644 --- a/modules/core/03-connection/types/tx.pb.go +++ b/modules/core/03-connection/types/tx.pb.go @@ -131,6 +131,8 @@ type MsgConnectionOpenTry struct { ProofConsensus []byte `protobuf:"bytes,10,opt,name=proof_consensus,json=proofConsensus,proto3" json:"proof_consensus,omitempty" yaml:"proof_consensus"` ConsensusHeight types1.Height `protobuf:"bytes,11,opt,name=consensus_height,json=consensusHeight,proto3" json:"consensus_height" yaml:"consensus_height"` Signer string `protobuf:"bytes,12,opt,name=signer,proto3" json:"signer,omitempty"` + // optional proof data for host state machines that are unable to introspect their own consensus state + HostConsensusStateProof []byte `protobuf:"bytes,13,opt,name=host_consensus_state_proof,json=hostConsensusStateProof,proto3" json:"host_consensus_state_proof,omitempty"` } func (m *MsgConnectionOpenTry) Reset() { *m = MsgConnectionOpenTry{} } @@ -220,6 +222,8 @@ type MsgConnectionOpenAck struct { ProofConsensus []byte `protobuf:"bytes,8,opt,name=proof_consensus,json=proofConsensus,proto3" json:"proof_consensus,omitempty" yaml:"proof_consensus"` ConsensusHeight types1.Height `protobuf:"bytes,9,opt,name=consensus_height,json=consensusHeight,proto3" json:"consensus_height" yaml:"consensus_height"` Signer string `protobuf:"bytes,10,opt,name=signer,proto3" json:"signer,omitempty"` + // optional proof data for host state machines that are unable to introspect their own consensus state + HostConsensusStateProof []byte `protobuf:"bytes,11,opt,name=host_consensus_state_proof,json=hostConsensusStateProof,proto3" json:"host_consensus_state_proof,omitempty"` } func (m *MsgConnectionOpenAck) Reset() { *m = MsgConnectionOpenAck{} } @@ -387,66 +391,68 @@ func init() { func init() { proto.RegisterFile("ibc/core/connection/v1/tx.proto", fileDescriptor_5d00fde5fc97399e) } var fileDescriptor_5d00fde5fc97399e = []byte{ - // 929 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x31, 0x73, 0xe3, 0x44, - 0x14, 0xb6, 0x62, 0x27, 0xb1, 0xd7, 0x86, 0xbb, 0x5b, 0x9c, 0x44, 0x88, 0x3b, 0xcb, 0x08, 0x18, - 0x52, 0x10, 0xe9, 0x7c, 0x77, 0x30, 0x90, 0x81, 0x22, 0x76, 0x43, 0x8a, 0x83, 0x1b, 0x71, 0x73, - 0x33, 0x5c, 0xe3, 0xb1, 0xe5, 0x8d, 0xb2, 0x63, 0x5b, 0xab, 0xd1, 0xca, 0x06, 0xd1, 0xd2, 0x30, - 0x54, 0x74, 0xb4, 0xf7, 0x1f, 0xf8, 0x13, 0x57, 0xa6, 0xa4, 0xd2, 0x40, 0xd2, 0x50, 0xab, 0xa3, - 0x63, 0xb4, 0x2b, 0xc9, 0x6b, 0x5b, 0x1e, 0x6c, 0x1c, 0xba, 0x7d, 0xfb, 0xbe, 0xf7, 0xde, 0xee, - 0x7b, 0xdf, 0xb7, 0xb3, 0x40, 0xc5, 0x7d, 0xcb, 0xb0, 0x88, 0x87, 0x0c, 0x8b, 0x38, 0x0e, 0xb2, - 0x7c, 0x4c, 0x1c, 0x63, 0xda, 0x32, 0xfc, 0xef, 0x75, 0xd7, 0x23, 0x3e, 0x81, 0x87, 0xb8, 0x6f, - 0xe9, 0x31, 0x40, 0x9f, 0x01, 0xf4, 0x69, 0x4b, 0xa9, 0xdb, 0xc4, 0x26, 0x0c, 0x62, 0xc4, 0x2b, - 0x8e, 0x56, 0xde, 0xb6, 0x09, 0xb1, 0x47, 0xc8, 0x60, 0x56, 0x7f, 0x72, 0x61, 0xf4, 0x9c, 0x20, - 0x71, 0x09, 0x95, 0x46, 0x18, 0x39, 0x7e, 0x5c, 0x85, 0xaf, 0x12, 0xc0, 0x87, 0x2b, 0x8e, 0x22, - 0xd4, 0x65, 0x40, 0xed, 0xb7, 0x1d, 0x70, 0xf0, 0x94, 0xda, 0x9d, 0x6c, 0xff, 0x6b, 0x17, 0x39, - 0xe7, 0x0e, 0xf6, 0x61, 0x0b, 0x54, 0x78, 0xca, 0x2e, 0x1e, 0xc8, 0x52, 0x53, 0x3a, 0xae, 0xb4, - 0xeb, 0x51, 0xa8, 0xde, 0x0d, 0x7a, 0xe3, 0xd1, 0xa9, 0x96, 0xb9, 0x34, 0xb3, 0xcc, 0xd7, 0xe7, - 0x03, 0xf8, 0x15, 0xa8, 0x59, 0x64, 0xe2, 0xf8, 0xc8, 0x73, 0x7b, 0x9e, 0x1f, 0xc8, 0x3b, 0x4d, - 0xe9, 0xb8, 0xfa, 0xe8, 0x7d, 0x3d, 0xff, 0xda, 0x7a, 0x47, 0xc0, 0xb6, 0x4b, 0xaf, 0x43, 0xb5, - 0x60, 0xce, 0xc5, 0xc3, 0xcf, 0xc0, 0xfe, 0x14, 0x79, 0x14, 0x13, 0x47, 0x2e, 0xb2, 0x54, 0xea, - 0xaa, 0x54, 0x2f, 0x38, 0xcc, 0x4c, 0xf1, 0xf0, 0x14, 0xd4, 0x06, 0x68, 0xd4, 0x0b, 0xba, 0x2e, - 0xf2, 0x30, 0x19, 0xc8, 0xa5, 0xa6, 0x74, 0x5c, 0x6a, 0x1f, 0x45, 0xa1, 0xfa, 0x16, 0xbf, 0x80, - 0xe8, 0xd5, 0xcc, 0x2a, 0x33, 0x9f, 0x31, 0x0b, 0x1e, 0x82, 0x3d, 0x8a, 0x6d, 0x07, 0x79, 0xf2, - 0x6e, 0x7c, 0x6d, 0x33, 0xb1, 0x4e, 0xcb, 0x3f, 0xbd, 0x52, 0x0b, 0x7f, 0xbd, 0x52, 0x0b, 0x9a, - 0x0a, 0x1e, 0xe4, 0x36, 0xcd, 0x44, 0xd4, 0x25, 0x0e, 0x45, 0xda, 0xaf, 0xfb, 0xa0, 0xbe, 0x84, - 0x78, 0xee, 0x05, 0xff, 0xa5, 0xab, 0xdf, 0x82, 0x43, 0xd7, 0x43, 0x53, 0x4c, 0x26, 0xb4, 0x3b, - 0xbb, 0x75, 0x1c, 0xbf, 0xc3, 0xe2, 0xdf, 0x8b, 0x42, 0xf5, 0x01, 0x8f, 0xcf, 0xc7, 0x69, 0xb2, - 0x64, 0xd6, 0x53, 0xd7, 0xec, 0x48, 0xe7, 0x03, 0xf8, 0x0c, 0xd4, 0x92, 0x92, 0xd4, 0xef, 0xf9, - 0x28, 0xe9, 0x72, 0x5d, 0xe7, 0xcc, 0xd3, 0x53, 0xe6, 0xe9, 0x67, 0x4e, 0x20, 0xf6, 0x4e, 0x8c, - 0xd1, 0xcc, 0x2a, 0x37, 0xbf, 0x89, 0xad, 0x25, 0x0a, 0x94, 0xb6, 0xa4, 0xc0, 0xe2, 0x1c, 0x77, - 0x37, 0x98, 0xe3, 0x14, 0x1c, 0x88, 0xb9, 0xba, 0x09, 0x37, 0xa8, 0xbc, 0xd7, 0x2c, 0xae, 0x41, - 0xa6, 0x76, 0x33, 0x0a, 0xd5, 0xfb, 0xc9, 0x8d, 0xf3, 0xf2, 0x68, 0x66, 0x5d, 0xdc, 0x4f, 0xc2, - 0x28, 0x7c, 0x09, 0x6a, 0xae, 0x47, 0xc8, 0x45, 0xf7, 0x12, 0x61, 0xfb, 0xd2, 0x97, 0xf7, 0x59, - 0x0f, 0x14, 0xa1, 0x1c, 0x97, 0xea, 0xb4, 0xa5, 0x7f, 0xc9, 0x10, 0xed, 0x77, 0xe2, 0x9b, 0xcf, - 0xee, 0x24, 0x46, 0x6b, 0x66, 0x95, 0x99, 0x1c, 0x09, 0x9f, 0x00, 0xc0, 0xbd, 0xd8, 0xc1, 0xbe, - 0x5c, 0x6e, 0x4a, 0xc7, 0xb5, 0xf6, 0x41, 0x14, 0xaa, 0xf7, 0xc4, 0xc8, 0xd8, 0xa7, 0x99, 0x15, - 0x66, 0x30, 0x2d, 0x9f, 0xa6, 0x27, 0xe2, 0x95, 0xe5, 0x0a, 0x8b, 0x3b, 0x5a, 0xac, 0xc8, 0xbd, - 0x69, 0xc5, 0x0e, 0xb3, 0x60, 0x07, 0xdc, 0x49, 0xbc, 0x31, 0xb3, 0x1d, 0x3a, 0xa1, 0x32, 0x60, - 0xe1, 0x4a, 0x14, 0xaa, 0x87, 0x73, 0xe1, 0x29, 0x40, 0x33, 0xdf, 0xe4, 0x19, 0xd2, 0x0d, 0x78, - 0x01, 0xee, 0x66, 0xde, 0xb4, 0x2d, 0xd5, 0x7f, 0x6d, 0x8b, 0x9a, 0xb4, 0xe5, 0x28, 0x1d, 0xc2, - 0x7c, 0x06, 0xcd, 0xbc, 0x93, 0x6d, 0x25, 0xed, 0x99, 0x49, 0xb7, 0xb6, 0x42, 0xba, 0x0d, 0x70, - 0x3f, 0x4f, 0x98, 0x99, 0x72, 0xff, 0xdc, 0xcd, 0x51, 0xee, 0x99, 0x35, 0x84, 0x5f, 0x80, 0x37, - 0xe6, 0xd5, 0xc7, 0xd5, 0x2b, 0x47, 0xa1, 0x5a, 0xcf, 0xce, 0x27, 0x88, 0x2e, 0x26, 0xb2, 0x20, - 0x35, 0x0b, 0x28, 0x73, 0x24, 0xca, 0x53, 0xf2, 0x07, 0x51, 0xa8, 0xbe, 0x9b, 0x43, 0xb8, 0x85, - 0xc4, 0xb2, 0xe8, 0x9c, 0xd3, 0xf3, 0x16, 0x0f, 0xe6, 0xe2, 0x53, 0x50, 0xda, 0xfa, 0x29, 0x58, - 0x94, 0xc1, 0xee, 0x2d, 0xca, 0xa0, 0x05, 0x38, 0xbb, 0xbb, 0xbe, 0x17, 0xc8, 0x7b, 0x8c, 0x8e, - 0xc2, 0x33, 0x9a, 0xb9, 0x34, 0xb3, 0xcc, 0xd6, 0xf1, 0xcb, 0xbb, 0xa8, 0x81, 0xfd, 0xed, 0x34, - 0x50, 0xbe, 0x15, 0x0d, 0x54, 0xfe, 0x57, 0x0d, 0x80, 0x0d, 0x34, 0x70, 0x66, 0x0d, 0x33, 0x0d, - 0xfc, 0xbc, 0x03, 0xe4, 0x25, 0x40, 0x87, 0x38, 0x17, 0xd8, 0x1b, 0x6f, 0xab, 0x83, 0x6c, 0x72, - 0x3d, 0x6b, 0xc8, 0x68, 0x9f, 0x33, 0xb9, 0x9e, 0x35, 0x4c, 0x27, 0x17, 0x2b, 0x6f, 0x91, 0x48, - 0xc5, 0x5b, 0x24, 0xd2, 0xac, 0x59, 0xa5, 0x15, 0xcd, 0xd2, 0x40, 0x73, 0x55, 0x2f, 0xd2, 0x86, - 0x3d, 0xfa, 0xbb, 0x08, 0x8a, 0x4f, 0xa9, 0x0d, 0x7f, 0x00, 0x30, 0xe7, 0x27, 0x75, 0xb2, 0x4a, - 0x84, 0xb9, 0x7f, 0x08, 0xe5, 0xe3, 0x8d, 0xe0, 0xe9, 0x19, 0xe0, 0x77, 0xe0, 0xde, 0xf2, 0x77, - 0xe3, 0xa3, 0xb5, 0x73, 0x3d, 0xf7, 0x02, 0xe5, 0xc9, 0x26, 0xe8, 0xd5, 0x85, 0xe3, 0x99, 0xad, - 0x5f, 0xf8, 0xcc, 0x1a, 0x6e, 0x50, 0x58, 0xa0, 0x29, 0xfc, 0x51, 0x02, 0x07, 0xf9, 0x1c, 0x7d, - 0xb8, 0x76, 0xbe, 0x24, 0x42, 0xf9, 0x74, 0xd3, 0x88, 0xf4, 0x14, 0xed, 0x17, 0xaf, 0xaf, 0x1b, - 0xd2, 0xd5, 0x75, 0x43, 0xfa, 0xe3, 0xba, 0x21, 0xfd, 0x72, 0xd3, 0x28, 0x5c, 0xdd, 0x34, 0x0a, - 0xbf, 0xdf, 0x34, 0x0a, 0x2f, 0x3f, 0xb7, 0xb1, 0x7f, 0x39, 0xe9, 0xeb, 0x16, 0x19, 0x1b, 0x16, - 0xa1, 0x63, 0x42, 0x0d, 0xdc, 0xb7, 0x4e, 0x6c, 0x62, 0x4c, 0x3f, 0x31, 0xc6, 0x64, 0x30, 0x19, - 0x21, 0xca, 0x3f, 0xe9, 0x0f, 0x1f, 0x9f, 0x08, 0xff, 0x74, 0x3f, 0x70, 0x11, 0xed, 0xef, 0xb1, - 0x27, 0xf7, 0xf1, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40, 0x1d, 0x16, 0xb2, 0x56, 0x0c, 0x00, - 0x00, + // 965 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x31, 0x73, 0xe3, 0x44, + 0x14, 0xb6, 0x62, 0xc7, 0xb1, 0xd7, 0x3e, 0xee, 0x6e, 0x71, 0x12, 0x21, 0xee, 0x2c, 0x23, 0x60, + 0x48, 0x41, 0xa4, 0xf3, 0xdd, 0xc1, 0x40, 0x80, 0x22, 0x76, 0x43, 0x8a, 0x83, 0x8c, 0xb8, 0xb9, + 0x19, 0xae, 0xf1, 0xd8, 0xf2, 0x46, 0xd9, 0xb1, 0xad, 0xf5, 0x68, 0x65, 0x83, 0x68, 0x69, 0x18, + 0x2a, 0x7e, 0x01, 0x73, 0xff, 0x81, 0x3f, 0x71, 0x65, 0x0a, 0x0a, 0x2a, 0x0d, 0x93, 0x34, 0xd4, + 0xee, 0xe8, 0x98, 0xdd, 0x95, 0xe4, 0xb5, 0x23, 0x0f, 0x31, 0x0e, 0x9d, 0x9e, 0xde, 0xf7, 0xde, + 0xdb, 0xf7, 0xf6, 0xfb, 0xde, 0x48, 0x40, 0xc7, 0x3d, 0xc7, 0x72, 0x88, 0x8f, 0x2c, 0x87, 0x78, + 0x1e, 0x72, 0x02, 0x4c, 0x3c, 0x6b, 0xda, 0xb4, 0x82, 0xef, 0xcd, 0xb1, 0x4f, 0x02, 0x02, 0xf7, + 0x70, 0xcf, 0x31, 0x19, 0xc0, 0x9c, 0x03, 0xcc, 0x69, 0x53, 0xab, 0xb9, 0xc4, 0x25, 0x1c, 0x62, + 0xb1, 0x27, 0x81, 0xd6, 0xde, 0x72, 0x09, 0x71, 0x87, 0xc8, 0xe2, 0x56, 0x6f, 0x72, 0x66, 0x75, + 0xbd, 0x30, 0x76, 0x49, 0x95, 0x86, 0x18, 0x79, 0x01, 0xab, 0x22, 0x9e, 0x62, 0xc0, 0x07, 0x2b, + 0x8e, 0x22, 0xd5, 0xe5, 0x40, 0xe3, 0xb7, 0x2d, 0xb0, 0xfb, 0x8c, 0xba, 0xed, 0xf4, 0xfd, 0xd7, + 0x63, 0xe4, 0x9d, 0x78, 0x38, 0x80, 0x4d, 0x50, 0x16, 0x29, 0x3b, 0xb8, 0xaf, 0x2a, 0x0d, 0xe5, + 0xa0, 0xdc, 0xaa, 0xcd, 0x22, 0xfd, 0x5e, 0xd8, 0x1d, 0x0d, 0x8f, 0x8c, 0xd4, 0x65, 0xd8, 0x25, + 0xf1, 0x7c, 0xd2, 0x87, 0x5f, 0x81, 0xaa, 0x43, 0x26, 0x5e, 0x80, 0xfc, 0x71, 0xd7, 0x0f, 0x42, + 0x75, 0xab, 0xa1, 0x1c, 0x54, 0x1e, 0xbf, 0x67, 0x66, 0xb7, 0x6d, 0xb6, 0x25, 0x6c, 0xab, 0xf0, + 0x3a, 0xd2, 0x73, 0xf6, 0x42, 0x3c, 0xfc, 0x14, 0xec, 0x4c, 0x91, 0x4f, 0x31, 0xf1, 0xd4, 0x3c, + 0x4f, 0xa5, 0xaf, 0x4a, 0xf5, 0x42, 0xc0, 0xec, 0x04, 0x0f, 0x8f, 0x40, 0xb5, 0x8f, 0x86, 0xdd, + 0xb0, 0x33, 0x46, 0x3e, 0x26, 0x7d, 0xb5, 0xd0, 0x50, 0x0e, 0x0a, 0xad, 0xfd, 0x59, 0xa4, 0xbf, + 0x29, 0x1a, 0x90, 0xbd, 0x86, 0x5d, 0xe1, 0xe6, 0x29, 0xb7, 0xe0, 0x1e, 0x28, 0x52, 0xec, 0x7a, + 0xc8, 0x57, 0xb7, 0x59, 0xdb, 0x76, 0x6c, 0x1d, 0x95, 0x7e, 0x7a, 0xa5, 0xe7, 0xfe, 0x7a, 0xa5, + 0xe7, 0x0c, 0x1d, 0x3c, 0xcc, 0x1c, 0x9a, 0x8d, 0xe8, 0x98, 0x78, 0x14, 0x19, 0xbf, 0xef, 0x80, + 0xda, 0x35, 0xc4, 0x73, 0x3f, 0xfc, 0x2f, 0x53, 0xfd, 0x16, 0xec, 0x8d, 0x7d, 0x34, 0xc5, 0x64, + 0x42, 0x3b, 0xf3, 0xae, 0x59, 0xfc, 0x16, 0x8f, 0x7f, 0x77, 0x16, 0xe9, 0x0f, 0x45, 0x7c, 0x36, + 0xce, 0x50, 0x15, 0xbb, 0x96, 0xb8, 0xe6, 0x47, 0x3a, 0xe9, 0xc3, 0x53, 0x50, 0x8d, 0x4b, 0xd2, + 0xa0, 0x1b, 0xa0, 0x78, 0xca, 0x35, 0x53, 0x30, 0xcf, 0x4c, 0x98, 0x67, 0x1e, 0x7b, 0xa1, 0x3c, + 0x3b, 0x39, 0xc6, 0xb0, 0x2b, 0xc2, 0xfc, 0x86, 0x59, 0xd7, 0x28, 0x50, 0xd8, 0x90, 0x02, 0xcb, + 0xf7, 0xb8, 0xbd, 0xc6, 0x3d, 0x4e, 0xc1, 0xae, 0x9c, 0xab, 0x13, 0x73, 0x83, 0xaa, 0xc5, 0x46, + 0xfe, 0x06, 0x64, 0x6a, 0x35, 0x66, 0x91, 0xfe, 0x20, 0xee, 0x38, 0x2b, 0x8f, 0x61, 0xd7, 0xe4, + 0xf7, 0x71, 0x18, 0x85, 0x2f, 0x41, 0x75, 0xec, 0x13, 0x72, 0xd6, 0x39, 0x47, 0xd8, 0x3d, 0x0f, + 0xd4, 0x1d, 0x3e, 0x03, 0x4d, 0x2a, 0x27, 0xa4, 0x3a, 0x6d, 0x9a, 0x5f, 0x72, 0x44, 0xeb, 0x6d, + 0xd6, 0xf9, 0xbc, 0x27, 0x39, 0xda, 0xb0, 0x2b, 0xdc, 0x14, 0x48, 0xf8, 0x14, 0x00, 0xe1, 0xc5, + 0x1e, 0x0e, 0xd4, 0x52, 0x43, 0x39, 0xa8, 0xb6, 0x76, 0x67, 0x91, 0x7e, 0x5f, 0x8e, 0x64, 0x3e, + 0xc3, 0x2e, 0x73, 0x83, 0x6b, 0xf9, 0x28, 0x39, 0x91, 0xa8, 0xac, 0x96, 0x79, 0xdc, 0xfe, 0x72, + 0x45, 0xe1, 0x4d, 0x2a, 0xb6, 0xb9, 0x05, 0xdb, 0xe0, 0x6e, 0xec, 0x65, 0xcc, 0xf6, 0xe8, 0x84, + 0xaa, 0x80, 0x87, 0x6b, 0xb3, 0x48, 0xdf, 0x5b, 0x08, 0x4f, 0x00, 0x86, 0xfd, 0x86, 0xc8, 0x90, + 0xbc, 0x80, 0x67, 0xe0, 0x5e, 0xea, 0x4d, 0xc6, 0x52, 0xf9, 0xd7, 0xb1, 0xe8, 0xf1, 0x58, 0xf6, + 0x93, 0x4b, 0x58, 0xcc, 0x60, 0xd8, 0x77, 0xd3, 0x57, 0xf1, 0x78, 0xe6, 0xd2, 0xad, 0xca, 0xd2, + 0x85, 0x9f, 0x01, 0xed, 0x9c, 0xd0, 0x60, 0x7e, 0x44, 0x41, 0xde, 0x0e, 0x3f, 0xa6, 0x7a, 0x87, + 0xf5, 0x63, 0xef, 0x33, 0x44, 0x7a, 0x64, 0x4e, 0xe7, 0x53, 0xe6, 0x96, 0x74, 0x5f, 0x07, 0x0f, + 0xb2, 0x54, 0x9d, 0xca, 0xfe, 0xd7, 0x62, 0x86, 0xec, 0x8f, 0x9d, 0x01, 0xfc, 0x02, 0xdc, 0x59, + 0x94, 0xae, 0x90, 0xbe, 0x3a, 0x8b, 0xf4, 0x5a, 0xda, 0x9c, 0xa4, 0x58, 0xa6, 0x02, 0x49, 0xa7, + 0x0e, 0xd0, 0x16, 0x18, 0x98, 0xb5, 0x06, 0xde, 0x9f, 0x45, 0xfa, 0x3b, 0x19, 0x6c, 0x5d, 0x4a, + 0xac, 0xca, 0xce, 0x85, 0x65, 0xb0, 0xc1, 0xb6, 0x5d, 0xde, 0x23, 0x85, 0x8d, 0xf7, 0xc8, 0xb2, + 0x86, 0xb6, 0x6f, 0x51, 0x43, 0x4d, 0x20, 0xa4, 0xd1, 0x09, 0xfc, 0x50, 0x2d, 0x72, 0x2e, 0x4b, + 0x3b, 0x38, 0x75, 0x19, 0x76, 0x89, 0x3f, 0xb3, 0xb5, 0xbd, 0x2c, 0xa0, 0x9d, 0xcd, 0x04, 0x54, + 0xba, 0x15, 0x01, 0x95, 0xff, 0x57, 0x01, 0x81, 0x35, 0x04, 0x54, 0xd9, 0x44, 0x40, 0xc7, 0xce, + 0x20, 0x15, 0xd0, 0xcf, 0x5b, 0x40, 0xbd, 0x06, 0x68, 0x13, 0xef, 0x0c, 0xfb, 0xa3, 0x4d, 0x45, + 0x94, 0x5e, 0x7b, 0xd7, 0x19, 0x70, 0xcd, 0x64, 0x5c, 0x7b, 0xd7, 0x19, 0x24, 0xd7, 0xce, 0x64, + 0xbb, 0xcc, 0xc2, 0xfc, 0x2d, 0xb2, 0x70, 0x3e, 0xe9, 0xc2, 0x8a, 0xaf, 0x0c, 0x03, 0x34, 0x56, + 0xcd, 0x22, 0x19, 0xd8, 0xe3, 0xbf, 0xf3, 0x20, 0xff, 0x8c, 0xba, 0xf0, 0x07, 0x00, 0x33, 0xbe, + 0xe1, 0x0e, 0x57, 0x29, 0x38, 0xf3, 0xeb, 0x45, 0xfb, 0x68, 0x2d, 0x78, 0x72, 0x06, 0xf8, 0x1d, + 0xb8, 0x7f, 0xfd, 0x43, 0xe7, 0xc3, 0x1b, 0xe7, 0x7a, 0xee, 0x87, 0xda, 0xd3, 0x75, 0xd0, 0xab, + 0x0b, 0xb3, 0x3b, 0xbb, 0x79, 0xe1, 0x63, 0x67, 0xb0, 0x46, 0x61, 0x89, 0xa6, 0xf0, 0x47, 0x05, + 0xec, 0x66, 0x73, 0xf4, 0xd1, 0x8d, 0xf3, 0xc5, 0x11, 0xda, 0x27, 0xeb, 0x46, 0x24, 0xa7, 0x68, + 0xbd, 0x78, 0x7d, 0x59, 0x57, 0x2e, 0x2e, 0xeb, 0xca, 0x9f, 0x97, 0x75, 0xe5, 0x97, 0xab, 0x7a, + 0xee, 0xe2, 0xaa, 0x9e, 0xfb, 0xe3, 0xaa, 0x9e, 0x7b, 0xf9, 0xb9, 0x8b, 0x83, 0xf3, 0x49, 0xcf, + 0x74, 0xc8, 0xc8, 0x72, 0x08, 0x1d, 0x11, 0x6a, 0xe1, 0x9e, 0x73, 0xe8, 0x12, 0x6b, 0xfa, 0xb1, + 0x35, 0x22, 0xfd, 0xc9, 0x10, 0x51, 0xf1, 0x7b, 0xf0, 0xe8, 0xc9, 0xa1, 0xf4, 0x87, 0x10, 0x84, + 0x63, 0x44, 0x7b, 0x45, 0xbe, 0xaf, 0x9f, 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0xae, 0x20, 0x0f, + 0xac, 0xd0, 0x0c, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -754,6 +760,13 @@ func (m *MsgConnectionOpenTry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.HostConsensusStateProof) > 0 { + i -= len(m.HostConsensusStateProof) + copy(dAtA[i:], m.HostConsensusStateProof) + i = encodeVarintTx(dAtA, i, uint64(len(m.HostConsensusStateProof))) + i-- + dAtA[i] = 0x6a + } if len(m.Signer) > 0 { i -= len(m.Signer) copy(dAtA[i:], m.Signer) @@ -903,6 +916,13 @@ func (m *MsgConnectionOpenAck) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.HostConsensusStateProof) > 0 { + i -= len(m.HostConsensusStateProof) + copy(dAtA[i:], m.HostConsensusStateProof) + i = encodeVarintTx(dAtA, i, uint64(len(m.HostConsensusStateProof))) + i-- + dAtA[i] = 0x5a + } if len(m.Signer) > 0 { i -= len(m.Signer) copy(dAtA[i:], m.Signer) @@ -1187,6 +1207,10 @@ func (m *MsgConnectionOpenTry) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.HostConsensusStateProof) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -1241,6 +1265,10 @@ func (m *MsgConnectionOpenAck) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.HostConsensusStateProof) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -1958,6 +1986,40 @@ func (m *MsgConnectionOpenTry) Unmarshal(dAtA []byte) error { } m.Signer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HostConsensusStateProof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HostConsensusStateProof = append(m.HostConsensusStateProof[:0], dAtA[iNdEx:postIndex]...) + if m.HostConsensusStateProof == nil { + m.HostConsensusStateProof = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -2394,6 +2456,40 @@ func (m *MsgConnectionOpenAck) Unmarshal(dAtA []byte) error { } m.Signer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HostConsensusStateProof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HostConsensusStateProof = append(m.HostConsensusStateProof[:0], dAtA[iNdEx:postIndex]...) + if m.HostConsensusStateProof == nil { + m.HostConsensusStateProof = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 88273ecc860..2a95abab5ae 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -19,6 +19,10 @@ const ( // Tendermint is used to indicate that the client uses the Tendermint Consensus Algorithm. Tendermint string = "07-tendermint" + // Localhost is the client type for the localhost client. + // It is also used as the clientID for the localhost client. + Localhost string = "09-localhost" + // Active is a status type of a client. An active client is allowed to be used. Active Status = "Active" diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go new file mode 100644 index 00000000000..2d9d9fd366f --- /dev/null +++ b/modules/light-clients/09-localhost/client_state.go @@ -0,0 +1,173 @@ +package localhost + +import ( + "bytes" + "errors" + "strings" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v6/modules/core/exported" +) + +var _ exported.ClientState = (*ClientState)(nil) + +// NewClientState creates a new ClientState instance +func NewClientState(chainID string, height clienttypes.Height) *ClientState { + return &ClientState{ + ChainId: chainID, + LatestHeight: height, + } +} + +// GetChainID returns an empty string +func (cs ClientState) GetChainID() string { + return cs.ChainId +} + +// ClientType is localhost. +func (cs ClientState) ClientType() string { + return ClientType +} + +// GetLatestHeight returns the latest height stored. +func (cs ClientState) GetLatestHeight() exported.Height { + return cs.LatestHeight +} + +// Status always returns Active. The localhost status cannot be changed. +func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec, +) exported.Status { + return exported.Active +} + +// Validate performs a basic validation of the client state fields. +func (cs ClientState) Validate() error { + if strings.TrimSpace(cs.ChainId) == "" { + return sdkerrors.Wrap(sdkerrors.ErrInvalidChainID, "chain id cannot be blank") + } + + if cs.LatestHeight.RevisionHeight == 0 { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "local revision height cannot be zero") + } + + return nil +} + +// ZeroCustomFields returns the same client state since there are no custom fields in localhost +func (cs ClientState) ZeroCustomFields() exported.ClientState { + return &cs +} + +// Initialize ensures that initial consensus state for localhost is nil +func (cs ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, consState exported.ConsensusState) error { + if consState != nil { + return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "initial consensus state for localhost must be nil.") + } + return nil +} + +// GetTimestampAtHeight must return the timestamp for the consensus state associated with the provided height. +func (cs ClientState) GetTimestampAtHeight(ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, height exported.Height) (uint64, error) { + return uint64(ctx.BlockTime().UnixNano()), nil +} + +// ExportMetadata is a no-op for localhost client +func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { + return nil +} + +// CheckSubstituteAndUpdateState returns an error. The localhost cannot be modified by +// proposals. +func (cs ClientState) CheckSubstituteAndUpdateState(ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore sdk.KVStore, substituteClient exported.ClientState) error { + return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") +} + +// VerifyUpgradeAndUpdateState returns an error since localhost cannot be upgraded +func (cs ClientState) VerifyUpgradeAndUpdateState( + ctx sdk.Context, + cdc codec.BinaryCodec, + store sdk.KVStore, + newClient exported.ClientState, + newConsState exported.ConsensusState, + proofUpgradeClient, + proofUpgradeConsState []byte, +) error { + return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") +} + +// VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. +// The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). +func (cs ClientState) VerifyMembership( + ctx sdk.Context, + store sdk.KVStore, + cdc codec.BinaryCodec, + height exported.Height, + delayTimePeriod uint64, + delayBlockPeriod uint64, + proof []byte, + path exported.Path, + value []byte, +) error { + bz := store.Get([]byte(path.String())) + if bz == nil { + return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + } + + if !bytes.Equal(bz, value) { + return sdkerrors.Wrapf( + clienttypes.ErrFailedChannelStateVerification, + "todo: update error", + ) + } + + return nil +} + +// VerifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath at a specified height. +// The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). +func (cs ClientState) VerifyNonMembership( + ctx sdk.Context, + store sdk.KVStore, + cdc codec.BinaryCodec, + height exported.Height, + delayTimePeriod uint64, + delayBlockPeriod uint64, + proof []byte, + path exported.Path, +) error { + bz := store.Get([]byte(path.String())) + if bz != nil { + return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- found for path %s", path) + } + + return nil +} + +// VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update. +// It must handle each type of ClientMessage appropriately. Calls to CheckForMisbehaviour, UpdateState, and UpdateStateOnMisbehaviour +// will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned +// if the ClientMessage fails to verify. +func (cs ClientState) VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) error { + return errors.New("todo: update") +} + +// Checks for evidence of a misbehaviour in Header or Misbehaviour type. It assumes the ClientMessage +// has already been verified. +func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) bool { + return false +} + +// UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified +func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) { + +} + +// UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. +// Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. +func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { + return []exported.Height{} +} diff --git a/modules/light-clients/09-localhost/localhost.pb.go b/modules/light-clients/09-localhost/localhost.pb.go new file mode 100644 index 00000000000..e91714fcb95 --- /dev/null +++ b/modules/light-clients/09-localhost/localhost.pb.go @@ -0,0 +1,368 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/lightclients/localhost/v1/localhost.proto + +package localhost + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// ClientState defines the 09-localhost client state +type ClientState struct { + // unique chain identifier + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + // the latest block height + LatestHeight types.Height `protobuf:"bytes,2,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height"` +} + +func (m *ClientState) Reset() { *m = ClientState{} } +func (m *ClientState) String() string { return proto.CompactTextString(m) } +func (*ClientState) ProtoMessage() {} +func (*ClientState) Descriptor() ([]byte, []int) { + return fileDescriptor_acd9f5b22d41bf6d, []int{0} +} +func (m *ClientState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClientState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClientState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClientState) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClientState.Merge(m, src) +} +func (m *ClientState) XXX_Size() int { + return m.Size() +} +func (m *ClientState) XXX_DiscardUnknown() { + xxx_messageInfo_ClientState.DiscardUnknown(m) +} + +var xxx_messageInfo_ClientState proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ClientState)(nil), "ibc.lightclients.localhost.v1.ClientState") +} + +func init() { + proto.RegisterFile("ibc/lightclients/localhost/v1/localhost.proto", fileDescriptor_acd9f5b22d41bf6d) +} + +var fileDescriptor_acd9f5b22d41bf6d = []byte{ + // 281 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xcd, 0x4c, 0x4a, 0xd6, + 0xcf, 0xc9, 0x4c, 0xcf, 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x29, 0xd6, 0xcf, 0xc9, 0x4f, + 0x4e, 0xcc, 0xc9, 0xc8, 0x2f, 0x2e, 0xd1, 0x2f, 0x33, 0x44, 0x70, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, + 0xf2, 0x85, 0x64, 0x33, 0x93, 0x92, 0xf5, 0x90, 0x95, 0xeb, 0x21, 0x54, 0x94, 0x19, 0x4a, 0xc9, + 0x83, 0x4c, 0x4b, 0xce, 0x2f, 0x4a, 0xd5, 0x87, 0x48, 0x83, 0x8c, 0x80, 0xb0, 0x20, 0xfa, 0xa5, + 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x54, 0xca, 0xc5, 0xed, + 0x0c, 0x56, 0x15, 0x5c, 0x92, 0x58, 0x92, 0x2a, 0x24, 0xc9, 0xc5, 0x91, 0x9c, 0x91, 0x98, 0x99, + 0x17, 0x9f, 0x99, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0xc4, 0x0e, 0xe6, 0x7b, 0xa6, 0x08, + 0xb9, 0x72, 0xf1, 0xe6, 0x24, 0x96, 0xa4, 0x16, 0x97, 0xc4, 0x67, 0xa4, 0x82, 0x5c, 0x21, 0xc1, + 0xa4, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa5, 0x07, 0x72, 0x17, 0xc8, 0x62, 0x3d, 0xa8, 0x75, 0x65, + 0x86, 0x7a, 0x1e, 0x60, 0x15, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0xf1, 0x40, 0xb4, 0x41, + 0xc4, 0xac, 0x58, 0x3a, 0x16, 0xc8, 0x33, 0x38, 0x25, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, + 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, + 0xb1, 0x1c, 0x43, 0x94, 0x47, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, + 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0xb1, 0x7e, 0x66, 0x52, 0xb2, 0x6e, 0x7a, 0xbe, 0x7e, 0x99, 0x99, + 0x7e, 0x6e, 0x7e, 0x4a, 0x69, 0x4e, 0x6a, 0x31, 0x24, 0xd4, 0x74, 0x61, 0xc1, 0x66, 0x60, 0xa9, + 0x0b, 0x0f, 0x0a, 0x6b, 0x38, 0x2b, 0x89, 0x0d, 0xec, 0x43, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xce, 0x05, 0x1b, 0x03, 0x68, 0x01, 0x00, 0x00, +} + +func (m *ClientState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClientState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.LatestHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintLocalhost(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintLocalhost(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintLocalhost(dAtA []byte, offset int, v uint64) int { + offset -= sovLocalhost(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ClientState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovLocalhost(uint64(l)) + } + l = m.LatestHeight.Size() + n += 1 + l + sovLocalhost(uint64(l)) + return n +} + +func sovLocalhost(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozLocalhost(x uint64) (n int) { + return sovLocalhost(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ClientState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLocalhost + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ClientState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClientState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLocalhost + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthLocalhost + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthLocalhost + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLocalhost + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthLocalhost + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthLocalhost + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LatestHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipLocalhost(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthLocalhost + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipLocalhost(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowLocalhost + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowLocalhost + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowLocalhost + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthLocalhost + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupLocalhost + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthLocalhost + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthLocalhost = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowLocalhost = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupLocalhost = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/light-clients/09-localhost/module.go b/modules/light-clients/09-localhost/module.go new file mode 100644 index 00000000000..d60cdeafb0f --- /dev/null +++ b/modules/light-clients/09-localhost/module.go @@ -0,0 +1,5 @@ +package localhost + +const ( + ClientType = "09-localhost" +) diff --git a/proto/ibc/core/connection/v1/tx.proto b/proto/ibc/core/connection/v1/tx.proto index 8d1a0f3ec1d..7ac67454dd3 100644 --- a/proto/ibc/core/connection/v1/tx.proto +++ b/proto/ibc/core/connection/v1/tx.proto @@ -96,8 +96,8 @@ message MsgConnectionOpenAck { ibc.core.client.v1.Height consensus_height = 9 [(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false]; string signer = 10; - // optional proof data for host state machines that are unable to introspect their own consensus state - bytes host_consensus_state_proof = 11; + // optional proof data for host state machines that are unable to introspect their own consensus state + bytes host_consensus_state_proof = 11; } // MsgConnectionOpenAckResponse defines the Msg/ConnectionOpenAck response type. diff --git a/proto/ibc/lightclients/localhost/v1/localhost.proto b/proto/ibc/lightclients/localhost/v1/localhost.proto new file mode 100644 index 00000000000..131c870abd3 --- /dev/null +++ b/proto/ibc/lightclients/localhost/v1/localhost.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package ibc.lightclients.localhost.v1; + +option go_package = "github.com/cosmos/ibc-go/v6/modules/light-clients/09-localhost;localhost"; + +import "ibc/core/client/v1/client.proto"; +import "gogoproto/gogo.proto"; + +// ClientState defines the 09-localhost client state +message ClientState { + option (gogoproto.goproto_getters) = false; + + // unique chain identifier + string chain_id = 1; + // the latest block height + ibc.core.client.v1.Height latest_height = 2 [(gogoproto.nullable) = false]; +} From 3416304818a5713b2e63a9f7b972e1b2806a3fea Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 18 Jan 2023 21:31:20 +0100 Subject: [PATCH 04/52] adding codec and app module basic --- .../09-localhost/client_state.go | 2 +- modules/light-clients/09-localhost/codec.go | 16 ++++++ modules/light-clients/09-localhost/module.go | 57 ++++++++++++++++++- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 modules/light-clients/09-localhost/codec.go diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 2d9d9fd366f..c9ef63b308b 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -30,7 +30,7 @@ func (cs ClientState) GetChainID() string { // ClientType is localhost. func (cs ClientState) ClientType() string { - return ClientType + return exported.Localhost } // GetLatestHeight returns the latest height stored. diff --git a/modules/light-clients/09-localhost/codec.go b/modules/light-clients/09-localhost/codec.go new file mode 100644 index 00000000000..dcefc84902a --- /dev/null +++ b/modules/light-clients/09-localhost/codec.go @@ -0,0 +1,16 @@ +package localhost + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + + "github.com/cosmos/ibc-go/v6/modules/core/exported" +) + +// RegisterInterfaces registers the tendermint concrete client-related +// implementations and interfaces. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*exported.ClientState)(nil), + &ClientState{}, + ) +} diff --git a/modules/light-clients/09-localhost/module.go b/modules/light-clients/09-localhost/module.go index d60cdeafb0f..05f9112a701 100644 --- a/modules/light-clients/09-localhost/module.go +++ b/modules/light-clients/09-localhost/module.go @@ -1,5 +1,60 @@ package localhost +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" +) + const ( - ClientType = "09-localhost" + ModuleName = "09-localhost" ) + +var _ module.AppModuleBasic = AppModuleBasic{} + +// AppModuleBasic defines the basic application module used by the localhost light client. +// Only the RegisterInterfaces function needs to be implemented. All other function perform +// a no-op. +type AppModuleBasic struct{} + +// Name returns the localhost module name. +func (AppModuleBasic) Name() string { + return ModuleName +} + +// RegisterLegacyAminoCodec performs a no-op. The localhost client does not support amino. +func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} + +// RegisterInterfaces registers module concrete types into protobuf Any. This allows core IBC +// to unmarshal localhost light client types. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + RegisterInterfaces(registry) +} + +// DefaultGenesis performs a no-op. Genesis is not supported for the localhost light client. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return nil +} + +// ValidateGenesis performs a no-op. Genesis is not supported for the localhost light cilent. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + return nil +} + +// RegisterGRPCGatewayRoutes performs a no-op. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {} + +// GetTxCmd performs a no-op. Please see the 02-client cli commands. +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd performs a no-op. Please see the 02-client cli commands. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil +} From 6b8535233f05102520023d8af3c8504e1861c61e Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 18 Jan 2023 21:35:06 +0100 Subject: [PATCH 05/52] rearrange code in client_state.go --- .../09-localhost/client_state.go | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index c9ef63b308b..6b999de5b03 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -67,6 +67,7 @@ func (cs ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVSto if consState != nil { return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "initial consensus state for localhost must be nil.") } + return nil } @@ -75,30 +76,6 @@ func (cs ClientState) GetTimestampAtHeight(ctx sdk.Context, clientStore sdk.KVSt return uint64(ctx.BlockTime().UnixNano()), nil } -// ExportMetadata is a no-op for localhost client -func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { - return nil -} - -// CheckSubstituteAndUpdateState returns an error. The localhost cannot be modified by -// proposals. -func (cs ClientState) CheckSubstituteAndUpdateState(ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore sdk.KVStore, substituteClient exported.ClientState) error { - return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") -} - -// VerifyUpgradeAndUpdateState returns an error since localhost cannot be upgraded -func (cs ClientState) VerifyUpgradeAndUpdateState( - ctx sdk.Context, - cdc codec.BinaryCodec, - store sdk.KVStore, - newClient exported.ClientState, - newConsState exported.ConsensusState, - proofUpgradeClient, - proofUpgradeConsState []byte, -) error { - return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") -} - // VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). func (cs ClientState) VerifyMembership( @@ -171,3 +148,27 @@ func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.Binar func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { return []exported.Height{} } + +// ExportMetadata is a no-op for localhost client +func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { + return nil +} + +// CheckSubstituteAndUpdateState returns an error. The localhost cannot be modified by +// proposals. +func (cs ClientState) CheckSubstituteAndUpdateState(ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore sdk.KVStore, substituteClient exported.ClientState) error { + return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") +} + +// VerifyUpgradeAndUpdateState returns an error since localhost cannot be upgraded +func (cs ClientState) VerifyUpgradeAndUpdateState( + ctx sdk.Context, + cdc codec.BinaryCodec, + store sdk.KVStore, + newClient exported.ClientState, + newConsState exported.ConsensusState, + proofUpgradeClient, + proofUpgradeConsState []byte, +) error { + return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") +} From 8f13c75e8d1d528a665d1d58cc828bad38b9c7b6 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 23 Jan 2023 10:40:14 +0100 Subject: [PATCH 06/52] adding conditional checks for localhost client --- modules/core/02-client/keeper/keeper.go | 4 +++ modules/core/02-client/types/keys.go | 5 +++ modules/core/02-client/types/params.go | 2 +- .../core/03-connection/keeper/handshake.go | 35 ++++++++++++------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index c20dad5383d..7d8d9f4e5e6 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -269,6 +269,10 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) ( // This function is only used to validate the client state the counterparty stores for this chain // Client must be in same revision as the executing chain func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { + if clientState.ClientType() == exported.Localhost { + return nil + } + tmClient, ok := clientState.(*ibctm.ClientState) if !ok { return sdkerrors.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", diff --git a/modules/core/02-client/types/keys.go b/modules/core/02-client/types/keys.go index 9f3c0e4659b..b73734e594d 100644 --- a/modules/core/02-client/types/keys.go +++ b/modules/core/02-client/types/keys.go @@ -9,6 +9,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + "github.com/cosmos/ibc-go/v6/modules/core/exported" ) const ( @@ -49,6 +50,10 @@ func IsValidClientID(clientID string) bool { // ParseClientIdentifier parses the client type and sequence from the client identifier. func ParseClientIdentifier(clientID string) (string, uint64, error) { + if clientID == exported.Localhost { + return clientID, 0, nil + } + if !IsClientIDFormat(clientID) { return "", 0, sdkerrors.Wrapf(host.ErrInvalidID, "invalid client identifier %s is not in format: `{client-type}-{N}`", clientID) } diff --git a/modules/core/02-client/types/params.go b/modules/core/02-client/types/params.go index 38a341f8e38..3033c86a822 100644 --- a/modules/core/02-client/types/params.go +++ b/modules/core/02-client/types/params.go @@ -11,7 +11,7 @@ import ( var ( // DefaultAllowedClients are "06-solomachine" and "07-tendermint" - DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint} + DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Localhost} // KeyAllowedClients is store's key for AllowedClients Params KeyAllowedClients = []byte("AllowedClients") diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index cb4b4240a41..0d335bc52d5 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -74,12 +74,8 @@ func (k Keeper) ConnOpenTry( // generate a new connection connectionID := k.GenerateConnectionIdentifier(ctx) - selfHeight := clienttypes.GetSelfHeight(ctx) - if consensusHeight.GTE(selfHeight) { - return "", sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, - "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, - ) + if err := k.validateHeight(ctx, clientState.ClientType(), consensusHeight); err != nil { + return "", err } // validate client parameters of a chainB client stored on chainA @@ -164,12 +160,8 @@ func (k Keeper) ConnOpenAck( consensusHeight exported.Height, // latest height of chainA that chainB has stored on its chainA client ) error { // Check that chainB client hasn't stored invalid height - selfHeight := clienttypes.GetSelfHeight(ctx) - if consensusHeight.GTE(selfHeight) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, - "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, - ) + if err := k.validateHeight(ctx, clientState.ClientType(), consensusHeight); err != nil { + return err } // Retrieve connection @@ -295,3 +287,22 @@ func (k Keeper) ConnOpenConfirm( return nil } + +func (k Keeper) validateHeight( + ctx sdk.Context, + clientType string, + consensusHeight exported.Height, +) error { + if clientType == exported.Localhost { + return nil + } + + selfHeight := clienttypes.GetSelfHeight(ctx) + if consensusHeight.GTE(selfHeight) { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidHeight, + "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, + ) + } + return nil +} From a6793685767a97f97ff1c61935d9077cc2f46500 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 23 Jan 2023 10:46:14 +0100 Subject: [PATCH 07/52] adding localhost connection id const --- modules/core/03-connection/keeper/keeper.go | 10 +++------- modules/core/03-connection/types/keys.go | 3 +++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index a8d6255316c..72a5c7f25b8 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -52,16 +52,12 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramt // - VerifyMembership // - VerifyNonMembership func (k Keeper) EnableLocalhost(ctx sdk.Context) { - connectionEnd := types.ConnectionEnd{ - State: types.OPEN, - ClientId: "09-localhost", // todo: replace strings with consts - Versions: types.ExportedVersionsToProto(types.GetCompatibleVersions()), - Counterparty: types.NewCounterparty("09-localhost", "connection-localhost", commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())), - } + counterparty := types.NewCounterparty(exported.Localhost, types.LocalhostID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) + connectionEnd := types.NewConnectionEnd(types.OPEN, exported.Localhost, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&connectionEnd) - store.Set(host.ConnectionKey("connection-localhost"), bz) + store.Set(host.ConnectionKey(types.LocalhostID), bz) } // Logger returns a module-specific logger. diff --git a/modules/core/03-connection/types/keys.go b/modules/core/03-connection/types/keys.go index 23ccdb8e23d..7d2e4658b59 100644 --- a/modules/core/03-connection/types/keys.go +++ b/modules/core/03-connection/types/keys.go @@ -28,6 +28,9 @@ const ( // ConnectionPrefix is the prefix used when creating a connection identifier ConnectionPrefix = "connection-" + + // LocalhostID is the sentinel connection ID used for localhost IBC connections + LocalhostID = "connection-localhost" ) // FormatConnectionIdentifier returns the connection identifier with the sequence appended. From f5d0abdbcf2a7a8768aab414c0c6aed3bcc3f935 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 23 Jan 2023 11:24:48 +0100 Subject: [PATCH 08/52] updating client state for localhost --- modules/light-clients/09-localhost/client_state.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 6b999de5b03..a3447bca275 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -39,8 +39,7 @@ func (cs ClientState) GetLatestHeight() exported.Height { } // Status always returns Active. The localhost status cannot be changed. -func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec, -) exported.Status { +func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) exported.Status { return exported.Active } From 2dee015e29be702d78b93b22e9bf4fc2c1ce5e27 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 24 Jan 2023 20:04:44 +0100 Subject: [PATCH 09/52] adding abci call to update localhost client state --- modules/core/02-client/abci.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/core/02-client/abci.go b/modules/core/02-client/abci.go index 5b77e45d3da..6222403f15a 100644 --- a/modules/core/02-client/abci.go +++ b/modules/core/02-client/abci.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v6/modules/core/02-client/keeper" + "github.com/cosmos/ibc-go/v6/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ) @@ -31,4 +32,9 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { keeper.EmitUpgradeChainEvent(ctx, plan.Height) } } + + // update the localhost client with the latest block height + if err := k.UpdateClient(ctx, exported.Localhost, nil); err != nil { + k.Logger(ctx).Error(err.Error()) + } } From 6c33d2ed6d5f57a04ef557857a722e29868e14f7 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 24 Jan 2023 20:07:59 +0100 Subject: [PATCH 10/52] add basic update method, update godocs --- .../09-localhost/client_state.go | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index a3447bca275..763e4894bba 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -2,7 +2,6 @@ package localhost import ( "bytes" - "errors" "strings" "github.com/cosmos/cosmos-sdk/codec" @@ -10,35 +9,36 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" "github.com/cosmos/ibc-go/v6/modules/core/exported" ) var _ exported.ClientState = (*ClientState)(nil) -// NewClientState creates a new ClientState instance -func NewClientState(chainID string, height clienttypes.Height) *ClientState { +// NewClientState creates a new 09-localhost ClientState instance. +func NewClientState(chainID string, height clienttypes.Height) exported.ClientState { return &ClientState{ ChainId: chainID, LatestHeight: height, } } -// GetChainID returns an empty string +// GetChainID returns the client state chain ID. func (cs ClientState) GetChainID() string { return cs.ChainId } -// ClientType is localhost. +// ClientType returns the 09-localhost client type. func (cs ClientState) ClientType() string { return exported.Localhost } -// GetLatestHeight returns the latest height stored. +// GetLatestHeight returns the 09-localhost client state latest height. func (cs ClientState) GetLatestHeight() exported.Height { return cs.LatestHeight } -// Status always returns Active. The localhost status cannot be changed. +// Status always returns Active. The 09-localhost status cannot be changed. func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) exported.Status { return exported.Active } @@ -56,12 +56,12 @@ func (cs ClientState) Validate() error { return nil } -// ZeroCustomFields returns the same client state since there are no custom fields in localhost +// ZeroCustomFields returns the same client state since there are no custom fields in the 09-localhost client state. func (cs ClientState) ZeroCustomFields() exported.ClientState { return &cs } -// Initialize ensures that initial consensus state for localhost is nil +// Initialize ensures that initial consensus state for localhost is nil. func (cs ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, consState exported.ConsensusState) error { if consState != nil { return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "initial consensus state for localhost must be nil.") @@ -128,7 +128,7 @@ func (cs ClientState) VerifyNonMembership( // will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned // if the ClientMessage fails to verify. func (cs ClientState) VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) error { - return errors.New("todo: update") + return nil } // Checks for evidence of a misbehaviour in Header or Misbehaviour type. It assumes the ClientMessage @@ -137,18 +137,22 @@ func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCode return false } -// UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified -func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) { - +// UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified. +func (cs ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage) { } // UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. // Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { - return []exported.Height{} + height := clienttypes.NewHeight(clienttypes.ParseChainID(ctx.ChainID()), uint64(ctx.BlockHeight())) + + clientState := NewClientState(ctx.ChainID(), height) + clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, clientState)) + + return []exported.Height{height} } -// ExportMetadata is a no-op for localhost client +// ExportMetadata is a no-op for the 09-localhost client. func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { return nil } From 42cb750883cad4f488a7dffd18b05ebb3bf4659c Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Mon, 30 Jan 2023 13:45:45 +0000 Subject: [PATCH 11/52] Add sentinel localhost connection end to genesis state (#3040) --- modules/core/03-connection/genesis.go | 3 +++ .../03-connection/keeper/grpc_query_test.go | 9 ++++--- modules/core/03-connection/keeper/keeper.go | 6 +++++ .../core/03-connection/keeper/keeper_test.go | 22 ++++++++++++++++- .../core/03-connection/keeper/migrations.go | 24 +++++++++++++++++++ .../migrations/v7/expected_keepers.go | 13 ++++++++++ .../03-connection/migrations/v7/localhost.go | 14 +++++++++++ modules/core/module.go | 13 ++++++---- 8 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 modules/core/03-connection/keeper/migrations.go create mode 100644 modules/core/03-connection/migrations/v7/expected_keepers.go create mode 100644 modules/core/03-connection/migrations/v7/localhost.go diff --git a/modules/core/03-connection/genesis.go b/modules/core/03-connection/genesis.go index 44a8585bcdb..6037c7b91c6 100644 --- a/modules/core/03-connection/genesis.go +++ b/modules/core/03-connection/genesis.go @@ -19,6 +19,9 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { } k.SetNextConnectionSequence(ctx, gs.NextConnectionSequence) k.SetParams(ctx, gs.Params) + + localhostConnection := k.CreateSentinelLocalhostConnection() + k.SetConnection(ctx, types.LocalhostID, localhostConnection) } // ExportGenesis returns the ibc connection submodule's exported genesis. diff --git a/modules/core/03-connection/keeper/grpc_query_test.go b/modules/core/03-connection/keeper/grpc_query_test.go index dd9531fb43e..6aee91f4793 100644 --- a/modules/core/03-connection/keeper/grpc_query_test.go +++ b/modules/core/03-connection/keeper/grpc_query_test.go @@ -87,9 +87,12 @@ func (suite *KeeperTestSuite) TestQueryConnection() { } func (suite *KeeperTestSuite) TestQueryConnections() { + localhostConnectionEnd := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection() + localhostConn := types.NewIdentifiedConnection(types.LocalhostID, localhostConnectionEnd) + var ( req *types.QueryConnectionsRequest - expConnections = []*types.IdentifiedConnection{} + expConnections = []*types.IdentifiedConnection{&localhostConn} ) testCases := []struct { @@ -137,11 +140,11 @@ func (suite *KeeperTestSuite) TestQueryConnections() { iconn2 := types.NewIdentifiedConnection(path2.EndpointA.ConnectionID, conn2) iconn3 := types.NewIdentifiedConnection(path3.EndpointA.ConnectionID, conn3) - expConnections = []*types.IdentifiedConnection{&iconn1, &iconn2, &iconn3} + expConnections = []*types.IdentifiedConnection{&iconn1, &iconn2, &iconn3, &localhostConn} req = &types.QueryConnectionsRequest{ Pagination: &query.PageRequest{ - Limit: 3, + Limit: 4, CountTotal: true, }, } diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index b4bdcb22c7c..5b5266db3c5 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -208,6 +208,12 @@ func (k Keeper) GetAllConnections(ctx sdk.Context) (connections []types.Identifi return connections } +// CreateSentinelLocalhostConnection returns the sentinel localhost connection end. +func (k Keeper) CreateSentinelLocalhostConnection() types.ConnectionEnd { + counterparty := types.NewCounterparty(exported.Localhost, types.LocalhostID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) + return types.NewConnectionEnd(types.OPEN, exported.Localhost, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) +} + // addConnectionToClient is used to add a connection identifier to the set of // connections associated with a client. func (k Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID string) error { diff --git a/modules/core/03-connection/keeper/keeper_test.go b/modules/core/03-connection/keeper/keeper_test.go index a82573788d3..58a0e5734d5 100644 --- a/modules/core/03-connection/keeper/keeper_test.go +++ b/modules/core/03-connection/keeper/keeper_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v7/testing" ) @@ -79,7 +80,10 @@ func (suite KeeperTestSuite) TestGetAllConnections() { //nolint:govet // this is iconn1 := types.NewIdentifiedConnection(path1.EndpointA.ConnectionID, conn1) iconn2 := types.NewIdentifiedConnection(path2.EndpointA.ConnectionID, conn2) - expConnections := []types.IdentifiedConnection{iconn1, iconn2} + localhostConnectionEnd := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection() + localhostConn := types.NewIdentifiedConnection(types.LocalhostID, localhostConnectionEnd) + + expConnections := []types.IdentifiedConnection{iconn1, iconn2, localhostConn} connections := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetAllConnections(suite.chainA.GetContext()) suite.Require().Len(connections, len(expConnections)) @@ -156,3 +160,19 @@ func (suite *KeeperTestSuite) TestGetTimestampAtHeight() { }) } } + +func (suite *KeeperTestSuite) TestLocalhostConnectionEndCreation() { + ctx := suite.chainA.GetContext() + connectionKeeper := suite.chainA.App.GetIBCKeeper().ConnectionKeeper + localhostConnection := connectionKeeper.CreateSentinelLocalhostConnection() + connectionKeeper.SetConnection(ctx, types.LocalhostID, localhostConnection) + + connectionEnd, found := connectionKeeper.GetConnection(ctx, types.LocalhostID) + + suite.Require().True(found) + suite.Require().Equal(types.OPEN, connectionEnd.State) + suite.Require().Equal(exported.Localhost, connectionEnd.ClientId) + suite.Require().Equal(types.ExportedVersionsToProto(types.GetCompatibleVersions()), connectionEnd.Versions) + expectedCounterParty := types.NewCounterparty(exported.Localhost, types.LocalhostID, commitmenttypes.NewMerklePrefix(connectionKeeper.GetCommitmentPrefix().Bytes())) + suite.Require().Equal(expectedCounterParty, connectionEnd.Counterparty) +} diff --git a/modules/core/03-connection/keeper/migrations.go b/modules/core/03-connection/keeper/migrations.go new file mode 100644 index 00000000000..9965eab28ca --- /dev/null +++ b/modules/core/03-connection/keeper/migrations.go @@ -0,0 +1,24 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + connectionv7 "github.com/cosmos/ibc-go/v7/modules/core/03-connection/migrations/v7" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +// Migrate3to4 migrates from version 3 to 4. +// This migration writes the sentinel localhost connection end to state. +func (m Migrator) Migrate3to4(ctx sdk.Context) error { + connectionv7.MigrateLocalhostConnection(ctx, m.keeper) + return nil +} diff --git a/modules/core/03-connection/migrations/v7/expected_keepers.go b/modules/core/03-connection/migrations/v7/expected_keepers.go new file mode 100644 index 00000000000..ff4c17c0335 --- /dev/null +++ b/modules/core/03-connection/migrations/v7/expected_keepers.go @@ -0,0 +1,13 @@ +package v7 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" +) + +// ConnectionKeeper expected IBC connection keeper +type ConnectionKeeper interface { + CreateSentinelLocalhostConnection() types.ConnectionEnd + SetConnection(ctx sdk.Context, connectionID string, connection types.ConnectionEnd) +} diff --git a/modules/core/03-connection/migrations/v7/localhost.go b/modules/core/03-connection/migrations/v7/localhost.go new file mode 100644 index 00000000000..4a637fb8aae --- /dev/null +++ b/modules/core/03-connection/migrations/v7/localhost.go @@ -0,0 +1,14 @@ +package v7 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" +) + +// MigrateLocalhostConnection creates the sentinel localhost connection end to enable +// localhost ibc functionality. +func MigrateLocalhostConnection(ctx sdk.Context, connectionKeeper ConnectionKeeper) { + localhostConnection := connectionKeeper.CreateSentinelLocalhostConnection() + connectionKeeper.SetConnection(ctx, connectiontypes.LocalhostID, localhostConnection) +} diff --git a/modules/core/module.go b/modules/core/module.go index ee0799f64c2..9171d121986 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -19,6 +19,7 @@ import ( ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectionkeeper "github.com/cosmos/ibc-go/v7/modules/core/03-connection/keeper" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v7/modules/core/client/cli" @@ -124,9 +125,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { channeltypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) types.RegisterQueryService(cfg.QueryServer(), am.keeper) - m := clientkeeper.NewMigrator(am.keeper.ClientKeeper) - err := cfg.RegisterMigration(exported.ModuleName, 2, m.Migrate2to3) - if err != nil { + clientMigrator := clientkeeper.NewMigrator(am.keeper.ClientKeeper) + if err := cfg.RegisterMigration(exported.ModuleName, 2, clientMigrator.Migrate2to3); err != nil { + panic(err) + } + + connectionMigrator := connectionkeeper.NewMigrator(am.keeper.ConnectionKeeper) + if err := cfg.RegisterMigration(exported.ModuleName, 3, connectionMigrator.Migrate3to4); err != nil { panic(err) } } @@ -150,7 +155,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 3 } +func (AppModule) ConsensusVersion() uint64 { return 4 } // BeginBlock returns the begin blocker for the ibc module. func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { From bf26904c9cc395122b90cccbe4f847a4a144bdf4 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 31 Jan 2023 11:45:06 +0100 Subject: [PATCH 12/52] adding getClientStateAndKVStore to 03-connection verify.go to retrieve core IBC store for localhost clients (#3083) --- modules/core/03-connection/keeper/verify.go | 96 ++++++++++----------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 2a505ec317e..d1624bbfbb0 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -24,11 +24,9 @@ func (k Keeper) VerifyClientState( clientState exported.ClientState, ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - targetClient, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + targetClient, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := targetClient.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -36,7 +34,7 @@ func (k Keeper) VerifyClientState( } merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.GetCounterparty().GetClientID())) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -68,11 +66,9 @@ func (k Keeper) VerifyClientConsensusState( consensusState exported.ConsensusState, ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - clientState, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -80,7 +76,7 @@ func (k Keeper) VerifyClientConsensusState( } merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.GetCounterparty().GetClientID(), consensusHeight)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -112,11 +108,9 @@ func (k Keeper) VerifyConnectionState( counterpartyConnection exported.ConnectionI, // opposite connection ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - clientState, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -124,7 +118,7 @@ func (k Keeper) VerifyConnectionState( } merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -162,11 +156,9 @@ func (k Keeper) VerifyChannelState( channel exported.ChannelI, ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - clientState, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -174,7 +166,7 @@ func (k Keeper) VerifyChannelState( } merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -213,11 +205,9 @@ func (k Keeper) VerifyPacketCommitment( commitmentBytes []byte, ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - clientState, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -229,7 +219,7 @@ func (k Keeper) VerifyPacketCommitment( blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(portID, channelID, sequence)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -258,11 +248,9 @@ func (k Keeper) VerifyPacketAcknowledgement( acknowledgement []byte, ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - clientState, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -274,7 +262,7 @@ func (k Keeper) VerifyPacketAcknowledgement( blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(portID, channelID, sequence)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -303,11 +291,9 @@ func (k Keeper) VerifyPacketReceiptAbsence( sequence uint64, ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - clientState, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -319,7 +305,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(portID, channelID, sequence)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -347,11 +333,9 @@ func (k Keeper) VerifyNextSequenceRecv( nextSequenceRecv uint64, ) error { clientID := connection.GetClientID() - clientStore := k.clientKeeper.ClientStore(ctx, clientID) - - clientState, found := k.clientKeeper.GetClientState(ctx, clientID) - if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + if err != nil { + return err } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { @@ -363,7 +347,7 @@ func (k Keeper) VerifyNextSequenceRecv( blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(portID, channelID)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err } @@ -393,3 +377,19 @@ func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) timeDelay := connection.GetDelayPeriod() return uint64(math.Ceil(float64(timeDelay) / float64(expectedTimePerBlock))) } + +// getClientStateAndKVStore returns the client state and associated KVStore for the provided client identifier. +// If the client type is localhost then the core IBC KVStore is returned, otherwise the client prefixed store is returned. +func (k Keeper) getClientStateAndKVStore(ctx sdk.Context, clientID string) (exported.ClientState, sdk.KVStore, error) { + clientState, found := k.clientKeeper.GetClientState(ctx, clientID) + if !found { + return nil, nil, sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + } + + store := k.clientKeeper.ClientStore(ctx, clientID) + if clientState.ClientType() == exported.Localhost { + store = ctx.KVStore(k.storeKey) + } + + return clientState, store, nil +} From d1b082553c81f9fc26b510ee034c118c92672bb2 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 31 Jan 2023 16:47:17 +0100 Subject: [PATCH 13/52] chore: adding 09-localhost to client InitGenesis (#3092) * adding localhost AppModuleBasic to app.go. adding localhost client to InitGenesis. Fixing update localhost client * renmaing variable * adding migration handler for enabling localhost client * updating to use clienttypes.GetSelfHeight() --- modules/core/02-client/abci.go | 4 +-- modules/core/02-client/genesis.go | 4 +++ .../core/02-client/keeper/grpc_query_test.go | 11 +++++--- modules/core/02-client/keeper/keeper.go | 12 +++++++++ modules/core/02-client/keeper/keeper_test.go | 23 +++++++++++----- modules/core/02-client/keeper/migrations.go | 8 +++++- .../migrations/v7/expected_keepers.go | 1 + .../core/02-client/migrations/v7/localhost.go | 10 +++++++ .../02-client/migrations/v7/localhost_test.go | 26 +++++++++++++++++++ modules/core/03-connection/keeper/keeper.go | 19 -------------- modules/core/module.go | 12 ++++++++- .../09-localhost/client_state.go | 11 ++++++-- testing/simapp/app.go | 2 ++ 13 files changed, 109 insertions(+), 34 deletions(-) create mode 100644 modules/core/02-client/migrations/v7/localhost.go create mode 100644 modules/core/02-client/migrations/v7/localhost_test.go diff --git a/modules/core/02-client/abci.go b/modules/core/02-client/abci.go index 7f2e1b72aef..66c092fa0d2 100644 --- a/modules/core/02-client/abci.go +++ b/modules/core/02-client/abci.go @@ -34,7 +34,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { } // update the localhost client with the latest block height - if err := k.UpdateClient(ctx, exported.Localhost, nil); err != nil { - k.Logger(ctx).Error(err.Error()) + if clientState, found := k.GetClientState(ctx, exported.Localhost); found { + k.UpdateLocalhostClient(ctx, clientState) } } diff --git a/modules/core/02-client/genesis.go b/modules/core/02-client/genesis.go index aae41d9ae5a..269eb7f6bd7 100644 --- a/modules/core/02-client/genesis.go +++ b/modules/core/02-client/genesis.go @@ -46,6 +46,10 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { } k.SetNextClientSequence(ctx, gs.NextClientSequence) + + if err := k.CreateLocalhostClient(ctx); err != nil { + panic(fmt.Sprintf("failed to initialise localhost client: %s", err.Error())) + } } // ExportGenesis returns the ibc client submodule's exported genesis. diff --git a/modules/core/02-client/keeper/grpc_query_test.go b/modules/core/02-client/keeper/grpc_query_test.go index aa4d12265ab..a10e8903dd1 100644 --- a/modules/core/02-client/keeper/grpc_query_test.go +++ b/modules/core/02-client/keeper/grpc_query_test.go @@ -111,13 +111,17 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { { "empty pagination", func() { + localhost := types.NewIdentifiedClientState(exported.Localhost, suite.chainA.GetClientState(exported.Localhost)) + expClientStates = types.IdentifiedClientStates{localhost} req = &types.QueryClientStatesRequest{} }, true, }, { - "success, no results", + "success, only localhost", func() { + localhost := types.NewIdentifiedClientState(exported.Localhost, suite.chainA.GetClientState(exported.Localhost)) + expClientStates = types.IdentifiedClientStates{localhost} req = &types.QueryClientStatesRequest{ Pagination: &query.PageRequest{ Limit: 3, @@ -139,11 +143,12 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { clientStateA1 := path1.EndpointA.GetClientState() clientStateA2 := path2.EndpointA.GetClientState() + localhost := types.NewIdentifiedClientState(exported.Localhost, suite.chainA.GetClientState(exported.Localhost)) idcs := types.NewIdentifiedClientState(path1.EndpointA.ClientID, clientStateA1) idcs2 := types.NewIdentifiedClientState(path2.EndpointA.ClientID, clientStateA2) // order is sorted by client id - expClientStates = types.IdentifiedClientStates{idcs, idcs2}.Sort() + expClientStates = types.IdentifiedClientStates{localhost, idcs, idcs2}.Sort() req = &types.QueryClientStatesRequest{ Pagination: &query.PageRequest{ Limit: 20, @@ -158,10 +163,10 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset + tc.malleate() ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) - res, err := suite.chainA.QueryServer.ClientStates(ctx, req) if tc.expPass { diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 3342e6b402d..00fb32ad1ed 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -20,6 +20,7 @@ import ( host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ) // Keeper represents a type that grants read and write permissions to any client @@ -53,6 +54,17 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) } +// CreateLocalhostClient initialises the 09-localhost client state and sets it in state. +func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error { + var clientState localhost.ClientState + return clientState.Initialize(ctx, k.cdc, k.ClientStore(ctx, exported.Localhost), nil) +} + +// UpdateLocalhostClient updates the 09-localhost client to the latest block height and chain ID. +func (k Keeper) UpdateLocalhostClient(ctx sdk.Context, clientState exported.ClientState) []exported.Height { + return clientState.UpdateState(ctx, k.cdc, k.ClientStore(ctx, exported.Localhost), nil) +} + // GenerateClientIdentifier returns the next client identifier. func (k Keeper) GenerateClientIdentifier(ctx sdk.Context, clientType string) string { nextClientSeq := k.GetNextClientSequence(ctx) diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index 8e5cac289d4..a995b56d1a5 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/exported" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibctesting "github.com/cosmos/ibc-go/v7/testing" ibctestingmock "github.com/cosmos/ibc-go/v7/testing/mock" "github.com/cosmos/ibc-go/v7/testing/simapp" @@ -236,9 +237,10 @@ func (suite *KeeperTestSuite) TestValidateSelfClient() { func (suite KeeperTestSuite) TestGetAllGenesisClients() { //nolint:govet // this is a test, we are okay with copying locks clientIDs := []string{ - testClientID2, testClientID3, testClientID, + exported.Localhost, testClientID2, testClientID3, testClientID, } expClients := []exported.ClientState{ + localhost.NewClientState(suite.chainA.ChainID, types.GetSelfHeight(suite.chainA.GetContext())), ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), @@ -418,22 +420,31 @@ func (suite KeeperTestSuite) TestIterateClientStates() { //nolint:govet // this testCases := []struct { name string prefix []byte - expClientIDs []string + expClientIDs func() []string }{ { "all clientIDs", nil, - append(expSMClientIDs, expTMClientIDs...), + func() []string { + allClientIDs := []string{exported.Localhost} + allClientIDs = append(allClientIDs, expSMClientIDs...) + allClientIDs = append(allClientIDs, expTMClientIDs...) + return allClientIDs + }, }, { "tendermint clientIDs", []byte(exported.Tendermint), - expTMClientIDs, + func() []string { + return expTMClientIDs + }, }, { "solo machine clientIDs", []byte(exported.Solomachine), - expSMClientIDs, + func() []string { + return expSMClientIDs + }, }, } @@ -446,7 +457,7 @@ func (suite KeeperTestSuite) TestIterateClientStates() { //nolint:govet // this return false }) - suite.Require().Equal(tc.expClientIDs, clientIDs) + suite.Require().ElementsMatch(tc.expClientIDs(), clientIDs) }) } } diff --git a/modules/core/02-client/keeper/migrations.go b/modules/core/02-client/keeper/migrations.go index ad3587ae901..b8290133042 100644 --- a/modules/core/02-client/keeper/migrations.go +++ b/modules/core/02-client/keeper/migrations.go @@ -16,7 +16,7 @@ func NewMigrator(keeper Keeper) Migrator { return Migrator{keeper: keeper} } -// Migrate2to3 migrates from version 2 to 3. +// Migrate2to3 migrates from consensus version 2 to 3. // This migration // - migrates solo machine client states from v2 to v3 protobuf definition // - prunes solo machine consensus states @@ -25,3 +25,9 @@ func NewMigrator(keeper Keeper) Migrator { func (m Migrator) Migrate2to3(ctx sdk.Context) error { return v7.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc, m.keeper) } + +// Migrate3to4 migrates from consensus version 3 to 4. +// This migration enables the localhost client. +func (m Migrator) Migrate3to4(ctx sdk.Context) error { + return v7.MigrateLocalhostClient(ctx, m.keeper) +} diff --git a/modules/core/02-client/migrations/v7/expected_keepers.go b/modules/core/02-client/migrations/v7/expected_keepers.go index 6d424cc0370..f36be5fabe2 100644 --- a/modules/core/02-client/migrations/v7/expected_keepers.go +++ b/modules/core/02-client/migrations/v7/expected_keepers.go @@ -11,4 +11,5 @@ type ClientKeeper interface { GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) SetClientState(ctx sdk.Context, clientID string, clientState exported.ClientState) ClientStore(ctx sdk.Context, clientID string) sdk.KVStore + CreateLocalhostClient(ctx sdk.Context) error } diff --git a/modules/core/02-client/migrations/v7/localhost.go b/modules/core/02-client/migrations/v7/localhost.go new file mode 100644 index 00000000000..49709b9db9f --- /dev/null +++ b/modules/core/02-client/migrations/v7/localhost.go @@ -0,0 +1,10 @@ +package v7 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// MigrateLocalhostClient initialises the 09-localhost client state and sets it in state. +func MigrateLocalhostClient(ctx sdk.Context, clientKeeper ClientKeeper) error { + return clientKeeper.CreateLocalhostClient(ctx) +} diff --git a/modules/core/02-client/migrations/v7/localhost_test.go b/modules/core/02-client/migrations/v7/localhost_test.go new file mode 100644 index 00000000000..982641f42d7 --- /dev/null +++ b/modules/core/02-client/migrations/v7/localhost_test.go @@ -0,0 +1,26 @@ +package v7_test + +import ( + v7 "github.com/cosmos/ibc-go/v7/modules/core/02-client/migrations/v7" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + "github.com/cosmos/ibc-go/v7/modules/core/exported" +) + +func (suite *MigrationsV7TestSuite) TestMigrateLocalhostClient() { + suite.SetupTest() + + // note: explicitly remove the localhost client before running migration handler + clientStore := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), exported.Localhost) + clientStore.Delete(host.ClientStateKey()) + + clientState, found := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), exported.Localhost) + suite.Require().False(found) + suite.Require().Nil(clientState) + + err := v7.MigrateLocalhostClient(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper) + suite.Require().NoError(err) + + clientState, found = suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), exported.Localhost) + suite.Require().True(found) + suite.Require().NotNil(clientState) +} diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 5b5266db3c5..3681f957aae 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -41,25 +41,6 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramt } } -// EnableLocalhost is called by init genesis or an upgrade handler? -// EnableLocalhost sets the localhost loopback connection end in store -// NOTES: -// - channel handshake code can remain the same -// - packet handlers require access to a ClientState and use the following methods: -// - Status() -// - GetLatestHeight() -// - GetTimestampAtHeight() -// - VerifyMembership -// - VerifyNonMembership -func (k Keeper) EnableLocalhost(ctx sdk.Context) { - counterparty := types.NewCounterparty(exported.Localhost, types.LocalhostID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) - connectionEnd := types.NewConnectionEnd(types.OPEN, exported.Localhost, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) - - store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&connectionEnd) - store.Set(host.ConnectionKey(types.LocalhostID), bz) -} - // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) diff --git a/modules/core/module.go b/modules/core/module.go index 9171d121986..15e901caa2d 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -131,7 +131,17 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } connectionMigrator := connectionkeeper.NewMigrator(am.keeper.ConnectionKeeper) - if err := cfg.RegisterMigration(exported.ModuleName, 3, connectionMigrator.Migrate3to4); err != nil { + if err := cfg.RegisterMigration(exported.ModuleName, 3, func(ctx sdk.Context) error { + if err := connectionMigrator.Migrate3to4(ctx); err != nil { + return err + } + + if err := clientMigrator.Migrate3to4(ctx); err != nil { + return err + } + + return nil + }); err != nil { panic(err) } } diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 859ccb1ac05..06dd4e8fd38 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -62,11 +62,18 @@ func (cs ClientState) ZeroCustomFields() exported.ClientState { } // Initialize ensures that initial consensus state for localhost is nil. -func (cs ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, consState exported.ConsensusState) error { +func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, consState exported.ConsensusState) error { if consState != nil { return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "initial consensus state for localhost must be nil.") } + clientState := ClientState{ + ChainId: ctx.ChainID(), + LatestHeight: clienttypes.GetSelfHeight(ctx), + } + + clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &clientState)) + return nil } @@ -144,7 +151,7 @@ func (cs ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCod // UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. // Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { - height := clienttypes.NewHeight(clienttypes.ParseChainID(ctx.ChainID()), uint64(ctx.BlockHeight())) + height := clienttypes.GetSelfHeight(ctx) clientState := NewClientState(ctx.ChainID(), height) clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, clientState)) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 6ed2411f9cd..d84e8fa6a06 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -114,6 +114,7 @@ import ( ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" simappparams "github.com/cosmos/ibc-go/v7/testing/simapp/params" simappupgrades "github.com/cosmos/ibc-go/v7/testing/simapp/upgrades" @@ -159,6 +160,7 @@ var ( slashing.AppModuleBasic{}, ibc.AppModuleBasic{}, ibctm.AppModuleBasic{}, + localhost.AppModuleBasic{}, solomachine.AppModuleBasic{}, feegrantmodule.AppModuleBasic{}, upgrade.AppModuleBasic{}, From 72fcd65ce2ccbed9faff6fe8a371d80223534840 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 2 Feb 2023 15:40:43 +0100 Subject: [PATCH 14/52] adding initial localhost client testing (#3085) * adding initial localhost client testing scaffolding * add testing placeholders, adapt initialise code, wire AppModuleBasic * adding happy path test cases, fixing store prefixing in verify membership/non-membership * formatting * adding additional test cases * adding remaining test cases * adding inline comments --- .../09-localhost/client_state.go | 36 +- .../09-localhost/client_state_test.go | 439 ++++++++++++++++++ .../09-localhost/localhost_test.go | 25 + 3 files changed, 491 insertions(+), 9 deletions(-) create mode 100644 modules/light-clients/09-localhost/client_state_test.go create mode 100644 modules/light-clients/09-localhost/localhost_test.go diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 06dd4e8fd38..deda5cdcdb6 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -9,6 +9,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -23,11 +24,6 @@ func NewClientState(chainID string, height clienttypes.Height) exported.ClientSt } } -// GetChainID returns the client state chain ID. -func (cs ClientState) GetChainID() string { - return cs.ChainId -} - // ClientType returns the 09-localhost client type. func (cs ClientState) ClientType() string { return exported.Localhost @@ -95,7 +91,17 @@ func (cs ClientState) VerifyMembership( path exported.Path, value []byte, ) error { - bz := store.Get([]byte(path.String())) + merklePath, ok := path.(commitmenttypes.MerklePath) + if !ok { + return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + } + + if len(merklePath.GetKeyPath()) != 2 { + return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + } + + // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store + bz := store.Get([]byte(merklePath.KeyPath[1])) if bz == nil { return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) } @@ -122,7 +128,17 @@ func (cs ClientState) VerifyNonMembership( proof []byte, path exported.Path, ) error { - bz := store.Get([]byte(path.String())) + merklePath, ok := path.(commitmenttypes.MerklePath) + if !ok { + return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + } + + if len(merklePath.GetKeyPath()) != 2 { + return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + } + + // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store + bz := store.Get([]byte(merklePath.KeyPath[1])) if bz != nil { return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- found for path %s", path) } @@ -153,8 +169,10 @@ func (cs ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCod func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { height := clienttypes.GetSelfHeight(ctx) - clientState := NewClientState(ctx.ChainID(), height) - clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, clientState)) + cs.ChainId = ctx.ChainID() + cs.LatestHeight = height + + clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &cs)) return []exported.Height{height} } diff --git a/modules/light-clients/09-localhost/client_state_test.go b/modules/light-clients/09-localhost/client_state_test.go new file mode 100644 index 00000000000..8896364a37b --- /dev/null +++ b/modules/light-clients/09-localhost/client_state_test.go @@ -0,0 +1,439 @@ +package localhost_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" + ibctesting "github.com/cosmos/ibc-go/v7/testing" + "github.com/cosmos/ibc-go/v7/testing/mock" +) + +func (suite *LocalhostTestSuite) TestStatus() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(3, 10)) + suite.Require().Equal(exported.Active, clientState.Status(suite.chain.GetContext(), nil, nil)) +} + +func (suite *LocalhostTestSuite) TestClientType() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(3, 10)) + suite.Require().Equal(exported.Localhost, clientState.ClientType()) +} + +func (suite *LocalhostTestSuite) TestGetLatestHeight() { + expectedHeight := clienttypes.NewHeight(3, 10) + clientState := localhost.NewClientState("chainID", expectedHeight) + suite.Require().Equal(expectedHeight, clientState.GetLatestHeight()) +} + +func (suite *LocalhostTestSuite) TestZeroCustomFields() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + suite.Require().Equal(clientState, clientState.ZeroCustomFields()) +} + +func (suite *LocalhostTestSuite) TestGetTimestampAtHeight() { + ctx := suite.chain.GetContext() + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + + timestamp, err := clientState.GetTimestampAtHeight(ctx, nil, nil, nil) + suite.Require().NoError(err) + suite.Require().Equal(uint64(ctx.BlockTime().UnixNano()), timestamp) +} + +func (suite *LocalhostTestSuite) TestValidate() { + testCases := []struct { + name string + clientState exported.ClientState + expPass bool + }{ + { + name: "valid client", + clientState: localhost.NewClientState("chainID", clienttypes.NewHeight(3, 10)), + expPass: true, + }, + { + name: "invalid chain id", + clientState: localhost.NewClientState(" ", clienttypes.NewHeight(3, 10)), + expPass: false, + }, + { + name: "invalid height", + clientState: localhost.NewClientState("chainID", clienttypes.ZeroHeight()), + expPass: false, + }, + } + + for _, tc := range testCases { + err := tc.clientState.Validate() + if tc.expPass { + suite.Require().NoError(err, tc.name) + } else { + suite.Require().Error(err, tc.name) + } + } +} + +func (suite *LocalhostTestSuite) TestInitialize() { + testCases := []struct { + name string + consState exported.ConsensusState + expPass bool + }{ + { + "valid initialization", + nil, + true, + }, + { + "invalid consenus state", + &ibctm.ConsensusState{}, + false, + }, + } + + for _, tc := range testCases { + suite.SetupTest() + + clientState := localhost.NewClientState(suite.chain.ChainID, clienttypes.NewHeight(3, 10)) + clientStore := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.Localhost) + + err := clientState.Initialize(suite.chain.GetContext(), suite.chain.Codec, clientStore, tc.consState) + + if tc.expPass { + suite.Require().NoError(err, "valid testcase: %s failed", tc.name) + } else { + suite.Require().Error(err, "invalid testcase: %s passed", tc.name) + } + } +} + +func (suite *LocalhostTestSuite) TestVerifyMembership() { + var ( + path exported.Path + value []byte + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success: client state verification", + func() { + clientState := suite.chain.GetClientState(exported.Localhost) + + merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(exported.Localhost)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + value = clienttypes.MustMarshalClientState(suite.chain.Codec, clientState) + }, + true, + }, + { + "success: connection state verification", + func() { + connectionEnd := connectiontypes.NewConnectionEnd( + connectiontypes.OPEN, + exported.Localhost, + connectiontypes.NewCounterparty(exported.Localhost, connectiontypes.LocalhostID, suite.chain.GetPrefix()), + connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions()), 0, + ) + + suite.chain.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chain.GetContext(), connectiontypes.LocalhostID, connectionEnd) + + merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectiontypes.LocalhostID)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + value = suite.chain.Codec.MustMarshal(&connectionEnd) + }, + true, + }, + { + "success: channel state verification", + func() { + channel := channeltypes.NewChannel( + channeltypes.OPEN, + channeltypes.UNORDERED, + channeltypes.NewCounterparty(mock.PortID, ibctesting.FirstChannelID), + []string{connectiontypes.LocalhostID}, + mock.Version, + ) + + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) + + merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + value = suite.chain.Codec.MustMarshal(&channel) + }, + true, + }, + { + "success: next sequence recv verification", + func() { + nextSeqRecv := uint64(100) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetNextSequenceRecv(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, nextSeqRecv) + + merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(mock.PortID, ibctesting.FirstChannelID)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + value = sdk.Uint64ToBigEndian(nextSeqRecv) + }, + true, + }, + { + "success: packet commitment verification", + func() { + packet := channeltypes.NewPacket( + ibctesting.MockPacketData, + 1, + ibctesting.MockPort, + ibctesting.FirstChannelID, + ibctesting.MockPort, + ibctesting.FirstChannelID, + clienttypes.NewHeight(0, 10), + 0, + ) + + commitmentBz := channeltypes.CommitPacket(suite.chain.Codec, packet) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, commitmentBz) + + merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + value = commitmentBz + }, + true, + }, + { + "success: packet acknowledgement verification", + func() { + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, ibctesting.MockAcknowledgement) + + merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(mock.PortID, ibctesting.FirstChannelID, 1)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + value = ibctesting.MockAcknowledgement + }, + true, + }, + { + "invalid type for key path", + func() { + path = mock.KeyPath{} + }, + false, + }, + { + "key path has too many elements", + func() { + path = commitmenttypes.NewMerklePath("ibc", "test", "key") + }, + false, + }, + { + "no value found at provided key path", + func() { + merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(mock.PortID, ibctesting.FirstChannelID, 100)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + value = ibctesting.MockAcknowledgement + }, + false, + }, + { + "invalid value, bytes are not equal", + func() { + channel := channeltypes.NewChannel( + channeltypes.OPEN, + channeltypes.UNORDERED, + channeltypes.NewCounterparty(mock.PortID, ibctesting.FirstChannelID), + []string{connectiontypes.LocalhostID}, + mock.Version, + ) + + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) + + merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + + channel.State = channeltypes.CLOSED // modify the channel before marshalling to value bz + value = suite.chain.Codec.MustMarshal(&channel) + }, + false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + tc.malleate() + + clientState := suite.chain.GetClientState(exported.Localhost) + store := suite.chain.GetContext().KVStore(suite.chain.GetSimApp().GetKey(exported.StoreKey)) + + err := clientState.VerifyMembership( + suite.chain.GetContext(), + store, + suite.chain.Codec, + clienttypes.ZeroHeight(), + 0, 0, // use zero values for delay periods + nil, // localhost proofs are nil + path, + value, + ) + + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + }) + } +} + +func (suite *LocalhostTestSuite) TestVerifyNonMembership() { + var path exported.Path + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success: packet receipt absence verification", + func() { + merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(mock.PortID, ibctesting.FirstChannelID, 1)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + }, + true, + }, + { + "packet receipt absence verification fails", + func() { + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketReceipt(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1) + + merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(mock.PortID, ibctesting.FirstChannelID, 1)) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) + + path = merklePath + }, + false, + }, + { + "invalid type for key path", + func() { + path = mock.KeyPath{} + }, + false, + }, + { + "key path has too many elements", + func() { + path = commitmenttypes.NewMerklePath("ibc", "test", "key") + }, + false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + tc.malleate() + + clientState := suite.chain.GetClientState(exported.Localhost) + store := suite.chain.GetContext().KVStore(suite.chain.GetSimApp().GetKey(exported.StoreKey)) + + err := clientState.VerifyNonMembership( + suite.chain.GetContext(), + store, + suite.chain.Codec, + clienttypes.ZeroHeight(), + 0, 0, // use zero values for delay periods + nil, // localhost proofs are nil + path, + ) + + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + }) + } +} + +func (suite *LocalhostTestSuite) TestVerifyClientMessage() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + suite.Require().Nil(clientState.VerifyClientMessage(suite.chain.GetContext(), nil, nil, nil)) +} + +func (suite *LocalhostTestSuite) TestVerifyCheckForMisbehaviour() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + suite.Require().False(clientState.CheckForMisbehaviour(suite.chain.GetContext(), nil, nil, nil)) +} + +func (suite *LocalhostTestSuite) TestUpdateState() { + clientState := localhost.NewClientState(suite.chain.ChainID, clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight()))) + store := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.Localhost) + + suite.coordinator.CommitBlock(suite.chain) + + heights := clientState.UpdateState(suite.chain.GetContext(), suite.chain.Codec, store, nil) + + expHeight := clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight())) + suite.Require().True(heights[0].EQ(expHeight)) + + clientState = suite.chain.GetClientState(exported.Localhost) + suite.Require().True(heights[0].EQ(clientState.GetLatestHeight())) +} + +func (suite *LocalhostTestSuite) TestExportMetadata() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + suite.Require().Nil(clientState.ExportMetadata(nil)) +} + +func (suite *LocalhostTestSuite) TestCheckSubstituteAndUpdateState() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + err := clientState.CheckSubstituteAndUpdateState(suite.chain.GetContext(), suite.chain.Codec, nil, nil, nil) + suite.Require().Error(err) +} + +func (suite *LocalhostTestSuite) TestVerifyUpgradeAndUpdateState() { + clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + err := clientState.VerifyUpgradeAndUpdateState(suite.chain.GetContext(), suite.chain.Codec, nil, nil, nil, nil, nil) + suite.Require().Error(err) +} diff --git a/modules/light-clients/09-localhost/localhost_test.go b/modules/light-clients/09-localhost/localhost_test.go new file mode 100644 index 00000000000..c22ef1e35ae --- /dev/null +++ b/modules/light-clients/09-localhost/localhost_test.go @@ -0,0 +1,25 @@ +package localhost_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + ibctesting "github.com/cosmos/ibc-go/v7/testing" +) + +type LocalhostTestSuite struct { + suite.Suite + + coordinator ibctesting.Coordinator + chain *ibctesting.TestChain +} + +func (suite *LocalhostTestSuite) SetupTest() { + suite.coordinator = *ibctesting.NewCoordinator(suite.T(), 1) + suite.chain = suite.coordinator.GetChain(ibctesting.GetChainID(1)) +} + +func TestLocalhostTestSuite(t *testing.T) { + suite.Run(t, new(LocalhostTestSuite)) +} From 371515391f34b1714a23560a3a5c8a9de0270164 Mon Sep 17 00:00:00 2001 From: Charly Date: Thu, 2 Feb 2023 16:32:55 +0100 Subject: [PATCH 15/52] Remove ProofHeight and Proof Validation in msg.ValidateBasic (#3061) --- modules/core/04-channel/types/msgs.go | 28 ------------------- modules/core/04-channel/types/msgs_test.go | 11 -------- .../07-tendermint/client_state.go | 16 +++++++++++ .../07-tendermint/client_state_test.go | 12 ++++++++ 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/modules/core/04-channel/types/msgs.go b/modules/core/04-channel/types/msgs.go index b3d9aaf0644..a617fb2b86f 100644 --- a/modules/core/04-channel/types/msgs.go +++ b/modules/core/04-channel/types/msgs.go @@ -7,7 +7,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -92,9 +91,6 @@ func (msg MsgChannelOpenTry) ValidateBasic() error { if msg.PreviousChannelId != "" { return sdkerrors.Wrap(ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") } - if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") - } if msg.Channel.State != TRYOPEN { return sdkerrors.Wrapf(ErrInvalidChannelState, "channel state must be TRYOPEN in MsgChannelOpenTry. expected: %s, got: %s", @@ -153,9 +149,6 @@ func (msg MsgChannelOpenAck) ValidateBasic() error { if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil { return sdkerrors.Wrap(err, "invalid counterparty channel ID") } - if len(msg.ProofTry) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") - } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -198,9 +191,6 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error { if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } - if len(msg.ProofAck) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack") - } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -282,9 +272,6 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error { if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } - if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") - } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -320,9 +307,6 @@ func NewMsgRecvPacket( // ValidateBasic implements sdk.Msg func (msg MsgRecvPacket) ValidateBasic() error { - if len(msg.ProofCommitment) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") - } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -366,9 +350,6 @@ func NewMsgTimeout( // ValidateBasic implements sdk.Msg func (msg MsgTimeout) ValidateBasic() error { - if len(msg.ProofUnreceived) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") - } if msg.NextSequenceRecv == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } @@ -411,12 +392,6 @@ func (msg MsgTimeoutOnClose) ValidateBasic() error { if msg.NextSequenceRecv == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } - if len(msg.ProofUnreceived) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") - } - if len(msg.ProofClose) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end") - } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -455,9 +430,6 @@ func NewMsgAcknowledgement( // ValidateBasic implements sdk.Msg func (msg MsgAcknowledgement) ValidateBasic() error { - if len(msg.ProofAcked) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") - } if len(msg.Acknowledgement) == 0 { return sdkerrors.Wrap(ErrInvalidAcknowledgement, "ack bytes cannot be empty") } diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 1aa2690209b..1085267a8a1 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -55,8 +55,6 @@ var ( packet = types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) invalidPacket = types.NewPacket(unknownPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) - emptyProof = []byte{} - addr = sdk.AccAddress("testaddr111111111111").String() emptyAddr string @@ -164,7 +162,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { {"", types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), true}, {"invalid counterparty port id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, invalidPort, cpchanid, version, suite.proof, height, addr), false}, {"invalid counterparty channel id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, invalidChannel, version, suite.proof, height, addr), false}, - {"empty proof", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, cpchanid, version, emptyProof, height, addr), false}, {"channel not in TRYOPEN state", &types.MsgChannelOpenTry{portid, "", initChannel, version, suite.proof, height, addr}, false}, {"previous channel id is not empty", &types.MsgChannelOpenTry{portid, chanid, initChannel, version, suite.proof, height, addr}, false}, } @@ -198,7 +195,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { {"too long channel id", types.NewMsgChannelOpenAck(portid, invalidLongChannel, chanid, version, suite.proof, height, addr), false}, {"channel id contains non-alpha", types.NewMsgChannelOpenAck(portid, invalidChannel, chanid, version, suite.proof, height, addr), false}, {"", types.NewMsgChannelOpenAck(portid, chanid, chanid, "", suite.proof, height, addr), true}, - {"empty proof", types.NewMsgChannelOpenAck(portid, chanid, chanid, version, emptyProof, height, addr), false}, {"invalid counterparty channel id", types.NewMsgChannelOpenAck(portid, chanid, invalidShortChannel, version, suite.proof, height, addr), false}, } @@ -230,7 +226,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { {"too short channel id", types.NewMsgChannelOpenConfirm(portid, invalidShortChannel, suite.proof, height, addr), false}, {"too long channel id", types.NewMsgChannelOpenConfirm(portid, invalidLongChannel, suite.proof, height, addr), false}, {"channel id contains non-alpha", types.NewMsgChannelOpenConfirm(portid, invalidChannel, suite.proof, height, addr), false}, - {"empty proof", types.NewMsgChannelOpenConfirm(portid, chanid, emptyProof, height, addr), false}, } for _, tc := range testCases { @@ -291,7 +286,6 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { {"too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr), false}, {"too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr), false}, {"channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr), false}, - {"empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr), false}, } for _, tc := range testCases { @@ -316,7 +310,6 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { expPass bool }{ {"success", types.NewMsgRecvPacket(packet, suite.proof, height, addr), true}, - {"proof contain empty proof", types.NewMsgRecvPacket(packet, emptyProof, height, addr), false}, {"missing signer address", types.NewMsgRecvPacket(packet, suite.proof, height, emptyAddr), false}, {"invalid packet", types.NewMsgRecvPacket(invalidPacket, suite.proof, height, addr), false}, } @@ -353,7 +346,6 @@ func (suite *TypesTestSuite) TestMsgTimeoutValidateBasic() { {"success", types.NewMsgTimeout(packet, 1, suite.proof, height, addr), true}, {"seq 0", types.NewMsgTimeout(packet, 0, suite.proof, height, addr), false}, {"missing signer address", types.NewMsgTimeout(packet, 1, suite.proof, height, emptyAddr), false}, - {"cannot submit an empty proof", types.NewMsgTimeout(packet, 1, emptyProof, height, addr), false}, {"invalid packet", types.NewMsgTimeout(invalidPacket, 1, suite.proof, height, addr), false}, } @@ -380,8 +372,6 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { }{ {"success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr), true}, {"seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr), false}, - {"empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr), false}, - {"empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr), false}, {"signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr), false}, {"invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr), false}, } @@ -410,7 +400,6 @@ func (suite *TypesTestSuite) TestMsgAcknowledgementValidateBasic() { {"success", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, addr), true}, {"empty ack", types.NewMsgAcknowledgement(packet, nil, suite.proof, height, addr), false}, {"missing signer address", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, emptyAddr), false}, - {"cannot submit an empty proof", types.NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, height, addr), false}, {"invalid packet", types.NewMsgAcknowledgement(invalidPacket, packet.GetData(), suite.proof, height, addr), false}, } diff --git a/modules/light-clients/07-tendermint/client_state.go b/modules/light-clients/07-tendermint/client_state.go index 5b083341415..9a74834a299 100644 --- a/modules/light-clients/07-tendermint/client_state.go +++ b/modules/light-clients/07-tendermint/client_state.go @@ -218,6 +218,14 @@ func (cs ClientState) VerifyMembership( path exported.Path, value []byte, ) error { + if height.IsZero() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be non-zero") + } + + if len(proof) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") + } + if cs.GetLatestHeight().LT(height) { return sdkerrors.Wrapf( sdkerrors.ErrInvalidHeight, @@ -264,6 +272,14 @@ func (cs ClientState) VerifyNonMembership( proof []byte, path exported.Path, ) error { + if height.IsZero() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be non-zero") + } + + if len(proof) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") + } + if cs.GetLatestHeight().LT(height) { return sdkerrors.Wrapf( sdkerrors.ErrInvalidHeight, diff --git a/modules/light-clients/07-tendermint/client_state_test.go b/modules/light-clients/07-tendermint/client_state_test.go index 2a70d4199a6..9df8c6047ba 100644 --- a/modules/light-clients/07-tendermint/client_state_test.go +++ b/modules/light-clients/07-tendermint/client_state_test.go @@ -420,6 +420,12 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { value = []byte("invalid value") }, false, }, + { + "proof is empty", func() { + // change the inserted proof + proof = []byte{} + }, false, + }, } for _, tc := range testCases { @@ -631,6 +637,12 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { proof, proofHeight = suite.chainB.QueryProof(key) }, false, }, + { + "proof is empty", func() { + // change the inserted proof + proof = []byte{} + }, false, + }, } for _, tc := range testCases { From badc331d9b5fdc312877c9a62e8069aa9e830862 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 6 Feb 2023 11:09:44 +0100 Subject: [PATCH 16/52] updating errors returns in 09-localhost (#3105) --- modules/core/02-client/types/errors.go | 2 ++ .../light-clients/09-localhost/client_state.go | 17 +++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 0c2bd65f339..39792948ae5 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -34,4 +34,6 @@ var ( ErrInvalidSubstitute = sdkerrors.Register(SubModuleName, 27, "invalid client state substitute") ErrInvalidUpgradeProposal = sdkerrors.Register(SubModuleName, 28, "invalid upgrade proposal") ErrClientNotActive = sdkerrors.Register(SubModuleName, 29, "client state is not active") + ErrFailedMembershipVerification = sdkerrors.Register(SubModuleName, 30, "membership verification failed") + ErrFailedNonMembershipVerification = sdkerrors.Register(SubModuleName, 31, "non-membership verification failed") ) diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index deda5cdcdb6..350fee7751f 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -93,24 +93,21 @@ func (cs ClientState) VerifyMembership( ) error { merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store bz := store.Get([]byte(merklePath.KeyPath[1])) if bz == nil { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) } if !bytes.Equal(bz, value) { - return sdkerrors.Wrapf( - clienttypes.ErrFailedChannelStateVerification, - "todo: update error", - ) + return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value provided does not equal value stored at path: %s", path) } return nil @@ -130,17 +127,17 @@ func (cs ClientState) VerifyNonMembership( ) error { merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store bz := store.Get([]byte(merklePath.KeyPath[1])) if bz != nil { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- found for path %s", path) + return sdkerrors.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) } return nil From 0e72157df9560f62ff42e3aff895b04f158af957 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 6 Feb 2023 11:10:02 +0100 Subject: [PATCH 17/52] remove chain id from localhost client (#3103) --- modules/core/02-client/keeper/keeper_test.go | 2 +- .../09-localhost/client_state.go | 11 +-- .../09-localhost/client_state_test.go | 33 +++---- .../09-localhost/localhost.pb.go | 85 +++++-------------- .../lightclients/localhost/v1/localhost.proto | 4 +- 5 files changed, 36 insertions(+), 99 deletions(-) diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index a995b56d1a5..bd5a10a5fe9 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -240,7 +240,7 @@ func (suite KeeperTestSuite) TestGetAllGenesisClients() { //nolint:govet // this exported.Localhost, testClientID2, testClientID3, testClientID, } expClients := []exported.ClientState{ - localhost.NewClientState(suite.chainA.ChainID, types.GetSelfHeight(suite.chainA.GetContext())), + localhost.NewClientState(types.GetSelfHeight(suite.chainA.GetContext())), ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 350fee7751f..88c3cadf4d1 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -2,7 +2,6 @@ package localhost import ( "bytes" - "strings" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,9 +16,8 @@ import ( var _ exported.ClientState = (*ClientState)(nil) // NewClientState creates a new 09-localhost ClientState instance. -func NewClientState(chainID string, height clienttypes.Height) exported.ClientState { +func NewClientState(height clienttypes.Height) exported.ClientState { return &ClientState{ - ChainId: chainID, LatestHeight: height, } } @@ -41,10 +39,6 @@ func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) // Validate performs a basic validation of the client state fields. func (cs ClientState) Validate() error { - if strings.TrimSpace(cs.ChainId) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidChainID, "chain id cannot be blank") - } - if cs.LatestHeight.RevisionHeight == 0 { return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "local revision height cannot be zero") } @@ -64,7 +58,6 @@ func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientS } clientState := ClientState{ - ChainId: ctx.ChainID(), LatestHeight: clienttypes.GetSelfHeight(ctx), } @@ -165,8 +158,6 @@ func (cs ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCod // Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { height := clienttypes.GetSelfHeight(ctx) - - cs.ChainId = ctx.ChainID() cs.LatestHeight = height clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &cs)) diff --git a/modules/light-clients/09-localhost/client_state_test.go b/modules/light-clients/09-localhost/client_state_test.go index 8896364a37b..d11cb7aab4f 100644 --- a/modules/light-clients/09-localhost/client_state_test.go +++ b/modules/light-clients/09-localhost/client_state_test.go @@ -16,29 +16,29 @@ import ( ) func (suite *LocalhostTestSuite) TestStatus() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(3, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(3, 10)) suite.Require().Equal(exported.Active, clientState.Status(suite.chain.GetContext(), nil, nil)) } func (suite *LocalhostTestSuite) TestClientType() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(3, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(3, 10)) suite.Require().Equal(exported.Localhost, clientState.ClientType()) } func (suite *LocalhostTestSuite) TestGetLatestHeight() { expectedHeight := clienttypes.NewHeight(3, 10) - clientState := localhost.NewClientState("chainID", expectedHeight) + clientState := localhost.NewClientState(expectedHeight) suite.Require().Equal(expectedHeight, clientState.GetLatestHeight()) } func (suite *LocalhostTestSuite) TestZeroCustomFields() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) suite.Require().Equal(clientState, clientState.ZeroCustomFields()) } func (suite *LocalhostTestSuite) TestGetTimestampAtHeight() { ctx := suite.chain.GetContext() - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) timestamp, err := clientState.GetTimestampAtHeight(ctx, nil, nil, nil) suite.Require().NoError(err) @@ -53,17 +53,12 @@ func (suite *LocalhostTestSuite) TestValidate() { }{ { name: "valid client", - clientState: localhost.NewClientState("chainID", clienttypes.NewHeight(3, 10)), + clientState: localhost.NewClientState(clienttypes.NewHeight(3, 10)), expPass: true, }, - { - name: "invalid chain id", - clientState: localhost.NewClientState(" ", clienttypes.NewHeight(3, 10)), - expPass: false, - }, { name: "invalid height", - clientState: localhost.NewClientState("chainID", clienttypes.ZeroHeight()), + clientState: localhost.NewClientState(clienttypes.ZeroHeight()), expPass: false, }, } @@ -99,7 +94,7 @@ func (suite *LocalhostTestSuite) TestInitialize() { for _, tc := range testCases { suite.SetupTest() - clientState := localhost.NewClientState(suite.chain.ChainID, clienttypes.NewHeight(3, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(3, 10)) clientStore := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.Localhost) err := clientState.Initialize(suite.chain.GetContext(), suite.chain.Codec, clientStore, tc.consState) @@ -397,17 +392,17 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { } func (suite *LocalhostTestSuite) TestVerifyClientMessage() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) suite.Require().Nil(clientState.VerifyClientMessage(suite.chain.GetContext(), nil, nil, nil)) } func (suite *LocalhostTestSuite) TestVerifyCheckForMisbehaviour() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) suite.Require().False(clientState.CheckForMisbehaviour(suite.chain.GetContext(), nil, nil, nil)) } func (suite *LocalhostTestSuite) TestUpdateState() { - clientState := localhost.NewClientState(suite.chain.ChainID, clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight()))) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight()))) store := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.Localhost) suite.coordinator.CommitBlock(suite.chain) @@ -422,18 +417,18 @@ func (suite *LocalhostTestSuite) TestUpdateState() { } func (suite *LocalhostTestSuite) TestExportMetadata() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) suite.Require().Nil(clientState.ExportMetadata(nil)) } func (suite *LocalhostTestSuite) TestCheckSubstituteAndUpdateState() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) err := clientState.CheckSubstituteAndUpdateState(suite.chain.GetContext(), suite.chain.Codec, nil, nil, nil) suite.Require().Error(err) } func (suite *LocalhostTestSuite) TestVerifyUpgradeAndUpdateState() { - clientState := localhost.NewClientState("chainID", clienttypes.NewHeight(1, 10)) + clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) err := clientState.VerifyUpgradeAndUpdateState(suite.chain.GetContext(), suite.chain.Codec, nil, nil, nil, nil, nil) suite.Require().Error(err) } diff --git a/modules/light-clients/09-localhost/localhost.pb.go b/modules/light-clients/09-localhost/localhost.pb.go index d76a909d274..398a383f18a 100644 --- a/modules/light-clients/09-localhost/localhost.pb.go +++ b/modules/light-clients/09-localhost/localhost.pb.go @@ -26,10 +26,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // ClientState defines the 09-localhost client state type ClientState struct { - // unique chain identifier - ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` // the latest block height - LatestHeight types.Height `protobuf:"bytes,2,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height"` + LatestHeight types.Height `protobuf:"bytes,1,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height"` } func (m *ClientState) Reset() { *m = ClientState{} } @@ -74,25 +72,23 @@ func init() { } var fileDescriptor_acd9f5b22d41bf6d = []byte{ - // 280 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xbf, 0x4e, 0xc3, 0x30, - 0x10, 0xc6, 0x63, 0x54, 0xf1, 0x27, 0x85, 0x25, 0x62, 0x28, 0x91, 0x70, 0x2a, 0xa6, 0x2e, 0xb1, - 0x09, 0x0c, 0x08, 0xd8, 0x8a, 0x90, 0xca, 0x5a, 0x36, 0x96, 0x2a, 0x76, 0xac, 0xc4, 0x92, 0xd3, - 0x43, 0xb5, 0x93, 0x67, 0x60, 0xe4, 0x11, 0x78, 0x9c, 0x8e, 0x1d, 0x99, 0x10, 0x4a, 0x5e, 0x04, - 0xd9, 0x86, 0x96, 0xed, 0xbb, 0xf3, 0xef, 0xee, 0x3e, 0x7f, 0x61, 0x2a, 0x19, 0xa7, 0x4a, 0x96, - 0x95, 0xe1, 0x4a, 0x8a, 0xa5, 0xd1, 0x54, 0x01, 0xcf, 0x55, 0x05, 0xda, 0xd0, 0x36, 0xdb, 0x15, - 0xe4, 0x75, 0x05, 0x06, 0xa2, 0x73, 0xc9, 0x38, 0xf9, 0x8f, 0x93, 0x1d, 0xd1, 0x66, 0x71, 0x62, - 0xb7, 0x71, 0x58, 0x09, 0xea, 0x9f, 0xed, 0x0a, 0xaf, 0xfc, 0x7c, 0x7c, 0x5a, 0x42, 0x09, 0x4e, - 0x52, 0xab, 0x7c, 0xf7, 0xa2, 0x09, 0x87, 0x0f, 0x8e, 0x7a, 0x36, 0xb9, 0x11, 0xd1, 0x59, 0x78, - 0xc8, 0xab, 0x5c, 0x2e, 0x17, 0xb2, 0x18, 0xa1, 0x31, 0x9a, 0x1c, 0xcd, 0x0f, 0x5c, 0xfd, 0x54, - 0x44, 0x8f, 0xe1, 0x89, 0xca, 0x8d, 0xd0, 0x66, 0x51, 0x09, 0xeb, 0x62, 0xb4, 0x37, 0x46, 0x93, - 0xe1, 0x55, 0x4c, 0xac, 0x2f, 0x7b, 0x98, 0xfc, 0x9e, 0x6b, 0x33, 0x32, 0x73, 0xc4, 0x74, 0xb0, - 0xfe, 0x4a, 0x82, 0xf9, 0xb1, 0x1f, 0xf3, 0xbd, 0xbb, 0xc1, 0xdb, 0x47, 0x12, 0x4c, 0xd9, 0xba, - 0xc3, 0x68, 0xd3, 0x61, 0xf4, 0xdd, 0x61, 0xf4, 0xde, 0xe3, 0x60, 0xd3, 0xe3, 0xe0, 0xb3, 0xc7, - 0xc1, 0xcb, 0xac, 0x94, 0xa6, 0x6a, 0x18, 0xe1, 0x50, 0x53, 0x0e, 0xba, 0x06, 0x4d, 0x25, 0xe3, - 0x69, 0x09, 0xb4, 0xbd, 0xa1, 0x35, 0x14, 0x8d, 0x12, 0xda, 0xa7, 0x96, 0xfe, 0xc5, 0x76, 0x79, - 0x9b, 0x6e, 0xa3, 0xb8, 0xdf, 0x2a, 0xb6, 0xef, 0x7e, 0x78, 0xfd, 0x13, 0x00, 0x00, 0xff, 0xff, - 0x78, 0xac, 0xbe, 0x02, 0x68, 0x01, 0x00, 0x00, + // 256 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xcd, 0x4c, 0x4a, 0xd6, + 0xcf, 0xc9, 0x4c, 0xcf, 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x29, 0xd6, 0xcf, 0xc9, 0x4f, + 0x4e, 0xcc, 0xc9, 0xc8, 0x2f, 0x2e, 0xd1, 0x2f, 0x33, 0x44, 0x70, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, + 0xf2, 0x85, 0x64, 0x33, 0x93, 0x92, 0xf5, 0x90, 0x95, 0xeb, 0x21, 0x54, 0x94, 0x19, 0x4a, 0xc9, + 0x83, 0x4c, 0x4b, 0xce, 0x2f, 0x4a, 0xd5, 0x87, 0x48, 0x83, 0x8c, 0x80, 0xb0, 0x20, 0xfa, 0xa5, + 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x14, 0xc5, 0xc5, 0xed, + 0x0c, 0x56, 0x15, 0x5c, 0x92, 0x58, 0x92, 0x2a, 0xe4, 0xca, 0xc5, 0x9b, 0x93, 0x58, 0x92, 0x5a, + 0x5c, 0x12, 0x9f, 0x91, 0x0a, 0xb2, 0x4a, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x4a, 0x0f, + 0x64, 0x39, 0xc8, 0x74, 0x3d, 0xa8, 0x99, 0x65, 0x86, 0x7a, 0x1e, 0x60, 0x15, 0x4e, 0x2c, 0x27, + 0xee, 0xc9, 0x33, 0x04, 0xf1, 0x40, 0xb4, 0x41, 0xc4, 0xac, 0x58, 0x3a, 0x16, 0xc8, 0x33, 0x38, + 0x25, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, + 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x47, 0x7a, 0x66, 0x49, + 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0xb1, 0x7e, 0x66, + 0x52, 0xb2, 0x6e, 0x7a, 0xbe, 0x7e, 0x99, 0xb9, 0x7e, 0x6e, 0x7e, 0x4a, 0x69, 0x4e, 0x6a, 0x31, + 0x24, 0x68, 0x74, 0x61, 0x61, 0x63, 0x60, 0xa9, 0x0b, 0xf7, 0xaf, 0x35, 0x9c, 0x95, 0xc4, 0x06, + 0xf6, 0x86, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x76, 0x18, 0x03, 0x8b, 0x4d, 0x01, 0x00, 0x00, } func (m *ClientState) Marshal() (dAtA []byte, err error) { @@ -124,14 +120,7 @@ func (m *ClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintLocalhost(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintLocalhost(dAtA, i, uint64(len(m.ChainId))) - i-- - dAtA[i] = 0xa - } + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -152,10 +141,6 @@ func (m *ClientState) Size() (n int) { } var l int _ = l - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovLocalhost(uint64(l)) - } l = m.LatestHeight.Size() n += 1 + l + sovLocalhost(uint64(l)) return n @@ -197,38 +182,6 @@ func (m *ClientState) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLocalhost - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthLocalhost - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthLocalhost - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChainId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field LatestHeight", wireType) } diff --git a/proto/ibc/lightclients/localhost/v1/localhost.proto b/proto/ibc/lightclients/localhost/v1/localhost.proto index 06a0019021a..04a2799f1a1 100644 --- a/proto/ibc/lightclients/localhost/v1/localhost.proto +++ b/proto/ibc/lightclients/localhost/v1/localhost.proto @@ -11,8 +11,6 @@ import "gogoproto/gogo.proto"; message ClientState { option (gogoproto.goproto_getters) = false; - // unique chain identifier - string chain_id = 1; // the latest block height - ibc.core.client.v1.Height latest_height = 2 [(gogoproto.nullable) = false]; + ibc.core.client.v1.Height latest_height = 1 [(gogoproto.nullable) = false]; } From 40ca344b124a87eb6238f4162caf96d280b1135a Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 7 Feb 2023 15:22:52 +0100 Subject: [PATCH 18/52] return error in 09-localhost VerifyClientMessage (#3115) * return an error from 09-localhost client VerifyClientMessage * fix typo --------- Co-authored-by: Carlos Rodriguez --- modules/light-clients/09-localhost/client_state.go | 12 ++++-------- .../light-clients/09-localhost/client_state_test.go | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 88c3cadf4d1..4c9d1aa2fee 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -136,21 +136,17 @@ func (cs ClientState) VerifyNonMembership( return nil } -// VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update. -// It must handle each type of ClientMessage appropriately. Calls to CheckForMisbehaviour, UpdateState, and UpdateStateOnMisbehaviour -// will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned -// if the ClientMessage fails to verify. +// VerifyClientMessage is unsupported by the 09-localhost client type and returns an error. func (cs ClientState) VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) error { - return nil + return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "client message verification is unsupported by the localhost client") } -// Checks for evidence of a misbehaviour in Header or Misbehaviour type. It assumes the ClientMessage -// has already been verified. +// CheckForMisbehaviour is unsupported by the 09-localhost client type and performs a no-op, returning false. func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) bool { return false } -// UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified. +// UpdateStateOnMisbehaviour is unsupported by the 09-localhost client type and performs a no-op. func (cs ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage) { } diff --git a/modules/light-clients/09-localhost/client_state_test.go b/modules/light-clients/09-localhost/client_state_test.go index d11cb7aab4f..0ac045647ab 100644 --- a/modules/light-clients/09-localhost/client_state_test.go +++ b/modules/light-clients/09-localhost/client_state_test.go @@ -393,7 +393,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { func (suite *LocalhostTestSuite) TestVerifyClientMessage() { clientState := localhost.NewClientState(clienttypes.NewHeight(1, 10)) - suite.Require().Nil(clientState.VerifyClientMessage(suite.chain.GetContext(), nil, nil, nil)) + suite.Require().Error(clientState.VerifyClientMessage(suite.chain.GetContext(), nil, nil, nil)) } func (suite *LocalhostTestSuite) TestVerifyCheckForMisbehaviour() { From c7d798b170fe2b8378e0fca4517e7b0872ab795a Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 8 Feb 2023 11:07:36 +0100 Subject: [PATCH 19/52] disallow localhost client creation in 02-client (#3114) * disallow localhost client creation, adapt tests * adapting logic to accomodate usage of allowed clients in InitGenesis * move localhost check to separate conditional --- go.mod | 2 +- modules/core/02-client/keeper/client.go | 4 +++ modules/core/02-client/keeper/client_test.go | 31 +++++++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 24c60c0705c..692c949614c 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/stretchr/testify v1.8.1 github.com/tendermint/tendermint v0.37.0-rc2 github.com/tendermint/tm-db v0.6.7 - golang.org/x/exp v0.0.0-20221019170559-20944726eadf google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef google.golang.org/grpc v1.52.3 google.golang.org/protobuf v1.28.1 @@ -147,6 +146,7 @@ require ( go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.4.0 // indirect + golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect golang.org/x/net v0.4.0 // indirect golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect golang.org/x/sys v0.3.0 // indirect diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index fd260d65d98..2b5e65a1cf7 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -16,6 +16,10 @@ import ( func (k Keeper) CreateClient( ctx sdk.Context, clientState exported.ClientState, consensusState exported.ConsensusState, ) (string, error) { + if clientState.ClientType() == exported.Localhost { + return "", sdkerrors.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientState.ClientType()) + } + params := k.GetParams(ctx) if !params.IsAllowedClient(clientState.ClientType()) { return "", sdkerrors.Wrapf( diff --git a/modules/core/02-client/keeper/client_test.go b/modules/core/02-client/keeper/client_test.go index 94b5fed855a..ce338d25853 100644 --- a/modules/core/02-client/keeper/client_test.go +++ b/modules/core/02-client/keeper/client_test.go @@ -13,22 +13,39 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/exported" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibctesting "github.com/cosmos/ibc-go/v7/testing" ) func (suite *KeeperTestSuite) TestCreateClient() { cases := []struct { - msg string - clientState exported.ClientState - expPass bool + msg string + clientState exported.ClientState + consensusState exported.ConsensusState + expPass bool }{ - {"success", ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), true}, - {"client type not supported", solomachine.NewClientState(0, &solomachine.ConsensusState{PublicKey: suite.solomachine.ConsensusState().PublicKey, Diversifier: suite.solomachine.Diversifier, Timestamp: suite.solomachine.Time}), false}, + { + "success: 07-tendermint client type supported", + ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), + suite.consensusState, + true, + }, + { + "success: 06-solomachine client type supported", + solomachine.NewClientState(0, &solomachine.ConsensusState{PublicKey: suite.solomachine.ConsensusState().PublicKey, Diversifier: suite.solomachine.Diversifier, Timestamp: suite.solomachine.Time}), + &solomachine.ConsensusState{PublicKey: suite.solomachine.ConsensusState().PublicKey, Diversifier: suite.solomachine.Diversifier, Timestamp: suite.solomachine.Time}, + true, + }, + { + "failure: 09-localhost client type not supported", + localhost.NewClientState(clienttypes.GetSelfHeight(suite.ctx)), + nil, + false, + }, } for i, tc := range cases { - - clientID, err := suite.keeper.CreateClient(suite.ctx, tc.clientState, suite.consensusState) + clientID, err := suite.keeper.CreateClient(suite.ctx, tc.clientState, tc.consensusState) if tc.expPass { suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.msg) suite.Require().NotNil(clientID, "valid test case %d failed: %s", i, tc.msg) From 63111ded264561f0544e6e143494e17c632d9ce1 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 15 Feb 2023 16:02:01 +0100 Subject: [PATCH 20/52] adding e2e tests for 09-localhost (#3119) * use temporary relayer tag for e2e testing localhost * WIP commiting * updating codec and handling txResp * WIP scaffold happy path out * adding some temporary todos * adding msg response unmarshalling, and adding interchain accounts handshake test * adding ica send packet testing, cleanup..etc * adding separate test suite for localhost transfer tests (#3144) * add separate test suite struct for ICA localhost * fixing testsuite embedding * review suggestions - events func and nits * testcase naming --------- Co-authored-by: Cian Hatton --- e2e/relayer/relayer.go | 4 +- e2e/testconfig/testconfig.go | 2 +- .../interchain_accounts/localhost_test.go | 197 ++++++++++++++++++ e2e/tests/transfer/localhost_test.go | 169 +++++++++++++++ e2e/testsuite/codec.go | 32 +++ e2e/testsuite/events.go | 21 ++ e2e/testsuite/testsuite.go | 3 +- 7 files changed, 423 insertions(+), 5 deletions(-) create mode 100644 e2e/tests/interchain_accounts/localhost_test.go create mode 100644 e2e/tests/transfer/localhost_test.go create mode 100644 e2e/testsuite/events.go diff --git a/e2e/relayer/relayer.go b/e2e/relayer/relayer.go index 7467a9f47f3..f96af34a7c9 100644 --- a/e2e/relayer/relayer.go +++ b/e2e/relayer/relayer.go @@ -15,8 +15,8 @@ const ( Rly = "rly" Hermes = "hermes" - cosmosRelayerRepository = "ghcr.io/cosmos/relayer" - cosmosRelayerUser = "100:1000" // docker run -it --rm --entrypoint echo ghcr.io/cosmos/relayer "$(id -u):$(id -g)" + cosmosRelayerRepository = "damiannolan/rly" //"ghcr.io/cosmos/relayer" + cosmosRelayerUser = "100:1000" // docker run -it --rm --entrypoint echo ghcr.io/cosmos/relayer "$(id -u):$(id -g)" ) // Config holds configuration values for the relayer used in the tests. diff --git a/e2e/testconfig/testconfig.go b/e2e/testconfig/testconfig.go index 0564d93175c..74255f838b5 100644 --- a/e2e/testconfig/testconfig.go +++ b/e2e/testconfig/testconfig.go @@ -44,7 +44,7 @@ const ( defaultBinary = "simd" // defaultRlyTag is the tag that will be used if no relayer tag is specified. // all images are here https://github.com/cosmos/relayer/pkgs/container/relayer/versions - defaultRlyTag = "andrew-tendermint_v0.37" // "v2.2.0" + defaultRlyTag = "latest" // "andrew-tendermint_v0.37" // "v2.2.0" // defaultChainTag is the tag that will be used for the chains if none is specified. defaultChainTag = "main" // defaultRelayerType is the default relayer that will be used if none is specified. diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go new file mode 100644 index 00000000000..bb334d4e798 --- /dev/null +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -0,0 +1,197 @@ +package interchain_accounts + +import ( + "context" + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/gogoproto/proto" + controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" + "github.com/stretchr/testify/suite" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + "github.com/strangelove-ventures/interchaintest/v7" + "github.com/strangelove-ventures/interchaintest/v7/ibc" + test "github.com/strangelove-ventures/interchaintest/v7/testutil" +) + +func TestInterchainAccountsLocalhostTestSuite(t *testing.T) { + suite.Run(t, new(LocalhostInterchainAccountsTestSuite)) +} + +type LocalhostInterchainAccountsTestSuite struct { + testsuite.E2ETestSuite +} + +func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { + t := s.T() + ctx := context.TODO() + + _, _ = s.SetupChainsRelayerAndChannel(ctx) + chainA, _ := s.GetChains() + + chainADenom := chainA.Config().Denom + + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + var ( + msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse + msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ack []byte + packet channeltypes.Packet + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + + version := icatypes.NewDefaultMetadataString(connectiontypes.LocalhostID, connectiontypes.LocalhostID) + controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) + s.Require().NoError(err) + + t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(connectiontypes.LocalhostID, userAWallet.FormattedAddress(), version) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + icatypes.HostPortID, icatypes.Version, + channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, + controllerPortID, msgChanOpenInitRes.GetChannelId(), + version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + controllerPortID, msgChanOpenInitRes.GetChannelId(), + msgChanOpenTryRes.GetChannelId(), msgChanOpenTryRes.GetVersion(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + icatypes.HostPortID, msgChanOpenTryRes.GetChannelId(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) + + t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + walletAmount := ibc.WalletAmount{ + Address: interchainAccAddress, + Amount: testvalues.StartingTokenAmount, + Denom: chainADenom, + } + + s.Require().NoError(chainA.SendFunds(ctx, interchaintest.FaucetAccountKeyName, walletAmount)) + }) + + t.Run("send packet localhost interchain accounts", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddress, + ToAddress: userBWallet.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), connectiontypes.LocalhostID, uint64(time.Hour.Nanoseconds()), packetData) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) + s.AssertValidTxResponse(txResp) + s.Require().NoError(err) + + events := testsuite.ABCIToSDKEvents(txResp.Events) + packet, err = ibctesting.ParsePacketFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("recv packet localhost interchain accounts", func(t *testing.T) { + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + events := testsuite.ABCIToSDKEvents(txResp.Events) + ack, err = ibctesting.ParseAckFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(ack) + }) + + t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + s.AssertPacketRelayed(ctx, chainA, controllerPortID, msgChanOpenInitRes.GetChannelId(), 1) + + balance, err := chainA.GetBalance(ctx, userBWallet.FormattedAddress(), chainADenom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance) + }) +} diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go new file mode 100644 index 00000000000..3464c1eccd1 --- /dev/null +++ b/e2e/tests/transfer/localhost_test.go @@ -0,0 +1,169 @@ +package transfer + +import ( + "context" + "testing" + + "github.com/stretchr/testify/suite" + + transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" + test "github.com/strangelove-ventures/interchaintest/v7/testutil" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" +) + +func TestTransferLocalhostTestSuite(t *testing.T) { + suite.Run(t, new(LocalhostTransferTestSuite)) +} + +type LocalhostTransferTestSuite struct { + testsuite.E2ETestSuite +} + +// TestMsgTransfer_Localhost creates two wallets on a single chain and performs MsgTransfers back and forth +// to ensure ibc functions as expected on localhost. This test is largely the same as TestMsgTransfer_Succeeds_Nonincentivized +// except that chain B is replaced with an additional wallet on chainA. +func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { + t := s.T() + ctx := context.TODO() + + _, _ = s.SetupChainsRelayerAndChannel(ctx, transferChannelOptions()) + chainA, _ := s.GetChains() + + chainADenom := chainA.Config().Denom + + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + var ( + msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse + msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ack []byte + packet channeltypes.Packet + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + + t.Run("channel open init localhost", func(t *testing.T) { + msgChanOpenInit := channeltypes.NewMsgChannelOpenInit( + transfertypes.PortID, transfertypes.Version, + channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, + transfertypes.PortID, rlyWallet.FormattedAddress(), + ) + + s.Require().NoError(msgChanOpenInit.ValidateBasic()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenInit) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + transfertypes.PortID, transfertypes.Version, + channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, + transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), + transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), + msgChanOpenTryRes.GetChannelId(), transfertypes.Version, + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + transfertypes.PortID, msgChanOpenTryRes.GetChannelId(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("query localhost transfer channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, msgChanOpenInitRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, msgChanOpenTryRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) + + t.Run("send packet localhost ibc transfer", func(t *testing.T) { + txResp, err := s.Transfer(ctx, chainA, userAWallet, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), testvalues.DefaultTransferAmount(chainADenom), userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), clienttypes.NewHeight(1, 100), 0, "") + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + events := testsuite.ABCIToSDKEvents(txResp.Events) + packet, err = ibctesting.ParsePacketFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("tokens are escrowed", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, userAWallet) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) + + t.Run("recv packet localhost ibc transfer", func(t *testing.T) { + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + events := testsuite.ABCIToSDKEvents(txResp.Events) + ack, err = ibctesting.ParseAckFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(ack) + }) + + t.Run("acknowledge packet localhost ibc transfer", func(t *testing.T) { + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + s.AssertPacketRelayed(ctx, chainA, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), 1) + + ibcToken := testsuite.GetIBCToken(chainADenom, transfertypes.PortID, msgChanOpenTryRes.GetChannelId()) + actualBalance, err := chainA.GetBalance(ctx, userBWallet.FormattedAddress(), ibcToken.IBCDenom()) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) +} diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index 5ad4a78febe..267f08886a9 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -1,8 +1,12 @@ package testsuite import ( + "encoding/hex" + "fmt" + "github.com/cosmos/cosmos-sdk/codec" sdkcodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -25,11 +29,13 @@ import ( simappparams "github.com/cosmos/ibc-go/v7/testing/simapp/params" ) +// Codec returns the global E2E protobuf codec. func Codec() *codec.ProtoCodec { cdc, _ := codecAndEncodingConfig() return cdc } +// EncodingConfig returns the global E2E encoding config. func EncodingConfig() simappparams.EncodingConfig { _, cfg := codecAndEncodingConfig() return cfg @@ -64,3 +70,29 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) { cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) return cdc, cfg } + +// UnmarshalMsgResponses attempts to unmarshal the tx msg responses into the provided message types. +func UnmarshalMsgResponses(txResp sdk.TxResponse, msgs ...codec.ProtoMarshaler) error { + cdc := Codec() + bz, err := hex.DecodeString(txResp.Data) + if err != nil { + return err + } + + var txMsgData sdk.TxMsgData + if err := cdc.Unmarshal(bz, &txMsgData); err != nil { + return err + } + + if len(msgs) != len(txMsgData.MsgResponses) { + return fmt.Errorf("expected %d message responses but got %d", len(msgs), len(txMsgData.MsgResponses)) + } + + for i, msg := range msgs { + if err := cdc.Unmarshal(txMsgData.MsgResponses[i].Value, msg); err != nil { + return err + } + } + + return nil +} diff --git a/e2e/testsuite/events.go b/e2e/testsuite/events.go new file mode 100644 index 00000000000..feb79372123 --- /dev/null +++ b/e2e/testsuite/events.go @@ -0,0 +1,21 @@ +package testsuite + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" +) + +// ABCIToSDKEvents converts a list of ABCI events to Cosmos SDK events. +func ABCIToSDKEvents(abciEvents []abci.Event) sdk.Events { + var events sdk.Events + for _, evt := range abciEvents { + var attributes []sdk.Attribute + for _, attr := range evt.GetAttributes() { + attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + } + + events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + } + + return events +} diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index a8c8fb01661..51b9e621711 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -2,7 +2,6 @@ package testsuite import ( "context" - "errors" "fmt" "strconv" "strings" @@ -544,7 +543,7 @@ func (s *E2ETestSuite) QueryModuleAccountAddress(ctx context.Context, moduleName } moduleAccount, ok := account.(authtypes.ModuleAccountI) if !ok { - return nil, errors.New(fmt.Sprintf("failed to cast account: %T as ModuleAccount", moduleAccount)) + return nil, fmt.Errorf("failed to cast account: %T as ModuleAccount", moduleAccount) } return moduleAccount.GetAddress(), nil From 2edfbd2de1ee3b00e44356408075673b7cde1206 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 16 Feb 2023 10:51:49 +0100 Subject: [PATCH 21/52] e2e localhost test create new channel for existing ica account (#3146) * use temporary relayer tag for e2e testing localhost * WIP commiting * updating codec and handling txResp * WIP scaffold happy path out * adding some temporary todos * adding msg response unmarshalling, and adding interchain accounts handshake test * adding ica send packet testing, cleanup..etc * adding separate test suite for localhost transfer tests (#3144) * add separate test suite struct for ICA localhost * fixing testsuite embedding * adding test for ica channel close and reopen --------- Co-authored-by: Cian Hatton --- .../interchain_accounts/localhost_test.go | 299 ++++++++++++++++++ 1 file changed, 299 insertions(+) diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index bb334d4e798..505f080dd8c 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -185,6 +185,305 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( s.AssertValidTxResponse(txResp) }) + t.Run("verify tokens transferred", func(t *testing.T) { + balance, err := chainA.GetBalance(ctx, userBWallet.FormattedAddress(), chainADenom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance) + }) +} + +func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChannel_Localhost() { + t := s.T() + ctx := context.TODO() + + // relayer and channel output is discarded, only a single chain is required + _, _ = s.SetupChainsRelayerAndChannel(ctx) + chainA, _ := s.GetChains() + + chainADenom := chainA.Config().Denom + + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + var ( + msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse + msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ack []byte + packet channeltypes.Packet + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + + version := icatypes.NewDefaultMetadataString(connectiontypes.LocalhostID, connectiontypes.LocalhostID) + controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) + s.Require().NoError(err) + + t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(connectiontypes.LocalhostID, userAWallet.FormattedAddress(), version) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + icatypes.HostPortID, icatypes.Version, + channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, + controllerPortID, msgChanOpenInitRes.GetChannelId(), + version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + controllerPortID, msgChanOpenInitRes.GetChannelId(), + msgChanOpenTryRes.GetChannelId(), msgChanOpenTryRes.GetVersion(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + icatypes.HostPortID, msgChanOpenTryRes.GetChannelId(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) + + t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + walletAmount := ibc.WalletAmount{ + Address: interchainAccAddress, + Amount: testvalues.StartingTokenAmount, + Denom: chainADenom, + } + + s.Require().NoError(chainA.SendFunds(ctx, interchaintest.FaucetAccountKeyName, walletAmount)) + }) + + t.Run("send localhost interchain accounts packet with timeout", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddress, + ToAddress: userBWallet.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), connectiontypes.LocalhostID, uint64(1), packetData) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) + s.AssertValidTxResponse(txResp) + s.Require().NoError(err) + + events := testsuite.ABCIToSDKEvents(txResp.Events) + packet, err = ibctesting.ParsePacketFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("timeout localhost interchain accounts packet", func(t *testing.T) { + msgTimeout := channeltypes.NewMsgTimeout(packet, 1, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgTimeout) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("close interchain accounts host channel end", func(t *testing.T) { + msgCloseConfirm := channeltypes.NewMsgChannelCloseConfirm(icatypes.HostPortID, msgChanOpenTryRes.ChannelId, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgCloseConfirm) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("verify localhost interchain accounts channel is closed", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.CLOSED, channelEndA.State, "the channel was not in an expected state") + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.CLOSED, channelEndB.State, "the channel was not in an expected state") + }) + + t.Run("channel open init localhost: create new channel for existing account", func(t *testing.T) { + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(connectiontypes.LocalhostID, userAWallet.FormattedAddress(), version) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + // note: response values are updated here in msgChanOpenInitRes + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + icatypes.HostPortID, icatypes.Version, + channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, + controllerPortID, msgChanOpenInitRes.GetChannelId(), + version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + // note: response values are updated here in msgChanOpenTryRes + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + controllerPortID, msgChanOpenInitRes.GetChannelId(), + msgChanOpenTryRes.GetChannelId(), msgChanOpenTryRes.GetVersion(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + icatypes.HostPortID, msgChanOpenTryRes.GetChannelId(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) + + t.Run("verify interchain account and existing balance", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + balance, err := chainA.GetBalance(ctx, interchainAccAddress, chainADenom) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount + s.Require().Equal(expected, balance) + }) + + t.Run("send packet localhost interchain accounts", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddress, + ToAddress: userBWallet.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), connectiontypes.LocalhostID, uint64(time.Hour.Nanoseconds()), packetData) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) + s.AssertValidTxResponse(txResp) + s.Require().NoError(err) + + events := testsuite.ABCIToSDKEvents(txResp.Events) + packet, err = ibctesting.ParsePacketFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("recv packet localhost interchain accounts", func(t *testing.T) { + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + events := testsuite.ABCIToSDKEvents(txResp.Events) + ack, err = ibctesting.ParseAckFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(ack) + }) + + t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + t.Run("verify tokens transferred", func(t *testing.T) { s.AssertPacketRelayed(ctx, chainA, controllerPortID, msgChanOpenInitRes.GetChannelId(), 1) From d4e24d1782a0d7346d2f9fe009c47a1fc6fd3be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:57:38 +0100 Subject: [PATCH 22/52] revert: unnecessary code change for localhost (#3170) --- modules/core/02-client/keeper/keeper.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 2aecd8459fd..cd13c506ba9 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -281,10 +281,6 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) ( // This function is only used to validate the client state the counterparty stores for this chain // Client must be in same revision as the executing chain func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { - if clientState.ClientType() == exported.Localhost { - return nil - } - tmClient, ok := clientState.(*ibctm.ClientState) if !ok { return sdkerrors.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", From 7568559f9a8685d45f71ba0e90992e3658276573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:58:28 +0100 Subject: [PATCH 23/52] revert: unnecessary changes in connection handshake for localhost (#3161) * imp: change validateHeight function name to validateConsensusHeight and improve code documentation * revert: change code back to how it is on main Revert code changes as they were unnecessary given that a localhost connection cannot be created via the connection handshake --- .../core/03-connection/keeper/handshake.go | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index bf4913549a6..04026bb20f8 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -74,8 +74,14 @@ func (k Keeper) ConnOpenTry( // generate a new connection connectionID := k.GenerateConnectionIdentifier(ctx) - if err := k.validateHeight(ctx, clientState.ClientType(), consensusHeight); err != nil { - return "", err + // check that the consensus height the counterparty chain is using to store a representation + // of this chain's consensus state is at a height in the past + selfHeight := clienttypes.GetSelfHeight(ctx) + if consensusHeight.GTE(selfHeight) { + return "", sdkerrors.Wrapf( + sdkerrors.ErrInvalidHeight, + "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, + ) } // validate client parameters of a chainB client stored on chainA @@ -159,9 +165,14 @@ func (k Keeper) ConnOpenAck( proofHeight exported.Height, // height that relayer constructed proofTry consensusHeight exported.Height, // latest height of chainA that chainB has stored on its chainA client ) error { - // Check that chainB client hasn't stored invalid height - if err := k.validateHeight(ctx, clientState.ClientType(), consensusHeight); err != nil { - return err + // check that the consensus height the counterparty chain is using to store a representation + // of this chain's consensus state is at a height in the past + selfHeight := clienttypes.GetSelfHeight(ctx) + if consensusHeight.GTE(selfHeight) { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidHeight, + "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, + ) } // Retrieve connection @@ -287,22 +298,3 @@ func (k Keeper) ConnOpenConfirm( return nil } - -func (k Keeper) validateHeight( - ctx sdk.Context, - clientType string, - consensusHeight exported.Height, -) error { - if clientType == exported.Localhost { - return nil - } - - selfHeight := clienttypes.GetSelfHeight(ctx) - if consensusHeight.GTE(selfHeight) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, - "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, - ) - } - return nil -} From fe24586686b78f268adf58a8e6c70b318a91e664 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 20 Feb 2023 14:04:29 +0100 Subject: [PATCH 24/52] adding localhost client ID checks to init and try validate basic (#3169) --- modules/core/03-connection/types/msgs.go | 8 ++++++++ modules/core/03-connection/types/msgs_test.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index b4b119837cd..fba1a623a67 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -43,6 +43,10 @@ func NewMsgConnectionOpenInit( // ValidateBasic implements sdk.Msg. func (msg MsgConnectionOpenInit) ValidateBasic() error { + if msg.ClientId == exported.Localhost { + return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connetion handshakes are disallowed") + } + if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { return sdkerrors.Wrap(err, "invalid client ID") } @@ -102,6 +106,10 @@ func NewMsgConnectionOpenTry( // ValidateBasic implements sdk.Msg func (msg MsgConnectionOpenTry) ValidateBasic() error { + if msg.ClientId == exported.Localhost { + return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connetion handshakes are disallowed") + } + if msg.PreviousConnectionId != "" { return sdkerrors.Wrap(ErrInvalidConnectionIdentifier, "previous connection identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") } diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index a89ba23a681..212948e3710 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -16,6 +16,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/cosmos/ibc-go/v7/testing/simapp" @@ -88,6 +89,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { msg *types.MsgConnectionOpenInit expPass bool }{ + {"localhost client ID", types.NewMsgConnectionOpenInit(exported.Localhost, "clienttotest", prefix, version, 500, signer), false}, {"invalid client ID", types.NewMsgConnectionOpenInit("test/iris", "clienttotest", prefix, version, 500, signer), false}, {"invalid counterparty client ID", types.NewMsgConnectionOpenInit("clienttotest", "(clienttotest)", prefix, version, 500, signer), false}, {"invalid counterparty connection ID", &types.MsgConnectionOpenInit{connectionID, types.NewCounterparty("clienttotest", "connectiontotest", prefix), version, 500, signer}, false}, @@ -134,6 +136,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { expPass bool }{ {"non empty connection ID", &types.MsgConnectionOpenTry{"connection-0", "clienttotesta", any, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, + {"localhost client ID", types.NewMsgConnectionOpenTry(exported.Localhost, "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid client ID", types.NewMsgConnectionOpenTry("test/iris", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid counterparty connection ID", types.NewMsgConnectionOpenTry("clienttotesta", "ibc/test", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid counterparty client ID", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "test/conn1", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, From 69e1a519ce3b7c063846b41945dfb08dd1fc794c Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Mon, 20 Feb 2023 13:26:09 +0000 Subject: [PATCH 25/52] Bumping localhost light client proto to v2 (#3168) --- go.mod | 2 +- .../09-localhost/localhost.pb.go | 41 ++++++++++--------- .../localhost/{v1 => v2}/localhost.proto | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) rename proto/ibc/lightclients/localhost/{v1 => v2}/localhost.proto (91%) diff --git a/go.mod b/go.mod index f5cdaa7c1a9..9309933950c 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ go 1.19 module github.com/cosmos/ibc-go/v7 require ( + cosmossdk.io/api v0.2.6 cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0-beta.6 cosmossdk.io/simapp v0.0.0-20221216140705-ee8890cf30e7 @@ -34,7 +35,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v0.8.0 // indirect cloud.google.com/go/storage v1.27.0 // indirect - cosmossdk.io/api v0.2.6 // indirect cosmossdk.io/core v0.3.2 // indirect cosmossdk.io/depinject v1.0.0-alpha.3 // indirect filippo.io/edwards25519 v1.0.0-rc.1 // indirect diff --git a/modules/light-clients/09-localhost/localhost.pb.go b/modules/light-clients/09-localhost/localhost.pb.go index 398a383f18a..09303d4f1b2 100644 --- a/modules/light-clients/09-localhost/localhost.pb.go +++ b/modules/light-clients/09-localhost/localhost.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ibc/lightclients/localhost/v1/localhost.proto +// source: ibc/lightclients/localhost/v2/localhost.proto package localhost @@ -34,7 +34,7 @@ func (m *ClientState) Reset() { *m = ClientState{} } func (m *ClientState) String() string { return proto.CompactTextString(m) } func (*ClientState) ProtoMessage() {} func (*ClientState) Descriptor() ([]byte, []int) { - return fileDescriptor_acd9f5b22d41bf6d, []int{0} + return fileDescriptor_60e51cfed1fd7859, []int{0} } func (m *ClientState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -64,31 +64,32 @@ func (m *ClientState) XXX_DiscardUnknown() { var xxx_messageInfo_ClientState proto.InternalMessageInfo func init() { - proto.RegisterType((*ClientState)(nil), "ibc.lightclients.localhost.v1.ClientState") + proto.RegisterType((*ClientState)(nil), "ibc.lightclients.localhost.v2.ClientState") } func init() { - proto.RegisterFile("ibc/lightclients/localhost/v1/localhost.proto", fileDescriptor_acd9f5b22d41bf6d) + proto.RegisterFile("ibc/lightclients/localhost/v2/localhost.proto", fileDescriptor_60e51cfed1fd7859) } -var fileDescriptor_acd9f5b22d41bf6d = []byte{ - // 256 bytes of a gzipped FileDescriptorProto +var fileDescriptor_60e51cfed1fd7859 = []byte{ + // 257 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xcd, 0x4c, 0x4a, 0xd6, 0xcf, 0xc9, 0x4c, 0xcf, 0x28, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x29, 0xd6, 0xcf, 0xc9, 0x4f, - 0x4e, 0xcc, 0xc9, 0xc8, 0x2f, 0x2e, 0xd1, 0x2f, 0x33, 0x44, 0x70, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, - 0xf2, 0x85, 0x64, 0x33, 0x93, 0x92, 0xf5, 0x90, 0x95, 0xeb, 0x21, 0x54, 0x94, 0x19, 0x4a, 0xc9, - 0x83, 0x4c, 0x4b, 0xce, 0x2f, 0x4a, 0xd5, 0x87, 0x48, 0x83, 0x8c, 0x80, 0xb0, 0x20, 0xfa, 0xa5, - 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x14, 0xc5, 0xc5, 0xed, - 0x0c, 0x56, 0x15, 0x5c, 0x92, 0x58, 0x92, 0x2a, 0xe4, 0xca, 0xc5, 0x9b, 0x93, 0x58, 0x92, 0x5a, - 0x5c, 0x12, 0x9f, 0x91, 0x0a, 0xb2, 0x4a, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x4a, 0x0f, - 0x64, 0x39, 0xc8, 0x74, 0x3d, 0xa8, 0x99, 0x65, 0x86, 0x7a, 0x1e, 0x60, 0x15, 0x4e, 0x2c, 0x27, - 0xee, 0xc9, 0x33, 0x04, 0xf1, 0x40, 0xb4, 0x41, 0xc4, 0xac, 0x58, 0x3a, 0x16, 0xc8, 0x33, 0x38, - 0x25, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, - 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x47, 0x7a, 0x66, 0x49, - 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0xb1, 0x7e, 0x66, - 0x52, 0xb2, 0x6e, 0x7a, 0xbe, 0x7e, 0x99, 0xb9, 0x7e, 0x6e, 0x7e, 0x4a, 0x69, 0x4e, 0x6a, 0x31, - 0x24, 0x68, 0x74, 0x61, 0x61, 0x63, 0x60, 0xa9, 0x0b, 0xf7, 0xaf, 0x35, 0x9c, 0x95, 0xc4, 0x06, - 0xf6, 0x86, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x76, 0x18, 0x03, 0x8b, 0x4d, 0x01, 0x00, 0x00, + 0x4e, 0xcc, 0xc9, 0xc8, 0x2f, 0x2e, 0xd1, 0x2f, 0x33, 0x42, 0x70, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, + 0xf2, 0x85, 0x64, 0x33, 0x93, 0x92, 0xf5, 0x90, 0x95, 0xeb, 0x21, 0x54, 0x94, 0x19, 0x49, 0xc9, + 0x83, 0x4c, 0x4b, 0xce, 0x2f, 0x4a, 0xd5, 0x87, 0x48, 0xeb, 0x97, 0x19, 0x42, 0x59, 0x10, 0xfd, + 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0xa6, 0x3e, 0x88, 0x05, 0x11, 0x55, 0x8a, 0xe2, 0xe2, + 0x76, 0x06, 0xab, 0x0a, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0x72, 0xe5, 0xe2, 0xcd, 0x49, 0x2c, 0x49, + 0x2d, 0x2e, 0x89, 0xcf, 0x48, 0x05, 0x59, 0x25, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa5, + 0x07, 0xb2, 0x1c, 0x64, 0xba, 0x1e, 0xd4, 0xcc, 0x32, 0x43, 0x3d, 0x0f, 0xb0, 0x0a, 0x27, 0x96, + 0x13, 0xf7, 0xe4, 0x19, 0x82, 0x78, 0x20, 0xda, 0x20, 0x62, 0x56, 0x2c, 0x1d, 0x0b, 0xe4, 0x19, + 0x9c, 0x92, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, + 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x23, 0x3d, 0xb3, + 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x58, 0x3f, + 0x33, 0x29, 0x59, 0x37, 0x3d, 0x5f, 0xbf, 0xcc, 0x5c, 0x3f, 0x37, 0x3f, 0xa5, 0x34, 0x27, 0xb5, + 0x18, 0x12, 0x34, 0xba, 0xb0, 0xb0, 0x31, 0xb0, 0xd4, 0x85, 0xfb, 0xd7, 0x1a, 0xce, 0x4a, 0x62, + 0x03, 0x7b, 0xc3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x1e, 0xed, 0x07, 0xba, 0x4d, 0x01, 0x00, + 0x00, } func (m *ClientState) Marshal() (dAtA []byte, err error) { diff --git a/proto/ibc/lightclients/localhost/v1/localhost.proto b/proto/ibc/lightclients/localhost/v2/localhost.proto similarity index 91% rename from proto/ibc/lightclients/localhost/v1/localhost.proto rename to proto/ibc/lightclients/localhost/v2/localhost.proto index 04a2799f1a1..ec970eb0008 100644 --- a/proto/ibc/lightclients/localhost/v1/localhost.proto +++ b/proto/ibc/lightclients/localhost/v2/localhost.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package ibc.lightclients.localhost.v1; +package ibc.lightclients.localhost.v2; option go_package = "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost;localhost"; From 9352d8315f0a88e541feedaa7a3b904394d2269d Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 20 Feb 2023 14:27:35 +0100 Subject: [PATCH 26/52] fix typo --- modules/core/03-connection/types/msgs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index fba1a623a67..98772afadb9 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -44,7 +44,7 @@ func NewMsgConnectionOpenInit( // ValidateBasic implements sdk.Msg. func (msg MsgConnectionOpenInit) ValidateBasic() error { if msg.ClientId == exported.Localhost { - return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connetion handshakes are disallowed") + return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") } if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { @@ -107,7 +107,7 @@ func NewMsgConnectionOpenTry( // ValidateBasic implements sdk.Msg func (msg MsgConnectionOpenTry) ValidateBasic() error { if msg.ClientId == exported.Localhost { - return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connetion handshakes are disallowed") + return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") } if msg.PreviousConnectionId != "" { From 34a99fee13c84603fd9826e99f0dfd7c3f329e5f Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 21 Feb 2023 13:43:32 +0100 Subject: [PATCH 27/52] adding e2e upgrade test for v7.1 localhost (#3164) Co-authored-by: Cian Hatton --- .github/workflows/e2e-upgrade.yaml | 12 +++++ e2e/tests/upgrades/upgrade_test.go | 30 +++++++++++++ e2e/testsuite/grpc_query.go | 14 ++++++ e2e/testsuite/testsuite.go | 35 ++++++++------- testing/simapp/app.go | 23 +++++----- testing/simapp/upgrades/upgrades.go | 62 +++++++++++++++++++++++++- testing/simapp/upgrades/v6/upgrades.go | 36 --------------- testing/simapp/upgrades/v7/upgrades.go | 42 ----------------- 8 files changed, 148 insertions(+), 106 deletions(-) delete mode 100644 testing/simapp/upgrades/v6/upgrades.go delete mode 100644 testing/simapp/upgrades/v7/upgrades.go diff --git a/.github/workflows/e2e-upgrade.yaml b/.github/workflows/e2e-upgrade.yaml index b596f22a9ce..79415380b5c 100644 --- a/.github/workflows/e2e-upgrade.yaml +++ b/.github/workflows/e2e-upgrade.yaml @@ -41,3 +41,15 @@ jobs: upgrade-plan-name: "v7" test-entry-point: "TestUpgradeTestSuite" test: "TestV6ToV7ChainUpgrade" + + upgrade-v7_1: + uses: cosmos/ibc-go/.github/workflows/e2e-test-workflow-call.yml@main + with: + chain-image: ghcr.io/cosmos/ibc-go-simd + chain-binary: simd + chain-a-tag: pr-3136 # TODO: needs v7.0.0 (with simapp fixes) when cut + chain-b-tag: pr-3136 # TODO: needs v7.0.0 (with simapp fixes) when cut + chain-upgrade-tag: pr-3164 # TODO: needs v7.1.0 when cut + upgrade-plan-name: "v7.1" + test-entry-point: "TestUpgradeTestSuite" + test: "TestV7ChainUpgradeAddLocalhost" diff --git a/e2e/tests/upgrades/upgrade_test.go b/e2e/tests/upgrades/upgrade_test.go index c8500e830dc..08a0635c91d 100644 --- a/e2e/tests/upgrades/upgrade_test.go +++ b/e2e/tests/upgrades/upgrade_test.go @@ -25,6 +25,7 @@ import ( icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" v7migrations "github.com/cosmos/ibc-go/v7/modules/core/02-client/migrations/v7" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctesting "github.com/cosmos/ibc-go/v7/testing" @@ -604,6 +605,35 @@ func (s *UpgradeTestSuite) TestV6ToV7ChainUpgrade() { }) } +func (s *UpgradeTestSuite) TestV7ChainUpgradeAddLocalhost() { + t := s.T() + testCfg := testconfig.FromEnv() + + ctx := context.Background() + _, _ = s.SetupChainsRelayerAndChannel(ctx) + chain, _ := s.GetChains() + + s.Require().NoError(test.WaitForBlocks(ctx, 5, chain), "failed to wait for blocks") + + t.Run("upgrade chain", func(t *testing.T) { + govProposalWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + s.UpgradeChain(ctx, chain, govProposalWallet, testCfg.UpgradePlanName, testCfg.ChainAConfig.Tag, testCfg.UpgradeTag) + }) + + t.Run("ensure the localhost client is active and sentinel connection is stored in state", func(t *testing.T) { + status, err := s.QueryClientStatus(ctx, chain, exported.Localhost) + s.Require().NoError(err) + s.Require().Equal(exported.Active.String(), status) + + connectionEnd, err := s.QueryConnection(ctx, chain, connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().Equal(connectiontypes.OPEN, connectionEnd.State) + s.Require().Equal(exported.Localhost, connectionEnd.ClientId) + s.Require().Equal(exported.Localhost, connectionEnd.Counterparty.ClientId) + s.Require().Equal(connectiontypes.LocalhostID, connectionEnd.Counterparty.ConnectionId) + }) +} + // RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain. func (s *UpgradeTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, msgRegisterAccount *intertxtypes.MsgRegisterAccount) error { txResp, err := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount) diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index ff38ae0f09e..a7449de94ec 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -12,6 +12,7 @@ import ( controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -47,6 +48,19 @@ func (s *E2ETestSuite) QueryClientStatus(ctx context.Context, chain ibc.Chain, c return res.Status, nil } +// QueryConnection queries the connection end using the given chain and connection id. +func (s *E2ETestSuite) QueryConnection(ctx context.Context, chain ibc.Chain, connectionID string) (connectiontypes.ConnectionEnd, error) { + queryClient := s.GetChainGRCPClients(chain).ConnectionQueryClient + res, err := queryClient.Connection(ctx, &connectiontypes.QueryConnectionRequest{ + ConnectionId: connectionID, + }) + if err != nil { + return connectiontypes.ConnectionEnd{}, err + } + + return *res.Connection, nil +} + // QueryChannel queries the channel on a given chain for the provided portID and channelID func (s *E2ETestSuite) QueryChannel(ctx context.Context, chain ibc.Chain, portID, channelID string) (channeltypes.Channel, error) { queryClient := s.GetChainGRCPClients(chain).ChannelQueryClient diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 7863c1be3b1..8a8af405d10 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -39,6 +39,7 @@ import ( feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -70,11 +71,12 @@ type E2ETestSuite struct { // These should typically be used for query clients only. If we need to make changes, we should // use E2ETestSuite.BroadcastMessages to broadcast transactions instead. type GRPCClients struct { - ClientQueryClient clienttypes.QueryClient - ChannelQueryClient channeltypes.QueryClient - FeeQueryClient feetypes.QueryClient - ICAQueryClient controllertypes.QueryClient - InterTxQueryClient intertxtypes.QueryClient + ClientQueryClient clienttypes.QueryClient + ConnectionQueryClient connectiontypes.QueryClient + ChannelQueryClient channeltypes.QueryClient + FeeQueryClient feetypes.QueryClient + ICAQueryClient controllertypes.QueryClient + InterTxQueryClient intertxtypes.QueryClient // SDK query clients GovQueryClient govtypesv1beta1.QueryClient @@ -405,17 +407,18 @@ func (s *E2ETestSuite) InitGRPCClients(chain *cosmos.CosmosChain) { } s.grpcClients[chain.Config().ChainID] = GRPCClients{ - ClientQueryClient: clienttypes.NewQueryClient(grpcConn), - ChannelQueryClient: channeltypes.NewQueryClient(grpcConn), - FeeQueryClient: feetypes.NewQueryClient(grpcConn), - ICAQueryClient: controllertypes.NewQueryClient(grpcConn), - InterTxQueryClient: intertxtypes.NewQueryClient(grpcConn), - GovQueryClient: govtypesv1beta1.NewQueryClient(grpcConn), - GovQueryClientV1: govtypesv1.NewQueryClient(grpcConn), - GroupsQueryClient: grouptypes.NewQueryClient(grpcConn), - ParamsQueryClient: paramsproposaltypes.NewQueryClient(grpcConn), - AuthQueryClient: authtypes.NewQueryClient(grpcConn), - AuthZQueryClient: authz.NewQueryClient(grpcConn), + ClientQueryClient: clienttypes.NewQueryClient(grpcConn), + ConnectionQueryClient: connectiontypes.NewQueryClient(grpcConn), + ChannelQueryClient: channeltypes.NewQueryClient(grpcConn), + FeeQueryClient: feetypes.NewQueryClient(grpcConn), + ICAQueryClient: controllertypes.NewQueryClient(grpcConn), + InterTxQueryClient: intertxtypes.NewQueryClient(grpcConn), + GovQueryClient: govtypesv1beta1.NewQueryClient(grpcConn), + GovQueryClientV1: govtypesv1.NewQueryClient(grpcConn), + GroupsQueryClient: grouptypes.NewQueryClient(grpcConn), + ParamsQueryClient: paramsproposaltypes.NewQueryClient(grpcConn), + AuthQueryClient: authtypes.NewQueryClient(grpcConn), + AuthZQueryClient: authz.NewQueryClient(grpcConn), } } diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 48450a021e5..f378364f731 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -121,9 +121,7 @@ import ( localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" simappparams "github.com/cosmos/ibc-go/v7/testing/simapp/params" - simappupgrades "github.com/cosmos/ibc-go/v7/testing/simapp/upgrades" - v6 "github.com/cosmos/ibc-go/v7/testing/simapp/upgrades/v6" - v7 "github.com/cosmos/ibc-go/v7/testing/simapp/upgrades/v7" + "github.com/cosmos/ibc-go/v7/testing/simapp/upgrades" ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types" ) @@ -929,8 +927,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino // setupUpgradeHandlers sets all necessary upgrade handlers for testing purposes func (app *SimApp) setupUpgradeHandlers() { app.UpgradeKeeper.SetUpgradeHandler( - simappupgrades.DefaultUpgradeName, - simappupgrades.CreateDefaultUpgradeHandler(app.mm, app.configurator), + upgrades.V5, + upgrades.CreateDefaultUpgradeHandler(app.mm, app.configurator), ) // NOTE: The moduleName arg of v6.CreateUpgradeHandler refers to the auth module ScopedKeeper name to which the channel capability should be migrated from. @@ -938,8 +936,8 @@ func (app *SimApp) setupUpgradeHandlers() { // TODO: update git tag in link below // See: https://github.com/cosmos/ibc-go/blob/v5.0.0-rc2/testing/simapp/app.go#L304 app.UpgradeKeeper.SetUpgradeHandler( - v6.UpgradeName, - v6.CreateUpgradeHandler( + upgrades.V6, + upgrades.CreateV6UpgradeHandler( app.mm, app.configurator, app.appCodec, @@ -950,8 +948,8 @@ func (app *SimApp) setupUpgradeHandlers() { ) app.UpgradeKeeper.SetUpgradeHandler( - v7.UpgradeName, - v7.CreateUpgradeHandler( + upgrades.V7, + upgrades.CreateV7UpgradeHandler( app.mm, app.configurator, app.appCodec, @@ -960,6 +958,11 @@ func (app *SimApp) setupUpgradeHandlers() { app.ParamsKeeper, ), ) + + app.UpgradeKeeper.SetUpgradeHandler( + upgrades.V7_1, + upgrades.CreateDefaultUpgradeHandler(app.mm, app.configurator), + ) } // setupUpgradeStoreLoaders sets all necessary store loaders required by upgrades. @@ -969,7 +972,7 @@ func (app *SimApp) setupUpgradeStoreLoaders() { tmos.Exit(fmt.Sprintf("failed to read upgrade info from disk %s", err)) } - if upgradeInfo.Name == v7.UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + if upgradeInfo.Name == upgrades.V7 && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { storeUpgrades := storetypes.StoreUpgrades{ Added: []string{ consensusparamtypes.StoreKey, diff --git a/testing/simapp/upgrades/upgrades.go b/testing/simapp/upgrades/upgrades.go index adc81349bdd..3730b0f3e6c 100644 --- a/testing/simapp/upgrades/upgrades.go +++ b/testing/simapp/upgrades/upgrades.go @@ -1,14 +1,31 @@ package upgrades import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + consensusparamskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + v6 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/migrations/v6" + clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" + ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations" ) const ( - // DefaultUpgradeName is the default upgrade name used for upgrade tests which do not require special handling. - DefaultUpgradeName = "normal upgrade" + // V5 defines the upgrade name for the ibc-go/v5 upgrade handler. + V5 = "normal upgrade" // NOTE: keeping as "normal upgrade" as existing tags depend on this name + // V6 defines the upgrade name for the ibc-go/v6 upgrade handler. + V6 = "v6" + // V7 defines the upgrade name for the ibc-go/v7 upgrade handler. + V7 = "v7" + // V7_1 defines the upgrade name for the ibc-go/v7.1 upgrade handler. + V7_1 = "v7.1" ) // CreateDefaultUpgradeHandler creates an upgrade handler which can be used for regular upgrade tests @@ -21,3 +38,44 @@ func CreateDefaultUpgradeHandler( return mm.RunMigrations(ctx, configurator, vm) } } + +// CreateV6UpgradeHandler creates an upgrade handler for the ibc-go/v6 SimApp upgrade. +// NOTE: The v6.MigrateICS27ChannelCapabiliity function can be omitted if chains do not yet implement an ICS27 controller module +func CreateV6UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + cdc codec.BinaryCodec, + capabilityStoreKey *storetypes.KVStoreKey, + capabilityKeeper *capabilitykeeper.Keeper, + moduleName string, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + if err := v6.MigrateICS27ChannelCapability(ctx, cdc, capabilityStoreKey, capabilityKeeper, moduleName); err != nil { + return nil, err + } + + return mm.RunMigrations(ctx, configurator, vm) + } +} + +// CreateV7UpgradeHandler creates an upgrade handler for the ibc-go/v7 SimApp upgrade. +func CreateV7UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + cdc codec.BinaryCodec, + clientKeeper clientkeeper.Keeper, + consensusParamsKeeper consensusparamskeeper.Keeper, + paramsKeeper paramskeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // OPTIONAL: prune expired tendermint consensus states to save storage space + if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper); err != nil { + return nil, err + } + + legacyBaseAppSubspace := paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + baseapp.MigrateParams(ctx, legacyBaseAppSubspace, &consensusParamsKeeper) + + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/testing/simapp/upgrades/v6/upgrades.go b/testing/simapp/upgrades/v6/upgrades.go deleted file mode 100644 index 953bccf37e9..00000000000 --- a/testing/simapp/upgrades/v6/upgrades.go +++ /dev/null @@ -1,36 +0,0 @@ -package v6 - -import ( - "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - v6 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/migrations/v6" -) - -const ( - // UpgradeName defines the on-chain upgrade name for the SimApp v6 upgrade. - UpgradeName = "v6" -) - -// CreateUpgradeHandler creates an upgrade handler for the v6 SimApp upgrade. -// NOTE: The v6.MigrateICS27ChannelCapabiliity function can be omitted if chains do not yet implement an ICS27 controller module -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - cdc codec.BinaryCodec, - capabilityStoreKey *storetypes.KVStoreKey, - capabilityKeeper *capabilitykeeper.Keeper, - moduleName string, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - if err := v6.MigrateICS27ChannelCapability(ctx, cdc, capabilityStoreKey, capabilityKeeper, moduleName); err != nil { - return nil, err - } - - return mm.RunMigrations(ctx, configurator, vm) - } -} diff --git a/testing/simapp/upgrades/v7/upgrades.go b/testing/simapp/upgrades/v7/upgrades.go deleted file mode 100644 index 4621c06339b..00000000000 --- a/testing/simapp/upgrades/v7/upgrades.go +++ /dev/null @@ -1,42 +0,0 @@ -package v7 - -import ( - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - consensusparamskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" - ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations" -) - -const ( - // UpgradeName defines the on-chain upgrade name for the SimApp v7 upgrade. - UpgradeName = "v7" -) - -// CreateUpgradeHandler creates an upgrade handler for the v7 SimApp upgrade. -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - cdc codec.BinaryCodec, - clientKeeper clientkeeper.Keeper, - consensusParamsKeeper consensusparamskeeper.Keeper, - paramsKeeper paramskeeper.Keeper, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - // OPTIONAL: prune expired tendermint consensus states to save storage space - if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper); err != nil { - return nil, err - } - - legacyBaseAppSubspace := paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) - baseapp.MigrateParams(ctx, legacyBaseAppSubspace, &consensusParamsKeeper) - - return mm.RunMigrations(ctx, configurator, vm) - } -} From d7d43b39557b47015f30066d5388a54f23b74f23 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 24 Feb 2023 10:31:30 +0100 Subject: [PATCH 28/52] localhost godocs and nits (#3199) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * addressing nits * Update modules/light-clients/09-localhost/client_state.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * updating godoc and underscoing all unused args --------- Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- .../09-localhost/client_state.go | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 4c9d1aa2fee..29f571c0f49 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -66,20 +66,22 @@ func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientS return nil } -// GetTimestampAtHeight must return the timestamp for the consensus state associated with the provided height. -func (cs ClientState) GetTimestampAtHeight(ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, height exported.Height) (uint64, error) { +// GetTimestampAtHeight returns the current block time retrieved from the application context. The localhost client does not store consensus states and thus +// cannot provide a timestamp for the provided height. +func (cs ClientState) GetTimestampAtHeight(ctx sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec, _ exported.Height) (uint64, error) { return uint64(ctx.BlockTime().UnixNano()), nil } -// VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. +// VerifyMembership is a generic proof verification method which verifies the existence of a given key and value within the IBC store. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). +// The caller must provide the full IBC store. func (cs ClientState) VerifyMembership( ctx sdk.Context, store sdk.KVStore, - cdc codec.BinaryCodec, - height exported.Height, - delayTimePeriod uint64, - delayBlockPeriod uint64, + _ codec.BinaryCodec, + _ exported.Height, + _ uint64, + _ uint64, proof []byte, path exported.Path, value []byte, @@ -106,15 +108,16 @@ func (cs ClientState) VerifyMembership( return nil } -// VerifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath at a specified height. +// VerifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath within the IBC store. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). +// The caller must provide the full IBC store. func (cs ClientState) VerifyNonMembership( ctx sdk.Context, store sdk.KVStore, - cdc codec.BinaryCodec, - height exported.Height, - delayTimePeriod uint64, - delayBlockPeriod uint64, + _ codec.BinaryCodec, + _ exported.Height, + _ uint64, + _ uint64, proof []byte, path exported.Path, ) error { @@ -128,8 +131,7 @@ func (cs ClientState) VerifyNonMembership( } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - bz := store.Get([]byte(merklePath.KeyPath[1])) - if bz != nil { + if store.Has([]byte(merklePath.KeyPath[1])) { return sdkerrors.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) } @@ -137,12 +139,12 @@ func (cs ClientState) VerifyNonMembership( } // VerifyClientMessage is unsupported by the 09-localhost client type and returns an error. -func (cs ClientState) VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) error { +func (cs ClientState) VerifyClientMessage(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage) error { return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "client message verification is unsupported by the localhost client") } // CheckForMisbehaviour is unsupported by the 09-localhost client type and performs a no-op, returning false. -func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) bool { +func (cs ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage) bool { return false } @@ -152,7 +154,7 @@ func (cs ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCod // UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. // Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. -func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { +func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, _ exported.ClientMessage) []exported.Height { height := clienttypes.GetSelfHeight(ctx) cs.LatestHeight = height @@ -168,19 +170,19 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { // CheckSubstituteAndUpdateState returns an error. The localhost cannot be modified by // proposals. -func (cs ClientState) CheckSubstituteAndUpdateState(ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore sdk.KVStore, substituteClient exported.ClientState) error { +func (cs ClientState) CheckSubstituteAndUpdateState(_ sdk.Context, _ codec.BinaryCodec, _, _ sdk.KVStore, _ exported.ClientState) error { return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") } // VerifyUpgradeAndUpdateState returns an error since localhost cannot be upgraded func (cs ClientState) VerifyUpgradeAndUpdateState( - ctx sdk.Context, - cdc codec.BinaryCodec, - store sdk.KVStore, - newClient exported.ClientState, - newConsState exported.ConsensusState, - proofUpgradeClient, - proofUpgradeConsState []byte, + _ sdk.Context, + _ codec.BinaryCodec, + _ sdk.KVStore, + _ exported.ClientState, + _ exported.ConsensusState, + _, + _ []byte, ) error { return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") } From 5d9639e88dc4f6a0b70cec734a73cec462d29949 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 24 Feb 2023 11:08:33 +0100 Subject: [PATCH 29/52] use sentinel proofs for localhost channels (#3195) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * put back proof validation in 04-channel msgs * adding sentinel proof to e2e tests * adding sentintel proof to localhost and updating testcases * make format lint my code pls * Apply suggestions from code review Co-authored-by: Carlos Rodriguez Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * updating godoc2 * review suggestions --------- Co-authored-by: Carlos Rodriguez Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- .../interchain_accounts/localhost_test.go | 31 ++++++++++--------- e2e/tests/transfer/localhost_test.go | 11 ++++--- modules/core/04-channel/types/msgs.go | 28 +++++++++++++++++ modules/core/04-channel/types/msgs_test.go | 11 +++++++ .../09-localhost/client_state.go | 10 ++++++ .../09-localhost/client_state_test.go | 4 +-- modules/light-clients/09-localhost/keys.go | 12 +++++++ modules/light-clients/09-localhost/module.go | 4 --- 8 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 modules/light-clients/09-localhost/keys.go diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index 505f080dd8c..f0f00d93b3b 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -13,6 +13,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/suite" @@ -72,7 +73,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( icatypes.HostPortID, icatypes.Version, channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, controllerPortID, msgChanOpenInitRes.GetChannelId(), - version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) @@ -86,7 +87,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( controllerPortID, msgChanOpenInitRes.GetChannelId(), msgChanOpenTryRes.GetChannelId(), msgChanOpenTryRes.GetVersion(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) @@ -97,7 +98,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( t.Run("channel open confirm localhost", func(t *testing.T) { msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( icatypes.HostPortID, msgChanOpenTryRes.GetChannelId(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) @@ -165,7 +166,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( }) t.Run("recv packet localhost interchain accounts", func(t *testing.T) { - msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) s.Require().NoError(err) @@ -178,7 +179,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( }) t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { - msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) s.Require().NoError(err) @@ -236,7 +237,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan icatypes.HostPortID, icatypes.Version, channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, controllerPortID, msgChanOpenInitRes.GetChannelId(), - version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) @@ -250,7 +251,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( controllerPortID, msgChanOpenInitRes.GetChannelId(), msgChanOpenTryRes.GetChannelId(), msgChanOpenTryRes.GetVersion(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) @@ -261,7 +262,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan t.Run("channel open confirm localhost", func(t *testing.T) { msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( icatypes.HostPortID, msgChanOpenTryRes.GetChannelId(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) @@ -329,7 +330,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("timeout localhost interchain accounts packet", func(t *testing.T) { - msgTimeout := channeltypes.NewMsgTimeout(packet, 1, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgTimeout := channeltypes.NewMsgTimeout(packet, 1, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgTimeout) s.Require().NoError(err) @@ -337,7 +338,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("close interchain accounts host channel end", func(t *testing.T) { - msgCloseConfirm := channeltypes.NewMsgChannelCloseConfirm(icatypes.HostPortID, msgChanOpenTryRes.ChannelId, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgCloseConfirm := channeltypes.NewMsgChannelCloseConfirm(icatypes.HostPortID, msgChanOpenTryRes.ChannelId, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgCloseConfirm) s.Require().NoError(err) @@ -372,7 +373,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan icatypes.HostPortID, icatypes.Version, channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, controllerPortID, msgChanOpenInitRes.GetChannelId(), - version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) @@ -387,7 +388,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( controllerPortID, msgChanOpenInitRes.GetChannelId(), msgChanOpenTryRes.GetChannelId(), msgChanOpenTryRes.GetVersion(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) @@ -398,7 +399,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan t.Run("channel open confirm localhost", func(t *testing.T) { msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( icatypes.HostPortID, msgChanOpenTryRes.GetChannelId(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) @@ -464,7 +465,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("recv packet localhost interchain accounts", func(t *testing.T) { - msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) s.Require().NoError(err) @@ -477,7 +478,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { - msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) s.Require().NoError(err) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 3464c1eccd1..3cde2b1dcf6 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -10,6 +10,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibctesting "github.com/cosmos/ibc-go/v7/testing" test "github.com/strangelove-ventures/interchaintest/v7/testutil" @@ -71,7 +72,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { transfertypes.PortID, transfertypes.Version, channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), - transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + transfertypes.Version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) @@ -85,7 +86,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), msgChanOpenTryRes.GetChannelId(), transfertypes.Version, - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) @@ -96,7 +97,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { t.Run("channel open confirm localhost", func(t *testing.T) { msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( transfertypes.PortID, msgChanOpenTryRes.GetChannelId(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) @@ -136,7 +137,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { }) t.Run("recv packet localhost ibc transfer", func(t *testing.T) { - msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) s.Require().NoError(err) @@ -149,7 +150,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { }) t.Run("acknowledge packet localhost ibc transfer", func(t *testing.T) { - msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) s.Require().NoError(err) diff --git a/modules/core/04-channel/types/msgs.go b/modules/core/04-channel/types/msgs.go index a617fb2b86f..5e248b7e676 100644 --- a/modules/core/04-channel/types/msgs.go +++ b/modules/core/04-channel/types/msgs.go @@ -7,6 +7,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -91,6 +92,9 @@ func (msg MsgChannelOpenTry) ValidateBasic() error { if msg.PreviousChannelId != "" { return sdkerrors.Wrap(ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") } + if len(msg.ProofInit) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof") + } if msg.Channel.State != TRYOPEN { return sdkerrors.Wrapf(ErrInvalidChannelState, "channel state must be TRYOPEN in MsgChannelOpenTry. expected: %s, got: %s", @@ -149,6 +153,9 @@ func (msg MsgChannelOpenAck) ValidateBasic() error { if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil { return sdkerrors.Wrap(err, "invalid counterparty channel ID") } + if len(msg.ProofTry) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty try proof") + } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -191,6 +198,9 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error { if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } + if len(msg.ProofAck) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof") + } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -272,6 +282,9 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error { if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } + if len(msg.ProofInit) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof") + } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -307,6 +320,9 @@ func NewMsgRecvPacket( // ValidateBasic implements sdk.Msg func (msg MsgRecvPacket) ValidateBasic() error { + if len(msg.ProofCommitment) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty commitment proof") + } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -350,6 +366,9 @@ func NewMsgTimeout( // ValidateBasic implements sdk.Msg func (msg MsgTimeout) ValidateBasic() error { + if len(msg.ProofUnreceived) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") + } if msg.NextSequenceRecv == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } @@ -392,6 +411,12 @@ func (msg MsgTimeoutOnClose) ValidateBasic() error { if msg.NextSequenceRecv == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } + if len(msg.ProofUnreceived) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") + } + if len(msg.ProofClose) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end") + } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) @@ -430,6 +455,9 @@ func NewMsgAcknowledgement( // ValidateBasic implements sdk.Msg func (msg MsgAcknowledgement) ValidateBasic() error { + if len(msg.ProofAcked) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof") + } if len(msg.Acknowledgement) == 0 { return sdkerrors.Wrap(ErrInvalidAcknowledgement, "ack bytes cannot be empty") } diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 1085267a8a1..d582a5203d4 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -55,6 +55,8 @@ var ( packet = types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) invalidPacket = types.NewPacket(unknownPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) + emptyProof = []byte{} + addr = sdk.AccAddress("testaddr111111111111").String() emptyAddr string @@ -162,6 +164,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { {"", types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), true}, {"invalid counterparty port id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, invalidPort, cpchanid, version, suite.proof, height, addr), false}, {"invalid counterparty channel id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, invalidChannel, version, suite.proof, height, addr), false}, + {"empty proof", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, cpchanid, version, emptyProof, height, addr), false}, {"channel not in TRYOPEN state", &types.MsgChannelOpenTry{portid, "", initChannel, version, suite.proof, height, addr}, false}, {"previous channel id is not empty", &types.MsgChannelOpenTry{portid, chanid, initChannel, version, suite.proof, height, addr}, false}, } @@ -195,6 +198,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { {"too long channel id", types.NewMsgChannelOpenAck(portid, invalidLongChannel, chanid, version, suite.proof, height, addr), false}, {"channel id contains non-alpha", types.NewMsgChannelOpenAck(portid, invalidChannel, chanid, version, suite.proof, height, addr), false}, {"", types.NewMsgChannelOpenAck(portid, chanid, chanid, "", suite.proof, height, addr), true}, + {"empty proof", types.NewMsgChannelOpenAck(portid, chanid, chanid, version, emptyProof, height, addr), false}, {"invalid counterparty channel id", types.NewMsgChannelOpenAck(portid, chanid, invalidShortChannel, version, suite.proof, height, addr), false}, } @@ -226,6 +230,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { {"too short channel id", types.NewMsgChannelOpenConfirm(portid, invalidShortChannel, suite.proof, height, addr), false}, {"too long channel id", types.NewMsgChannelOpenConfirm(portid, invalidLongChannel, suite.proof, height, addr), false}, {"channel id contains non-alpha", types.NewMsgChannelOpenConfirm(portid, invalidChannel, suite.proof, height, addr), false}, + {"empty proof", types.NewMsgChannelOpenConfirm(portid, chanid, emptyProof, height, addr), false}, } for _, tc := range testCases { @@ -286,6 +291,7 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { {"too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr), false}, {"too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr), false}, {"channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr), false}, + {"empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr), false}, } for _, tc := range testCases { @@ -311,6 +317,7 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { }{ {"success", types.NewMsgRecvPacket(packet, suite.proof, height, addr), true}, {"missing signer address", types.NewMsgRecvPacket(packet, suite.proof, height, emptyAddr), false}, + {"proof contain empty proof", types.NewMsgRecvPacket(packet, emptyProof, height, addr), false}, {"invalid packet", types.NewMsgRecvPacket(invalidPacket, suite.proof, height, addr), false}, } @@ -346,6 +353,7 @@ func (suite *TypesTestSuite) TestMsgTimeoutValidateBasic() { {"success", types.NewMsgTimeout(packet, 1, suite.proof, height, addr), true}, {"seq 0", types.NewMsgTimeout(packet, 0, suite.proof, height, addr), false}, {"missing signer address", types.NewMsgTimeout(packet, 1, suite.proof, height, emptyAddr), false}, + {"cannot submit an empty proof", types.NewMsgTimeout(packet, 1, emptyProof, height, addr), false}, {"invalid packet", types.NewMsgTimeout(invalidPacket, 1, suite.proof, height, addr), false}, } @@ -373,6 +381,8 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { {"success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr), true}, {"seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr), false}, {"signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr), false}, + {"empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr), false}, + {"empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr), false}, {"invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr), false}, } @@ -400,6 +410,7 @@ func (suite *TypesTestSuite) TestMsgAcknowledgementValidateBasic() { {"success", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, addr), true}, {"empty ack", types.NewMsgAcknowledgement(packet, nil, suite.proof, height, addr), false}, {"missing signer address", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, emptyAddr), false}, + {"cannot submit an empty proof", types.NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, height, addr), false}, {"invalid packet", types.NewMsgAcknowledgement(invalidPacket, packet.GetData(), suite.proof, height, addr), false}, } diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 29f571c0f49..4a792900527 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -86,6 +86,11 @@ func (cs ClientState) VerifyMembership( path exported.Path, value []byte, ) error { + // ensure the proof provided is the expected sentintel localhost client proof + if !bytes.Equal(proof, SentinelProof) { + return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) + } + merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) @@ -121,6 +126,11 @@ func (cs ClientState) VerifyNonMembership( proof []byte, path exported.Path, ) error { + // ensure the proof provided is the expected sentintel localhost client proof + if !bytes.Equal(proof, SentinelProof) { + return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) + } + merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) diff --git a/modules/light-clients/09-localhost/client_state_test.go b/modules/light-clients/09-localhost/client_state_test.go index 0ac045647ab..7b37829bb71 100644 --- a/modules/light-clients/09-localhost/client_state_test.go +++ b/modules/light-clients/09-localhost/client_state_test.go @@ -299,7 +299,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { suite.chain.Codec, clienttypes.ZeroHeight(), 0, 0, // use zero values for delay periods - nil, // localhost proofs are nil + localhost.SentinelProof, path, value, ) @@ -378,7 +378,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { suite.chain.Codec, clienttypes.ZeroHeight(), 0, 0, // use zero values for delay periods - nil, // localhost proofs are nil + localhost.SentinelProof, path, ) diff --git a/modules/light-clients/09-localhost/keys.go b/modules/light-clients/09-localhost/keys.go new file mode 100644 index 00000000000..bf10ed0d800 --- /dev/null +++ b/modules/light-clients/09-localhost/keys.go @@ -0,0 +1,12 @@ +package localhost + +const ( + // ModuleName defines the 09-localhost light client module name + ModuleName = "09-localhost" +) + +// SentinelProof defines the 09-localhost sentinel proof. +// Submission of nil or empty proofs is disallowed in core IBC messaging. +// This serves as a placeholder value for relayers to leverage as the proof field in various message types. +// Localhost client state verification will fail if the sentintel proof value is not provided. +var SentinelProof = []byte{0x01} diff --git a/modules/light-clients/09-localhost/module.go b/modules/light-clients/09-localhost/module.go index 05f9112a701..bca3360a4ca 100644 --- a/modules/light-clients/09-localhost/module.go +++ b/modules/light-clients/09-localhost/module.go @@ -11,10 +11,6 @@ import ( "github.com/spf13/cobra" ) -const ( - ModuleName = "09-localhost" -) - var _ module.AppModuleBasic = AppModuleBasic{} // AppModuleBasic defines the basic application module used by the localhost light client. From 3bd6eab549b04c6d5982aa28e81b13e4dd51df6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:44:07 +0100 Subject: [PATCH 30/52] chore: update AllowedClients godoc (#3200) * update allowed clients documentation * Update proto/ibc/core/client/v1/client.proto Co-authored-by: Carlos Rodriguez --------- Co-authored-by: Carlos Rodriguez --- modules/core/02-client/types/client.pb.go | 4 +++- modules/core/02-client/types/params.go | 4 ++-- proto/ibc/core/client/v1/client.proto | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/core/02-client/types/client.pb.go b/modules/core/02-client/types/client.pb.go index 6b4f4351245..7c42017bd88 100644 --- a/modules/core/02-client/types/client.pb.go +++ b/modules/core/02-client/types/client.pb.go @@ -341,7 +341,9 @@ var xxx_messageInfo_Height proto.InternalMessageInfo // Params defines the set of IBC light client parameters. type Params struct { - // allowed_clients defines the list of allowed client state types. + // allowed_clients defines the list of allowed client state types which can be created + // and interacted with. If a client type is removed from the allowed clients list, usage + // of this client will be temporarily disabled. AllowedClients []string `protobuf:"bytes,1,rep,name=allowed_clients,json=allowedClients,proto3" json:"allowed_clients,omitempty" yaml:"allowed_clients"` } diff --git a/modules/core/02-client/types/params.go b/modules/core/02-client/types/params.go index ab6cfd7c43d..b0c43b156ef 100644 --- a/modules/core/02-client/types/params.go +++ b/modules/core/02-client/types/params.go @@ -10,7 +10,7 @@ import ( ) var ( - // DefaultAllowedClients are "06-solomachine" and "07-tendermint" + // DefaultAllowedClients are the default clients for the AllowedClients parameter. DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Localhost} // KeyAllowedClients is store's key for AllowedClients Params @@ -29,7 +29,7 @@ func NewParams(allowedClients ...string) Params { } } -// DefaultParams is the default parameter configuration for the ibc-client module +// DefaultParams is the default parameter configuration for the ibc-client module. func DefaultParams() Params { return NewParams(DefaultAllowedClients...) } diff --git a/proto/ibc/core/client/v1/client.proto b/proto/ibc/core/client/v1/client.proto index 266649ba01c..15b47e55548 100644 --- a/proto/ibc/core/client/v1/client.proto +++ b/proto/ibc/core/client/v1/client.proto @@ -98,6 +98,8 @@ message Height { // Params defines the set of IBC light client parameters. message Params { - // allowed_clients defines the list of allowed client state types. + // allowed_clients defines the list of allowed client state types which can be created + // and interacted with. If a client type is removed from the allowed clients list, usage + // of this client will be disabled until it is added again to the list. repeated string allowed_clients = 1 [(gogoproto.moretags) = "yaml:\"allowed_clients\""]; } From 9fb39d32473ec48366b72750192581faadd74a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 27 Feb 2023 13:06:09 +0100 Subject: [PATCH 31/52] chore: use single attribute for connection id in channel events (#3203) --- docs/migrations/v7-to-v7_1.md | 30 ++++++++++++++++++++++++ modules/core/04-channel/keeper/events.go | 13 ++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 docs/migrations/v7-to-v7_1.md diff --git a/docs/migrations/v7-to-v7_1.md b/docs/migrations/v7-to-v7_1.md new file mode 100644 index 00000000000..00a233a0ac4 --- /dev/null +++ b/docs/migrations/v7-to-v7_1.md @@ -0,0 +1,30 @@ +# Migrating from v7 to v7.1 + +This guide provides instructions for migrating to a new version of ibc-go. + +There are four sections based on the four potential user groups of this document: + +- [Chains](#chains) +- [IBC Apps](#ibc-apps) +- [Relayers](#relayers) +- [IBC Light Clients](#ibc-light-clients) + +**Note:** ibc-go supports golang semantic versioning and therefore all imports must be updated on major version releases. + +## Chains + +- No relevant changes were made in this release. + +## IBC Apps + +- No relevant changes were made in this release. + +## Relayers + +The event attribute `packet_connection` (`connectiontypes.AttributeKeyConnection`) has been deprecated. +Please use the `connection_id` attribute (`connectiontypes.AttributeKeyConnectionID`) which is emitted by all channel events. +Only send packet, receive packet, write acknowledgement, and acknowledge packet events used `packet_connection` previously. + +## IBC Light Clients + +- No relevant changes were made in this release. diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index ddefecc697e..78dfdbe1644 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -138,7 +138,8 @@ func EmitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()), // we only support 1-hop packets now, and that is the most important hop for a relayer // (is it going to a chain I am connected to) - sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), + sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), //nolint:staticcheck // DEPRECATED + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), ), sdk.NewEvent( sdk.EventTypeMessage, @@ -165,7 +166,8 @@ func EmitRecvPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()), // we only support 1-hop packets now, and that is the most important hop for a relayer // (is it going to a chain I am connected to) - sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), + sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), //nolint:staticcheck // DEPRECATED + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), ), sdk.NewEvent( sdk.EventTypeMessage, @@ -192,7 +194,8 @@ func EmitWriteAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, cha sdk.NewAttribute(types.AttributeKeyAckHex, hex.EncodeToString(acknowledgement)), // we only support 1-hop packets now, and that is the most important hop for a relayer // (is it going to a chain I am connected to) - sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), + sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), //nolint:staticcheck // DEPRECATED + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), ), sdk.NewEvent( sdk.EventTypeMessage, @@ -217,7 +220,8 @@ func EmitAcknowledgePacketEvent(ctx sdk.Context, packet exported.PacketI, channe sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()), // we only support 1-hop packets now, and that is the most important hop for a relayer // (is it going to a chain I am connected to) - sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), + sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), //nolint:staticcheck // DEPRECATED + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), ), sdk.NewEvent( sdk.EventTypeMessage, @@ -239,6 +243,7 @@ func EmitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel ty sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()), sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()), sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()), ), sdk.NewEvent( From 5a955e06326b3b9aae6699e3ce39c7dda4e4f752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 27 Feb 2023 13:29:35 +0100 Subject: [PATCH 32/52] fix: make proto-all (#3211) --- modules/core/02-client/types/client.pb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/02-client/types/client.pb.go b/modules/core/02-client/types/client.pb.go index 7c42017bd88..badaa482f47 100644 --- a/modules/core/02-client/types/client.pb.go +++ b/modules/core/02-client/types/client.pb.go @@ -343,7 +343,7 @@ var xxx_messageInfo_Height proto.InternalMessageInfo type Params struct { // allowed_clients defines the list of allowed client state types which can be created // and interacted with. If a client type is removed from the allowed clients list, usage - // of this client will be temporarily disabled. + // of this client will be disabled until it is added again to the list. AllowedClients []string `protobuf:"bytes,1,rep,name=allowed_clients,json=allowedClients,proto3" json:"allowed_clients,omitempty" yaml:"allowed_clients"` } From da5061f2aa5de0a5413abbf48fe2f4d26ac04122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:56:49 +0100 Subject: [PATCH 33/52] chore: move localhost client and connection IDs to the exported package (#3201) * chore: move localhost client and connection identifiers to the exported package * chore: move LocalhostConnectionID to connection.go * fix: e2e build --- .../interchain_accounts/localhost_test.go | 36 +++++++++---------- e2e/tests/transfer/localhost_test.go | 6 ++-- e2e/tests/upgrades/upgrade_test.go | 10 +++--- modules/core/02-client/abci.go | 2 +- .../core/02-client/keeper/grpc_query_test.go | 6 ++-- modules/core/02-client/keeper/keeper.go | 4 +-- modules/core/02-client/keeper/keeper_test.go | 4 +-- .../02-client/migrations/v7/localhost_test.go | 6 ++-- modules/core/02-client/types/keys.go | 2 +- modules/core/03-connection/genesis.go | 3 +- .../03-connection/keeper/grpc_query_test.go | 2 +- modules/core/03-connection/keeper/keeper.go | 4 +-- .../core/03-connection/keeper/keeper_test.go | 10 +++--- modules/core/03-connection/keeper/verify.go | 2 +- .../03-connection/migrations/v7/localhost.go | 4 +-- modules/core/03-connection/types/keys.go | 3 -- modules/core/03-connection/types/msgs.go | 4 +-- modules/core/03-connection/types/msgs_test.go | 4 +-- modules/core/exported/client.go | 4 ++- modules/core/exported/connection.go | 3 ++ .../09-localhost/client_state_test.go | 26 +++++++------- 21 files changed, 74 insertions(+), 71 deletions(-) diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index f0f00d93b3b..1b374b3ff8e 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -11,8 +11,8 @@ import ( controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/suite" @@ -54,12 +54,12 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") - version := icatypes.NewDefaultMetadataString(connectiontypes.LocalhostID, connectiontypes.LocalhostID) + version := icatypes.NewDefaultMetadataString(exported.LocalhostConnectionID, exported.LocalhostConnectionID) controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) s.Require().NoError(err) t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(connectiontypes.LocalhostID, userAWallet.FormattedAddress(), version) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version) txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) s.Require().NoError(err) @@ -71,7 +71,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( t.Run("channel open try localhost", func(t *testing.T) { msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( icatypes.HostPortID, icatypes.Version, - channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, + channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, controllerPortID, msgChanOpenInitRes.GetChannelId(), version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) @@ -119,7 +119,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( }) t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) s.Require().NoError(err) s.Require().NotZero(len(interchainAccAddress)) @@ -133,7 +133,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( }) t.Run("send packet localhost interchain accounts", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) s.Require().NoError(err) s.Require().NotZero(len(interchainAccAddress)) @@ -153,7 +153,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( Memo: "e2e", } - msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), connectiontypes.LocalhostID, uint64(time.Hour.Nanoseconds()), packetData) + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(time.Hour.Nanoseconds()), packetData) txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) s.AssertValidTxResponse(txResp) @@ -218,12 +218,12 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") - version := icatypes.NewDefaultMetadataString(connectiontypes.LocalhostID, connectiontypes.LocalhostID) + version := icatypes.NewDefaultMetadataString(exported.LocalhostConnectionID, exported.LocalhostConnectionID) controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) s.Require().NoError(err) t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(connectiontypes.LocalhostID, userAWallet.FormattedAddress(), version) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version) txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) s.Require().NoError(err) @@ -235,7 +235,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan t.Run("channel open try localhost", func(t *testing.T) { msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( icatypes.HostPortID, icatypes.Version, - channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, + channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, controllerPortID, msgChanOpenInitRes.GetChannelId(), version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) @@ -283,7 +283,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) s.Require().NoError(err) s.Require().NotZero(len(interchainAccAddress)) @@ -297,7 +297,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("send localhost interchain accounts packet with timeout", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) s.Require().NoError(err) s.Require().NotZero(len(interchainAccAddress)) @@ -317,7 +317,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan Memo: "e2e", } - msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), connectiontypes.LocalhostID, uint64(1), packetData) + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(1), packetData) txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) s.AssertValidTxResponse(txResp) @@ -358,7 +358,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("channel open init localhost: create new channel for existing account", func(t *testing.T) { - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(connectiontypes.LocalhostID, userAWallet.FormattedAddress(), version) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version) txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) s.Require().NoError(err) @@ -371,7 +371,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan t.Run("channel open try localhost", func(t *testing.T) { msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( icatypes.HostPortID, icatypes.Version, - channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, + channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, controllerPortID, msgChanOpenInitRes.GetChannelId(), version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) @@ -420,7 +420,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("verify interchain account and existing balance", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) s.Require().NoError(err) s.Require().NotZero(len(interchainAccAddress)) @@ -432,7 +432,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan }) t.Run("send packet localhost interchain accounts", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) s.Require().NoError(err) s.Require().NotZero(len(interchainAccAddress)) @@ -452,7 +452,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan Memo: "e2e", } - msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), connectiontypes.LocalhostID, uint64(time.Hour.Nanoseconds()), packetData) + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(time.Hour.Nanoseconds()), packetData) txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) s.AssertValidTxResponse(txResp) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 3cde2b1dcf6..af42a1c3488 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -8,8 +8,8 @@ import ( transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibctesting "github.com/cosmos/ibc-go/v7/testing" test "github.com/strangelove-ventures/interchaintest/v7/testutil" @@ -54,7 +54,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { t.Run("channel open init localhost", func(t *testing.T) { msgChanOpenInit := channeltypes.NewMsgChannelOpenInit( transfertypes.PortID, transfertypes.Version, - channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, + channeltypes.UNORDERED, []string{exported.LocalhostConnectionID}, transfertypes.PortID, rlyWallet.FormattedAddress(), ) @@ -70,7 +70,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { t.Run("channel open try localhost", func(t *testing.T) { msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( transfertypes.PortID, transfertypes.Version, - channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, + channeltypes.UNORDERED, []string{exported.LocalhostConnectionID}, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), transfertypes.Version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) diff --git a/e2e/tests/upgrades/upgrade_test.go b/e2e/tests/upgrades/upgrade_test.go index 08a0635c91d..b4b46d8cb4c 100644 --- a/e2e/tests/upgrades/upgrade_test.go +++ b/e2e/tests/upgrades/upgrade_test.go @@ -621,16 +621,16 @@ func (s *UpgradeTestSuite) TestV7ChainUpgradeAddLocalhost() { }) t.Run("ensure the localhost client is active and sentinel connection is stored in state", func(t *testing.T) { - status, err := s.QueryClientStatus(ctx, chain, exported.Localhost) + status, err := s.QueryClientStatus(ctx, chain, exported.LocalhostClientID) s.Require().NoError(err) s.Require().Equal(exported.Active.String(), status) - connectionEnd, err := s.QueryConnection(ctx, chain, connectiontypes.LocalhostID) + connectionEnd, err := s.QueryConnection(ctx, chain, exported.LocalhostConnectionID) s.Require().NoError(err) s.Require().Equal(connectiontypes.OPEN, connectionEnd.State) - s.Require().Equal(exported.Localhost, connectionEnd.ClientId) - s.Require().Equal(exported.Localhost, connectionEnd.Counterparty.ClientId) - s.Require().Equal(connectiontypes.LocalhostID, connectionEnd.Counterparty.ConnectionId) + s.Require().Equal(exported.LocalhostClientID, connectionEnd.ClientId) + s.Require().Equal(exported.LocalhostClientID, connectionEnd.Counterparty.ClientId) + s.Require().Equal(exported.LocalhostConnectionID, connectionEnd.Counterparty.ConnectionId) }) } diff --git a/modules/core/02-client/abci.go b/modules/core/02-client/abci.go index 66c092fa0d2..c8dec0dcf9c 100644 --- a/modules/core/02-client/abci.go +++ b/modules/core/02-client/abci.go @@ -34,7 +34,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { } // update the localhost client with the latest block height - if clientState, found := k.GetClientState(ctx, exported.Localhost); found { + if clientState, found := k.GetClientState(ctx, exported.LocalhostClientID); found { k.UpdateLocalhostClient(ctx, clientState) } } diff --git a/modules/core/02-client/keeper/grpc_query_test.go b/modules/core/02-client/keeper/grpc_query_test.go index ed33d324a30..6b48f466aba 100644 --- a/modules/core/02-client/keeper/grpc_query_test.go +++ b/modules/core/02-client/keeper/grpc_query_test.go @@ -111,7 +111,7 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { { "empty pagination", func() { - localhost := types.NewIdentifiedClientState(exported.Localhost, suite.chainA.GetClientState(exported.Localhost)) + localhost := types.NewIdentifiedClientState(exported.LocalhostClientID, suite.chainA.GetClientState(exported.LocalhostClientID)) expClientStates = types.IdentifiedClientStates{localhost} req = &types.QueryClientStatesRequest{} }, @@ -120,7 +120,7 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { { "success, only localhost", func() { - localhost := types.NewIdentifiedClientState(exported.Localhost, suite.chainA.GetClientState(exported.Localhost)) + localhost := types.NewIdentifiedClientState(exported.LocalhostClientID, suite.chainA.GetClientState(exported.LocalhostClientID)) expClientStates = types.IdentifiedClientStates{localhost} req = &types.QueryClientStatesRequest{ Pagination: &query.PageRequest{ @@ -143,7 +143,7 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { clientStateA1 := path1.EndpointA.GetClientState() clientStateA2 := path2.EndpointA.GetClientState() - localhost := types.NewIdentifiedClientState(exported.Localhost, suite.chainA.GetClientState(exported.Localhost)) + localhost := types.NewIdentifiedClientState(exported.LocalhostClientID, suite.chainA.GetClientState(exported.LocalhostClientID)) idcs := types.NewIdentifiedClientState(path1.EndpointA.ClientID, clientStateA1) idcs2 := types.NewIdentifiedClientState(path2.EndpointA.ClientID, clientStateA2) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index cd13c506ba9..d84b83629af 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -57,12 +57,12 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // CreateLocalhostClient initialises the 09-localhost client state and sets it in state. func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error { var clientState localhost.ClientState - return clientState.Initialize(ctx, k.cdc, k.ClientStore(ctx, exported.Localhost), nil) + return clientState.Initialize(ctx, k.cdc, k.ClientStore(ctx, exported.LocalhostClientID), nil) } // UpdateLocalhostClient updates the 09-localhost client to the latest block height and chain ID. func (k Keeper) UpdateLocalhostClient(ctx sdk.Context, clientState exported.ClientState) []exported.Height { - return clientState.UpdateState(ctx, k.cdc, k.ClientStore(ctx, exported.Localhost), nil) + return clientState.UpdateState(ctx, k.cdc, k.ClientStore(ctx, exported.LocalhostClientID), nil) } // GenerateClientIdentifier returns the next client identifier. diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index bd5a10a5fe9..506a2156df2 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -237,7 +237,7 @@ func (suite *KeeperTestSuite) TestValidateSelfClient() { func (suite KeeperTestSuite) TestGetAllGenesisClients() { //nolint:govet // this is a test, we are okay with copying locks clientIDs := []string{ - exported.Localhost, testClientID2, testClientID3, testClientID, + exported.LocalhostClientID, testClientID2, testClientID3, testClientID, } expClients := []exported.ClientState{ localhost.NewClientState(types.GetSelfHeight(suite.chainA.GetContext())), @@ -426,7 +426,7 @@ func (suite KeeperTestSuite) TestIterateClientStates() { //nolint:govet // this "all clientIDs", nil, func() []string { - allClientIDs := []string{exported.Localhost} + allClientIDs := []string{exported.LocalhostClientID} allClientIDs = append(allClientIDs, expSMClientIDs...) allClientIDs = append(allClientIDs, expTMClientIDs...) return allClientIDs diff --git a/modules/core/02-client/migrations/v7/localhost_test.go b/modules/core/02-client/migrations/v7/localhost_test.go index 982641f42d7..fc09523a94c 100644 --- a/modules/core/02-client/migrations/v7/localhost_test.go +++ b/modules/core/02-client/migrations/v7/localhost_test.go @@ -10,17 +10,17 @@ func (suite *MigrationsV7TestSuite) TestMigrateLocalhostClient() { suite.SetupTest() // note: explicitly remove the localhost client before running migration handler - clientStore := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), exported.Localhost) + clientStore := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), exported.LocalhostClientID) clientStore.Delete(host.ClientStateKey()) - clientState, found := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), exported.Localhost) + clientState, found := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), exported.LocalhostClientID) suite.Require().False(found) suite.Require().Nil(clientState) err := v7.MigrateLocalhostClient(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper) suite.Require().NoError(err) - clientState, found = suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), exported.Localhost) + clientState, found = suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), exported.LocalhostClientID) suite.Require().True(found) suite.Require().NotNil(clientState) } diff --git a/modules/core/02-client/types/keys.go b/modules/core/02-client/types/keys.go index 471de76e977..9a2c67df3c5 100644 --- a/modules/core/02-client/types/keys.go +++ b/modules/core/02-client/types/keys.go @@ -50,7 +50,7 @@ func IsValidClientID(clientID string) bool { // ParseClientIdentifier parses the client type and sequence from the client identifier. func ParseClientIdentifier(clientID string) (string, uint64, error) { - if clientID == exported.Localhost { + if clientID == exported.LocalhostClientID { return clientID, 0, nil } diff --git a/modules/core/03-connection/genesis.go b/modules/core/03-connection/genesis.go index 6037c7b91c6..b5efd9c4bdc 100644 --- a/modules/core/03-connection/genesis.go +++ b/modules/core/03-connection/genesis.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/03-connection/keeper" "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // InitGenesis initializes the ibc connection submodule's state from a provided genesis @@ -21,7 +22,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { k.SetParams(ctx, gs.Params) localhostConnection := k.CreateSentinelLocalhostConnection() - k.SetConnection(ctx, types.LocalhostID, localhostConnection) + k.SetConnection(ctx, exported.LocalhostConnectionID, localhostConnection) } // ExportGenesis returns the ibc connection submodule's exported genesis. diff --git a/modules/core/03-connection/keeper/grpc_query_test.go b/modules/core/03-connection/keeper/grpc_query_test.go index 6aee91f4793..fdcb04426db 100644 --- a/modules/core/03-connection/keeper/grpc_query_test.go +++ b/modules/core/03-connection/keeper/grpc_query_test.go @@ -88,7 +88,7 @@ func (suite *KeeperTestSuite) TestQueryConnection() { func (suite *KeeperTestSuite) TestQueryConnections() { localhostConnectionEnd := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection() - localhostConn := types.NewIdentifiedConnection(types.LocalhostID, localhostConnectionEnd) + localhostConn := types.NewIdentifiedConnection(exported.LocalhostConnectionID, localhostConnectionEnd) var ( req *types.QueryConnectionsRequest diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 6a66cde6803..8194352bece 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -198,8 +198,8 @@ func (k Keeper) GetAllConnections(ctx sdk.Context) (connections []types.Identifi // CreateSentinelLocalhostConnection returns the sentinel localhost connection end. func (k Keeper) CreateSentinelLocalhostConnection() types.ConnectionEnd { - counterparty := types.NewCounterparty(exported.Localhost, types.LocalhostID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) - return types.NewConnectionEnd(types.OPEN, exported.Localhost, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) + counterparty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) + return types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) } // addConnectionToClient is used to add a connection identifier to the set of diff --git a/modules/core/03-connection/keeper/keeper_test.go b/modules/core/03-connection/keeper/keeper_test.go index 58a0e5734d5..5b2a163bc72 100644 --- a/modules/core/03-connection/keeper/keeper_test.go +++ b/modules/core/03-connection/keeper/keeper_test.go @@ -81,7 +81,7 @@ func (suite KeeperTestSuite) TestGetAllConnections() { //nolint:govet // this is iconn2 := types.NewIdentifiedConnection(path2.EndpointA.ConnectionID, conn2) localhostConnectionEnd := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection() - localhostConn := types.NewIdentifiedConnection(types.LocalhostID, localhostConnectionEnd) + localhostConn := types.NewIdentifiedConnection(exported.LocalhostConnectionID, localhostConnectionEnd) expConnections := []types.IdentifiedConnection{iconn1, iconn2, localhostConn} @@ -165,14 +165,14 @@ func (suite *KeeperTestSuite) TestLocalhostConnectionEndCreation() { ctx := suite.chainA.GetContext() connectionKeeper := suite.chainA.App.GetIBCKeeper().ConnectionKeeper localhostConnection := connectionKeeper.CreateSentinelLocalhostConnection() - connectionKeeper.SetConnection(ctx, types.LocalhostID, localhostConnection) + connectionKeeper.SetConnection(ctx, exported.LocalhostConnectionID, localhostConnection) - connectionEnd, found := connectionKeeper.GetConnection(ctx, types.LocalhostID) + connectionEnd, found := connectionKeeper.GetConnection(ctx, exported.LocalhostConnectionID) suite.Require().True(found) suite.Require().Equal(types.OPEN, connectionEnd.State) - suite.Require().Equal(exported.Localhost, connectionEnd.ClientId) + suite.Require().Equal(exported.LocalhostClientID, connectionEnd.ClientId) suite.Require().Equal(types.ExportedVersionsToProto(types.GetCompatibleVersions()), connectionEnd.Versions) - expectedCounterParty := types.NewCounterparty(exported.Localhost, types.LocalhostID, commitmenttypes.NewMerklePrefix(connectionKeeper.GetCommitmentPrefix().Bytes())) + expectedCounterParty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(connectionKeeper.GetCommitmentPrefix().Bytes())) suite.Require().Equal(expectedCounterParty, connectionEnd.Counterparty) } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index d1624bbfbb0..82d6208d437 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -387,7 +387,7 @@ func (k Keeper) getClientStateAndKVStore(ctx sdk.Context, clientID string) (expo } store := k.clientKeeper.ClientStore(ctx, clientID) - if clientState.ClientType() == exported.Localhost { + if clientID == exported.LocalhostClientID { store = ctx.KVStore(k.storeKey) } diff --git a/modules/core/03-connection/migrations/v7/localhost.go b/modules/core/03-connection/migrations/v7/localhost.go index 4a637fb8aae..57661e43bf9 100644 --- a/modules/core/03-connection/migrations/v7/localhost.go +++ b/modules/core/03-connection/migrations/v7/localhost.go @@ -3,12 +3,12 @@ package v7 import ( sdk "github.com/cosmos/cosmos-sdk/types" - connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // MigrateLocalhostConnection creates the sentinel localhost connection end to enable // localhost ibc functionality. func MigrateLocalhostConnection(ctx sdk.Context, connectionKeeper ConnectionKeeper) { localhostConnection := connectionKeeper.CreateSentinelLocalhostConnection() - connectionKeeper.SetConnection(ctx, connectiontypes.LocalhostID, localhostConnection) + connectionKeeper.SetConnection(ctx, exported.LocalhostConnectionID, localhostConnection) } diff --git a/modules/core/03-connection/types/keys.go b/modules/core/03-connection/types/keys.go index 0049031188b..7037452d83e 100644 --- a/modules/core/03-connection/types/keys.go +++ b/modules/core/03-connection/types/keys.go @@ -28,9 +28,6 @@ const ( // ConnectionPrefix is the prefix used when creating a connection identifier ConnectionPrefix = "connection-" - - // LocalhostID is the sentinel connection ID used for localhost IBC connections - LocalhostID = "connection-localhost" ) // FormatConnectionIdentifier returns the connection identifier with the sequence appended. diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index ae6f6ad7fe6..0b1bbf62d13 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -43,7 +43,7 @@ func NewMsgConnectionOpenInit( // ValidateBasic implements sdk.Msg. func (msg MsgConnectionOpenInit) ValidateBasic() error { - if msg.ClientId == exported.Localhost { + if msg.ClientId == exported.LocalhostClientID { return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") } @@ -106,7 +106,7 @@ func NewMsgConnectionOpenTry( // ValidateBasic implements sdk.Msg func (msg MsgConnectionOpenTry) ValidateBasic() error { - if msg.ClientId == exported.Localhost { + if msg.ClientId == exported.LocalhostClientID { return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") } diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index f3541ba02be..2eceedd06ef 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -89,7 +89,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { msg *types.MsgConnectionOpenInit expPass bool }{ - {"localhost client ID", types.NewMsgConnectionOpenInit(exported.Localhost, "clienttotest", prefix, version, 500, signer), false}, + {"localhost client ID", types.NewMsgConnectionOpenInit(exported.LocalhostClientID, "clienttotest", prefix, version, 500, signer), false}, {"invalid client ID", types.NewMsgConnectionOpenInit("test/iris", "clienttotest", prefix, version, 500, signer), false}, {"invalid counterparty client ID", types.NewMsgConnectionOpenInit("clienttotest", "(clienttotest)", prefix, version, 500, signer), false}, {"invalid counterparty connection ID", &types.MsgConnectionOpenInit{connectionID, types.NewCounterparty("clienttotest", "connectiontotest", prefix), version, 500, signer}, false}, @@ -136,7 +136,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { expPass bool }{ {"non empty connection ID", &types.MsgConnectionOpenTry{"connection-0", "clienttotesta", protoAny, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, - {"localhost client ID", types.NewMsgConnectionOpenTry(exported.Localhost, "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"localhost client ID", types.NewMsgConnectionOpenTry(exported.LocalhostClientID, "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid client ID", types.NewMsgConnectionOpenTry("test/iris", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid counterparty connection ID", types.NewMsgConnectionOpenTry("clienttotesta", "ibc/test", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, {"invalid counterparty client ID", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "test/conn1", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 2a95abab5ae..8fa78295e33 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -20,9 +20,11 @@ const ( Tendermint string = "07-tendermint" // Localhost is the client type for the localhost client. - // It is also used as the clientID for the localhost client. Localhost string = "09-localhost" + // LocalhostClientID is the sentinel client ID for the localhost client. + LocalhostClientID string = Localhost + // Active is a status type of a client. An active client is allowed to be used. Active Status = "Active" diff --git a/modules/core/exported/connection.go b/modules/core/exported/connection.go index 93129050db2..c418e8497a7 100644 --- a/modules/core/exported/connection.go +++ b/modules/core/exported/connection.go @@ -1,5 +1,8 @@ package exported +// LocalhostConnectionID is the sentinel connection ID for the localhost connection. +const LocalhostConnectionID string = "connection-localhost" + // ConnectionI describes the required methods for a connection. type ConnectionI interface { GetClientID() string diff --git a/modules/light-clients/09-localhost/client_state_test.go b/modules/light-clients/09-localhost/client_state_test.go index 7b37829bb71..b11034a87e3 100644 --- a/modules/light-clients/09-localhost/client_state_test.go +++ b/modules/light-clients/09-localhost/client_state_test.go @@ -95,7 +95,7 @@ func (suite *LocalhostTestSuite) TestInitialize() { suite.SetupTest() clientState := localhost.NewClientState(clienttypes.NewHeight(3, 10)) - clientStore := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.Localhost) + clientStore := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.LocalhostClientID) err := clientState.Initialize(suite.chain.GetContext(), suite.chain.Codec, clientStore, tc.consState) @@ -121,9 +121,9 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { { "success: client state verification", func() { - clientState := suite.chain.GetClientState(exported.Localhost) + clientState := suite.chain.GetClientState(exported.LocalhostClientID) - merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(exported.Localhost)) + merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(exported.LocalhostClientID)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -137,14 +137,14 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { func() { connectionEnd := connectiontypes.NewConnectionEnd( connectiontypes.OPEN, - exported.Localhost, - connectiontypes.NewCounterparty(exported.Localhost, connectiontypes.LocalhostID, suite.chain.GetPrefix()), + exported.LocalhostClientID, + connectiontypes.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, suite.chain.GetPrefix()), connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions()), 0, ) - suite.chain.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chain.GetContext(), connectiontypes.LocalhostID, connectionEnd) + suite.chain.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chain.GetContext(), exported.LocalhostConnectionID, connectionEnd) - merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectiontypes.LocalhostID)) + merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(exported.LocalhostConnectionID)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -160,7 +160,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { channeltypes.OPEN, channeltypes.UNORDERED, channeltypes.NewCounterparty(mock.PortID, ibctesting.FirstChannelID), - []string{connectiontypes.LocalhostID}, + []string{exported.LocalhostConnectionID}, mock.Version, ) @@ -263,7 +263,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { channeltypes.OPEN, channeltypes.UNORDERED, channeltypes.NewCounterparty(mock.PortID, ibctesting.FirstChannelID), - []string{connectiontypes.LocalhostID}, + []string{exported.LocalhostConnectionID}, mock.Version, ) @@ -290,7 +290,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { tc.malleate() - clientState := suite.chain.GetClientState(exported.Localhost) + clientState := suite.chain.GetClientState(exported.LocalhostClientID) store := suite.chain.GetContext().KVStore(suite.chain.GetSimApp().GetKey(exported.StoreKey)) err := clientState.VerifyMembership( @@ -369,7 +369,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { tc.malleate() - clientState := suite.chain.GetClientState(exported.Localhost) + clientState := suite.chain.GetClientState(exported.LocalhostClientID) store := suite.chain.GetContext().KVStore(suite.chain.GetSimApp().GetKey(exported.StoreKey)) err := clientState.VerifyNonMembership( @@ -403,7 +403,7 @@ func (suite *LocalhostTestSuite) TestVerifyCheckForMisbehaviour() { func (suite *LocalhostTestSuite) TestUpdateState() { clientState := localhost.NewClientState(clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight()))) - store := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.Localhost) + store := suite.chain.GetSimApp().GetIBCKeeper().ClientKeeper.ClientStore(suite.chain.GetContext(), exported.LocalhostClientID) suite.coordinator.CommitBlock(suite.chain) @@ -412,7 +412,7 @@ func (suite *LocalhostTestSuite) TestUpdateState() { expHeight := clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight())) suite.Require().True(heights[0].EQ(expHeight)) - clientState = suite.chain.GetClientState(exported.Localhost) + clientState = suite.chain.GetClientState(exported.LocalhostClientID) suite.Require().True(heights[0].EQ(clientState.GetLatestHeight())) } From 610d8128854791c0ed27a5700f213c16b140d918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:58:26 +0100 Subject: [PATCH 34/52] chore: rename function (#3202) --- modules/core/03-connection/keeper/verify.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 82d6208d437..acb6c03c4d2 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -24,7 +24,7 @@ func (k Keeper) VerifyClientState( clientState exported.ClientState, ) error { clientID := connection.GetClientID() - targetClient, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + targetClient, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -66,7 +66,7 @@ func (k Keeper) VerifyClientConsensusState( consensusState exported.ConsensusState, ) error { clientID := connection.GetClientID() - clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -108,7 +108,7 @@ func (k Keeper) VerifyConnectionState( counterpartyConnection exported.ConnectionI, // opposite connection ) error { clientID := connection.GetClientID() - clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -156,7 +156,7 @@ func (k Keeper) VerifyChannelState( channel exported.ChannelI, ) error { clientID := connection.GetClientID() - clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -205,7 +205,7 @@ func (k Keeper) VerifyPacketCommitment( commitmentBytes []byte, ) error { clientID := connection.GetClientID() - clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -248,7 +248,7 @@ func (k Keeper) VerifyPacketAcknowledgement( acknowledgement []byte, ) error { clientID := connection.GetClientID() - clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -291,7 +291,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( sequence uint64, ) error { clientID := connection.GetClientID() - clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -333,7 +333,7 @@ func (k Keeper) VerifyNextSequenceRecv( nextSequenceRecv uint64, ) error { clientID := connection.GetClientID() - clientState, clientStore, err := k.getClientStateAndKVStore(ctx, clientID) + clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err } @@ -378,9 +378,9 @@ func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) return uint64(math.Ceil(float64(timeDelay) / float64(expectedTimePerBlock))) } -// getClientStateAndKVStore returns the client state and associated KVStore for the provided client identifier. +// getClientStateAndVerificationStore returns the client state and associated KVStore for the provided client identifier. // If the client type is localhost then the core IBC KVStore is returned, otherwise the client prefixed store is returned. -func (k Keeper) getClientStateAndKVStore(ctx sdk.Context, clientID string) (exported.ClientState, sdk.KVStore, error) { +func (k Keeper) getClientStateAndVerificationStore(ctx sdk.Context, clientID string) (exported.ClientState, sdk.KVStore, error) { clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { return nil, nil, sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) From e50870d943dc2a22913ef6fc38fc6775a4c4f736 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 27 Feb 2023 17:16:30 +0100 Subject: [PATCH 35/52] update localhost upgrade handler to explicitly set allowed clients param (#3207) * updating v7.1 upgrade handler to explicitly set allowed clients params * retrieve params and append localhost client type * use localhost client id const --- testing/simapp/app.go | 2 +- testing/simapp/upgrades/upgrades.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index f378364f731..76575485ff1 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -961,7 +961,7 @@ func (app *SimApp) setupUpgradeHandlers() { app.UpgradeKeeper.SetUpgradeHandler( upgrades.V7_1, - upgrades.CreateDefaultUpgradeHandler(app.mm, app.configurator), + upgrades.CreateV7LocalhostUpgradeHandler(app.mm, app.configurator, app.IBCKeeper.ClientKeeper), ) } diff --git a/testing/simapp/upgrades/upgrades.go b/testing/simapp/upgrades/upgrades.go index 3730b0f3e6c..ec7ae6b8577 100644 --- a/testing/simapp/upgrades/upgrades.go +++ b/testing/simapp/upgrades/upgrades.go @@ -14,6 +14,7 @@ import ( v6 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/migrations/v6" clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" + "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations" ) @@ -79,3 +80,19 @@ func CreateV7UpgradeHandler( return mm.RunMigrations(ctx, configurator, vm) } } + +// CreateV7LocalhostUpgradeHandler creates an upgrade handler for the ibc-go/v7.1 SimApp upgrade. +func CreateV7LocalhostUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + clientKeeper clientkeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // explicitly update the IBC 02-client params with the new default allowed clients + params := clientKeeper.GetParams(ctx) + params.AllowedClients = append(params.AllowedClients, exported.LocalhostClientID) + clientKeeper.SetParams(ctx, params) + + return mm.RunMigrations(ctx, configurator, vm) + } +} From b6cd296573f05887dfca6549334581a2120e590f Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 27 Feb 2023 17:23:01 +0100 Subject: [PATCH 36/52] correcting error - use client type, not client id in upgrade handler --- testing/simapp/upgrades/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/simapp/upgrades/upgrades.go b/testing/simapp/upgrades/upgrades.go index ec7ae6b8577..40535eba24a 100644 --- a/testing/simapp/upgrades/upgrades.go +++ b/testing/simapp/upgrades/upgrades.go @@ -90,7 +90,7 @@ func CreateV7LocalhostUpgradeHandler( return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { // explicitly update the IBC 02-client params with the new default allowed clients params := clientKeeper.GetParams(ctx) - params.AllowedClients = append(params.AllowedClients, exported.LocalhostClientID) + params.AllowedClients = append(params.AllowedClients, exported.Localhost) clientKeeper.SetParams(ctx, params) return mm.RunMigrations(ctx, configurator, vm) From 53eea553d17758f6ddf89f2a6e7e0d63719f5338 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 27 Feb 2023 18:08:18 +0100 Subject: [PATCH 37/52] moving set connection to create localhost sentinel connection (#3209) --- modules/core/03-connection/genesis.go | 4 +--- modules/core/03-connection/keeper/grpc_query_test.go | 11 +++++++---- modules/core/03-connection/keeper/keeper.go | 8 +++++--- modules/core/03-connection/keeper/keeper_test.go | 10 +++++----- .../03-connection/migrations/v7/expected_keepers.go | 5 +---- modules/core/03-connection/migrations/v7/localhost.go | 5 +---- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/modules/core/03-connection/genesis.go b/modules/core/03-connection/genesis.go index b5efd9c4bdc..df8fb28945e 100644 --- a/modules/core/03-connection/genesis.go +++ b/modules/core/03-connection/genesis.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/03-connection/keeper" "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" - "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // InitGenesis initializes the ibc connection submodule's state from a provided genesis @@ -21,8 +20,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { k.SetNextConnectionSequence(ctx, gs.NextConnectionSequence) k.SetParams(ctx, gs.Params) - localhostConnection := k.CreateSentinelLocalhostConnection() - k.SetConnection(ctx, exported.LocalhostConnectionID, localhostConnection) + k.CreateSentinelLocalhostConnection(ctx) } // ExportGenesis returns the ibc connection submodule's exported genesis. diff --git a/modules/core/03-connection/keeper/grpc_query_test.go b/modules/core/03-connection/keeper/grpc_query_test.go index fdcb04426db..0573e3e02aa 100644 --- a/modules/core/03-connection/keeper/grpc_query_test.go +++ b/modules/core/03-connection/keeper/grpc_query_test.go @@ -87,12 +87,15 @@ func (suite *KeeperTestSuite) TestQueryConnection() { } func (suite *KeeperTestSuite) TestQueryConnections() { - localhostConnectionEnd := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection() - localhostConn := types.NewIdentifiedConnection(exported.LocalhostConnectionID, localhostConnectionEnd) + suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection(suite.chainA.GetContext()) + localhostConn, found := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetConnection(suite.chainA.GetContext(), exported.LocalhostConnectionID) + suite.Require().True(found) + + identifiedConn := types.NewIdentifiedConnection(exported.LocalhostConnectionID, localhostConn) var ( req *types.QueryConnectionsRequest - expConnections = []*types.IdentifiedConnection{&localhostConn} + expConnections = []*types.IdentifiedConnection{&identifiedConn} ) testCases := []struct { @@ -140,7 +143,7 @@ func (suite *KeeperTestSuite) TestQueryConnections() { iconn2 := types.NewIdentifiedConnection(path2.EndpointA.ConnectionID, conn2) iconn3 := types.NewIdentifiedConnection(path3.EndpointA.ConnectionID, conn3) - expConnections = []*types.IdentifiedConnection{&iconn1, &iconn2, &iconn3, &localhostConn} + expConnections = []*types.IdentifiedConnection{&iconn1, &iconn2, &iconn3, &identifiedConn} req = &types.QueryConnectionsRequest{ Pagination: &query.PageRequest{ diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 8194352bece..31bb339534f 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -196,10 +196,12 @@ func (k Keeper) GetAllConnections(ctx sdk.Context) (connections []types.Identifi return connections } -// CreateSentinelLocalhostConnection returns the sentinel localhost connection end. -func (k Keeper) CreateSentinelLocalhostConnection() types.ConnectionEnd { +// CreateSentinelLocalhostConnection creates and sets the sentinel localhost connection end in the IBC store. +func (k Keeper) CreateSentinelLocalhostConnection(ctx sdk.Context) { counterparty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) - return types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) + connectionEnd := types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) + + k.SetConnection(ctx, exported.LocalhostConnectionID, connectionEnd) } // addConnectionToClient is used to add a connection identifier to the set of diff --git a/modules/core/03-connection/keeper/keeper_test.go b/modules/core/03-connection/keeper/keeper_test.go index 5b2a163bc72..dbae331d690 100644 --- a/modules/core/03-connection/keeper/keeper_test.go +++ b/modules/core/03-connection/keeper/keeper_test.go @@ -80,10 +80,11 @@ func (suite KeeperTestSuite) TestGetAllConnections() { //nolint:govet // this is iconn1 := types.NewIdentifiedConnection(path1.EndpointA.ConnectionID, conn1) iconn2 := types.NewIdentifiedConnection(path2.EndpointA.ConnectionID, conn2) - localhostConnectionEnd := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection() - localhostConn := types.NewIdentifiedConnection(exported.LocalhostConnectionID, localhostConnectionEnd) + suite.chainA.App.GetIBCKeeper().ConnectionKeeper.CreateSentinelLocalhostConnection(suite.chainA.GetContext()) + localhostConn, found := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetConnection(suite.chainA.GetContext(), exported.LocalhostConnectionID) + suite.Require().True(found) - expConnections := []types.IdentifiedConnection{iconn1, iconn2, localhostConn} + expConnections := []types.IdentifiedConnection{iconn1, iconn2, types.NewIdentifiedConnection(exported.LocalhostConnectionID, localhostConn)} connections := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetAllConnections(suite.chainA.GetContext()) suite.Require().Len(connections, len(expConnections)) @@ -164,8 +165,7 @@ func (suite *KeeperTestSuite) TestGetTimestampAtHeight() { func (suite *KeeperTestSuite) TestLocalhostConnectionEndCreation() { ctx := suite.chainA.GetContext() connectionKeeper := suite.chainA.App.GetIBCKeeper().ConnectionKeeper - localhostConnection := connectionKeeper.CreateSentinelLocalhostConnection() - connectionKeeper.SetConnection(ctx, exported.LocalhostConnectionID, localhostConnection) + connectionKeeper.CreateSentinelLocalhostConnection(ctx) connectionEnd, found := connectionKeeper.GetConnection(ctx, exported.LocalhostConnectionID) diff --git a/modules/core/03-connection/migrations/v7/expected_keepers.go b/modules/core/03-connection/migrations/v7/expected_keepers.go index ff4c17c0335..8427e2cc2bf 100644 --- a/modules/core/03-connection/migrations/v7/expected_keepers.go +++ b/modules/core/03-connection/migrations/v7/expected_keepers.go @@ -2,12 +2,9 @@ package v7 import ( sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ) // ConnectionKeeper expected IBC connection keeper type ConnectionKeeper interface { - CreateSentinelLocalhostConnection() types.ConnectionEnd - SetConnection(ctx sdk.Context, connectionID string, connection types.ConnectionEnd) + CreateSentinelLocalhostConnection(ctx sdk.Context) } diff --git a/modules/core/03-connection/migrations/v7/localhost.go b/modules/core/03-connection/migrations/v7/localhost.go index 57661e43bf9..76f768402de 100644 --- a/modules/core/03-connection/migrations/v7/localhost.go +++ b/modules/core/03-connection/migrations/v7/localhost.go @@ -2,13 +2,10 @@ package v7 import ( sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // MigrateLocalhostConnection creates the sentinel localhost connection end to enable // localhost ibc functionality. func MigrateLocalhostConnection(ctx sdk.Context, connectionKeeper ConnectionKeeper) { - localhostConnection := connectionKeeper.CreateSentinelLocalhostConnection() - connectionKeeper.SetConnection(ctx, exported.LocalhostConnectionID, localhostConnection) + connectionKeeper.CreateSentinelLocalhostConnection(ctx) } From c6beda391ff52f63f7eeb798d5d8eee27e6d37ed Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 28 Feb 2023 09:06:23 +0000 Subject: [PATCH 38/52] Allow disabling of client type via allowed_clients param (#3196) --- docs/.vuepress/config.js | 5 ++ docs/ibc/troubleshooting.md | 8 ++++ modules/core/02-client/abci.go | 8 ++-- modules/core/02-client/keeper/client.go | 4 +- modules/core/02-client/keeper/grpc_query.go | 3 +- modules/core/02-client/keeper/keeper.go | 9 ++++ modules/core/02-client/keeper/proposal.go | 4 +- .../core/03-connection/keeper/handshake.go | 9 ++++ .../03-connection/keeper/handshake_test.go | 22 +++++++-- modules/core/03-connection/keeper/verify.go | 16 +++---- .../03-connection/types/expected_keepers.go | 1 + modules/core/04-channel/keeper/handshake.go | 19 ++++++++ .../core/04-channel/keeper/handshake_test.go | 46 +++++++++++++++++-- modules/core/04-channel/keeper/packet.go | 3 +- .../core/04-channel/types/expected_keepers.go | 1 + modules/core/exported/client.go | 3 ++ 16 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 docs/ibc/troubleshooting.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index ba11c556e9e..0fe317a7322 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -215,6 +215,11 @@ module.exports = { directory: false, path: "/roadmap/roadmap.html", }, + { + title: "Troubleshooting", + directory: false, + path: "/ibc/troubleshooting.html", + }, ], }, { diff --git a/docs/ibc/troubleshooting.md b/docs/ibc/troubleshooting.md new file mode 100644 index 00000000000..95576752e73 --- /dev/null +++ b/docs/ibc/troubleshooting.md @@ -0,0 +1,8 @@ +# Troubleshooting + +### Unauthorized client states + +If it is being reported that a client state is unauthorized, this is due to the client type not being present +in the [`AllowedClients`](https://github.com/cosmos/ibc-go/blob/v6.0.0/modules/core/02-client/types/client.pb.go#L345) array. + +Unless the client type is present in this array, all usage of clients of this type will be prevented. diff --git a/modules/core/02-client/abci.go b/modules/core/02-client/abci.go index c8dec0dcf9c..d5b4b2deb65 100644 --- a/modules/core/02-client/abci.go +++ b/modules/core/02-client/abci.go @@ -33,8 +33,10 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { } } - // update the localhost client with the latest block height - if clientState, found := k.GetClientState(ctx, exported.LocalhostClientID); found { - k.UpdateLocalhostClient(ctx, clientState) + // update the localhost client with the latest block height if it is active. + if clientState, found := k.GetClientState(ctx, exported.Localhost); found { + if k.GetClientStatus(ctx, clientState, exported.Localhost) == exported.Active { + k.UpdateLocalhostClient(ctx, clientState) + } } } diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index 2b5e65a1cf7..271efb4d14b 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -57,7 +57,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exporte clientStore := k.ClientStore(ctx, clientID) - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) } @@ -118,7 +118,7 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e clientStore := k.ClientStore(ctx, clientID) - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status) } diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index 84a38304d74..5ef92cb2c88 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -245,8 +245,7 @@ func (q Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequ ) } - clientStore := q.ClientStore(ctx, req.ClientId) - status := clientState.Status(ctx, clientStore, q.cdc) + status := q.GetClientStatus(ctx, clientState, req.ClientId) return &types.QueryClientStatusResponse{ Status: status.String(), diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index d84b83629af..c3888b55234 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -403,3 +403,12 @@ func (k Keeper) ClientStore(ctx sdk.Context, clientID string) sdk.KVStore { clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) return prefix.NewStore(ctx.KVStore(k.storeKey), clientPrefix) } + +// GetClientStatus returns the status for a given clientState. If the client type is not in the allowed +// clients param field, Unauthorized is returned, otherwise the client state status is returned. +func (k Keeper) GetClientStatus(ctx sdk.Context, clientState exported.ClientState, clientID string) exported.Status { + if !k.GetParams(ctx).IsAllowedClient(clientState.ClientType()) { + return exported.Unauthorized + } + return clientState.Status(ctx, k.ClientStore(ctx, clientID), k.cdc) +} diff --git a/modules/core/02-client/keeper/proposal.go b/modules/core/02-client/keeper/proposal.go index a8c0d072ab3..024939080a4 100644 --- a/modules/core/02-client/keeper/proposal.go +++ b/modules/core/02-client/keeper/proposal.go @@ -25,7 +25,7 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo subjectClientStore := k.ClientStore(ctx, p.SubjectClientId) - if status := subjectClientState.Status(ctx, subjectClientStore, k.cdc); status == exported.Active { + if status := k.GetClientStatus(ctx, subjectClientState, p.SubjectClientId); status == exported.Active { return sdkerrors.Wrap(types.ErrInvalidUpdateClientProposal, "cannot update Active subject client") } @@ -40,7 +40,7 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo substituteClientStore := k.ClientStore(ctx, p.SubstituteClientId) - if status := substituteClientState.Status(ctx, substituteClientStore, k.cdc); status != exported.Active { + if status := k.GetClientStatus(ctx, substituteClientState, p.SubstituteClientId); status != exported.Active { return sdkerrors.Wrapf(types.ErrClientNotActive, "substitute client is not Active, status is %s", status) } diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index 04026bb20f8..53417a2aa9e 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -32,6 +32,15 @@ func (k Keeper) ConnOpenInit( versions = []exported.Version{version} } + clientState, found := k.clientKeeper.GetClientState(ctx, clientID) + if !found { + return "", sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", clientID) + } + + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { + return "", sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + } + connectionID := k.GenerateConnectionIdentifier(ctx) if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil { return "", err diff --git a/modules/core/03-connection/keeper/handshake_test.go b/modules/core/03-connection/keeper/handshake_test.go index c14ec879204..5751c9e531a 100644 --- a/modules/core/03-connection/keeper/handshake_test.go +++ b/modules/core/03-connection/keeper/handshake_test.go @@ -15,10 +15,11 @@ import ( // chainB which is yet UNINITIALIZED func (suite *KeeperTestSuite) TestConnOpenInit() { var ( - path *ibctesting.Path - version *types.Version - delayPeriod uint64 - emptyConnBID bool + path *ibctesting.Path + version *types.Version + delayPeriod uint64 + emptyConnBID bool + expErrorMsgSubstring string ) testCases := []struct { @@ -45,6 +46,17 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { // set path.EndpointA.ClientID to invalid client identifier path.EndpointA.ClientID = "clientidentifier" }, false}, + { + msg: "unauthorized client", + expPass: false, + malleate: func() { + expErrorMsgSubstring = "status is Unauthorized" + // remove client from allowed list + params := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetParams(suite.chainA.GetContext()) + params.AllowedClients = []string{} + suite.chainA.App.GetIBCKeeper().ClientKeeper.SetParams(suite.chainA.GetContext(), params) + }, + }, } for _, tc := range testCases { @@ -53,6 +65,7 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { suite.SetupTest() // reset emptyConnBID = false // must be explicitly changed version = nil // must be explicitly changed + expErrorMsgSubstring = "" path = ibctesting.NewPath(suite.chainA, suite.chainB) suite.coordinator.SetupClients(path) @@ -70,6 +83,7 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { suite.Require().Equal(types.FormatConnectionIdentifier(0), connectionID) } else { suite.Require().Error(err) + suite.Contains(err.Error(), expErrorMsgSubstring) suite.Require().Equal("", connectionID) } }) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index acb6c03c4d2..e55970a9de7 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -29,7 +29,7 @@ func (k Keeper) VerifyClientState( return err } - if status := targetClient.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, targetClient, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } @@ -71,7 +71,7 @@ func (k Keeper) VerifyClientConsensusState( return err } - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } @@ -113,7 +113,7 @@ func (k Keeper) VerifyConnectionState( return err } - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } @@ -161,7 +161,7 @@ func (k Keeper) VerifyChannelState( return err } - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } @@ -210,7 +210,7 @@ func (k Keeper) VerifyPacketCommitment( return err } - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } @@ -253,7 +253,7 @@ func (k Keeper) VerifyPacketAcknowledgement( return err } - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } @@ -296,7 +296,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( return err } - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } @@ -338,7 +338,7 @@ func (k Keeper) VerifyNextSequenceRecv( return err } - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index 5945766726d..d9b8dec6599 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -8,6 +8,7 @@ import ( // ClientKeeper expected account IBC client keeper type ClientKeeper interface { + GetClientStatus(ctx sdk.Context, clientState exported.ClientState, clientID string) exported.Status GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 922b681f104..94cce64b8f9 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -8,6 +8,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" @@ -50,6 +51,15 @@ func (k Keeper) ChanOpenInit( ) } + clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.ClientId) + if !found { + return "", nil, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", connectionEnd.ClientId) + } + + if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.ClientId); status != exported.Active { + return "", nil, sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) + } + if !k.portKeeper.Authenticate(ctx, portCap, portID) { return "", nil, sdkerrors.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) } @@ -401,6 +411,15 @@ func (k Keeper) ChanCloseInit( return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } + clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.ClientId) + if !found { + return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", connectionEnd.ClientId) + } + + if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.ClientId); status != exported.Active { + return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) + } + if connectionEnd.GetState() != int32(connectiontypes.OPEN) { return sdkerrors.Wrapf( connectiontypes.ErrInvalidConnectionState, diff --git a/modules/core/04-channel/keeper/handshake_test.go b/modules/core/04-channel/keeper/handshake_test.go index bf77d7ed530..8c721d1f438 100644 --- a/modules/core/04-channel/keeper/handshake_test.go +++ b/modules/core/04-channel/keeper/handshake_test.go @@ -25,9 +25,10 @@ type testCase = struct { // can succeed. func (suite *KeeperTestSuite) TestChanOpenInit() { var ( - path *ibctesting.Path - features []string - portCap *capabilitytypes.Capability + path *ibctesting.Path + features []string + portCap *capabilitytypes.Capability + expErrorMsgSubstring string ) testCases := []testCase{ @@ -85,6 +86,22 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) portCap = suite.chainA.GetPortCapability(ibctesting.MockPort) }, true}, + { + msg: "unauthorized client", + expPass: false, + malleate: func() { + expErrorMsgSubstring = "status is Unauthorized" + suite.coordinator.SetupConnections(path) + + // remove client from allowed list + params := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetParams(suite.chainA.GetContext()) + params.AllowedClients = []string{} + suite.chainA.App.GetIBCKeeper().ClientKeeper.SetParams(suite.chainA.GetContext(), params) + + suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) + portCap = suite.chainA.GetPortCapability(ibctesting.MockPort) + }, + }, } for _, tc := range testCases { @@ -96,6 +113,7 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { path = ibctesting.NewPath(suite.chainA, suite.chainB) path.EndpointA.ChannelConfig.Order = order path.EndpointB.ChannelConfig.Order = order + expErrorMsgSubstring = "" tc.malleate() @@ -129,6 +147,7 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { suite.Require().Equal(chanCap.String(), cap.String(), "channel capability is not correct") } else { suite.Require().Error(err) + suite.Require().Contains(err.Error(), expErrorMsgSubstring) suite.Require().Nil(cap) suite.Require().Equal("", channelID) } @@ -598,8 +617,9 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { // ChanCloseInit. Both chains will use message passing to setup OPEN channels. func (suite *KeeperTestSuite) TestChanCloseInit() { var ( - path *ibctesting.Path - channelCap *capabilitytypes.Capability + path *ibctesting.Path + channelCap *capabilitytypes.Capability + expErrorMsgSubstring string ) testCases := []testCase{ @@ -655,6 +675,20 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { suite.coordinator.Setup(path) channelCap = capabilitytypes.NewCapability(3) }, false}, + { + msg: "unauthorized client", + expPass: false, + malleate: func() { + suite.coordinator.Setup(path) + channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + + // remove client from allowed list + params := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetParams(suite.chainA.GetContext()) + params.AllowedClients = []string{} + suite.chainA.App.GetIBCKeeper().ClientKeeper.SetParams(suite.chainA.GetContext(), params) + expErrorMsgSubstring = "status is Unauthorized" + }, + }, } for _, tc := range testCases { @@ -662,6 +696,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset path = ibctesting.NewPath(suite.chainA, suite.chainB) + expErrorMsgSubstring = "" tc.malleate() @@ -673,6 +708,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Contains(err.Error(), expErrorMsgSubstring) } }) } diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 7268c37c574..e57ec06e943 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -71,8 +71,7 @@ func (k Keeper) SendPacket( } // prevent accidental sends with clients that cannot be updated - clientStore := k.clientKeeper.ClientStore(ctx, connectionEnd.GetClientID()) - if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { + if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.GetClientID()); status != exported.Active { return 0, sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) } diff --git a/modules/core/04-channel/types/expected_keepers.go b/modules/core/04-channel/types/expected_keepers.go index 3a5460502c6..3c0b0b0198d 100644 --- a/modules/core/04-channel/types/expected_keepers.go +++ b/modules/core/04-channel/types/expected_keepers.go @@ -10,6 +10,7 @@ import ( // ClientKeeper expected account IBC client keeper type ClientKeeper interface { + GetClientStatus(ctx sdk.Context, clientState exported.ClientState, clientID string) exported.Status GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) ClientStore(ctx sdk.Context, clientID string) sdk.KVStore diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 8fa78295e33..731d7e5edf7 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -36,6 +36,9 @@ const ( // Unknown indicates there was an error in determining the status of a client. Unknown Status = "Unknown" + + // Unauthorized indicates that the client type is not registered as an allowed client type. + Unauthorized Status = "Unauthorized" ) // ClientState defines the required common functions for light clients. From dc9a7a7f0a658831fb4d52874730f26a30a84cfc Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 28 Feb 2023 15:39:29 +0000 Subject: [PATCH 39/52] Sync localhost branch with main (#3215) --- Makefile | 9 +- .../adr-010-light-clients-as-sdk-modules.md | 100 +++++++++++ internal/errors/errors.go | 63 +++++++ .../controller/ibc_middleware.go | 11 +- .../controller/keeper/account.go | 13 +- .../controller/keeper/handshake.go | 26 +-- .../controller/keeper/keeper.go | 4 +- .../controller/keeper/migrations.go | 6 +- .../controller/keeper/msg_server.go | 4 +- .../controller/keeper/relay.go | 8 +- .../controller/types/errors.go | 4 +- .../controller/types/msgs.go | 15 +- .../27-interchain-accounts/host/ibc_module.go | 20 ++- .../host/keeper/account.go | 4 +- .../host/keeper/handshake.go | 18 +- .../host/keeper/relay.go | 20 +-- .../host/types/errors.go | 4 +- .../27-interchain-accounts/types/account.go | 10 +- .../27-interchain-accounts/types/codec.go | 6 +- .../27-interchain-accounts/types/errors.go | 38 ++-- .../27-interchain-accounts/types/metadata.go | 18 +- .../27-interchain-accounts/types/packet.go | 8 +- .../apps/27-interchain-accounts/types/port.go | 4 +- modules/apps/29-fee/ibc_middleware.go | 16 +- modules/apps/29-fee/keeper/escrow.go | 4 +- modules/apps/29-fee/keeper/grpc_query.go | 10 +- modules/apps/29-fee/keeper/msg_server.go | 13 +- modules/apps/29-fee/keeper/relay.go | 4 +- modules/apps/29-fee/types/errors.go | 22 +-- modules/apps/29-fee/types/fee.go | 9 +- modules/apps/29-fee/types/genesis.go | 21 +-- modules/apps/29-fee/types/keys.go | 25 +-- modules/apps/29-fee/types/msgs.go | 13 +- modules/apps/transfer/ibc_module.go | 30 ++-- modules/apps/transfer/keeper/grpc_query.go | 6 +- .../apps/transfer/keeper/mbt_relay_test.go | 5 +- modules/apps/transfer/keeper/msg_server.go | 7 +- modules/apps/transfer/keeper/relay.go | 29 ++-- modules/apps/transfer/types/errors.go | 20 +-- modules/apps/transfer/types/msgs.go | 15 +- modules/apps/transfer/types/packet.go | 12 +- modules/apps/transfer/types/trace.go | 16 +- .../transfer/types/transfer_authorization.go | 25 +-- modules/core/02-client/client/utils/utils.go | 6 +- modules/core/02-client/keeper/client.go | 16 +- modules/core/02-client/keeper/grpc_query.go | 8 +- modules/core/02-client/keeper/keeper.go | 29 ++-- modules/core/02-client/keeper/proposal.go | 16 +- .../core/02-client/migrations/v7/genesis.go | 4 +- modules/core/02-client/migrations/v7/store.go | 15 +- modules/core/02-client/proposal_handler.go | 5 +- modules/core/02-client/types/client.go | 10 +- modules/core/02-client/types/codec.go | 27 +-- modules/core/02-client/types/errors.go | 62 +++---- modules/core/02-client/types/height.go | 13 +- modules/core/02-client/types/keys.go | 8 +- modules/core/02-client/types/msgs.go | 21 +-- modules/core/02-client/types/proposal.go | 10 +- .../core/03-connection/client/utils/utils.go | 6 +- .../core/03-connection/keeper/grpc_query.go | 14 +- .../core/03-connection/keeper/handshake.go | 33 ++-- modules/core/03-connection/keeper/keeper.go | 6 +- modules/core/03-connection/keeper/verify.go | 41 ++--- .../core/03-connection/types/connection.go | 15 +- modules/core/03-connection/types/errors.go | 22 +-- modules/core/03-connection/types/keys.go | 6 +- modules/core/03-connection/types/msgs.go | 63 +++---- modules/core/03-connection/types/version.go | 16 +- modules/core/04-channel/client/utils/utils.go | 13 +- modules/core/04-channel/keeper/grpc_query.go | 12 +- modules/core/04-channel/keeper/handshake.go | 74 ++++---- modules/core/04-channel/keeper/keeper.go | 14 +- modules/core/04-channel/keeper/packet.go | 74 ++++---- modules/core/04-channel/keeper/packet_test.go | 6 +- modules/core/04-channel/keeper/timeout.go | 40 ++--- .../core/04-channel/keeper/timeout_test.go | 4 +- .../core/04-channel/types/acknowledgement.go | 10 +- .../04-channel/types/acknowledgement_test.go | 14 +- modules/core/04-channel/types/channel.go | 16 +- modules/core/04-channel/types/errors.go | 52 +++--- modules/core/04-channel/types/keys.go | 6 +- modules/core/04-channel/types/msgs.go | 71 ++++---- modules/core/04-channel/types/packet.go | 22 +-- modules/core/05-port/types/errors.go | 10 +- modules/core/23-commitment/types/errors.go | 8 +- modules/core/23-commitment/types/merkle.go | 48 ++--- modules/core/23-commitment/types/utils.go | 6 +- modules/core/24-host/errors.go | 8 +- modules/core/24-host/parse.go | 24 +-- modules/core/24-host/validate.go | 16 +- modules/core/keeper/msg_server.go | 164 +++++++++--------- .../06-solomachine/client_state.go | 25 +-- modules/light-clients/06-solomachine/codec.go | 4 +- .../06-solomachine/consensus_state.go | 12 +- .../light-clients/06-solomachine/errors.go | 12 +- .../light-clients/06-solomachine/header.go | 14 +- .../06-solomachine/misbehaviour.go | 20 +-- .../06-solomachine/misbehaviour_handle.go | 6 +- modules/light-clients/06-solomachine/proof.go | 6 +- .../06-solomachine/proposal_handle.go | 10 +- .../light-clients/06-solomachine/update.go | 8 +- .../07-tendermint/client_state.go | 65 +++---- .../07-tendermint/consensus_state.go | 8 +- modules/light-clients/07-tendermint/errors.go | 28 +-- modules/light-clients/07-tendermint/header.go | 18 +- .../07-tendermint/migrations/migrations.go | 6 +- .../07-tendermint/misbehaviour.go | 38 ++-- .../07-tendermint/misbehaviour_handle.go | 18 +- .../07-tendermint/proposal_handle.go | 12 +- modules/light-clients/07-tendermint/update.go | 22 +-- .../light-clients/07-tendermint/upgrade.go | 27 +-- .../09-localhost/client_state.go | 31 ++-- scripts/linting/lint-changed-go-files.sh | 14 ++ scripts/linting/lint-changed-md-files.sh | 13 ++ testing/chain.go | 4 +- testing/simapp/ante_handler.go | 9 +- testing/simapp/app.go | 14 +- 117 files changed, 1290 insertions(+), 1053 deletions(-) create mode 100644 docs/architecture/adr-010-light-clients-as-sdk-modules.md create mode 100644 internal/errors/errors.go create mode 100755 scripts/linting/lint-changed-go-files.sh create mode 100755 scripts/linting/lint-changed-md-files.sh diff --git a/Makefile b/Makefile index 037571717c3..73c89cb236b 100644 --- a/Makefile +++ b/Makefile @@ -295,7 +295,9 @@ lint: lint-fix: golangci-lint run --fix --out-format=tab --issues-exit-code=0 -.PHONY: lint lint-fix + +lint-fix-changed: + ./scripts/linting/lint-changed-go-files.sh format: find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs gofumpt -w @@ -305,6 +307,11 @@ format: docs-lint: markdownlint . --fix +docs-lint-changed: + ./scripts/linting/lint-changed-md-files.sh + +.PHONY: lint lint-fix lint-fix-changed docs-lint docs-lint-changed + ############################################################################### ### Protobuf ### ############################################################################### diff --git a/docs/architecture/adr-010-light-clients-as-sdk-modules.md b/docs/architecture/adr-010-light-clients-as-sdk-modules.md new file mode 100644 index 00000000000..62186debaf3 --- /dev/null +++ b/docs/architecture/adr-010-light-clients-as-sdk-modules.md @@ -0,0 +1,100 @@ +# ADR 010: IBC light clients as SDK modules + +## Changelog +* 12/12/2022: initial draft + +## Status + +Proposed + +## Context + +ibc-go has 3 main consumers: +- IBC light clients +- IBC applications +- relayers + +Relayers listen and respond to events emitted by ibc-go while IBC light clients and applications are invoked by core IBC. +Currently there exists two different approaches to callbacks being invoked by core IBC. + +IBC light clients currently are invoked by a `ClientState` and `ConsensusState` interface as defined by [core IBC](https://github.com/cosmos/ibc-go/blob/fb9dedd706e5835cdd607392320df79fcea7ca7f/modules/core/exported/client.go#L36). +The 02-client submodule will retrieve the `ClientState` or `ConsensusState` from the IBC store in order to perform callbacks to the light client. +This design requires all required information for the light client to function to be stored in the `ClientState` or `ConsensusState` or potentially under metadata keys for a specific client instance. +Additional information may be provided by core IBC via the defined interface arguments if that information is generic enough to be useful to all IBC light clients. +This constraint has proved problematic as pass through clients (such as wasm) cannot maintain easy access to a VM instance. +In addition, without increasing the size of the defined `ClientState` interface, light clients are unable to take advantage of basic built-in SDK functionality such as genesis import/export and migrations. + +The other approach used to perform callback logic is via registered SDK modules. +This approach is used by core IBC to interact with IBC applications. +IBC applications will register their callbacks on the IBC router at compile time. +When a packet comes in, core IBC will use the IBC router to lookup the registered callback functions for the provided packet. +The benefit of registered callbacks opposed to interface functions is that additional information may be accessed via external keepers. +Because the IBC applications are also SDK modules, they additionally get access to a host of functionality provided by the SDK. +This includes: genesis import/export, migrations, query/transaction CLI commands, type registration, gRPC query registration, and message server registration. + +As described in [ADR 006](./adr-006-02-client-refactor.md), generalizing light client behaviour is difficult. +IBC light clients will obtain greater flexibility and control via the registered SDK module approach. + +## Decision + +Instead of using two different approaches to invoking callbacks, IBC light clients should be invoked as SDK modules. +Over time and as necessary, core IBC should adjust its interactions with light clients such that they are SDK modules as opposed to interfaces. + +One immediate decision that has already been applied is to formalize light client type registration via the inclusion of an `AppModuleBasic` within the `ModuleManager` for a chain. +The [tendermint](https://github.com/cosmos/ibc-go/pull/2825) and [solo machine](https://github.com/cosmos/ibc-go/pull/2826) clients were refactored to include this `AppModuleBasic` implementation and core IBC will no longer include either type as registered by default. + +Longer term solutions include using internal module communication as described in [ADR 033](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-033-protobuf-inter-module-comm.md) on the SDK. +The following functions should become callbacks invoked via intermodule communication: +- `Status` +- `GetTimestampAtHeight` +- `VerifyMembership` +- `VerifyNonMembership` +- `Initialize` +- `VerifyClientMessage` +- `CheckForMisbehaviour` +- `UpdateStateOnMisbehaviour` +- `UpdateState` +- `CheckSubstituteAndUpdateState` +- `VerifyUpgradeAndUpdateState` + +The ClientState interface should eventually be trimmed down to something along the lines of: +```go +type ClientState interface { + proto.Message + + ClientType() string + GetLatestHeight() Height + Validate() error + + ZeroCustomFields() ClientState + + // ADDITION + Route() string // route used for intermodule communication +} +``` + +For the most part, any functions which require access to the client store should likely not be an interface function of the `ClientState`. + +`ExportMetadata` should eventually be replaced by a light client's ability to import/export it's own genesis information. + +### Intermodule communication + +To keep the transition from interface callbacks to SDK module callbacks as simple as possible, intermodule communication (when available) should be used to route to light client modules. +Without intermodule communication, a routing system would need to be developed/maintained to register callbacks. +This functionality of routing to another SDK module should and will be provided by the SDK. +Once it is possible to route to SDK modules, a `ClientState` type could expose the function `Route` which returns the callback route used to call the light client module. + +## Consequences + +### Positive +- use a single approach for interacting with callbacks +- greater flexibilty and control for IBC light clients +- does not require developing another routing system + +### Negative +- requires breaking changes +- requires waiting for intermodule communication + +### Neutral +N/A + diff --git a/internal/errors/errors.go b/internal/errors/errors.go new file mode 100644 index 00000000000..79b96856a87 --- /dev/null +++ b/internal/errors/errors.go @@ -0,0 +1,63 @@ +package errors + +import ( + errorsmod "cosmossdk.io/errors" + + "github.com/cosmos/ibc-go/v7/modules/core/exported" +) + +const codespace = exported.ModuleName + +var ( + // ErrInvalidSequence is used the sequence number (nonce) is incorrect + // for the signature. + ErrInvalidSequence = errorsmod.Register(codespace, 1, "invalid sequence") + + // ErrUnauthorized is used whenever a request without sufficient + // authorization is handled. + ErrUnauthorized = errorsmod.Register(codespace, 2, "unauthorized") + + // ErrInsufficientFunds is used when the account cannot pay requested amount. + ErrInsufficientFunds = errorsmod.Register(codespace, 3, "insufficient funds") + + // ErrUnknownRequest is used when the request body. + ErrUnknownRequest = errorsmod.Register(codespace, 4, "unknown request") + + // ErrInvalidAddress is used when an address is found to be invalid. + ErrInvalidAddress = errorsmod.Register(codespace, 5, "invalid address") + + // ErrInvalidCoins is used when sdk.Coins are invalid. + ErrInvalidCoins = errorsmod.Register(codespace, 6, "invalid coins") + + // ErrOutOfGas is used when there is not enough gas. + ErrOutOfGas = errorsmod.Register(codespace, 7, "out of gas") + + // ErrInvalidRequest defines an ABCI typed error where the request contains + // invalid data. + ErrInvalidRequest = errorsmod.Register(codespace, 8, "invalid request") + + // ErrInvalidHeight defines an error for an invalid height + ErrInvalidHeight = errorsmod.Register(codespace, 9, "invalid height") + + // ErrInvalidVersion defines a general error for an invalid version + ErrInvalidVersion = errorsmod.Register(codespace, 10, "invalid version") + + // ErrInvalidChainID defines an error when the chain-id is invalid. + ErrInvalidChainID = errorsmod.Register(codespace, 11, "invalid chain-id") + + // ErrInvalidType defines an error an invalid type. + ErrInvalidType = errorsmod.Register(codespace, 12, "invalid type") + + // ErrPackAny defines an error when packing a protobuf message to Any fails. + ErrPackAny = errorsmod.Register(codespace, 13, "failed packing protobuf message to Any") + + // ErrUnpackAny defines an error when unpacking a protobuf message from Any fails. + ErrUnpackAny = errorsmod.Register(codespace, 14, "failed unpacking protobuf message from Any") + + // ErrLogic defines an internal logic error, e.g. an invariant or assertion + // that is violated. It is a programmer error, not a user-facing error. + ErrLogic = errorsmod.Register(codespace, 15, "internal logic error") + + // ErrNotFound defines an error when requested entity doesn't exist in the state. + ErrNotFound = errorsmod.Register(codespace, 16, "not found") +) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 5fc09e5e028..56a0d529a8a 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -1,10 +1,11 @@ package controller import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -84,7 +85,7 @@ func (im IBCMiddleware) OnChanOpenTry( counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return "", errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanOpenAck implements the IBCMiddleware interface @@ -127,7 +128,7 @@ func (im IBCMiddleware) OnChanOpenConfirm( portID, channelID string, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanCloseInit implements the IBCMiddleware interface @@ -137,7 +138,7 @@ func (im IBCMiddleware) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for interchain account channels - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "user cannot close channel") } // OnChanCloseConfirm implements the IBCMiddleware interface @@ -168,7 +169,7 @@ func (im IBCMiddleware) OnRecvPacket( packet channeltypes.Packet, _ sdk.AccAddress, ) ibcexported.Acknowledgement { - err := sdkerrors.Wrapf(icatypes.ErrInvalidChannelFlow, "cannot receive packet on controller chain") + err := errorsmod.Wrapf(icatypes.ErrInvalidChannelFlow, "cannot receive packet on controller chain") ack := channeltypes.NewErrorAcknowledgement(err) keeper.EmitAcknowledgementEvent(ctx, packet, ack, err) return ack diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index c1418595508..5044e50b962 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -1,10 +1,11 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/internal/logging" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -34,7 +35,7 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, } if k.IsMiddlewareDisabled(ctx, portID, connectionID) && !k.IsActiveChannelClosed(ctx, connectionID, portID) { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") } k.SetMiddlewareEnabled(ctx, portID, connectionID) @@ -53,16 +54,16 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, // if there is an active channel for this portID / connectionID return an error activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) if found { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s on connection %s", activeChannelID, portID, connectionID) + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s on connection %s", activeChannelID, portID, connectionID) } switch { case k.portKeeper.IsBound(ctx, portID) && !k.IsBound(ctx, portID): - return "", sdkerrors.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID) + return "", errorsmod.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID) case !k.portKeeper.IsBound(ctx, portID): cap := k.BindPort(ctx, portID) if err := k.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil { - return "", sdkerrors.Wrapf(err, "unable to bind to newly generated portID: %s", portID) + return "", errorsmod.Wrapf(err, "unable to bind to newly generated portID: %s", portID) } } @@ -82,7 +83,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, firstMsgResponse := res.MsgResponses[0] channelOpenInitResponse, ok := firstMsgResponse.GetCachedValue().(*channeltypes.MsgChannelOpenInitResponse) if !ok { - return "", sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "failed to covert %T message response to %T", firstMsgResponse.GetCachedValue(), &channeltypes.MsgChannelOpenInitResponse{}) + return "", errorsmod.Wrapf(ibcerrors.ErrInvalidType, "failed to covert %T message response to %T", firstMsgResponse.GetCachedValue(), &channeltypes.MsgChannelOpenInitResponse{}) } return channelOpenInitResponse.ChannelId, nil diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index 51644e4050e..916f32382f2 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -30,15 +30,15 @@ func (k Keeper) OnChanOpenInit( version string, ) (string, error) { if order != channeltypes.ORDERED { - return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) } if !strings.HasPrefix(portID, icatypes.ControllerPortPrefix) { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) + return "", errorsmod.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) } if counterparty.PortId != icatypes.HostPortID { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, counterparty.PortId) + return "", errorsmod.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, counterparty.PortId) } var metadata icatypes.Metadata @@ -51,7 +51,7 @@ func (k Keeper) OnChanOpenInit( metadata = icatypes.NewDefaultMetadata(connectionHops[0], connection.GetCounterparty().GetConnectionID()) } else { if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(version), &metadata); err != nil { - return "", sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") + return "", errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") } } @@ -67,7 +67,7 @@ func (k Keeper) OnChanOpenInit( } if channel.State == channeltypes.OPEN { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) @@ -76,7 +76,7 @@ func (k Keeper) OnChanOpenInit( } if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") + return "", errorsmod.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") } } @@ -92,25 +92,25 @@ func (k Keeper) OnChanOpenAck( counterpartyVersion string, ) error { if portID == icatypes.HostPortID { - return sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "portID cannot be host chain port ID: %s", icatypes.HostPortID) + return errorsmod.Wrapf(icatypes.ErrInvalidControllerPort, "portID cannot be host chain port ID: %s", icatypes.HostPortID) } if !strings.HasPrefix(portID, icatypes.ControllerPortPrefix) { - return sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) + return errorsmod.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) } var metadata icatypes.Metadata if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &metadata); err != nil { - return sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") + return errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") } if activeChannelID, found := k.GetOpenActiveChannel(ctx, metadata.ControllerConnectionId, portID); found { - return sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s", activeChannelID, portID) + return errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s", activeChannelID, portID) } channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) } if err := icatypes.ValidateControllerMetadata(ctx, k.channelKeeper, channel.ConnectionHops, metadata); err != nil { @@ -118,7 +118,7 @@ func (k Keeper) OnChanOpenAck( } if strings.TrimSpace(metadata.Address) == "" { - return sdkerrors.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be empty") + return errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be empty") } k.SetActiveChannelID(ctx, metadata.ControllerConnectionId, portID, channelID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 5e576bba2a8..061a20a233c 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -5,10 +5,10 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/tendermint/libs/log" @@ -69,7 +69,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { func (k Keeper) GetConnectionID(ctx sdk.Context, portID, channelID string) (string, error) { channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { - return "", sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return "", errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } return channel.ConnectionHops[0], nil } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go index 0b9dae6cbcb..92a3a21d8e3 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go @@ -3,8 +3,8 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" @@ -33,13 +33,13 @@ func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error { capability, found := m.keeper.scopedKeeper.GetCapability(ctx, name) if !found { logger.Error(fmt.Sprintf("failed to find capability: %s", name)) - return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name) + return errorsmod.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name) } isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, capability, name) if !isAuthenticated { logger.Error(fmt.Sprintf("expected capability owner: %s", controllertypes.SubModuleName)) - return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", controllertypes.SubModuleName) + return errorsmod.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", controllertypes.SubModuleName) } m.keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ConnectionHops[0]) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go index ed953fd8c1e..a41eae140a3 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -3,8 +3,8 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -32,7 +32,7 @@ func (s msgServer) RegisterInterchainAccount(goCtx context.Context, msg *types.M } if s.IsMiddlewareEnabled(ctx, portID, msg.ConnectionId) && !s.IsActiveChannelClosed(ctx, msg.ConnectionId, portID) { - return nil, sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") + return nil, errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") } s.SetMiddlewareDisabled(ctx, portID, msg.ConnectionId) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index cb2f85dcaf8..b8a5996a5a0 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -1,8 +1,8 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -28,12 +28,12 @@ func (k Keeper) SendTx(ctx sdk.Context, _ *capabilitytypes.Capability, connectio func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) if !found { - return 0, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) + return 0, errorsmod.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) } chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, activeChannelID)) if !found { - return 0, sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", host.ChannelCapabilityPath(portID, activeChannelID)) + return 0, errorsmod.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", host.ChannelCapabilityPath(portID, activeChannelID)) } if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp { @@ -41,7 +41,7 @@ func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketDa } if err := icaPacketData.ValidateBasic(); err != nil { - return 0, sdkerrors.Wrap(err, "invalid interchain account packet data") + return 0, errorsmod.Wrap(err, "invalid interchain account packet data") } sequence, err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, clienttypes.ZeroHeight(), timeoutTimestamp, icaPacketData.GetBytes()) diff --git a/modules/apps/27-interchain-accounts/controller/types/errors.go b/modules/apps/27-interchain-accounts/controller/types/errors.go index 3a0ade00fe1..2f2d5595e21 100644 --- a/modules/apps/27-interchain-accounts/controller/types/errors.go +++ b/modules/apps/27-interchain-accounts/controller/types/errors.go @@ -1,10 +1,10 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // ICA Controller sentinel errors var ( - ErrControllerSubModuleDisabled = sdkerrors.Register(SubModuleName, 2, "controller submodule is disabled") + ErrControllerSubModuleDisabled = errorsmod.Register(SubModuleName, 2, "controller submodule is disabled") ) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs.go b/modules/apps/27-interchain-accounts/controller/types/msgs.go index e01a3798203..5837b76a01b 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -24,11 +25,11 @@ func NewMsgRegisterInterchainAccount(connectionID, owner, version string) *MsgRe // ValidateBasic implements sdk.Msg func (msg MsgRegisterInterchainAccount) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(msg.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid connection ID") + return errorsmod.Wrap(err, "invalid connection ID") } if strings.TrimSpace(msg.Owner) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "owner address cannot be empty") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "owner address cannot be empty") } return nil @@ -57,19 +58,19 @@ func NewMsgSendTx(owner, connectionID string, relativeTimeoutTimestamp uint64, p // ValidateBasic implements sdk.Msg func (msg MsgSendTx) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(msg.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid connection ID") + return errorsmod.Wrap(err, "invalid connection ID") } if strings.TrimSpace(msg.Owner) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "owner address cannot be empty") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "owner address cannot be empty") } if err := msg.PacketData.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "invalid interchain account packet data") + return errorsmod.Wrap(err, "invalid interchain account packet data") } if msg.RelativeTimeout == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "relative timeout cannot be zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "relative timeout cannot be zero") } return nil diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 5c652f19b23..1620ce87bc5 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -1,10 +1,13 @@ package host import ( + "fmt" + + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -35,7 +38,7 @@ func (im IBCModule) OnChanOpenInit( counterparty channeltypes.Counterparty, version string, ) (string, error) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return "", errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanOpenTry implements the IBCModule interface @@ -64,7 +67,7 @@ func (im IBCModule) OnChanOpenAck( counterpartyChannelID string, counterpartyVersion string, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanOpenAck implements the IBCModule interface @@ -87,7 +90,7 @@ func (im IBCModule) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for interchain account channels - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "user cannot close channel") } // OnChanCloseConfirm implements the IBCModule interface @@ -105,7 +108,9 @@ func (im IBCModule) OnRecvPacket( packet channeltypes.Packet, _ sdk.AccAddress, ) ibcexported.Acknowledgement { + logger := im.keeper.Logger(ctx) if !im.keeper.IsHostEnabled(ctx) { + logger.Info("host submodule is disabled") return channeltypes.NewErrorAcknowledgement(types.ErrHostSubModuleDisabled) } @@ -113,6 +118,9 @@ func (im IBCModule) OnRecvPacket( ack := channeltypes.NewResultAcknowledgement(txResponse) if err != nil { ack = channeltypes.NewErrorAcknowledgement(err) + logger.Error(fmt.Sprintf("%s sequence %d", err.Error(), packet.Sequence)) + } else { + logger.Info("successfully handled packet sequence: %d", packet.Sequence) } // Emit an event indicating a successful or failed acknowledgement. @@ -129,7 +137,7 @@ func (im IBCModule) OnAcknowledgementPacket( acknowledgement []byte, relayer sdk.AccAddress, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "cannot receive acknowledgement on a host channel end, a host chain does not send a packet over the channel") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "cannot receive acknowledgement on a host channel end, a host chain does not send a packet over the channel") } // OnTimeoutPacket implements the IBCModule interface @@ -138,5 +146,5 @@ func (im IBCModule) OnTimeoutPacket( packet channeltypes.Packet, relayer sdk.AccAddress, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "cannot cause a packet timeout on a host channel end, a host chain does not send a packet over the channel") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "cannot cause a packet timeout on a host channel end, a host chain does not send a packet over the channel") } diff --git a/modules/apps/27-interchain-accounts/host/keeper/account.go b/modules/apps/27-interchain-accounts/host/keeper/account.go index 7af16d0911a..3b02d3c7cae 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/account.go +++ b/modules/apps/27-interchain-accounts/host/keeper/account.go @@ -1,8 +1,8 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -15,7 +15,7 @@ func (k Keeper) createInterchainAccount(ctx sdk.Context, connectionID, controlle accAddress := icatypes.GenerateAddress(ctx, connectionID, controllerPortID) if acc := k.accountKeeper.GetAccount(ctx, accAddress); acc != nil { - return nil, sdkerrors.Wrapf(icatypes.ErrAccountAlreadyExist, "existing account for newly generated interchain account address %s", accAddress) + return nil, errorsmod.Wrapf(icatypes.ErrAccountAlreadyExist, "existing account for newly generated interchain account address %s", accAddress) } interchainAccount := icatypes.NewInterchainAccount( diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 9f31c787ff3..8f3f4a0ccff 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -3,8 +3,8 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -27,16 +27,16 @@ func (k Keeper) OnChanOpenTry( counterpartyVersion string, ) (string, error) { if order != channeltypes.ORDERED { - return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) } if portID != icatypes.HostPortID { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, portID) + return "", errorsmod.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, portID) } var metadata icatypes.Metadata if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &metadata); err != nil { - return "", sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") + return "", errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") } if err := icatypes.ValidateHostMetadata(ctx, k.channelKeeper, connectionHops, metadata); err != nil { @@ -51,7 +51,7 @@ func (k Keeper) OnChanOpenTry( } if channel.State == channeltypes.OPEN { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) @@ -60,14 +60,14 @@ func (k Keeper) OnChanOpenTry( } if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") + return "", errorsmod.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") } } // On the host chain the capability may only be claimed during the OnChanOpenTry // The capability being claimed in OpenInit is for a controller chain (the port is different) if err := k.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", sdkerrors.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID) + return "", errorsmod.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID) } var ( @@ -81,7 +81,7 @@ func (k Keeper) OnChanOpenTry( k.Logger(ctx).Info("reopening existing interchain account", "address", interchainAccAddr) accAddress = sdk.MustAccAddressFromBech32(interchainAccAddr) if _, ok := k.accountKeeper.GetAccount(ctx, accAddress).(*icatypes.InterchainAccount); !ok { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidAccountReopening, "existing account address %s, does not have interchain account type", accAddress) + return "", errorsmod.Wrapf(icatypes.ErrInvalidAccountReopening, "existing account address %s, does not have interchain account type", accAddress) } } else { @@ -109,7 +109,7 @@ func (k Keeper) OnChanOpenConfirm( ) error { channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) } // It is assumed the controller chain will not allow multiple active channels to be created for the same connectionID/portID diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay.go b/modules/apps/27-interchain-accounts/host/keeper/relay.go index a1f082f55e1..4e620291a6b 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay.go @@ -1,11 +1,12 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/gogoproto/proto" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -18,21 +19,20 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byt if err := icatypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { // UnmarshalJSON errors are indeterminate and therefore are not wrapped and included in failed acks - return nil, sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data") + return nil, errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data") } switch data.Type { case icatypes.EXECUTE_TX: msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data) if err != nil { - return nil, err + return nil, errorsmod.Wrapf(err, "failed to deserialize interchain account transaction") } txResponse, err := k.executeTx(ctx, packet.SourcePort, packet.DestinationPort, packet.DestinationChannel, msgs) if err != nil { - return nil, err + return nil, errorsmod.Wrapf(err, "failed to execute interchain account transaction") } - return txResponse, nil default: return nil, icatypes.ErrUnknownDataType @@ -77,7 +77,7 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str txResponse, err := proto.Marshal(txMsgData) if err != nil { - return nil, sdkerrors.Wrap(err, "failed to marshal tx data") + return nil, errorsmod.Wrap(err, "failed to marshal tx data") } return txResponse, nil @@ -88,18 +88,18 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str func (k Keeper) authenticateTx(ctx sdk.Context, msgs []sdk.Msg, connectionID, portID string) error { interchainAccountAddr, found := k.GetInterchainAccountAddress(ctx, connectionID, portID) if !found { - return sdkerrors.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) + return errorsmod.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) } allowMsgs := k.GetAllowMessages(ctx) for _, msg := range msgs { if !types.ContainsMsgType(allowMsgs, msg) { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "message type not allowed: %s", sdk.MsgTypeURL(msg)) + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "message type not allowed: %s", sdk.MsgTypeURL(msg)) } for _, signer := range msg.GetSigners() { if interchainAccountAddr != signer.String() { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "unexpected signer address: expected %s, got %s", interchainAccountAddr, signer.String()) + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "unexpected signer address: expected %s, got %s", interchainAccountAddr, signer.String()) } } } @@ -126,7 +126,7 @@ func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error // Each individual sdk.Result has exactly one Msg response. We aggregate here. msgResponse := res.MsgResponses[0] if msgResponse == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "got nil Msg response for msg %s", sdk.MsgTypeURL(msg)) + return nil, errorsmod.Wrapf(ibcerrors.ErrLogic, "got nil Msg response for msg %s", sdk.MsgTypeURL(msg)) } return msgResponse, nil diff --git a/modules/apps/27-interchain-accounts/host/types/errors.go b/modules/apps/27-interchain-accounts/host/types/errors.go index b16b4093e5e..adba00f6596 100644 --- a/modules/apps/27-interchain-accounts/host/types/errors.go +++ b/modules/apps/27-interchain-accounts/host/types/errors.go @@ -1,10 +1,10 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // ICA Host sentinel errors var ( - ErrHostSubModuleDisabled = sdkerrors.Register(SubModuleName, 2, "host submodule is disabled") + ErrHostSubModuleDisabled = errorsmod.Register(SubModuleName, 2, "host submodule is disabled") ) diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index 8c44b277a9f..472b509818c 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -5,10 +5,10 @@ import ( "regexp" "strings" + errorsmod "cosmossdk.io/errors" crypto "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkaddress "github.com/cosmos/cosmos-sdk/types/address" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" yaml "gopkg.in/yaml.v2" ) @@ -56,7 +56,7 @@ func GenerateAddress(ctx sdk.Context, connectionID, portID string) sdk.AccAddres // on address length and character set func ValidateAccountAddress(addr string) error { if !isValidAddr(addr) || len(addr) > DefaultMaxAddrLength { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidAccountAddress, "address must contain strictly alphanumeric characters, not exceeding %d characters in length", DefaultMaxAddrLength, @@ -76,18 +76,18 @@ func NewInterchainAccount(ba *authtypes.BaseAccount, accountOwner string) *Inter // SetPubKey implements the authtypes.AccountI interface func (ia InterchainAccount) SetPubKey(pubKey crypto.PubKey) error { - return sdkerrors.Wrap(ErrUnsupported, "cannot set public key for interchain account") + return errorsmod.Wrap(ErrUnsupported, "cannot set public key for interchain account") } // SetSequence implements the authtypes.AccountI interface func (ia InterchainAccount) SetSequence(seq uint64) error { - return sdkerrors.Wrap(ErrUnsupported, "cannot set sequence number for interchain account") + return errorsmod.Wrap(ErrUnsupported, "cannot set sequence number for interchain account") } // Validate implements basic validation of the InterchainAccount func (ia InterchainAccount) Validate() error { if strings.TrimSpace(ia.AccountOwner) == "" { - return sdkerrors.Wrap(ErrInvalidAccountAddress, "AccountOwner cannot be empty") + return errorsmod.Wrap(ErrInvalidAccountAddress, "AccountOwner cannot be empty") } return ia.BaseAccount.Validate() diff --git a/modules/apps/27-interchain-accounts/types/codec.go b/modules/apps/27-interchain-accounts/types/codec.go index f91d3f0ed1a..b0ba7b8902b 100644 --- a/modules/apps/27-interchain-accounts/types/codec.go +++ b/modules/apps/27-interchain-accounts/types/codec.go @@ -1,10 +1,10 @@ package types import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/gogoproto/proto" ) @@ -29,7 +29,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { func SerializeCosmosTx(cdc codec.BinaryCodec, msgs []proto.Message) (bz []byte, err error) { // only ProtoCodec is supported if _, ok := cdc.(*codec.ProtoCodec); !ok { - return nil, sdkerrors.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") + return nil, errorsmod.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") } msgAnys := make([]*codectypes.Any, len(msgs)) @@ -59,7 +59,7 @@ func SerializeCosmosTx(cdc codec.BinaryCodec, msgs []proto.Message) (bz []byte, func DeserializeCosmosTx(cdc codec.BinaryCodec, data []byte) ([]sdk.Msg, error) { // only ProtoCodec is supported if _, ok := cdc.(*codec.ProtoCodec); !ok { - return nil, sdkerrors.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") + return nil, errorsmod.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") } var cosmosTx CosmosTx diff --git a/modules/apps/27-interchain-accounts/types/errors.go b/modules/apps/27-interchain-accounts/types/errors.go index 5c80da561bc..06989327dfb 100644 --- a/modules/apps/27-interchain-accounts/types/errors.go +++ b/modules/apps/27-interchain-accounts/types/errors.go @@ -1,26 +1,26 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) var ( - ErrUnknownDataType = sdkerrors.Register(ModuleName, 2, "unknown data type") - ErrAccountAlreadyExist = sdkerrors.Register(ModuleName, 3, "account already exist") - ErrPortAlreadyBound = sdkerrors.Register(ModuleName, 4, "port is already bound") - ErrInvalidChannelFlow = sdkerrors.Register(ModuleName, 5, "invalid message sent to channel end") - ErrInvalidOutgoingData = sdkerrors.Register(ModuleName, 6, "invalid outgoing data") - ErrInvalidRoute = sdkerrors.Register(ModuleName, 7, "invalid route") - ErrInterchainAccountNotFound = sdkerrors.Register(ModuleName, 8, "interchain account not found") - ErrInterchainAccountAlreadySet = sdkerrors.Register(ModuleName, 9, "interchain account is already set") - ErrActiveChannelAlreadySet = sdkerrors.Register(ModuleName, 10, "active channel already set for this owner") - ErrActiveChannelNotFound = sdkerrors.Register(ModuleName, 11, "no active channel for this owner") - ErrInvalidVersion = sdkerrors.Register(ModuleName, 12, "invalid interchain accounts version") - ErrInvalidAccountAddress = sdkerrors.Register(ModuleName, 13, "invalid account address") - ErrUnsupported = sdkerrors.Register(ModuleName, 14, "interchain account does not support this action") - ErrInvalidControllerPort = sdkerrors.Register(ModuleName, 15, "invalid controller port") - ErrInvalidHostPort = sdkerrors.Register(ModuleName, 16, "invalid host port") - ErrInvalidTimeoutTimestamp = sdkerrors.Register(ModuleName, 17, "timeout timestamp must be in the future") - ErrInvalidCodec = sdkerrors.Register(ModuleName, 18, "codec is not supported") - ErrInvalidAccountReopening = sdkerrors.Register(ModuleName, 19, "invalid account reopening") + ErrUnknownDataType = errorsmod.Register(ModuleName, 2, "unknown data type") + ErrAccountAlreadyExist = errorsmod.Register(ModuleName, 3, "account already exist") + ErrPortAlreadyBound = errorsmod.Register(ModuleName, 4, "port is already bound") + ErrInvalidChannelFlow = errorsmod.Register(ModuleName, 5, "invalid message sent to channel end") + ErrInvalidOutgoingData = errorsmod.Register(ModuleName, 6, "invalid outgoing data") + ErrInvalidRoute = errorsmod.Register(ModuleName, 7, "invalid route") + ErrInterchainAccountNotFound = errorsmod.Register(ModuleName, 8, "interchain account not found") + ErrInterchainAccountAlreadySet = errorsmod.Register(ModuleName, 9, "interchain account is already set") + ErrActiveChannelAlreadySet = errorsmod.Register(ModuleName, 10, "active channel already set for this owner") + ErrActiveChannelNotFound = errorsmod.Register(ModuleName, 11, "no active channel for this owner") + ErrInvalidVersion = errorsmod.Register(ModuleName, 12, "invalid interchain accounts version") + ErrInvalidAccountAddress = errorsmod.Register(ModuleName, 13, "invalid account address") + ErrUnsupported = errorsmod.Register(ModuleName, 14, "interchain account does not support this action") + ErrInvalidControllerPort = errorsmod.Register(ModuleName, 15, "invalid controller port") + ErrInvalidHostPort = errorsmod.Register(ModuleName, 16, "invalid host port") + ErrInvalidTimeoutTimestamp = errorsmod.Register(ModuleName, 17, "timeout timestamp must be in the future") + ErrInvalidCodec = errorsmod.Register(ModuleName, 18, "codec is not supported") + ErrInvalidAccountReopening = errorsmod.Register(ModuleName, 19, "invalid account reopening") ) diff --git a/modules/apps/27-interchain-accounts/types/metadata.go b/modules/apps/27-interchain-accounts/types/metadata.go index c2d06976da2..ee986a006f9 100644 --- a/modules/apps/27-interchain-accounts/types/metadata.go +++ b/modules/apps/27-interchain-accounts/types/metadata.go @@ -1,8 +1,8 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ) @@ -67,11 +67,11 @@ func IsPreviousMetadataEqual(previousVersion string, metadata Metadata) bool { // ValidateControllerMetadata performs validation of the provided ICS27 controller metadata parameters func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { if !isSupportedEncoding(metadata.Encoding) { - return sdkerrors.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) + return errorsmod.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) } if !isSupportedTxType(metadata.TxType) { - return sdkerrors.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) + return errorsmod.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) } connection, err := channelKeeper.GetConnection(ctx, connectionHops[0]) @@ -90,7 +90,7 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co } if metadata.Version != Version { - return sdkerrors.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) + return errorsmod.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) } return nil @@ -99,11 +99,11 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co // ValidateHostMetadata performs validation of the provided ICS27 host metadata parameters func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { if !isSupportedEncoding(metadata.Encoding) { - return sdkerrors.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) + return errorsmod.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) } if !isSupportedTxType(metadata.TxType) { - return sdkerrors.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) + return errorsmod.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) } connection, err := channelKeeper.GetConnection(ctx, connectionHops[0]) @@ -122,7 +122,7 @@ func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connecti } if metadata.Version != Version { - return sdkerrors.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) + return errorsmod.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) } return nil @@ -163,11 +163,11 @@ func getSupportedTxTypes() []string { // validateConnectionParams compares the given the controller and host connection IDs to those set in the provided ICS27 Metadata func validateConnectionParams(metadata Metadata, controllerConnectionID, hostConnectionID string) error { if metadata.ControllerConnectionId != controllerConnectionID { - return sdkerrors.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", controllerConnectionID, metadata.ControllerConnectionId) + return errorsmod.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", controllerConnectionID, metadata.ControllerConnectionId) } if metadata.HostConnectionId != hostConnectionID { - return sdkerrors.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", hostConnectionID, metadata.HostConnectionId) + return errorsmod.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", hostConnectionID, metadata.HostConnectionId) } return nil diff --git a/modules/apps/27-interchain-accounts/types/packet.go b/modules/apps/27-interchain-accounts/types/packet.go index 383b192507f..f7d1c6648be 100644 --- a/modules/apps/27-interchain-accounts/types/packet.go +++ b/modules/apps/27-interchain-accounts/types/packet.go @@ -3,9 +3,9 @@ package types import ( "time" + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // MaxMemoCharLength defines the maximum length for the InterchainAccountPacketData memo field @@ -28,15 +28,15 @@ var ( // The memo may be empty. func (iapd InterchainAccountPacketData) ValidateBasic() error { if iapd.Type == UNSPECIFIED { - return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data type cannot be unspecified") + return errorsmod.Wrap(ErrInvalidOutgoingData, "packet data type cannot be unspecified") } if len(iapd.Data) == 0 { - return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty") + return errorsmod.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty") } if len(iapd.Memo) > MaxMemoCharLength { - return sdkerrors.Wrapf(ErrInvalidOutgoingData, "packet data memo cannot be greater than %d characters", MaxMemoCharLength) + return errorsmod.Wrapf(ErrInvalidOutgoingData, "packet data memo cannot be greater than %d characters", MaxMemoCharLength) } return nil diff --git a/modules/apps/27-interchain-accounts/types/port.go b/modules/apps/27-interchain-accounts/types/port.go index f1b9ebed825..ee814279cf8 100644 --- a/modules/apps/27-interchain-accounts/types/port.go +++ b/modules/apps/27-interchain-accounts/types/port.go @@ -4,13 +4,13 @@ import ( "fmt" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // NewControllerPortID creates and returns a new prefixed controller port identifier using the provided owner string func NewControllerPortID(owner string) (string, error) { if strings.TrimSpace(owner) == "" { - return "", sdkerrors.Wrap(ErrInvalidAccountAddress, "owner address cannot be empty") + return "", errorsmod.Wrap(ErrInvalidAccountAddress, "owner address cannot be empty") } return fmt.Sprint(ControllerPortPrefix, owner), nil diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 22290392848..9ac7eec370c 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -3,8 +3,8 @@ package fee import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" @@ -62,7 +62,7 @@ func (im IBCMiddleware) OnChanOpenInit( } if versionMetadata.FeeVersion != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) } appVersion, err := im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, versionMetadata.AppVersion) @@ -104,7 +104,7 @@ func (im IBCMiddleware) OnChanOpenTry( } if versionMetadata.FeeVersion != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) } im.keeper.SetFeeEnabled(ctx, portID, channelID) @@ -137,11 +137,11 @@ func (im IBCMiddleware) OnChanOpenAck( if im.keeper.IsFeeEnabled(ctx, portID, channelID) { var versionMetadata types.Metadata if err := types.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &versionMetadata); err != nil { - return sdkerrors.Wrapf(err, "failed to unmarshal ICS29 counterparty version metadata: %s", counterpartyVersion) + return errorsmod.Wrapf(err, "failed to unmarshal ICS29 counterparty version metadata: %s", counterpartyVersion) } if versionMetadata.FeeVersion != types.Version { - return sdkerrors.Wrapf(types.ErrInvalidVersion, "expected counterparty fee version: %s, got: %s", types.Version, versionMetadata.FeeVersion) + return errorsmod.Wrapf(types.ErrInvalidVersion, "expected counterparty fee version: %s, got: %s", types.Version, versionMetadata.FeeVersion) } // call underlying app's OnChanOpenAck callback with the counterparty app version. @@ -251,7 +251,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket( var ack types.IncentivizedAcknowledgement if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { - return sdkerrors.Wrapf(err, "cannot unmarshal ICS-29 incentivized packet acknowledgement: %v", ack) + return errorsmod.Wrapf(err, "cannot unmarshal ICS-29 incentivized packet acknowledgement: %v", ack) } if im.keeper.IsLocked(ctx) { @@ -283,7 +283,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket( payeeAddr, err := sdk.AccAddressFromBech32(payee) if err != nil { - return sdkerrors.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) + return errorsmod.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) } im.keeper.DistributePacketFeesOnAcknowledgement(ctx, ack.ForwardRelayerAddress, payeeAddr, feesInEscrow.PacketFees, packetID) @@ -325,7 +325,7 @@ func (im IBCMiddleware) OnTimeoutPacket( payeeAddr, err := sdk.AccAddressFromBech32(payee) if err != nil { - return sdkerrors.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) + return errorsmod.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) } im.keeper.DistributePacketFeesOnTimeout(ctx, payeeAddr, feesInEscrow.PacketFees, packetID) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index d32ec6baae4..b526bdfcea1 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -21,7 +21,7 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, refundAcc := k.authKeeper.GetAccount(ctx, refundAddr) if refundAcc == nil { - return sdkerrors.Wrapf(types.ErrRefundAccNotFound, "account with address: %s not found", packetFee.RefundAddress) + return errorsmod.Wrapf(types.ErrRefundAccNotFound, "account with address: %s not found", packetFee.RefundAddress) } coins := packetFee.Fee.Total() diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index a1485824a4d..021459e864a 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -3,9 +3,9 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -57,7 +57,7 @@ func (k Keeper) IncentivizedPacket(goCtx context.Context, req *types.QueryIncent if !exists { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error()) + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error()) } return &types.QueryIncentivizedPacketResponse{ @@ -107,7 +107,7 @@ func (k Keeper) TotalRecvFees(goCtx context.Context, req *types.QueryTotalRecvFe if !found { return nil, status.Errorf( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), ) } @@ -133,7 +133,7 @@ func (k Keeper) TotalAckFees(goCtx context.Context, req *types.QueryTotalAckFees if !found { return nil, status.Errorf( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), ) } @@ -159,7 +159,7 @@ func (k Keeper) TotalTimeoutFees(goCtx context.Context, req *types.QueryTotalTim if !found { return nil, status.Errorf( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), ) } diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 96a2ece8b55..8fe0aed2f04 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -3,9 +3,10 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -26,7 +27,7 @@ func (k Keeper) RegisterPayee(goCtx context.Context, msg *types.MsgRegisterPayee } if k.bankKeeper.BlockedAddr(payee) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not authorized to be a payee", payee) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not authorized to be a payee", payee) } // only register payee address if the channel exists and is fee enabled @@ -97,7 +98,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) } if k.bankKeeper.BlockedAddr(refundAcc) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) } // get the next sequence @@ -142,12 +143,12 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket } if k.bankKeeper.BlockedAddr(refundAcc) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) } nextSeqSend, found := k.GetNextSequenceSend(ctx, msg.PacketId.PortId, msg.PacketId.ChannelId) if !found { - return nil, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "channel does not exist, portID: %s, channelID: %s", msg.PacketId.PortId, msg.PacketId.ChannelId) + return nil, errorsmod.Wrapf(channeltypes.ErrSequenceSendNotFound, "channel does not exist, portID: %s, channelID: %s", msg.PacketId.PortId, msg.PacketId.ChannelId) } // only allow incentivizing of packets which have been sent @@ -157,7 +158,7 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket // only allow incentivizng of packets which have not completed the packet life cycle if bz := k.GetPacketCommitment(ctx, msg.PacketId.PortId, msg.PacketId.ChannelId, msg.PacketId.Sequence); len(bz) == 0 { - return nil, sdkerrors.Wrapf(channeltypes.ErrPacketCommitmentNotFound, "packet has already been acknowledged or timed out") + return nil, errorsmod.Wrapf(channeltypes.ErrPacketCommitmentNotFound, "packet has already been acknowledged or timed out") } if err := k.escrowPacketFee(ctx, msg.PacketId, msg.PacketFee); err != nil { diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 1c10a46645b..556e056c22d 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -3,8 +3,8 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" @@ -39,7 +39,7 @@ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.C // retrieve the forward relayer that was stored in `onRecvPacket` relayer, found := k.GetRelayerAddressForAsyncAck(ctx, packetID) if !found { - return sdkerrors.Wrapf(types.ErrRelayerNotFoundForAsyncAck, "no relayer address stored for async acknowledgement for packet with portID: %s, channelID: %s, sequence: %d", packetID.PortId, packetID.ChannelId, packetID.Sequence) + return errorsmod.Wrapf(types.ErrRelayerNotFoundForAsyncAck, "no relayer address stored for async acknowledgement for packet with portID: %s, channelID: %s, sequence: %d", packetID.PortId, packetID.ChannelId, packetID.Sequence) } // it is possible that a relayer has not registered a counterparty address. diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 700864b9a33..26167c71016 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -1,19 +1,19 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // 29-fee sentinel errors var ( - ErrInvalidVersion = sdkerrors.Register(ModuleName, 2, "invalid ICS29 middleware version") - ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 3, "no account found for given refund address") - ErrBalanceNotFound = sdkerrors.Register(ModuleName, 4, "balance not found for given account address") - ErrFeeNotFound = sdkerrors.Register(ModuleName, 5, "there is no fee escrowed for the given packetID") - ErrRelayersNotEmpty = sdkerrors.Register(ModuleName, 6, "relayers must not be set. This feature is not supported") - ErrCounterpartyPayeeEmpty = sdkerrors.Register(ModuleName, 7, "counterparty payee must not be empty") - ErrForwardRelayerAddressNotFound = sdkerrors.Register(ModuleName, 8, "forward relayer address not found") - ErrFeeNotEnabled = sdkerrors.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled") - ErrRelayerNotFoundForAsyncAck = sdkerrors.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement") - ErrFeeModuleLocked = sdkerrors.Register(ModuleName, 11, "the fee module is currently locked, a severe bug has been detected") + ErrInvalidVersion = errorsmod.Register(ModuleName, 2, "invalid ICS29 middleware version") + ErrRefundAccNotFound = errorsmod.Register(ModuleName, 3, "no account found for given refund address") + ErrBalanceNotFound = errorsmod.Register(ModuleName, 4, "balance not found for given account address") + ErrFeeNotFound = errorsmod.Register(ModuleName, 5, "there is no fee escrowed for the given packetID") + ErrRelayersNotEmpty = errorsmod.Register(ModuleName, 6, "relayers must not be set. This feature is not supported") + ErrCounterpartyPayeeEmpty = errorsmod.Register(ModuleName, 7, "counterparty payee must not be empty") + ErrForwardRelayerAddressNotFound = errorsmod.Register(ModuleName, 8, "forward relayer address not found") + ErrFeeNotEnabled = errorsmod.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled") + ErrRelayerNotFoundForAsyncAck = errorsmod.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement") + ErrFeeModuleLocked = errorsmod.Register(ModuleName, 11, "the fee module is currently locked, a severe bug has been detected") ) diff --git a/modules/apps/29-fee/types/fee.go b/modules/apps/29-fee/types/fee.go index 59f7ad657c1..81948ebdcbc 100644 --- a/modules/apps/29-fee/types/fee.go +++ b/modules/apps/29-fee/types/fee.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -22,7 +23,7 @@ func NewPacketFee(fee Fee, refundAddr string, relayers []string) PacketFee { func (p PacketFee) Validate() error { _, err := sdk.AccAddressFromBech32(p.RefundAddress) if err != nil { - return sdkerrors.Wrap(err, "failed to convert RefundAddress into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert RefundAddress into sdk.AccAddress") } // enforce relayers are not set @@ -80,12 +81,12 @@ func (f Fee) Validate() error { } if len(errFees) > 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "contains invalid fees: %s", strings.Join(errFees, " , ")) + return errorsmod.Wrapf(ibcerrors.ErrInvalidCoins, "contains invalid fees: %s", strings.Join(errFees, " , ")) } // if all three fee's are zero or empty return an error if f.AckFee.IsZero() && f.RecvFee.IsZero() && f.TimeoutFee.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "all fees are zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, "all fees are zero") } return nil diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go index a265c297d40..e08d457367d 100644 --- a/modules/apps/29-fee/types/genesis.go +++ b/modules/apps/29-fee/types/genesis.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -56,36 +57,36 @@ func (gs GenesisState) Validate() error { // Validate FeeEnabledChannels for _, feeCh := range gs.FeeEnabledChannels { if err := host.PortIdentifierValidator(feeCh.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(feeCh.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } } // Validate RegisteredPayees for _, registeredPayee := range gs.RegisteredPayees { if registeredPayee.Relayer == registeredPayee.Payee { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "relayer address and payee address must not be equal") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "relayer address and payee address must not be equal") } if _, err := sdk.AccAddressFromBech32(registeredPayee.Relayer); err != nil { - return sdkerrors.Wrap(err, "failed to convert relayer address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert relayer address into sdk.AccAddress") } if _, err := sdk.AccAddressFromBech32(registeredPayee.Payee); err != nil { - return sdkerrors.Wrap(err, "failed to convert payee address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert payee address into sdk.AccAddress") } if err := host.ChannelIdentifierValidator(registeredPayee.ChannelId); err != nil { - return sdkerrors.Wrapf(err, "invalid channel identifier: %s", registeredPayee.ChannelId) + return errorsmod.Wrapf(err, "invalid channel identifier: %s", registeredPayee.ChannelId) } } // Validate RegisteredCounterpartyPayees for _, registeredCounterpartyPayee := range gs.RegisteredCounterpartyPayees { if _, err := sdk.AccAddressFromBech32(registeredCounterpartyPayee.Relayer); err != nil { - return sdkerrors.Wrap(err, "failed to convert relayer address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert relayer address into sdk.AccAddress") } if strings.TrimSpace(registeredCounterpartyPayee.CounterpartyPayee) == "" { @@ -93,14 +94,14 @@ func (gs GenesisState) Validate() error { } if err := host.ChannelIdentifierValidator(registeredCounterpartyPayee.ChannelId); err != nil { - return sdkerrors.Wrapf(err, "invalid channel identifier: %s", registeredCounterpartyPayee.ChannelId) + return errorsmod.Wrapf(err, "invalid channel identifier: %s", registeredCounterpartyPayee.ChannelId) } } // Validate ForwardRelayers for _, rel := range gs.ForwardRelayers { if _, err := sdk.AccAddressFromBech32(rel.Address); err != nil { - return sdkerrors.Wrap(err, "failed to convert forward relayer address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert forward relayer address into sdk.AccAddress") } if err := rel.PacketId.Validate(); err != nil { diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 78113ba365e..823fe951071 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -5,8 +5,9 @@ import ( "strconv" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -58,13 +59,13 @@ func KeyFeeEnabled(portID, channelID string) []byte { func ParseKeyFeeEnabled(key string) (portID, channelID string, err error) { keySplit := strings.Split(key, "/") if len(keySplit) != 3 { - return "", "", sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), + return "", "", errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), ) } if keySplit[0] != FeeEnabledKeyPrefix { - return "", "", sdkerrors.Wrapf(sdkerrors.ErrLogic, "key prefix is incorrect: expected %s, got %s", FeeEnabledKeyPrefix, keySplit[0]) + return "", "", errorsmod.Wrapf(ibcerrors.ErrLogic, "key prefix is incorrect: expected %s, got %s", FeeEnabledKeyPrefix, keySplit[0]) } portID = keySplit[1] @@ -82,8 +83,8 @@ func KeyPayee(relayerAddr, channelID string) []byte { func ParseKeyPayeeAddress(key string) (relayerAddr, channelID string, err error) { keySplit := strings.Split(key, "/") if len(keySplit) != 3 { - return "", "", sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), + return "", "", errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), ) } @@ -99,8 +100,8 @@ func KeyCounterpartyPayee(address, channelID string) []byte { func ParseKeyCounterpartyPayee(key string) (address string, channelID string, error error) { keySplit := strings.Split(key, "/") if len(keySplit) != 3 { - return "", "", sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), + return "", "", errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), ) } @@ -116,8 +117,8 @@ func KeyRelayerAddressForAsyncAck(packetID channeltypes.PacketId) []byte { func ParseKeyRelayerAddressForAsyncAck(key string) (channeltypes.PacketId, error) { keySplit := strings.Split(key, "/") if len(keySplit) != 4 { - return channeltypes.PacketId{}, sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), + return channeltypes.PacketId{}, errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), ) } @@ -139,8 +140,8 @@ func KeyFeesInEscrow(packetID channeltypes.PacketId) []byte { func ParseKeyFeesInEscrow(key string) (channeltypes.PacketId, error) { keySplit := strings.Split(key, "/") if len(keySplit) != 4 { - return channeltypes.PacketId{}, sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), + return channeltypes.PacketId{}, errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), ) } diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 047b48b9ec1..0828beba868 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -31,17 +32,17 @@ func (msg MsgRegisterPayee) ValidateBasic() error { } if msg.Relayer == msg.Payee { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "relayer address and payee must not be equal") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "relayer address and payee must not be equal") } _, err := sdk.AccAddressFromBech32(msg.Relayer) if err != nil { - return sdkerrors.Wrap(err, "failed to create sdk.AccAddress from relayer address") + return errorsmod.Wrap(err, "failed to create sdk.AccAddress from relayer address") } _, err = sdk.AccAddressFromBech32(msg.Payee) if err != nil { - return sdkerrors.Wrap(err, "failed to create sdk.AccAddress from payee address") + return errorsmod.Wrap(err, "failed to create sdk.AccAddress from payee address") } return nil @@ -79,7 +80,7 @@ func (msg MsgRegisterCounterpartyPayee) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Relayer) if err != nil { - return sdkerrors.Wrap(err, "failed to create sdk.AccAddress from relayer address") + return errorsmod.Wrap(err, "failed to create sdk.AccAddress from relayer address") } if strings.TrimSpace(msg.CounterpartyPayee) == "" { @@ -124,7 +125,7 @@ func (msg MsgPayPacketFee) ValidateBasic() error { // signer check if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { - return sdkerrors.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress") } // enforce relayer is not set diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index fcaff5e1ddc..3503f51da20 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -5,10 +5,11 @@ import ( "math" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -46,16 +47,16 @@ func ValidateTransferChannelParams( return err } if channelSequence > uint64(math.MaxUint32) { - return sdkerrors.Wrapf(types.ErrMaxTransferChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, uint64(math.MaxUint32)) + return errorsmod.Wrapf(types.ErrMaxTransferChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, uint64(math.MaxUint32)) } if order != channeltypes.UNORDERED { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s ", channeltypes.UNORDERED, order) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s ", channeltypes.UNORDERED, order) } // Require portID is the portID transfer module is bound to boundPort := keeper.GetPort(ctx) if boundPort != portID { - return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort) + return errorsmod.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort) } return nil @@ -81,7 +82,7 @@ func (im IBCModule) OnChanOpenInit( } if version != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "got %s, expected %s", version, types.Version) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "got %s, expected %s", version, types.Version) } // Claim channel capability passed back by IBC module @@ -108,7 +109,7 @@ func (im IBCModule) OnChanOpenTry( } if counterpartyVersion != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version) } // OpenTry must claim the channelCapability that IBC passes into the callback @@ -128,7 +129,7 @@ func (im IBCModule) OnChanOpenAck( counterpartyVersion string, ) error { if counterpartyVersion != types.Version { - return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version) + return errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version) } return nil } @@ -149,7 +150,7 @@ func (im IBCModule) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for transfer channels - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "user cannot close channel") } // OnChanCloseConfirm implements the IBCModule interface @@ -169,12 +170,14 @@ func (im IBCModule) OnRecvPacket( packet channeltypes.Packet, relayer sdk.AccAddress, ) ibcexported.Acknowledgement { + logger := im.keeper.Logger(ctx) ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) var data types.FungibleTokenPacketData var ackErr error if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - ackErr = sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot unmarshal ICS-20 transfer packet data") + ackErr = errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot unmarshal ICS-20 transfer packet data") + logger.Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence)) ack = channeltypes.NewErrorAcknowledgement(ackErr) } @@ -185,6 +188,9 @@ func (im IBCModule) OnRecvPacket( if err != nil { ack = channeltypes.NewErrorAcknowledgement(err) ackErr = err + logger.Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence)) + } else { + logger.Info("successfully handled ICS-20 packet sequence: %d", packet.Sequence) } } @@ -222,11 +228,11 @@ func (im IBCModule) OnAcknowledgementPacket( ) error { var ack channeltypes.Acknowledgement if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) } var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } if err := im.keeper.OnAcknowledgementPacket(ctx, packet, data, ack); err != nil { @@ -274,7 +280,7 @@ func (im IBCModule) OnTimeoutPacket( ) error { var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } // refund tokens if err := im.keeper.OnTimeoutPacket(ctx, packet, data); err != nil { diff --git a/modules/apps/transfer/keeper/grpc_query.go b/modules/apps/transfer/keeper/grpc_query.go index 869daf20758..d6a1eaefdaa 100644 --- a/modules/apps/transfer/keeper/grpc_query.go +++ b/modules/apps/transfer/keeper/grpc_query.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -33,7 +33,7 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest) if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrTraceNotFound, req.Hash).Error(), + errorsmod.Wrap(types.ErrTraceNotFound, req.Hash).Error(), ) } @@ -100,7 +100,7 @@ func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) ( if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrTraceNotFound, req.Trace).Error(), + errorsmod.Wrap(types.ErrTraceNotFound, req.Trace).Error(), ) } diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 92e190ce9b3..ef016dff3c3 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -11,11 +11,12 @@ import ( "strconv" "strings" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/crypto" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -270,7 +271,7 @@ func (suite *KeeperTestSuite) CheckBankBalances(chain *ibctesting.TestChain, ban diff := bankChange.Sub(expectedBankChange) NonZeroString := diff.NonZeroString() if len(NonZeroString) != 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Unexpected changes in the bank: \n"+NonZeroString) + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, "Unexpected changes in the bank: \n"+NonZeroString) } return nil } diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 26b0c05f963..8eb436ba6ec 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -3,9 +3,10 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ) @@ -25,11 +26,11 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. } if !k.bankKeeper.IsSendEnabledCoin(ctx, msg.Token) { - return nil, sdkerrors.Wrapf(types.ErrSendDisabled, "%s transfers are currently disabled", msg.Token.Denom) + return nil, errorsmod.Wrapf(types.ErrSendDisabled, "%s transfers are currently disabled", msg.Token.Denom) } if k.bankKeeper.BlockedAddr(sender) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) } sequence, err := k.sendTransfer( diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index c464b5dbbbd..62d4135e072 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -4,11 +4,12 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -61,7 +62,7 @@ func (k Keeper) sendTransfer( ) (uint64, error) { channel, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return 0, sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + return 0, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } destinationPort := channel.GetCounterparty().GetPortID() @@ -71,7 +72,7 @@ func (k Keeper) sendTransfer( // See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) if !ok { - return 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return 0, errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } // NOTE: denomination and hex hash correctness checked during msg.ValidateBasic @@ -165,7 +166,7 @@ func (k Keeper) sendTransfer( func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData) error { // validate packet data upon receiving if err := data.ValidateBasic(); err != nil { - return err + return errorsmod.Wrapf(err, "error validating ICS-20 transfer packet data") } if !k.GetReceiveEnabled(ctx) { @@ -175,13 +176,13 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // decode the receiver address receiver, err := sdk.AccAddressFromBech32(data.Receiver) if err != nil { - return err + return errorsmod.Wrapf(err, "failed to decode receiver address: %s", data.Receiver) } // parse the transfer amount transferAmount, ok := sdk.NewIntFromString(data.Amount) if !ok { - return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", data.Amount) + return errorsmod.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount: %s", data.Amount) } labels := []metrics.Label{ @@ -216,7 +217,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t token := sdk.NewCoin(denom, transferAmount) if k.bankKeeper.BlockedAddr(receiver) { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver) + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver) } // unescrow tokens @@ -226,7 +227,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // counterparty module. The bug may occur in bank or any part of the code that allows // the escrow address to be drained. A malicious counterparty module could drain the // escrow address by allowing more tokens to be sent back then were escrowed. - return sdkerrors.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") + return errorsmod.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") } defer func() { @@ -279,14 +280,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t if err := k.bankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins(voucher), ); err != nil { - return err + return errorsmod.Wrap(err, "failed to mint IBC tokens") } // send to receiver if err := k.bankKeeper.SendCoinsFromModuleToAccount( ctx, types.ModuleName, receiver, sdk.NewCoins(voucher), ); err != nil { - return err + return errorsmod.Wrapf(err, "failed to send coins to receiver %s", receiver.String()) } defer func() { @@ -344,7 +345,7 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // parse the transfer amount transferAmount, ok := sdk.NewIntFromString(data.Amount) if !ok { - return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", data.Amount) + return errorsmod.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", data.Amount) } token := sdk.NewCoin(trace.IBCDenom(), transferAmount) @@ -362,7 +363,7 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // counterparty module. The bug may occur in bank or any part of the code that allows // the escrow address to be drained. A malicious counterparty module could drain the // escrow address by allowing more tokens to be sent back then were escrowed. - return sdkerrors.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") + return errorsmod.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") } return nil @@ -390,12 +391,12 @@ func (k Keeper) DenomPathFromHash(ctx sdk.Context, denom string) (string, error) hash, err := types.ParseHexHash(hexHash) if err != nil { - return "", sdkerrors.Wrap(types.ErrInvalidDenomForTransfer, err.Error()) + return "", errorsmod.Wrap(types.ErrInvalidDenomForTransfer, err.Error()) } denomTrace, found := k.GetDenomTrace(ctx, hash) if !found { - return "", sdkerrors.Wrap(types.ErrTraceNotFound, hexHash) + return "", errorsmod.Wrap(types.ErrTraceNotFound, hexHash) } fullDenomPath := denomTrace.GetFullDenomPath() diff --git a/modules/apps/transfer/types/errors.go b/modules/apps/transfer/types/errors.go index d4f85cf4fa7..d62134b27cd 100644 --- a/modules/apps/transfer/types/errors.go +++ b/modules/apps/transfer/types/errors.go @@ -1,18 +1,18 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC transfer sentinel errors var ( - ErrInvalidPacketTimeout = sdkerrors.Register(ModuleName, 2, "invalid packet timeout") - ErrInvalidDenomForTransfer = sdkerrors.Register(ModuleName, 3, "invalid denomination for cross-chain transfer") - ErrInvalidVersion = sdkerrors.Register(ModuleName, 4, "invalid ICS20 version") - ErrInvalidAmount = sdkerrors.Register(ModuleName, 5, "invalid token amount") - ErrTraceNotFound = sdkerrors.Register(ModuleName, 6, "denomination trace not found") - ErrSendDisabled = sdkerrors.Register(ModuleName, 7, "fungible token transfers from this chain are disabled") - ErrReceiveDisabled = sdkerrors.Register(ModuleName, 8, "fungible token transfers to this chain are disabled") - ErrMaxTransferChannels = sdkerrors.Register(ModuleName, 9, "max transfer channels") - ErrInvalidAuthorization = sdkerrors.Register(ModuleName, 10, "invalid transfer authorization") + ErrInvalidPacketTimeout = errorsmod.Register(ModuleName, 2, "invalid packet timeout") + ErrInvalidDenomForTransfer = errorsmod.Register(ModuleName, 3, "invalid denomination for cross-chain transfer") + ErrInvalidVersion = errorsmod.Register(ModuleName, 4, "invalid ICS20 version") + ErrInvalidAmount = errorsmod.Register(ModuleName, 5, "invalid token amount") + ErrTraceNotFound = errorsmod.Register(ModuleName, 6, "denomination trace not found") + ErrSendDisabled = errorsmod.Register(ModuleName, 7, "fungible token transfers from this chain are disabled") + ErrReceiveDisabled = errorsmod.Register(ModuleName, 8, "fungible token transfers to this chain are disabled") + ErrMaxTransferChannels = errorsmod.Register(ModuleName, 9, "max transfer channels") + ErrInvalidAuthorization = errorsmod.Register(ModuleName, 10, "invalid transfer authorization") ) diff --git a/modules/apps/transfer/types/msgs.go b/modules/apps/transfer/types/msgs.go index d6c70fec93a..de573544257 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -42,24 +43,24 @@ func (MsgTransfer) Route() string { // the chain is not known to IBC. func (msg MsgTransfer) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.SourcePort); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(msg.SourceChannel); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } if !msg.Token.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Token.String()) + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, msg.Token.String()) } if !msg.Token.IsPositive() { - return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, msg.Token.String()) + return errorsmod.Wrap(ibcerrors.ErrInsufficientFunds, msg.Token.String()) } // NOTE: sender format must be validated as it is required by the GetSigners function. _, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } if strings.TrimSpace(msg.Receiver) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "missing recipient address") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "missing recipient address") } return ValidateIBCDenom(msg.Token.Denom) } diff --git a/modules/apps/transfer/types/packet.go b/modules/apps/transfer/types/packet.go index aed80c6043b..ec795fa2482 100644 --- a/modules/apps/transfer/types/packet.go +++ b/modules/apps/transfer/types/packet.go @@ -4,8 +4,10 @@ import ( "strings" "time" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" ) var ( @@ -42,16 +44,16 @@ func NewFungibleTokenPacketData( func (ftpd FungibleTokenPacketData) ValidateBasic() error { amount, ok := sdk.NewIntFromString(ftpd.Amount) if !ok { - return sdkerrors.Wrapf(ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", ftpd.Amount) + return errorsmod.Wrapf(ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", ftpd.Amount) } if !amount.IsPositive() { - return sdkerrors.Wrapf(ErrInvalidAmount, "amount must be strictly positive: got %d", amount) + return errorsmod.Wrapf(ErrInvalidAmount, "amount must be strictly positive: got %d", amount) } if strings.TrimSpace(ftpd.Sender) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be blank") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "sender address cannot be blank") } if strings.TrimSpace(ftpd.Receiver) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "receiver address cannot be blank") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "receiver address cannot be blank") } return ValidatePrefixedDenom(ftpd.Denom) } diff --git a/modules/apps/transfer/types/trace.go b/modules/apps/transfer/types/trace.go index 7123e5eed68..7145ff15d96 100644 --- a/modules/apps/transfer/types/trace.go +++ b/modules/apps/transfer/types/trace.go @@ -7,8 +7,8 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" @@ -113,10 +113,10 @@ func validateTraceIdentifiers(identifiers []string) error { // validate correctness of port and channel identifiers for i := 0; i < len(identifiers); i += 2 { if err := host.PortIdentifierValidator(identifiers[i]); err != nil { - return sdkerrors.Wrapf(err, "invalid port ID at position %d", i) + return errorsmod.Wrapf(err, "invalid port ID at position %d", i) } if err := host.ChannelIdentifierValidator(identifiers[i+1]); err != nil { - return sdkerrors.Wrapf(err, "invalid channel ID at position %d", i) + return errorsmod.Wrapf(err, "invalid channel ID at position %d", i) } } return nil @@ -151,7 +151,7 @@ func (t Traces) Validate() error { } if err := trace.Validate(); err != nil { - return sdkerrors.Wrapf(err, "failed denom trace %d validation", i) + return errorsmod.Wrapf(err, "failed denom trace %d validation", i) } seenTraces[hash] = true } @@ -190,7 +190,7 @@ func ValidatePrefixedDenom(denom string) error { } if strings.TrimSpace(denomSplit[len(denomSplit)-1]) == "" { - return sdkerrors.Wrap(ErrInvalidDenomForTransfer, "base denomination cannot be blank") + return errorsmod.Wrap(ErrInvalidDenomForTransfer, "base denomination cannot be blank") } path, _ := extractPathAndBaseFromFullDenom(denomSplit) @@ -216,15 +216,15 @@ func ValidateIBCDenom(denom string) error { switch { case denom == DenomPrefix: - return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) + return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) case len(denomSplit) == 2 && denomSplit[0] == DenomPrefix: if strings.TrimSpace(denomSplit[1]) == "" { - return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) + return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) } if _, err := ParseHexHash(denomSplit[1]); err != nil { - return sdkerrors.Wrapf(err, "invalid denom trace hash %s", denomSplit[1]) + return errorsmod.Wrapf(err, "invalid denom trace hash %s", denomSplit[1]) } } diff --git a/modules/apps/transfer/types/transfer_authorization.go b/modules/apps/transfer/types/transfer_authorization.go index fed33b0a909..709972afc49 100644 --- a/modules/apps/transfer/types/transfer_authorization.go +++ b/modules/apps/transfer/types/transfer_authorization.go @@ -1,10 +1,11 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -29,18 +30,18 @@ func (a TransferAuthorization) MsgTypeURL() string { func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) { msgTransfer, ok := msg.(*MsgTransfer) if !ok { - return authz.AcceptResponse{}, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "type mismatch") + return authz.AcceptResponse{}, errorsmod.Wrap(ibcerrors.ErrInvalidType, "type mismatch") } for index, allocation := range a.Allocations { if allocation.SourceChannel == msgTransfer.SourceChannel && allocation.SourcePort == msgTransfer.SourcePort { limitLeft, isNegative := allocation.SpendLimit.SafeSub(msgTransfer.Token) if isNegative { - return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "requested amount is more than spend limit") + return authz.AcceptResponse{}, errorsmod.Wrapf(ibcerrors.ErrInsufficientFunds, "requested amount is more than spend limit") } if !isAllowedAddress(ctx, msgTransfer.Receiver, allocation.AllowList) { - return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "not allowed address for transfer") + return authz.AcceptResponse{}, errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "not allowed address for transfer") } if limitLeft.IsZero() { @@ -64,44 +65,44 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep }}, nil } } - return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "requested port and channel allocation does not exist") + return authz.AcceptResponse{}, errorsmod.Wrapf(ibcerrors.ErrNotFound, "requested port and channel allocation does not exist") } // ValidateBasic implements Authorization.ValidateBasic. func (a TransferAuthorization) ValidateBasic() error { if len(a.Allocations) == 0 { - return sdkerrors.Wrap(ErrInvalidAuthorization, "allocations cannot be empty") + return errorsmod.Wrap(ErrInvalidAuthorization, "allocations cannot be empty") } foundChannels := make(map[string]bool, 0) for _, allocation := range a.Allocations { if _, found := foundChannels[allocation.SourceChannel]; found { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannel, "duplicate source channel ID: %s", allocation.SourceChannel) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannel, "duplicate source channel ID: %s", allocation.SourceChannel) } foundChannels[allocation.SourceChannel] = true if allocation.SpendLimit == nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "spend limit cannot be nil") + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, "spend limit cannot be nil") } if err := allocation.SpendLimit.Validate(); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, err.Error()) + return errorsmod.Wrapf(ibcerrors.ErrInvalidCoins, err.Error()) } if err := host.PortIdentifierValidator(allocation.SourcePort); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(allocation.SourceChannel); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } found := make(map[string]bool, 0) for i := 0; i < len(allocation.AllowList); i++ { if found[allocation.AllowList[i]] { - return sdkerrors.Wrapf(ErrInvalidAuthorization, "duplicate entry in allow list %s") + return errorsmod.Wrapf(ErrInvalidAuthorization, "duplicate entry in allow list %s", allocation.AllowList[i]) } found[allocation.AllowList[i]] = true } diff --git a/modules/core/02-client/client/utils/utils.go b/modules/core/02-client/client/utils/utils.go index 18fecf9d8e2..9dd2675087a 100644 --- a/modules/core/02-client/client/utils/utils.go +++ b/modules/core/02-client/client/utils/utils.go @@ -3,9 +3,9 @@ package utils import ( "context" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -46,7 +46,7 @@ func QueryClientStateABCI( // check if client exists if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrClientNotFound, clientID) + return nil, errorsmod.Wrap(types.ErrClientNotFound, clientID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) @@ -99,7 +99,7 @@ func QueryConsensusStateABCI( // check if consensus state exists if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrConsensusStateNotFound, clientID) + return nil, errorsmod.Wrap(types.ErrConsensusStateNotFound, clientID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index 271efb4d14b..1fe4ea733f1 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -1,10 +1,10 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -17,12 +17,12 @@ func (k Keeper) CreateClient( ctx sdk.Context, clientState exported.ClientState, consensusState exported.ConsensusState, ) (string, error) { if clientState.ClientType() == exported.Localhost { - return "", sdkerrors.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientState.ClientType()) + return "", errorsmod.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientState.ClientType()) } params := k.GetParams(ctx) if !params.IsAllowedClient(clientState.ClientType()) { - return "", sdkerrors.Wrapf( + return "", errorsmod.Wrapf( types.ErrInvalidClientType, "client state type %s is not registered in the allowlist", clientState.ClientType(), ) @@ -52,13 +52,13 @@ func (k Keeper) CreateClient( func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { clientState, found := k.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) + return errorsmod.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) } clientStore := k.ClientStore(ctx, clientID) if status := k.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) } if err := clientState.VerifyClientMessage(ctx, k.cdc, clientStore, clientMsg); err != nil { @@ -113,19 +113,19 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e ) error { clientState, found := k.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) + return errorsmod.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) } clientStore := k.ClientStore(ctx, clientID) if status := k.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status) + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status) } if err := clientState.VerifyUpgradeAndUpdateState(ctx, k.cdc, clientStore, upgradedClient, upgradedConsState, proofUpgradeClient, proofUpgradeConsState, ); err != nil { - return sdkerrors.Wrapf(err, "cannot upgrade client with ID %s", clientID) + return errorsmod.Wrapf(err, "cannot upgrade client with ID %s", clientID) } k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", upgradedClient.GetLatestHeight().String()) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index 5ef92cb2c88..073f59b2995 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -7,9 +7,9 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -36,7 +36,7 @@ func (q Keeper) ClientState(c context.Context, req *types.QueryClientStateReques if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrClientNotFound, req.ClientId).Error(), + errorsmod.Wrap(types.ErrClientNotFound, req.ClientId).Error(), ) } @@ -127,7 +127,7 @@ func (q Keeper) ConsensusState(c context.Context, req *types.QueryConsensusState if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrConsensusStateNotFound, "client-id: %s, height: %s", req.ClientId, height).Error(), + errorsmod.Wrapf(types.ErrConsensusStateNotFound, "client-id: %s, height: %s", req.ClientId, height).Error(), ) } @@ -241,7 +241,7 @@ func (q Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequ if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrClientNotFound, req.ClientId).Error(), + errorsmod.Wrap(types.ErrClientNotFound, req.ClientId).Error(), ) } diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index c3888b55234..abc773332c3 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -5,16 +5,17 @@ import ( "reflect" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/light" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -185,7 +186,7 @@ func (k Keeper) GetAllClientMetadata(ctx sdk.Context, genClients []types.Identif for i, metadata := range gms { cmd, ok := metadata.(types.GenesisMetadata) if !ok { - return nil, sdkerrors.Wrapf(types.ErrInvalidClientMetadata, "expected metadata type: %T, got: %T", + return nil, errorsmod.Wrapf(types.ErrInvalidClientMetadata, "expected metadata type: %T, got: %T", types.GenesisMetadata{}, cmd) } clientMetadata[i] = cmd @@ -257,16 +258,16 @@ func (k Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { selfHeight, ok := height.(types.Height) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", types.Height{}, height) + return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", types.Height{}, height) } // check that height revision matches chainID revision revision := types.ParseChainID(ctx.ChainID()) if revision != height.GetRevisionNumber() { - return nil, sdkerrors.Wrapf(types.ErrInvalidHeight, "chainID revision number does not match height revision number: expected %d, got %d", revision, height.GetRevisionNumber()) + return nil, errorsmod.Wrapf(types.ErrInvalidHeight, "chainID revision number does not match height revision number: expected %d, got %d", revision, height.GetRevisionNumber()) } histInfo, found := k.stakingKeeper.GetHistoricalInfo(ctx, int64(selfHeight.RevisionHeight)) if !found { - return nil, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "no historical info found at height %d", selfHeight.RevisionHeight) + return nil, errorsmod.Wrapf(ibcerrors.ErrNotFound, "no historical info found at height %d", selfHeight.RevisionHeight) } consensusState := &ibctm.ConsensusState{ @@ -283,7 +284,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) ( func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { tmClient, ok := clientState.(*ibctm.ClientState) if !ok { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", + return errorsmod.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", &ibctm.ClientState{}, tmClient) } @@ -292,7 +293,7 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS } if ctx.ChainID() != tmClient.ChainId { - return sdkerrors.Wrapf(types.ErrInvalidClient, "invalid chain-id. expected: %s, got: %s", + return errorsmod.Wrapf(types.ErrInvalidClient, "invalid chain-id. expected: %s, got: %s", ctx.ChainID(), tmClient.ChainId) } @@ -300,34 +301,34 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS // client must be in the same revision as executing chain if tmClient.LatestHeight.RevisionNumber != revision { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client is not in the same revision as the chain. expected revision: %d, got: %d", + return errorsmod.Wrapf(types.ErrInvalidClient, "client is not in the same revision as the chain. expected revision: %d, got: %d", tmClient.LatestHeight.RevisionNumber, revision) } selfHeight := types.NewHeight(revision, uint64(ctx.BlockHeight())) if tmClient.LatestHeight.GTE(selfHeight) { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client has LatestHeight %d greater than or equal to chain height %d", + return errorsmod.Wrapf(types.ErrInvalidClient, "client has LatestHeight %d greater than or equal to chain height %d", tmClient.LatestHeight, selfHeight) } expectedProofSpecs := commitmenttypes.GetSDKSpecs() if !reflect.DeepEqual(expectedProofSpecs, tmClient.ProofSpecs) { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client has invalid proof specs. expected: %v got: %v", + return errorsmod.Wrapf(types.ErrInvalidClient, "client has invalid proof specs. expected: %v got: %v", expectedProofSpecs, tmClient.ProofSpecs) } if err := light.ValidateTrustLevel(tmClient.TrustLevel.ToTendermint()); err != nil { - return sdkerrors.Wrapf(types.ErrInvalidClient, "trust-level invalid: %v", err) + return errorsmod.Wrapf(types.ErrInvalidClient, "trust-level invalid: %v", err) } expectedUbdPeriod := k.stakingKeeper.UnbondingTime(ctx) if expectedUbdPeriod != tmClient.UnbondingPeriod { - return sdkerrors.Wrapf(types.ErrInvalidClient, "invalid unbonding period. expected: %s, got: %s", + return errorsmod.Wrapf(types.ErrInvalidClient, "invalid unbonding period. expected: %s, got: %s", expectedUbdPeriod, tmClient.UnbondingPeriod) } if tmClient.UnbondingPeriod < tmClient.TrustingPeriod { - return sdkerrors.Wrapf(types.ErrInvalidClient, "unbonding period must be greater than trusting period. unbonding period (%d) < trusting period (%d)", + return errorsmod.Wrapf(types.ErrInvalidClient, "unbonding period must be greater than trusting period. unbonding period (%d) < trusting period (%d)", tmClient.UnbondingPeriod, tmClient.TrustingPeriod) } @@ -335,7 +336,7 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS // For now, SDK IBC implementation assumes that upgrade path (if defined) is defined by SDK upgrade module expectedUpgradePath := []string{upgradetypes.StoreKey, upgradetypes.KeyUpgradedIBCState} if !reflect.DeepEqual(expectedUpgradePath, tmClient.UpgradePath) { - return sdkerrors.Wrapf(types.ErrInvalidClient, "upgrade path must be the upgrade path defined by upgrade module. expected %v, got %v", + return errorsmod.Wrapf(types.ErrInvalidClient, "upgrade path must be the upgrade path defined by upgrade module. expected %v, got %v", expectedUpgradePath, tmClient.UpgradePath) } } diff --git a/modules/core/02-client/keeper/proposal.go b/modules/core/02-client/keeper/proposal.go index 024939080a4..2b30b89ba99 100644 --- a/modules/core/02-client/keeper/proposal.go +++ b/modules/core/02-client/keeper/proposal.go @@ -1,10 +1,10 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -20,28 +20,28 @@ import ( func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdateProposal) error { subjectClientState, found := k.GetClientState(ctx, p.SubjectClientId) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "subject client with ID %s", p.SubjectClientId) + return errorsmod.Wrapf(types.ErrClientNotFound, "subject client with ID %s", p.SubjectClientId) } subjectClientStore := k.ClientStore(ctx, p.SubjectClientId) if status := k.GetClientStatus(ctx, subjectClientState, p.SubjectClientId); status == exported.Active { - return sdkerrors.Wrap(types.ErrInvalidUpdateClientProposal, "cannot update Active subject client") + return errorsmod.Wrap(types.ErrInvalidUpdateClientProposal, "cannot update Active subject client") } substituteClientState, found := k.GetClientState(ctx, p.SubstituteClientId) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "substitute client with ID %s", p.SubstituteClientId) + return errorsmod.Wrapf(types.ErrClientNotFound, "substitute client with ID %s", p.SubstituteClientId) } if subjectClientState.GetLatestHeight().GTE(substituteClientState.GetLatestHeight()) { - return sdkerrors.Wrapf(types.ErrInvalidHeight, "subject client state latest height is greater or equal to substitute client state latest height (%s >= %s)", subjectClientState.GetLatestHeight(), substituteClientState.GetLatestHeight()) + return errorsmod.Wrapf(types.ErrInvalidHeight, "subject client state latest height is greater or equal to substitute client state latest height (%s >= %s)", subjectClientState.GetLatestHeight(), substituteClientState.GetLatestHeight()) } substituteClientStore := k.ClientStore(ctx, p.SubstituteClientId) if status := k.GetClientStatus(ctx, substituteClientState, p.SubstituteClientId); status != exported.Active { - return sdkerrors.Wrapf(types.ErrClientNotActive, "substitute client is not Active, status is %s", status) + return errorsmod.Wrapf(types.ErrClientNotActive, "substitute client is not Active, status is %s", status) } if err := subjectClientState.CheckSubstituteAndUpdateState(ctx, k.cdc, subjectClientStore, substituteClientStore, substituteClientState); err != nil { @@ -75,14 +75,14 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo func (k Keeper) HandleUpgradeProposal(ctx sdk.Context, p *types.UpgradeProposal) error { clientState, err := types.UnpackClientState(p.UpgradedClientState) if err != nil { - return sdkerrors.Wrap(err, "could not unpack UpgradedClientState") + return errorsmod.Wrap(err, "could not unpack UpgradedClientState") } // zero out any custom fields before setting cs := clientState.ZeroCustomFields() bz, err := types.MarshalClientState(k.cdc, cs) if err != nil { - return sdkerrors.Wrap(err, "could not marshal UpgradedClientState") + return errorsmod.Wrap(err, "could not marshal UpgradedClientState") } if err := k.upgradeKeeper.ScheduleUpgrade(ctx, p.Plan); err != nil { diff --git a/modules/core/02-client/migrations/v7/genesis.go b/modules/core/02-client/migrations/v7/genesis.go index 9cbafa37029..e2f803dd35d 100644 --- a/modules/core/02-client/migrations/v7/genesis.go +++ b/modules/core/02-client/migrations/v7/genesis.go @@ -1,8 +1,8 @@ package v7 import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -31,7 +31,7 @@ func MigrateGenesis(clientGenState *clienttypes.GenesisState, cdc codec.ProtoCod case exported.Solomachine: var clientState ClientState if err := cdc.Unmarshal(client.ClientState.Value, &clientState); err != nil { - return nil, sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + return nil, errorsmod.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") } updatedClientState := migrateSolomachine(clientState) diff --git a/modules/core/02-client/migrations/v7/store.go b/modules/core/02-client/migrations/v7/store.go index b70e541e671..56afc9e0c8b 100644 --- a/modules/core/02-client/migrations/v7/store.go +++ b/modules/core/02-client/migrations/v7/store.go @@ -4,12 +4,13 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -59,17 +60,17 @@ func handleSolomachineMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bi bz := clientStore.Get(host.ClientStateKey()) if len(bz) == 0 { - return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) + return errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) } var any codectypes.Any if err := cdc.Unmarshal(bz, &any); err != nil { - return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + return errorsmod.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") } var clientState ClientState if err := cdc.Unmarshal(any.Value, &clientState); err != nil { - return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + return errorsmod.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") } updatedClientState := migrateSolomachine(clientState) @@ -96,7 +97,7 @@ func handleTendermintMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bin } if len(clients) > 1 { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "more than one Tendermint client collected") + return errorsmod.Wrap(ibcerrors.ErrLogic, "more than one Tendermint client collected") } clientID := clients[0] @@ -105,12 +106,12 @@ func handleTendermintMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bin // in GetClientState clientState, ok := clientKeeper.GetClientState(ctx, clientID) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) + return errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) } _, ok = clientState.(*ibctm.ClientState) if !ok { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") } return nil diff --git a/modules/core/02-client/proposal_handler.go b/modules/core/02-client/proposal_handler.go index 33c27e0f23c..3d9f6002118 100644 --- a/modules/core/02-client/proposal_handler.go +++ b/modules/core/02-client/proposal_handler.go @@ -1,10 +1,11 @@ package client import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ) @@ -19,7 +20,7 @@ func NewClientProposalHandler(k keeper.Keeper) govtypes.Handler { return k.HandleUpgradeProposal(ctx, c) default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c) } } } diff --git a/modules/core/02-client/types/client.go b/modules/core/02-client/types/client.go index b60e9237e07..86039dc5847 100644 --- a/modules/core/02-client/types/client.go +++ b/modules/core/02-client/types/client.go @@ -6,8 +6,8 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" proto "github.com/cosmos/gogoproto/proto" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -89,7 +89,7 @@ func (cswh ConsensusStateWithHeight) UnpackInterfaces(unpacker codectypes.AnyUnp // client identifier when used with '0' or the maximum uint64 as the sequence. func ValidateClientType(clientType string) error { if strings.TrimSpace(clientType) == "" { - return sdkerrors.Wrap(ErrInvalidClientType, "client type cannot be blank") + return errorsmod.Wrap(ErrInvalidClientType, "client type cannot be blank") } smallestPossibleClientID := FormatClientIdentifier(clientType, 0) @@ -97,14 +97,14 @@ func ValidateClientType(clientType string) error { // IsValidClientID will check client type format and if the sequence is a uint64 if !IsValidClientID(smallestPossibleClientID) { - return sdkerrors.Wrap(ErrInvalidClientType, "") + return errorsmod.Wrap(ErrInvalidClientType, "") } if err := host.ClientIdentifierValidator(smallestPossibleClientID); err != nil { - return sdkerrors.Wrap(err, "client type results in smallest client identifier being invalid") + return errorsmod.Wrap(err, "client type results in smallest client identifier being invalid") } if err := host.ClientIdentifierValidator(largestPossibleClientID); err != nil { - return sdkerrors.Wrap(err, "client type results in largest client identifier being invalid") + return errorsmod.Wrap(err, "client type results in largest client identifier being invalid") } return nil diff --git a/modules/core/02-client/types/codec.go b/modules/core/02-client/types/codec.go index 926e5d7fda6..766f414e376 100644 --- a/modules/core/02-client/types/codec.go +++ b/modules/core/02-client/types/codec.go @@ -1,13 +1,14 @@ package types import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/msgservice" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" proto "github.com/cosmos/gogoproto/proto" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -56,12 +57,12 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { func PackClientState(clientState exported.ClientState) (*codectypes.Any, error) { msg, ok := clientState.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", clientState) + return nil, errorsmod.Wrapf(ibcerrors.ErrPackAny, "cannot proto marshal %T", clientState) } anyClientState, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errorsmod.Wrap(ibcerrors.ErrPackAny, err.Error()) } return anyClientState, nil @@ -71,12 +72,12 @@ func PackClientState(clientState exported.ClientState) (*codectypes.Any, error) // client state can't be unpacked into a ClientState. func UnpackClientState(any *codectypes.Any) (exported.ClientState, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errorsmod.Wrap(ibcerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } clientState, ok := any.GetCachedValue().(exported.ClientState) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into ClientState %T", any) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnpackAny, "cannot unpack Any into ClientState %T", any) } return clientState, nil @@ -88,12 +89,12 @@ func UnpackClientState(any *codectypes.Any) (exported.ClientState, error) { func PackConsensusState(consensusState exported.ConsensusState) (*codectypes.Any, error) { msg, ok := consensusState.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", consensusState) + return nil, errorsmod.Wrapf(ibcerrors.ErrPackAny, "cannot proto marshal %T", consensusState) } anyConsensusState, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errorsmod.Wrap(ibcerrors.ErrPackAny, err.Error()) } return anyConsensusState, nil @@ -113,12 +114,12 @@ func MustPackConsensusState(consensusState exported.ConsensusState) *codectypes. // consensus state can't be unpacked into a ConsensusState. func UnpackConsensusState(any *codectypes.Any) (exported.ConsensusState, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errorsmod.Wrap(ibcerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } consensusState, ok := any.GetCachedValue().(exported.ConsensusState) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into ConsensusState %T", any) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnpackAny, "cannot unpack Any into ConsensusState %T", any) } return consensusState, nil @@ -130,12 +131,12 @@ func UnpackConsensusState(any *codectypes.Any) (exported.ConsensusState, error) func PackClientMessage(clientMessage exported.ClientMessage) (*codectypes.Any, error) { msg, ok := clientMessage.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", clientMessage) + return nil, errorsmod.Wrapf(ibcerrors.ErrPackAny, "cannot proto marshal %T", clientMessage) } protoAny, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errorsmod.Wrap(ibcerrors.ErrPackAny, err.Error()) } return protoAny, nil @@ -145,12 +146,12 @@ func PackClientMessage(clientMessage exported.ClientMessage) (*codectypes.Any, e // consensus state can't be unpacked into a ClientMessage. func UnpackClientMessage(any *codectypes.Any) (exported.ClientMessage, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errorsmod.Wrap(ibcerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } clientMessage, ok := any.GetCachedValue().(exported.ClientMessage) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into Header %T", any) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnpackAny, "cannot unpack Any into Header %T", any) } return clientMessage, nil diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 39792948ae5..cdc84871ca0 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -1,39 +1,39 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC client sentinel errors var ( - ErrClientExists = sdkerrors.Register(SubModuleName, 2, "light client already exists") - ErrInvalidClient = sdkerrors.Register(SubModuleName, 3, "light client is invalid") - ErrClientNotFound = sdkerrors.Register(SubModuleName, 4, "light client not found") - ErrClientFrozen = sdkerrors.Register(SubModuleName, 5, "light client is frozen due to misbehaviour") - ErrInvalidClientMetadata = sdkerrors.Register(SubModuleName, 6, "invalid client metadata") - ErrConsensusStateNotFound = sdkerrors.Register(SubModuleName, 7, "consensus state not found") - ErrInvalidConsensus = sdkerrors.Register(SubModuleName, 8, "invalid consensus state") - ErrClientTypeNotFound = sdkerrors.Register(SubModuleName, 9, "client type not found") - ErrInvalidClientType = sdkerrors.Register(SubModuleName, 10, "invalid client type") - ErrRootNotFound = sdkerrors.Register(SubModuleName, 11, "commitment root not found") - ErrInvalidHeader = sdkerrors.Register(SubModuleName, 12, "invalid client header") - ErrInvalidMisbehaviour = sdkerrors.Register(SubModuleName, 13, "invalid light client misbehaviour") - ErrFailedClientStateVerification = sdkerrors.Register(SubModuleName, 14, "client state verification failed") - ErrFailedClientConsensusStateVerification = sdkerrors.Register(SubModuleName, 15, "client consensus state verification failed") - ErrFailedConnectionStateVerification = sdkerrors.Register(SubModuleName, 16, "connection state verification failed") - ErrFailedChannelStateVerification = sdkerrors.Register(SubModuleName, 17, "channel state verification failed") - ErrFailedPacketCommitmentVerification = sdkerrors.Register(SubModuleName, 18, "packet commitment verification failed") - ErrFailedPacketAckVerification = sdkerrors.Register(SubModuleName, 19, "packet acknowledgement verification failed") - ErrFailedPacketReceiptVerification = sdkerrors.Register(SubModuleName, 20, "packet receipt verification failed") - ErrFailedNextSeqRecvVerification = sdkerrors.Register(SubModuleName, 21, "next sequence receive verification failed") - ErrSelfConsensusStateNotFound = sdkerrors.Register(SubModuleName, 22, "self consensus state not found") - ErrUpdateClientFailed = sdkerrors.Register(SubModuleName, 23, "unable to update light client") - ErrInvalidUpdateClientProposal = sdkerrors.Register(SubModuleName, 24, "invalid update client proposal") - ErrInvalidUpgradeClient = sdkerrors.Register(SubModuleName, 25, "invalid client upgrade") - ErrInvalidHeight = sdkerrors.Register(SubModuleName, 26, "invalid height") - ErrInvalidSubstitute = sdkerrors.Register(SubModuleName, 27, "invalid client state substitute") - ErrInvalidUpgradeProposal = sdkerrors.Register(SubModuleName, 28, "invalid upgrade proposal") - ErrClientNotActive = sdkerrors.Register(SubModuleName, 29, "client state is not active") - ErrFailedMembershipVerification = sdkerrors.Register(SubModuleName, 30, "membership verification failed") - ErrFailedNonMembershipVerification = sdkerrors.Register(SubModuleName, 31, "non-membership verification failed") + ErrClientExists = errorsmod.Register(SubModuleName, 2, "light client already exists") + ErrInvalidClient = errorsmod.Register(SubModuleName, 3, "light client is invalid") + ErrClientNotFound = errorsmod.Register(SubModuleName, 4, "light client not found") + ErrClientFrozen = errorsmod.Register(SubModuleName, 5, "light client is frozen due to misbehaviour") + ErrInvalidClientMetadata = errorsmod.Register(SubModuleName, 6, "invalid client metadata") + ErrConsensusStateNotFound = errorsmod.Register(SubModuleName, 7, "consensus state not found") + ErrInvalidConsensus = errorsmod.Register(SubModuleName, 8, "invalid consensus state") + ErrClientTypeNotFound = errorsmod.Register(SubModuleName, 9, "client type not found") + ErrInvalidClientType = errorsmod.Register(SubModuleName, 10, "invalid client type") + ErrRootNotFound = errorsmod.Register(SubModuleName, 11, "commitment root not found") + ErrInvalidHeader = errorsmod.Register(SubModuleName, 12, "invalid client header") + ErrInvalidMisbehaviour = errorsmod.Register(SubModuleName, 13, "invalid light client misbehaviour") + ErrFailedClientStateVerification = errorsmod.Register(SubModuleName, 14, "client state verification failed") + ErrFailedClientConsensusStateVerification = errorsmod.Register(SubModuleName, 15, "client consensus state verification failed") + ErrFailedConnectionStateVerification = errorsmod.Register(SubModuleName, 16, "connection state verification failed") + ErrFailedChannelStateVerification = errorsmod.Register(SubModuleName, 17, "channel state verification failed") + ErrFailedPacketCommitmentVerification = errorsmod.Register(SubModuleName, 18, "packet commitment verification failed") + ErrFailedPacketAckVerification = errorsmod.Register(SubModuleName, 19, "packet acknowledgement verification failed") + ErrFailedPacketReceiptVerification = errorsmod.Register(SubModuleName, 20, "packet receipt verification failed") + ErrFailedNextSeqRecvVerification = errorsmod.Register(SubModuleName, 21, "next sequence receive verification failed") + ErrSelfConsensusStateNotFound = errorsmod.Register(SubModuleName, 22, "self consensus state not found") + ErrUpdateClientFailed = errorsmod.Register(SubModuleName, 23, "unable to update light client") + ErrInvalidUpdateClientProposal = errorsmod.Register(SubModuleName, 24, "invalid update client proposal") + ErrInvalidUpgradeClient = errorsmod.Register(SubModuleName, 25, "invalid client upgrade") + ErrInvalidHeight = errorsmod.Register(SubModuleName, 26, "invalid height") + ErrInvalidSubstitute = errorsmod.Register(SubModuleName, 27, "invalid client state substitute") + ErrInvalidUpgradeProposal = errorsmod.Register(SubModuleName, 28, "invalid upgrade proposal") + ErrClientNotActive = errorsmod.Register(SubModuleName, 29, "client state is not active") + ErrFailedMembershipVerification = errorsmod.Register(SubModuleName, 30, "membership verification failed") + ErrFailedNonMembershipVerification = errorsmod.Register(SubModuleName, 31, "non-membership verification failed") ) diff --git a/modules/core/02-client/types/height.go b/modules/core/02-client/types/height.go index 0054cec7baa..b4df09e5324 100644 --- a/modules/core/02-client/types/height.go +++ b/modules/core/02-client/types/height.go @@ -7,9 +7,10 @@ import ( "strconv" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -135,15 +136,15 @@ func MustParseHeight(heightStr string) Height { func ParseHeight(heightStr string) (Height, error) { splitStr := strings.Split(heightStr, "-") if len(splitStr) != 2 { - return Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "expected height string format: {revision}-{height}. Got: %s", heightStr) + return Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "expected height string format: {revision}-{height}. Got: %s", heightStr) } revisionNumber, err := strconv.ParseUint(splitStr[0], 10, 64) if err != nil { - return Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "invalid revision number. parse err: %s", err) + return Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "invalid revision number. parse err: %s", err) } revisionHeight, err := strconv.ParseUint(splitStr[1], 10, 64) if err != nil { - return Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "invalid revision height. parse err: %s", err) + return Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "invalid revision height. parse err: %s", err) } return NewHeight(revisionNumber, revisionHeight), nil } @@ -152,8 +153,8 @@ func ParseHeight(heightStr string) (Height, error) { // in the chainID with the given revision number. func SetRevisionNumber(chainID string, revision uint64) (string, error) { if !IsRevisionFormat(chainID) { - return "", sdkerrors.Wrapf( - sdkerrors.ErrInvalidChainID, "chainID is not in revision format: %s", chainID, + return "", errorsmod.Wrapf( + ibcerrors.ErrInvalidChainID, "chainID is not in revision format: %s", chainID, ) } diff --git a/modules/core/02-client/types/keys.go b/modules/core/02-client/types/keys.go index 9a2c67df3c5..892268e2368 100644 --- a/modules/core/02-client/types/keys.go +++ b/modules/core/02-client/types/keys.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -55,7 +55,7 @@ func ParseClientIdentifier(clientID string) (string, uint64, error) { } if !IsClientIDFormat(clientID) { - return "", 0, sdkerrors.Wrapf(host.ErrInvalidID, "invalid client identifier %s is not in format: `{client-type}-{N}`", clientID) + return "", 0, errorsmod.Wrapf(host.ErrInvalidID, "invalid client identifier %s is not in format: `{client-type}-{N}`", clientID) } splitStr := strings.Split(clientID, "-") @@ -63,12 +63,12 @@ func ParseClientIdentifier(clientID string) (string, uint64, error) { clientType := strings.Join(splitStr[:lastIndex], "-") if strings.TrimSpace(clientType) == "" { - return "", 0, sdkerrors.Wrap(host.ErrInvalidID, "client identifier must be in format: `{client-type}-{N}` and client type cannot be blank") + return "", 0, errorsmod.Wrap(host.ErrInvalidID, "client identifier must be in format: `{client-type}-{N}` and client type cannot be blank") } sequence, err := strconv.ParseUint(splitStr[lastIndex], 10, 64) if err != nil { - return "", 0, sdkerrors.Wrap(err, "failed to parse client identifier sequence") + return "", 0, errorsmod.Wrap(err, "failed to parse client identifier sequence") } return clientType, sequence, nil diff --git a/modules/core/02-client/types/msgs.go b/modules/core/02-client/types/msgs.go index 1ae308e1b66..9f2c76f4141 100644 --- a/modules/core/02-client/types/msgs.go +++ b/modules/core/02-client/types/msgs.go @@ -1,10 +1,11 @@ package types import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -48,7 +49,7 @@ func NewMsgCreateClient( func (msg MsgCreateClient) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } clientState, err := UnpackClientState(msg.ClientState) if err != nil { @@ -62,10 +63,10 @@ func (msg MsgCreateClient) ValidateBasic() error { return err } if clientState.ClientType() != consensusState.ClientType() { - return sdkerrors.Wrap(ErrInvalidClientType, "client type for client state and consensus state do not match") + return errorsmod.Wrap(ErrInvalidClientType, "client type for client state and consensus state do not match") } if err := ValidateClientType(clientState.ClientType()); err != nil { - return sdkerrors.Wrap(err, "client type does not meet naming constraints") + return errorsmod.Wrap(err, "client type does not meet naming constraints") } return consensusState.ValidateBasic() } @@ -111,7 +112,7 @@ func NewMsgUpdateClient(id string, clientMsg exported.ClientMessage, signer stri func (msg MsgUpdateClient) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } clientMsg, err := UnpackClientMessage(msg.ClientMessage) if err != nil { @@ -179,18 +180,18 @@ func (msg MsgUpgradeClient) ValidateBasic() error { } if clientState.ClientType() != consensusState.ClientType() { - return sdkerrors.Wrapf(ErrInvalidUpgradeClient, "consensus state's client-type does not match client. expected: %s, got: %s", + return errorsmod.Wrapf(ErrInvalidUpgradeClient, "consensus state's client-type does not match client. expected: %s, got: %s", clientState.ClientType(), consensusState.ClientType()) } if len(msg.ProofUpgradeClient) == 0 { - return sdkerrors.Wrap(ErrInvalidUpgradeClient, "proof of upgrade client cannot be empty") + return errorsmod.Wrap(ErrInvalidUpgradeClient, "proof of upgrade client cannot be empty") } if len(msg.ProofUpgradeConsensusState) == 0 { - return sdkerrors.Wrap(ErrInvalidUpgradeClient, "proof of upgrade consensus state cannot be empty") + return errorsmod.Wrap(ErrInvalidUpgradeClient, "proof of upgrade consensus state cannot be empty") } _, err = sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return host.ClientIdentifierValidator(msg.ClientId) } @@ -236,7 +237,7 @@ func NewMsgSubmitMisbehaviour(clientID string, misbehaviour exported.ClientMessa func (msg MsgSubmitMisbehaviour) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } misbehaviour, err := UnpackClientMessage(msg.Misbehaviour) if err != nil { diff --git a/modules/core/02-client/types/proposal.go b/modules/core/02-client/types/proposal.go index e73c52146af..2e6655d0ce9 100644 --- a/modules/core/02-client/types/proposal.go +++ b/modules/core/02-client/types/proposal.go @@ -4,8 +4,8 @@ import ( "fmt" "reflect" + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -59,7 +59,7 @@ func (cup *ClientUpdateProposal) ValidateBasic() error { } if cup.SubjectClientId == cup.SubstituteClientId { - return sdkerrors.Wrap(ErrInvalidSubstitute, "subject and substitute client identifiers are equal") + return errorsmod.Wrap(ErrInvalidSubstitute, "subject and substitute client identifiers are equal") } if _, _, err := ParseClientIdentifier(cup.SubjectClientId); err != nil { return err @@ -109,16 +109,16 @@ func (up *UpgradeProposal) ValidateBasic() error { } if up.UpgradedClientState == nil { - return sdkerrors.Wrap(ErrInvalidUpgradeProposal, "upgraded client state cannot be nil") + return errorsmod.Wrap(ErrInvalidUpgradeProposal, "upgraded client state cannot be nil") } clientState, err := UnpackClientState(up.UpgradedClientState) if err != nil { - return sdkerrors.Wrap(err, "failed to unpack upgraded client state") + return errorsmod.Wrap(err, "failed to unpack upgraded client state") } if !reflect.DeepEqual(clientState, clientState.ZeroCustomFields()) { - return sdkerrors.Wrap(ErrInvalidUpgradeProposal, "upgraded client state is not zeroed out") + return errorsmod.Wrap(ErrInvalidUpgradeProposal, "upgraded client state is not zeroed out") } return nil diff --git a/modules/core/03-connection/client/utils/utils.go b/modules/core/03-connection/client/utils/utils.go index 2a0aaf7e315..a7cab07d6bf 100644 --- a/modules/core/03-connection/client/utils/utils.go +++ b/modules/core/03-connection/client/utils/utils.go @@ -6,9 +6,9 @@ import ( "fmt" "os" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientutils "github.com/cosmos/ibc-go/v7/modules/core/02-client/client/utils" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -47,7 +47,7 @@ func queryConnectionABCI(clientCtx client.Context, connectionID string) (*types. // check if connection exists if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID) + return nil, errorsmod.Wrap(types.ErrConnectionNotFound, connectionID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) @@ -88,7 +88,7 @@ func queryClientConnectionsABCI(clientCtx client.Context, clientID string) (*typ // check if connection paths exist if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrClientConnectionPathsNotFound, clientID) + return nil, errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, clientID) } var paths []string diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 745dd6eed9f..c2a0afb2bf5 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -3,9 +3,9 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -32,7 +32,7 @@ func (q Keeper) Connection(c context.Context, req *types.QueryConnectionRequest) if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrConnectionNotFound, req.ConnectionId).Error(), + errorsmod.Wrap(types.ErrConnectionNotFound, req.ConnectionId).Error(), ) } @@ -94,7 +94,7 @@ func (q Keeper) ClientConnections(c context.Context, req *types.QueryClientConne if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrClientConnectionPathsNotFound, req.ClientId).Error(), + errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, req.ClientId).Error(), ) } @@ -120,7 +120,7 @@ func (q Keeper) ConnectionClientState(c context.Context, req *types.QueryConnect if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), + errorsmod.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), ) } @@ -128,7 +128,7 @@ func (q Keeper) ConnectionClientState(c context.Context, req *types.QueryConnect if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId).Error(), + errorsmod.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId).Error(), ) } @@ -154,7 +154,7 @@ func (q Keeper) ConnectionConsensusState(c context.Context, req *types.QueryConn if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), + errorsmod.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), ) } @@ -163,7 +163,7 @@ func (q Keeper) ConnectionConsensusState(c context.Context, req *types.QueryConn if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), + errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), ) } diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index 53417a2aa9e..acfde3183b1 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -1,10 +1,11 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" @@ -26,7 +27,7 @@ func (k Keeper) ConnOpenInit( versions := types.GetCompatibleVersions() if version != nil { if !types.IsSupportedVersion(types.GetCompatibleVersions(), version) { - return "", sdkerrors.Wrap(types.ErrInvalidVersion, "version is not supported") + return "", errorsmod.Wrap(types.ErrInvalidVersion, "version is not supported") } versions = []exported.Version{version} @@ -34,11 +35,11 @@ func (k Keeper) ConnOpenInit( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return "", sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", clientID) + return "", errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", clientID) } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return "", sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return "", errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } connectionID := k.GenerateConnectionIdentifier(ctx) @@ -87,8 +88,8 @@ func (k Keeper) ConnOpenTry( // of this chain's consensus state is at a height in the past selfHeight := clienttypes.GetSelfHeight(ctx) if consensusHeight.GTE(selfHeight) { - return "", sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return "", errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, ) } @@ -100,7 +101,7 @@ func (k Keeper) ConnOpenTry( expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) if err != nil { - return "", sdkerrors.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) + return "", errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) } // expectedConnection defines Chain A's ConnectionEnd @@ -143,7 +144,7 @@ func (k Keeper) ConnOpenTry( // store connection in chainB state if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil { - return "", sdkerrors.Wrapf(err, "failed to add connection with ID %s to client with ID %s", connectionID, clientID) + return "", errorsmod.Wrapf(err, "failed to add connection with ID %s to client with ID %s", connectionID, clientID) } k.SetConnection(ctx, connectionID, connection) @@ -178,8 +179,8 @@ func (k Keeper) ConnOpenAck( // of this chain's consensus state is at a height in the past selfHeight := clienttypes.GetSelfHeight(ctx) if consensusHeight.GTE(selfHeight) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, ) } @@ -187,12 +188,12 @@ func (k Keeper) ConnOpenAck( // Retrieve connection connection, found := k.GetConnection(ctx, connectionID) if !found { - return sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID) + return errorsmod.Wrap(types.ErrConnectionNotFound, connectionID) } // verify the previously set connection state if connection.State != types.INIT { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidConnectionState, "connection state is not INIT (got %s)", connection.State.String(), ) @@ -200,7 +201,7 @@ func (k Keeper) ConnOpenAck( // ensure selected version is supported if !types.IsSupportedVersion(types.ProtoVersionsToExported(connection.Versions), version) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidConnectionState, "the counterparty selected version %s is not supported by versions selected on INIT", version, ) @@ -214,7 +215,7 @@ func (k Keeper) ConnOpenAck( // Retrieve chainA's consensus state at consensusheight expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) if err != nil { - return sdkerrors.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) + return errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) } prefix := k.GetCommitmentPrefix() @@ -271,12 +272,12 @@ func (k Keeper) ConnOpenConfirm( // Retrieve connection connection, found := k.GetConnection(ctx, connectionID) if !found { - return sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID) + return errorsmod.Wrap(types.ErrConnectionNotFound, connectionID) } // Check that connection state on ChainB is on state: TRYOPEN if connection.State != types.TRYOPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidConnectionState, "connection state is not TRYOPEN (got %s)", connection.State.String(), ) diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 31bb339534f..efc8889b58f 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -1,10 +1,10 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/tendermint/libs/log" @@ -95,7 +95,7 @@ func (k Keeper) SetConnection(ctx sdk.Context, connectionID string, connection t func (k Keeper) GetTimestampAtHeight(ctx sdk.Context, connection types.ConnectionEnd, height exported.Height) (uint64, error) { clientState, found := k.clientKeeper.GetClientState(ctx, connection.GetClientID()) if !found { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( clienttypes.ErrClientNotFound, "clientID (%s)", connection.GetClientID(), ) } @@ -209,7 +209,7 @@ func (k Keeper) CreateSentinelLocalhostConnection(ctx sdk.Context) { func (k Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID string) error { _, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } conns, found := k.GetClientConnectionPaths(ctx, clientID) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index e55970a9de7..22f23d70866 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -3,9 +3,10 @@ package keeper import ( "math" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -30,7 +31,7 @@ func (k Keeper) VerifyClientState( } if status := k.clientKeeper.GetClientStatus(ctx, targetClient, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.GetCounterparty().GetClientID())) @@ -49,7 +50,7 @@ func (k Keeper) VerifyClientState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed client state verification for target client: %s", clientID) + return errorsmod.Wrapf(err, "failed client state verification for target client: %s", clientID) } return nil @@ -72,7 +73,7 @@ func (k Keeper) VerifyClientConsensusState( } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.GetCounterparty().GetClientID(), consensusHeight)) @@ -91,7 +92,7 @@ func (k Keeper) VerifyClientConsensusState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed consensus state verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed consensus state verification for client (%s)", clientID) } return nil @@ -114,7 +115,7 @@ func (k Keeper) VerifyConnectionState( } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID)) @@ -125,7 +126,7 @@ func (k Keeper) VerifyConnectionState( connectionEnd, ok := counterpartyConnection.(connectiontypes.ConnectionEnd) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection) } bz, err := k.cdc.Marshal(&connectionEnd) @@ -138,7 +139,7 @@ func (k Keeper) VerifyConnectionState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed connection state verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed connection state verification for client (%s)", clientID) } return nil @@ -162,7 +163,7 @@ func (k Keeper) VerifyChannelState( } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID)) @@ -173,7 +174,7 @@ func (k Keeper) VerifyChannelState( channelEnd, ok := channel.(channeltypes.Channel) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid channel type %T", channel) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid channel type %T", channel) } bz, err := k.cdc.Marshal(&channelEnd) @@ -186,7 +187,7 @@ func (k Keeper) VerifyChannelState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed channel state verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed channel state verification for client (%s)", clientID) } return nil @@ -211,7 +212,7 @@ func (k Keeper) VerifyPacketCommitment( } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -229,7 +230,7 @@ func (k Keeper) VerifyPacketCommitment( timeDelay, blockDelay, proof, merklePath, commitmentBytes, ); err != nil { - return sdkerrors.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) } return nil @@ -254,7 +255,7 @@ func (k Keeper) VerifyPacketAcknowledgement( } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -272,7 +273,7 @@ func (k Keeper) VerifyPacketAcknowledgement( timeDelay, blockDelay, proof, merklePath, channeltypes.CommitAcknowledgement(acknowledgement), ); err != nil { - return sdkerrors.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID) } return nil @@ -297,7 +298,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -315,7 +316,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( timeDelay, blockDelay, proof, merklePath, ); err != nil { - return sdkerrors.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) } return nil @@ -339,7 +340,7 @@ func (k Keeper) VerifyNextSequenceRecv( } if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -357,7 +358,7 @@ func (k Keeper) VerifyNextSequenceRecv( timeDelay, blockDelay, proof, merklePath, sdk.Uint64ToBigEndian(nextSequenceRecv), ); err != nil { - return sdkerrors.Wrapf(err, "failed next sequence receive verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed next sequence receive verification for client (%s)", clientID) } return nil @@ -383,7 +384,7 @@ func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) func (k Keeper) getClientStateAndVerificationStore(ctx sdk.Context, clientID string) (exported.ClientState, sdk.KVStore, error) { clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return nil, nil, sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return nil, nil, errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } store := k.clientKeeper.ClientStore(ctx, clientID) diff --git a/modules/core/03-connection/types/connection.go b/modules/core/03-connection/types/connection.go index 5f3a523bb16..eddd471d51a 100644 --- a/modules/core/03-connection/types/connection.go +++ b/modules/core/03-connection/types/connection.go @@ -1,8 +1,9 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -51,10 +52,10 @@ func (c ConnectionEnd) GetDelayPeriod() uint64 { // counterparty's. func (c ConnectionEnd) ValidateBasic() error { if err := host.ClientIdentifierValidator(c.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid client ID") + return errorsmod.Wrap(err, "invalid client ID") } if len(c.Versions) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "empty connection versions") + return errorsmod.Wrap(ibcerrors.ErrInvalidVersion, "empty connection versions") } for _, version := range c.Versions { if err := ValidateVersion(version); err != nil { @@ -94,14 +95,14 @@ func (c Counterparty) GetPrefix() exported.Prefix { func (c Counterparty) ValidateBasic() error { if c.ConnectionId != "" { if err := host.ConnectionIdentifierValidator(c.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty connection ID") + return errorsmod.Wrap(err, "invalid counterparty connection ID") } } if err := host.ClientIdentifierValidator(c.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty client ID") + return errorsmod.Wrap(err, "invalid counterparty client ID") } if c.Prefix.Empty() { - return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty prefix cannot be empty") + return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty prefix cannot be empty") } return nil } @@ -121,7 +122,7 @@ func NewIdentifiedConnection(connectionID string, conn ConnectionEnd) Identified // ValidateBasic performs a basic validation of the connection identifier and connection fields. func (ic IdentifiedConnection) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(ic.Id); err != nil { - return sdkerrors.Wrap(err, "invalid connection ID") + return errorsmod.Wrap(err, "invalid connection ID") } connection := NewConnectionEnd(ic.State, ic.ClientId, ic.Counterparty, ic.Versions, ic.DelayPeriod) return connection.ValidateBasic() diff --git a/modules/core/03-connection/types/errors.go b/modules/core/03-connection/types/errors.go index 107a0e087c1..d131db91d93 100644 --- a/modules/core/03-connection/types/errors.go +++ b/modules/core/03-connection/types/errors.go @@ -1,19 +1,19 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC connection sentinel errors var ( - ErrConnectionExists = sdkerrors.Register(SubModuleName, 2, "connection already exists") - ErrConnectionNotFound = sdkerrors.Register(SubModuleName, 3, "connection not found") - ErrClientConnectionPathsNotFound = sdkerrors.Register(SubModuleName, 4, "light client connection paths not found") - ErrConnectionPath = sdkerrors.Register(SubModuleName, 5, "connection path is not associated to the given light client") - ErrInvalidConnectionState = sdkerrors.Register(SubModuleName, 6, "invalid connection state") - ErrInvalidCounterparty = sdkerrors.Register(SubModuleName, 7, "invalid counterparty connection") - ErrInvalidConnection = sdkerrors.Register(SubModuleName, 8, "invalid connection") - ErrInvalidVersion = sdkerrors.Register(SubModuleName, 9, "invalid connection version") - ErrVersionNegotiationFailed = sdkerrors.Register(SubModuleName, 10, "connection version negotiation failed") - ErrInvalidConnectionIdentifier = sdkerrors.Register(SubModuleName, 11, "invalid connection identifier") + ErrConnectionExists = errorsmod.Register(SubModuleName, 2, "connection already exists") + ErrConnectionNotFound = errorsmod.Register(SubModuleName, 3, "connection not found") + ErrClientConnectionPathsNotFound = errorsmod.Register(SubModuleName, 4, "light client connection paths not found") + ErrConnectionPath = errorsmod.Register(SubModuleName, 5, "connection path is not associated to the given light client") + ErrInvalidConnectionState = errorsmod.Register(SubModuleName, 6, "invalid connection state") + ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 7, "invalid counterparty connection") + ErrInvalidConnection = errorsmod.Register(SubModuleName, 8, "invalid connection") + ErrInvalidVersion = errorsmod.Register(SubModuleName, 9, "invalid connection version") + ErrVersionNegotiationFailed = errorsmod.Register(SubModuleName, 10, "connection version negotiation failed") + ErrInvalidConnectionIdentifier = errorsmod.Register(SubModuleName, 11, "invalid connection identifier") ) diff --git a/modules/core/03-connection/types/keys.go b/modules/core/03-connection/types/keys.go index 7037452d83e..1b0b5132d90 100644 --- a/modules/core/03-connection/types/keys.go +++ b/modules/core/03-connection/types/keys.go @@ -4,7 +4,7 @@ import ( "fmt" "regexp" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -50,12 +50,12 @@ func IsValidConnectionID(connectionID string) bool { // ParseConnectionSequence parses the connection sequence from the connection identifier. func ParseConnectionSequence(connectionID string) (uint64, error) { if !IsConnectionIDFormat(connectionID) { - return 0, sdkerrors.Wrap(host.ErrInvalidID, "connection identifier is not in the format: `connection-{N}`") + return 0, errorsmod.Wrap(host.ErrInvalidID, "connection identifier is not in the format: `connection-{N}`") } sequence, err := host.ParseIdentifier(connectionID, ConnectionPrefix) if err != nil { - return 0, sdkerrors.Wrap(err, "invalid connection identifier") + return 0, errorsmod.Wrap(err, "invalid connection identifier") } return sequence, nil diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index 0b1bbf62d13..b8a9d1e4e5d 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -1,10 +1,11 @@ package types import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -44,25 +45,25 @@ func NewMsgConnectionOpenInit( // ValidateBasic implements sdk.Msg. func (msg MsgConnectionOpenInit) ValidateBasic() error { if msg.ClientId == exported.LocalhostClientID { - return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") + return errorsmod.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") } if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid client ID") + return errorsmod.Wrap(err, "invalid client ID") } if msg.Counterparty.ConnectionId != "" { - return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty connection identifier must be empty") + return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty connection identifier must be empty") } // NOTE: Version can be nil on MsgConnectionOpenInit if msg.Version != nil { if err := ValidateVersion(msg.Version); err != nil { - return sdkerrors.Wrap(err, "basic validation of the provided version failed") + return errorsmod.Wrap(err, "basic validation of the provided version failed") } } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Counterparty.ValidateBasic() } @@ -107,52 +108,52 @@ func NewMsgConnectionOpenTry( // ValidateBasic implements sdk.Msg func (msg MsgConnectionOpenTry) ValidateBasic() error { if msg.ClientId == exported.LocalhostClientID { - return sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") + return errorsmod.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") } if msg.PreviousConnectionId != "" { - return sdkerrors.Wrap(ErrInvalidConnectionIdentifier, "previous connection identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") + return errorsmod.Wrap(ErrInvalidConnectionIdentifier, "previous connection identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") } if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid client ID") + return errorsmod.Wrap(err, "invalid client ID") } // counterparty validate basic allows empty counterparty connection identifiers if err := host.ConnectionIdentifierValidator(msg.Counterparty.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty connection ID") + return errorsmod.Wrap(err, "invalid counterparty connection ID") } if msg.ClientState == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") } clientState, err := clienttypes.UnpackClientState(msg.ClientState) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) } if err := clientState.Validate(); err != nil { - return sdkerrors.Wrap(err, "counterparty client is invalid") + return errorsmod.Wrap(err, "counterparty client is invalid") } if len(msg.CounterpartyVersions) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "empty counterparty versions") + return errorsmod.Wrap(ibcerrors.ErrInvalidVersion, "empty counterparty versions") } for i, version := range msg.CounterpartyVersions { if err := ValidateVersion(version); err != nil { - return sdkerrors.Wrapf(err, "basic validation failed on version with index %d", i) + return errorsmod.Wrapf(err, "basic validation failed on version with index %d", i) } } if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") } if len(msg.ProofClient) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") } if len(msg.ProofConsensus) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") } if msg.ConsensusHeight.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "consensus height must be non-zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "consensus height must be non-zero") } _, err = sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Counterparty.ValidateBasic() } @@ -207,36 +208,36 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { return ErrInvalidConnectionIdentifier } if err := host.ConnectionIdentifierValidator(msg.CounterpartyConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty connection ID") + return errorsmod.Wrap(err, "invalid counterparty connection ID") } if err := ValidateVersion(msg.Version); err != nil { return err } if msg.ClientState == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") } clientState, err := clienttypes.UnpackClientState(msg.ClientState) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) } if err := clientState.Validate(); err != nil { - return sdkerrors.Wrap(err, "counterparty client is invalid") + return errorsmod.Wrap(err, "counterparty client is invalid") } if len(msg.ProofTry) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") } if len(msg.ProofClient) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") } if len(msg.ProofConsensus) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") } if msg.ConsensusHeight.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "consensus height must be non-zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "consensus height must be non-zero") } _, err = sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -271,11 +272,11 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error { return ErrInvalidConnectionIdentifier } if len(msg.ProofAck) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } diff --git a/modules/core/03-connection/types/version.go b/modules/core/03-connection/types/version.go index a9a9f3df699..f986236dc53 100644 --- a/modules/core/03-connection/types/version.go +++ b/modules/core/03-connection/types/version.go @@ -3,7 +3,7 @@ package types import ( "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -50,14 +50,14 @@ func (version Version) GetFeatures() []string { // features. It unmarshals the version string into a Version object. func ValidateVersion(version *Version) error { if version == nil { - return sdkerrors.Wrap(ErrInvalidVersion, "version cannot be nil") + return errorsmod.Wrap(ErrInvalidVersion, "version cannot be nil") } if strings.TrimSpace(version.Identifier) == "" { - return sdkerrors.Wrap(ErrInvalidVersion, "version identifier cannot be blank") + return errorsmod.Wrap(ErrInvalidVersion, "version identifier cannot be blank") } for i, feature := range version.Features { if strings.TrimSpace(feature) == "" { - return sdkerrors.Wrapf(ErrInvalidVersion, "feature cannot be blank, index %d", i) + return errorsmod.Wrapf(ErrInvalidVersion, "feature cannot be blank, index %d", i) } } @@ -70,14 +70,14 @@ func ValidateVersion(version *Version) error { // identifier. func (version Version) VerifyProposedVersion(proposedVersion exported.Version) error { if proposedVersion.GetIdentifier() != version.GetIdentifier() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrVersionNegotiationFailed, "proposed version identifier does not equal supported version identifier (%s != %s)", proposedVersion.GetIdentifier(), version.GetIdentifier(), ) } if len(proposedVersion.GetFeatures()) == 0 && !allowNilFeatureSet[proposedVersion.GetIdentifier()] { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrVersionNegotiationFailed, "nil feature sets are not supported for version identifier (%s)", proposedVersion.GetIdentifier(), ) @@ -85,7 +85,7 @@ func (version Version) VerifyProposedVersion(proposedVersion exported.Version) e for _, proposedFeature := range proposedVersion.GetFeatures() { if !contains(proposedFeature, version.GetFeatures()) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrVersionNegotiationFailed, "proposed feature (%s) is not a supported feature set (%s)", proposedFeature, version.GetFeatures(), ) @@ -166,7 +166,7 @@ func PickVersion(supportedVersions, counterpartyVersions []exported.Version) (*V } } - return nil, sdkerrors.Wrapf( + return nil, errorsmod.Wrapf( ErrVersionNegotiationFailed, "failed to find a matching counterparty version (%v) from the supported version list (%v)", counterpartyVersions, supportedVersions, ) diff --git a/modules/core/04-channel/client/utils/utils.go b/modules/core/04-channel/client/utils/utils.go index 24f2d8eb7ad..be06badf011 100644 --- a/modules/core/04-channel/client/utils/utils.go +++ b/modules/core/04-channel/client/utils/utils.go @@ -4,10 +4,11 @@ import ( "context" "encoding/binary" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clientutils "github.com/cosmos/ibc-go/v7/modules/core/02-client/client/utils" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -45,7 +46,7 @@ func queryChannelABCI(clientCtx client.Context, portID, channelID string) (*type // check if channel exists if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) + return nil, errorsmod.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) @@ -140,7 +141,7 @@ func QueryLatestConsensusState( clientHeight, ok := clientState.GetLatestHeight().(clienttypes.Height) if !ok { - return nil, clienttypes.Height{}, clienttypes.Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "invalid height type. expected type: %T, got: %T", + return nil, clienttypes.Height{}, clienttypes.Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "invalid height type. expected type: %T, got: %T", clienttypes.Height{}, clientHeight) } res, err := QueryChannelConsensusState(clientCtx, portID, channelID, clientHeight, false) @@ -185,7 +186,7 @@ func queryNextSequenceRecvABCI(clientCtx client.Context, portID, channelID strin // check if next sequence receive exists if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) + return nil, errorsmod.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) } sequence := binary.BigEndian.Uint64(value) @@ -226,7 +227,7 @@ func queryPacketCommitmentABCI( // check if packet commitment exists if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrPacketCommitmentNotFound, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) + return nil, errorsmod.Wrapf(types.ErrPacketCommitmentNotFound, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) } return types.NewQueryPacketCommitmentResponse(value, proofBz, proofHeight), nil @@ -293,7 +294,7 @@ func queryPacketAcknowledgementABCI(clientCtx client.Context, portID, channelID } if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrInvalidAcknowledgement, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) + return nil, errorsmod.Wrapf(types.ErrInvalidAcknowledgement, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) } return types.NewQueryPacketAcknowledgementResponse(value, proofBz, proofHeight), nil diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 6385076de75..ee11b40251e 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -5,9 +5,9 @@ import ( "strconv" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -35,7 +35,7 @@ func (q Keeper) Channel(c context.Context, req *types.QueryChannelRequest) (*typ if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), ) } @@ -169,7 +169,7 @@ func (q Keeper) ChannelConsensusState(c context.Context, req *types.QueryChannel if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), ) } @@ -177,7 +177,7 @@ func (q Keeper) ChannelConsensusState(c context.Context, req *types.QueryChannel if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]).Error(), + errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]).Error(), ) } @@ -186,7 +186,7 @@ func (q Keeper) ChannelConsensusState(c context.Context, req *types.QueryChannel if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), + errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), ) } @@ -484,7 +484,7 @@ func (q Keeper) NextSequenceReceive(c context.Context, req *types.QueryNextSeque if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrSequenceReceiveNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), + errorsmod.Wrapf(types.ErrSequenceReceiveNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), ) } diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 94cce64b8f9..72765182d26 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -3,9 +3,9 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -31,12 +31,12 @@ func (k Keeper) ChanOpenInit( // connection hop length checked on msg.ValidateBasic() connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0]) if !found { - return "", nil, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) + return "", nil, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) } getVersions := connectionEnd.GetVersions() if len(getVersions) != 1 { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "single version must be negotiated on connection before opening channel, got: %v", getVersions, @@ -44,7 +44,7 @@ func (k Keeper) ChanOpenInit( } if !connectiontypes.VerifySupportedFeature(getVersions[0], order.String()) { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "connection version %s does not support channel ordering: %s", getVersions[0], order.String(), @@ -53,22 +53,22 @@ func (k Keeper) ChanOpenInit( clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.ClientId) if !found { - return "", nil, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", connectionEnd.ClientId) + return "", nil, errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", connectionEnd.ClientId) } if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.ClientId); status != exported.Active { - return "", nil, sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) + return "", nil, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) } if !k.portKeeper.Authenticate(ctx, portCap, portID) { - return "", nil, sdkerrors.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) + return "", nil, errorsmod.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) } channelID := k.GenerateChannelIdentifier(ctx) capKey, err := k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { - return "", nil, sdkerrors.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) + return "", nil, errorsmod.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) } return channelID, capKey, nil @@ -117,23 +117,23 @@ func (k Keeper) ChanOpenTry( ) (string, *capabilitytypes.Capability, error) { // connection hops only supports a single connection if len(connectionHops) != 1 { - return "", nil, sdkerrors.Wrapf(types.ErrTooManyConnectionHops, "expected 1, got %d", len(connectionHops)) + return "", nil, errorsmod.Wrapf(types.ErrTooManyConnectionHops, "expected 1, got %d", len(connectionHops)) } // generate a new channel channelID := k.GenerateChannelIdentifier(ctx) if !k.portKeeper.Authenticate(ctx, portCap, portID) { - return "", nil, sdkerrors.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) + return "", nil, errorsmod.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0]) if !found { - return "", nil, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) + return "", nil, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -141,7 +141,7 @@ func (k Keeper) ChanOpenTry( getVersions := connectionEnd.GetVersions() if len(getVersions) != 1 { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "single version must be negotiated on connection before opening channel, got: %v", getVersions, @@ -149,7 +149,7 @@ func (k Keeper) ChanOpenTry( } if !connectiontypes.VerifySupportedFeature(getVersions[0], order.String()) { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "connection version %s does not support channel ordering: %s", getVersions[0], order.String(), @@ -180,7 +180,7 @@ func (k Keeper) ChanOpenTry( capKey, err = k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { - return "", nil, sdkerrors.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) + return "", nil, errorsmod.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) } return channelID, capKey, nil @@ -229,24 +229,24 @@ func (k Keeper) ChanOpenAck( ) error { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State != types.INIT { - return sdkerrors.Wrapf(types.ErrInvalidChannelState, "channel state should be INIT (got %s)", channel.State.String()) + return errorsmod.Wrapf(types.ErrInvalidChannelState, "channel state should be INIT (got %s)", channel.State.String()) } if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -312,27 +312,27 @@ func (k Keeper) ChanOpenConfirm( ) error { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State != types.TRYOPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not TRYOPEN (got %s)", channel.State.String(), ) } if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -394,34 +394,34 @@ func (k Keeper) ChanCloseInit( chanCap *capabilitytypes.Capability, ) error { if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) } channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State == types.CLOSED { - return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") + return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.ClientId) if !found { - return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", connectionEnd.ClientId) + return errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID (%s)", connectionEnd.ClientId) } if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.ClientId); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -452,25 +452,25 @@ func (k Keeper) ChanCloseConfirm( proofHeight exported.Height, ) error { if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)") + return errorsmod.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)") } channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State == types.CLOSED { - return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") + return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index b83d6b2f6bf..3c800ad3795 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/tendermint/tendermint/libs/log" db "github.com/tendermint/tm-db" @@ -425,17 +425,17 @@ func (k Keeper) GetAllChannels(ctx sdk.Context) (channels []types.IdentifiedChan func (k Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string) (string, exported.ClientState, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return "", nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) + return "", nil, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) } connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return "", nil, sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]) + return "", nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]) } clientState, found := k.clientKeeper.GetClientState(ctx, connection.ClientId) if !found { - return "", nil, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId) + return "", nil, errorsmod.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId) } return connection.ClientId, clientState, nil @@ -445,7 +445,7 @@ func (k Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string) func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (exported.ConnectionI, error) { connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { - return nil, sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) + return nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) } return connection, nil @@ -455,14 +455,14 @@ func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (exported.Co func (k Keeper) GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, exported.ConnectionI, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return "", nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) + return "", nil, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) } connectionID := channel.ConnectionHops[0] connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { - return "", nil, sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) + return "", nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) } return connectionID, connection, nil diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index e57ec06e943..726df04c3aa 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -5,8 +5,8 @@ import ( "strconv" "time" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -30,23 +30,23 @@ func (k Keeper) SendPacket( ) (uint64, error) { channel, found := k.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return 0, sdkerrors.Wrap(types.ErrChannelNotFound, sourceChannel) + return 0, errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel) } if channel.State != types.OPEN { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrInvalidChannelState, "channel is not OPEN (got %s)", channel.State.String(), ) } if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(sourcePort, sourceChannel)) { - return 0, sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + return 0, errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } sequence, found := k.GetNextSequenceSend(ctx, sourcePort, sourceChannel) if !found { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrSequenceSendNotFound, "source port: %s, source channel: %s", sourcePort, sourceChannel, ) @@ -57,12 +57,12 @@ func (k Keeper) SendPacket( channel.Counterparty.PortId, channel.Counterparty.ChannelId, timeoutHeight, timeoutTimestamp) if err := packet.ValidateBasic(); err != nil { - return 0, sdkerrors.Wrap(err, "constructed packet failed basic validation") + return 0, errorsmod.Wrap(err, "constructed packet failed basic validation") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return 0, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return 0, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.GetClientID()) @@ -72,13 +72,13 @@ func (k Keeper) SendPacket( // prevent accidental sends with clients that cannot be updated if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.GetClientID()); status != exported.Active { - return 0, sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) } // check if packet is timed out on the receiving chain latestHeight := clientState.GetLatestHeight() if !timeoutHeight.IsZero() && latestHeight.GTE(timeoutHeight) { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrPacketTimeout, "receiving chain block height >= packet timeout height (%s >= %s)", latestHeight, timeoutHeight, ) @@ -90,7 +90,7 @@ func (k Keeper) SendPacket( } if packet.GetTimeoutTimestamp() != 0 && latestTimestamp >= packet.GetTimeoutTimestamp() { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrPacketTimeout, "receiving chain block timestamp >= packet timeout timestamp (%s >= %s)", time.Unix(0, int64(latestTimestamp)), time.Unix(0, int64(packet.GetTimeoutTimestamp())), ) @@ -126,11 +126,11 @@ func (k Keeper) RecvPacket( ) error { channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel()) if !found { - return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) + return errorsmod.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -139,7 +139,7 @@ func (k Keeper) RecvPacket( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, ) @@ -147,14 +147,14 @@ func (k Keeper) RecvPacket( // packet must come from the channel's counterparty if packet.GetSourcePort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet source port doesn't match the counterparty's port (%s ≠ %s)", packet.GetSourcePort(), channel.Counterparty.PortId, ) } if packet.GetSourceChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet source channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetSourceChannel(), channel.Counterparty.ChannelId, ) @@ -165,11 +165,11 @@ func (k Keeper) RecvPacket( // connection and channel must both be open connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -179,7 +179,7 @@ func (k Keeper) RecvPacket( selfHeight := clienttypes.GetSelfHeight(ctx) timeoutHeight := packet.GetTimeoutHeight() if !timeoutHeight.IsZero() && selfHeight.GTE(timeoutHeight) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketTimeout, "block height >= packet timeout height (%s >= %s)", selfHeight, timeoutHeight, ) @@ -187,7 +187,7 @@ func (k Keeper) RecvPacket( // check if packet timeouted by comparing it with the latest timestamp of the chain if packet.GetTimeoutTimestamp() != 0 && uint64(ctx.BlockTime().UnixNano()) >= packet.GetTimeoutTimestamp() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketTimeout, "block timestamp >= packet timeout timestamp (%s >= %s)", ctx.BlockTime(), time.Unix(0, int64(packet.GetTimeoutTimestamp())), ) @@ -201,7 +201,7 @@ func (k Keeper) RecvPacket( packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), commitment, ); err != nil { - return sdkerrors.Wrap(err, "couldn't verify counterparty packet commitment") + return errorsmod.Wrap(err, "couldn't verify counterparty packet commitment") } switch channel.Ordering { @@ -226,7 +226,7 @@ func (k Keeper) RecvPacket( // check if the packet is being received in order nextSequenceRecv, found := k.GetNextSequenceRecv(ctx, packet.GetDestPort(), packet.GetDestChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrSequenceReceiveNotFound, "destination port: %s, destination channel: %s", packet.GetDestPort(), packet.GetDestChannel(), ) @@ -241,7 +241,7 @@ func (k Keeper) RecvPacket( } if packet.GetSequence() != nextSequenceRecv { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketSequenceOutOfOrder, "packet sequence ≠ next receive sequence (%d ≠ %d)", packet.GetSequence(), nextSequenceRecv, ) @@ -292,11 +292,11 @@ func (k Keeper) WriteAcknowledgement( ) error { channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel()) if !found { - return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) + return errorsmod.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -305,7 +305,7 @@ func (k Keeper) WriteAcknowledgement( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, ) @@ -319,12 +319,12 @@ func (k Keeper) WriteAcknowledgement( } if acknowledgement == nil { - return sdkerrors.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be nil") + return errorsmod.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be nil") } bz := acknowledgement.Acknowledgement() if len(bz) == 0 { - return sdkerrors.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") + return errorsmod.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") } // set the acknowledgement so that it can be verified on the other side @@ -364,14 +364,14 @@ func (k Keeper) AcknowledgePacket( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel(), ) } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -380,7 +380,7 @@ func (k Keeper) AcknowledgePacket( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, ) @@ -388,14 +388,14 @@ func (k Keeper) AcknowledgePacket( // packet must have been sent to the channel's counterparty if packet.GetDestPort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortId, ) } if packet.GetDestChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelId, ) @@ -403,11 +403,11 @@ func (k Keeper) AcknowledgePacket( connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -428,7 +428,7 @@ func (k Keeper) AcknowledgePacket( // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) + return errorsmod.Wrapf(types.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) } if err := k.connectionKeeper.VerifyPacketAcknowledgement( @@ -442,14 +442,14 @@ func (k Keeper) AcknowledgePacket( if channel.Ordering == types.ORDERED { nextSequenceAck, found := k.GetNextSequenceAck(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrSequenceAckNotFound, "source port: %s, source channel: %s", packet.GetSourcePort(), packet.GetSourceChannel(), ) } if packet.GetSequence() != nextSequenceAck { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketSequenceOutOfOrder, "packet sequence ≠ next ack sequence (%d ≠ %d)", packet.GetSequence(), nextSequenceAck, ) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 6302b8d15a9..64a1154a2a2 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - sdkerrors "cosmossdk.io/errors" + errorsmod "cosmossdk.io/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -261,7 +261,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path *ibctesting.Path packet exported.PacketI channelCap *capabilitytypes.Capability - expError *sdkerrors.Error + expError *errorsmod.Error ) testCases := []testCase{ @@ -622,7 +622,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { ack = ibcmock.MockAcknowledgement channelCap *capabilitytypes.Capability - expError *sdkerrors.Error + expError *errorsmod.Error ) testCases := []testCase{ diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 3ea9e48317e..fd6686b35b9 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -4,8 +4,8 @@ import ( "bytes" "strconv" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -29,7 +29,7 @@ func (k Keeper) TimeoutPacket( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel(), ) @@ -39,14 +39,14 @@ func (k Keeper) TimeoutPacket( // so the capability authentication can be omitted here if packet.GetDestPort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortId, ) } if packet.GetDestChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelId, ) @@ -54,7 +54,7 @@ func (k Keeper) TimeoutPacket( connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap( + return errorsmod.Wrap( connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0], ) @@ -69,7 +69,7 @@ func (k Keeper) TimeoutPacket( timeoutHeight := packet.GetTimeoutHeight() if (timeoutHeight.IsZero() || proofHeight.LT(timeoutHeight)) && (packet.GetTimeoutTimestamp() == 0 || proofTimestamp < packet.GetTimeoutTimestamp()) { - return sdkerrors.Wrap(types.ErrPacketTimeout, "packet timeout has not been reached for height or timestamp") + return errorsmod.Wrap(types.ErrPacketTimeout, "packet timeout has not been reached for height or timestamp") } commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) @@ -84,7 +84,7 @@ func (k Keeper) TimeoutPacket( } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -94,14 +94,14 @@ func (k Keeper) TimeoutPacket( // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) + return errorsmod.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) } switch channel.Ordering { case types.ORDERED: // check that packet has not been received if nextSequenceRecv > packet.GetSequence() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketReceived, "packet already received, next sequence receive > packet sequence (%d > %d)", nextSequenceRecv, packet.GetSequence(), ) @@ -118,7 +118,7 @@ func (k Keeper) TimeoutPacket( packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ) default: - panic(sdkerrors.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) + panic(errorsmod.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) } if err != nil { @@ -140,12 +140,12 @@ func (k Keeper) TimeoutExecuted( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) } capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrChannelCapabilityNotFound, "caller does not own capability for channel with capability name %s", capName, ) @@ -191,26 +191,26 @@ func (k Keeper) TimeoutOnClose( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) } capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication with capability name %s", capName, ) } if packet.GetDestPort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortId, ) } if packet.GetDestChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelId, ) @@ -218,7 +218,7 @@ func (k Keeper) TimeoutOnClose( connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) @@ -236,7 +236,7 @@ func (k Keeper) TimeoutOnClose( // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) + return errorsmod.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) } counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()} @@ -260,7 +260,7 @@ func (k Keeper) TimeoutOnClose( case types.ORDERED: // check that packet has not been received if nextSequenceRecv > packet.GetSequence() { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet already received, next sequence receive > packet sequence (%d > %d", nextSequenceRecv, packet.GetSequence()) + return errorsmod.Wrapf(types.ErrInvalidPacket, "packet already received, next sequence receive > packet sequence (%d > %d", nextSequenceRecv, packet.GetSequence()) } // check that the recv sequence is as claimed @@ -274,7 +274,7 @@ func (k Keeper) TimeoutOnClose( packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ) default: - panic(sdkerrors.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) + panic(errorsmod.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) } if err != nil { diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index 876cba720ee..e2f8ebc9305 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - sdkerrors "cosmossdk.io/errors" + errorsmod "cosmossdk.io/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -24,7 +24,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet types.Packet nextSeqRecv uint64 ordered bool - expError *sdkerrors.Error + expError *errorsmod.Error ) testCases := []testCase{ diff --git a/modules/core/04-channel/types/acknowledgement.go b/modules/core/04-channel/types/acknowledgement.go index 49c795d0d55..3e4d02a1180 100644 --- a/modules/core/04-channel/types/acknowledgement.go +++ b/modules/core/04-channel/types/acknowledgement.go @@ -5,8 +5,8 @@ import ( "reflect" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) const ( @@ -32,7 +32,7 @@ func NewResultAcknowledgement(result []byte) Acknowledgement { func NewErrorAcknowledgement(err error) Acknowledgement { // the ABCI code is included in the abcitypes.ResponseDeliverTx hash // constructed in Tendermint and is therefore deterministic - _, code, _ := sdkerrors.ABCIInfo(err, false) // discard non-determinstic codespace and log values + _, code, _ := errorsmod.ABCIInfo(err, false) // discard non-determinstic codespace and log values return Acknowledgement{ Response: &Acknowledgement_Error{ @@ -46,15 +46,15 @@ func (ack Acknowledgement) ValidateBasic() error { switch resp := ack.Response.(type) { case *Acknowledgement_Result: if len(resp.Result) == 0 { - return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") + return errorsmod.Wrap(ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") } case *Acknowledgement_Error: if strings.TrimSpace(resp.Error) == "" { - return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement error cannot be empty") + return errorsmod.Wrap(ErrInvalidAcknowledgement, "acknowledgement error cannot be empty") } default: - return sdkerrors.Wrapf(ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", resp) + return errorsmod.Wrapf(ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", resp) } return nil } diff --git a/modules/core/04-channel/types/acknowledgement_test.go b/modules/core/04-channel/types/acknowledgement_test.go index 5a08f093500..13ca093fa91 100644 --- a/modules/core/04-channel/types/acknowledgement_test.go +++ b/modules/core/04-channel/types/acknowledgement_test.go @@ -3,11 +3,13 @@ package types_test import ( "fmt" + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abcitypes "github.com/tendermint/tendermint/abci/types" tmprotostate "github.com/tendermint/tendermint/proto/tendermint/state" tmstate "github.com/tendermint/tendermint/state" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -91,11 +93,11 @@ func (suite TypesTestSuite) TestAcknowledgement() { //nolint:govet // this is a // This test acts as an indicator that the ABCI error codes may no longer be deterministic. func (suite *TypesTestSuite) TestABCICodeDeterminism() { // same ABCI error code used - err := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 1") - errSameABCICode := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 2") + err := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 1") + errSameABCICode := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 2") // different ABCI error code used - errDifferentABCICode := sdkerrors.ErrNotFound + errDifferentABCICode := ibcerrors.ErrNotFound deliverTx := sdkerrors.ResponseDeliverTxWithEvents(err, gasUsed, gasWanted, []abcitypes.Event{}, false) responses := tmprotostate.ABCIResponses{ @@ -130,11 +132,11 @@ func (suite *TypesTestSuite) TestABCICodeDeterminism() { // ABCI error code are used in constructing the acknowledgement error string func (suite *TypesTestSuite) TestAcknowledgementError() { // same ABCI error code used - err := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 1") - errSameABCICode := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 2") + err := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 1") + errSameABCICode := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 2") // different ABCI error code used - errDifferentABCICode := sdkerrors.ErrNotFound + errDifferentABCICode := ibcerrors.ErrNotFound ack := types.NewErrorAcknowledgement(err) ackSameABCICode := types.NewErrorAcknowledgement(errSameABCICode) diff --git a/modules/core/04-channel/types/channel.go b/modules/core/04-channel/types/channel.go index 0251571e3ee..012b571fb07 100644 --- a/modules/core/04-channel/types/channel.go +++ b/modules/core/04-channel/types/channel.go @@ -1,7 +1,7 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -57,16 +57,16 @@ func (ch Channel) ValidateBasic() error { return ErrInvalidChannelState } if !(ch.Ordering == ORDERED || ch.Ordering == UNORDERED) { - return sdkerrors.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String()) + return errorsmod.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String()) } if len(ch.ConnectionHops) != 1 { - return sdkerrors.Wrap( + return errorsmod.Wrap( ErrTooManyConnectionHops, "current IBC version only supports one connection hop", ) } if err := host.ConnectionIdentifierValidator(ch.ConnectionHops[0]); err != nil { - return sdkerrors.Wrap(err, "invalid connection hop ID") + return errorsmod.Wrap(err, "invalid connection hop ID") } return ch.Counterparty.ValidateBasic() } @@ -92,11 +92,11 @@ func (c Counterparty) GetChannelID() string { // ValidateBasic performs a basic validation check of the identifiers func (c Counterparty) ValidateBasic() error { if err := host.PortIdentifierValidator(c.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty port ID") + return errorsmod.Wrap(err, "invalid counterparty port ID") } if c.ChannelId != "" { if err := host.ChannelIdentifierValidator(c.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty channel ID") + return errorsmod.Wrap(err, "invalid counterparty channel ID") } } return nil @@ -118,10 +118,10 @@ func NewIdentifiedChannel(portID, channelID string, ch Channel) IdentifiedChanne // ValidateBasic performs a basic validation of the identifiers and channel fields. func (ic IdentifiedChannel) ValidateBasic() error { if err := host.ChannelIdentifierValidator(ic.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid channel ID") + return errorsmod.Wrap(err, "invalid channel ID") } if err := host.PortIdentifierValidator(ic.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } channel := NewChannel(ic.State, ic.Ordering, ic.Counterparty, ic.ConnectionHops, ic.Version) return channel.ValidateBasic() diff --git a/modules/core/04-channel/types/errors.go b/modules/core/04-channel/types/errors.go index e807200c2cd..dfbbf30a1cb 100644 --- a/modules/core/04-channel/types/errors.go +++ b/modules/core/04-channel/types/errors.go @@ -1,43 +1,43 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC channel sentinel errors var ( - ErrChannelExists = sdkerrors.Register(SubModuleName, 2, "channel already exists") - ErrChannelNotFound = sdkerrors.Register(SubModuleName, 3, "channel not found") - ErrInvalidChannel = sdkerrors.Register(SubModuleName, 4, "invalid channel") - ErrInvalidChannelState = sdkerrors.Register(SubModuleName, 5, "invalid channel state") - ErrInvalidChannelOrdering = sdkerrors.Register(SubModuleName, 6, "invalid channel ordering") - ErrInvalidCounterparty = sdkerrors.Register(SubModuleName, 7, "invalid counterparty channel") - ErrInvalidChannelCapability = sdkerrors.Register(SubModuleName, 8, "invalid channel capability") - ErrChannelCapabilityNotFound = sdkerrors.Register(SubModuleName, 9, "channel capability not found") - ErrSequenceSendNotFound = sdkerrors.Register(SubModuleName, 10, "sequence send not found") - ErrSequenceReceiveNotFound = sdkerrors.Register(SubModuleName, 11, "sequence receive not found") - ErrSequenceAckNotFound = sdkerrors.Register(SubModuleName, 12, "sequence acknowledgement not found") - ErrInvalidPacket = sdkerrors.Register(SubModuleName, 13, "invalid packet") - ErrPacketTimeout = sdkerrors.Register(SubModuleName, 14, "packet timeout") - ErrTooManyConnectionHops = sdkerrors.Register(SubModuleName, 15, "too many connection hops") - ErrInvalidAcknowledgement = sdkerrors.Register(SubModuleName, 16, "invalid acknowledgement") - ErrAcknowledgementExists = sdkerrors.Register(SubModuleName, 17, "acknowledgement for packet already exists") - ErrInvalidChannelIdentifier = sdkerrors.Register(SubModuleName, 18, "invalid channel identifier") + ErrChannelExists = errorsmod.Register(SubModuleName, 2, "channel already exists") + ErrChannelNotFound = errorsmod.Register(SubModuleName, 3, "channel not found") + ErrInvalidChannel = errorsmod.Register(SubModuleName, 4, "invalid channel") + ErrInvalidChannelState = errorsmod.Register(SubModuleName, 5, "invalid channel state") + ErrInvalidChannelOrdering = errorsmod.Register(SubModuleName, 6, "invalid channel ordering") + ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 7, "invalid counterparty channel") + ErrInvalidChannelCapability = errorsmod.Register(SubModuleName, 8, "invalid channel capability") + ErrChannelCapabilityNotFound = errorsmod.Register(SubModuleName, 9, "channel capability not found") + ErrSequenceSendNotFound = errorsmod.Register(SubModuleName, 10, "sequence send not found") + ErrSequenceReceiveNotFound = errorsmod.Register(SubModuleName, 11, "sequence receive not found") + ErrSequenceAckNotFound = errorsmod.Register(SubModuleName, 12, "sequence acknowledgement not found") + ErrInvalidPacket = errorsmod.Register(SubModuleName, 13, "invalid packet") + ErrPacketTimeout = errorsmod.Register(SubModuleName, 14, "packet timeout") + ErrTooManyConnectionHops = errorsmod.Register(SubModuleName, 15, "too many connection hops") + ErrInvalidAcknowledgement = errorsmod.Register(SubModuleName, 16, "invalid acknowledgement") + ErrAcknowledgementExists = errorsmod.Register(SubModuleName, 17, "acknowledgement for packet already exists") + ErrInvalidChannelIdentifier = errorsmod.Register(SubModuleName, 18, "invalid channel identifier") // packets already relayed errors - ErrPacketReceived = sdkerrors.Register(SubModuleName, 19, "packet already received") - ErrPacketCommitmentNotFound = sdkerrors.Register(SubModuleName, 20, "packet commitment not found") // may occur for already received acknowledgements or timeouts and in rare cases for packets never sent + ErrPacketReceived = errorsmod.Register(SubModuleName, 19, "packet already received") + ErrPacketCommitmentNotFound = errorsmod.Register(SubModuleName, 20, "packet commitment not found") // may occur for already received acknowledgements or timeouts and in rare cases for packets never sent // ORDERED channel error - ErrPacketSequenceOutOfOrder = sdkerrors.Register(SubModuleName, 21, "packet sequence is out of order") + ErrPacketSequenceOutOfOrder = errorsmod.Register(SubModuleName, 21, "packet sequence is out of order") // Antehandler error - ErrRedundantTx = sdkerrors.Register(SubModuleName, 22, "packet messages are redundant") + ErrRedundantTx = errorsmod.Register(SubModuleName, 22, "packet messages are redundant") // Perform a no-op on the current Msg - ErrNoOpMsg = sdkerrors.Register(SubModuleName, 23, "message is redundant, no-op will be performed") + ErrNoOpMsg = errorsmod.Register(SubModuleName, 23, "message is redundant, no-op will be performed") - ErrInvalidChannelVersion = sdkerrors.Register(SubModuleName, 24, "invalid channel version") - ErrPacketNotSent = sdkerrors.Register(SubModuleName, 25, "packet has not been sent") - ErrInvalidTimeout = sdkerrors.Register(SubModuleName, 26, "invalid packet timeout") + ErrInvalidChannelVersion = errorsmod.Register(SubModuleName, 24, "invalid channel version") + ErrPacketNotSent = errorsmod.Register(SubModuleName, 25, "packet has not been sent") + ErrInvalidTimeout = errorsmod.Register(SubModuleName, 26, "invalid packet timeout") ) diff --git a/modules/core/04-channel/types/keys.go b/modules/core/04-channel/types/keys.go index 48abec46b20..d961abe3dc0 100644 --- a/modules/core/04-channel/types/keys.go +++ b/modules/core/04-channel/types/keys.go @@ -4,7 +4,7 @@ import ( "fmt" "regexp" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -50,12 +50,12 @@ func IsValidChannelID(channelID string) bool { // ParseChannelSequence parses the channel sequence from the channel identifier. func ParseChannelSequence(channelID string) (uint64, error) { if !IsChannelIDFormat(channelID) { - return 0, sdkerrors.Wrap(host.ErrInvalidID, "channel identifier is not in the format: `channel-{N}`") + return 0, errorsmod.Wrap(host.ErrInvalidID, "channel identifier is not in the format: `channel-{N}`") } sequence, err := host.ParseIdentifier(channelID, ChannelPrefix) if err != nil { - return 0, sdkerrors.Wrap(err, "invalid channel identifier") + return 0, errorsmod.Wrap(err, "invalid channel identifier") } return sequence, nil diff --git a/modules/core/04-channel/types/msgs.go b/modules/core/04-channel/types/msgs.go index 5e248b7e676..eab7f00bba5 100644 --- a/modules/core/04-channel/types/msgs.go +++ b/modules/core/04-channel/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "encoding/base64" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -33,20 +34,20 @@ func NewMsgChannelOpenInit( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenInit) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if msg.Channel.State != INIT { - return sdkerrors.Wrapf(ErrInvalidChannelState, + return errorsmod.Wrapf(ErrInvalidChannelState, "channel state must be INIT in MsgChannelOpenInit. expected: %s, got: %s", INIT, msg.Channel.State, ) } if msg.Channel.Counterparty.ChannelId != "" { - return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty channel identifier must be empty") + return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty channel identifier must be empty") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Channel.ValidateBasic() } @@ -87,28 +88,28 @@ func NewMsgChannelOpenTry( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenTry) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if msg.PreviousChannelId != "" { - return sdkerrors.Wrap(ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") + return errorsmod.Wrap(ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") } if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof") } if msg.Channel.State != TRYOPEN { - return sdkerrors.Wrapf(ErrInvalidChannelState, + return errorsmod.Wrapf(ErrInvalidChannelState, "channel state must be TRYOPEN in MsgChannelOpenTry. expected: %s, got: %s", TRYOPEN, msg.Channel.State, ) } // counterparty validate basic allows empty counterparty channel identifiers if err := host.ChannelIdentifierValidator(msg.Channel.Counterparty.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty channel ID") + return errorsmod.Wrap(err, "invalid counterparty channel ID") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Channel.ValidateBasic() } @@ -145,20 +146,20 @@ func NewMsgChannelOpenAck( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenAck) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty channel ID") + return errorsmod.Wrap(err, "invalid counterparty channel ID") } if len(msg.ProofTry) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty try proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty try proof") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -193,17 +194,17 @@ func NewMsgChannelOpenConfirm( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenConfirm) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } if len(msg.ProofAck) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -235,14 +236,14 @@ func NewMsgChannelCloseInit( // ValidateBasic implements sdk.Msg func (msg MsgChannelCloseInit) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -277,17 +278,17 @@ func NewMsgChannelCloseConfirm( // ValidateBasic implements sdk.Msg func (msg MsgChannelCloseConfirm) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -321,11 +322,11 @@ func NewMsgRecvPacket( // ValidateBasic implements sdk.Msg func (msg MsgRecvPacket) ValidateBasic() error { if len(msg.ProofCommitment) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty commitment proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty commitment proof") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } @@ -367,14 +368,14 @@ func NewMsgTimeout( // ValidateBasic implements sdk.Msg func (msg MsgTimeout) ValidateBasic() error { if len(msg.ProofUnreceived) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") } if msg.NextSequenceRecv == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") + return errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } @@ -409,17 +410,17 @@ func NewMsgTimeoutOnClose( // ValidateBasic implements sdk.Msg func (msg MsgTimeoutOnClose) ValidateBasic() error { if msg.NextSequenceRecv == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") + return errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } if len(msg.ProofUnreceived) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") } if len(msg.ProofClose) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } @@ -456,14 +457,14 @@ func NewMsgAcknowledgement( // ValidateBasic implements sdk.Msg func (msg MsgAcknowledgement) ValidateBasic() error { if len(msg.ProofAcked) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof") } if len(msg.Acknowledgement) == 0 { - return sdkerrors.Wrap(ErrInvalidAcknowledgement, "ack bytes cannot be empty") + return errorsmod.Wrap(ErrInvalidAcknowledgement, "ack bytes cannot be empty") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } diff --git a/modules/core/04-channel/types/packet.go b/modules/core/04-channel/types/packet.go index 3f2390bd11b..c007f3af9b0 100644 --- a/modules/core/04-channel/types/packet.go +++ b/modules/core/04-channel/types/packet.go @@ -3,9 +3,9 @@ package types import ( "crypto/sha256" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -89,25 +89,25 @@ func (p Packet) GetTimeoutTimestamp() uint64 { return p.TimeoutTimestamp } // ValidateBasic implements PacketI interface func (p Packet) ValidateBasic() error { if err := host.PortIdentifierValidator(p.SourcePort); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.PortIdentifierValidator(p.DestinationPort); err != nil { - return sdkerrors.Wrap(err, "invalid destination port ID") + return errorsmod.Wrap(err, "invalid destination port ID") } if err := host.ChannelIdentifierValidator(p.SourceChannel); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } if err := host.ChannelIdentifierValidator(p.DestinationChannel); err != nil { - return sdkerrors.Wrap(err, "invalid destination channel ID") + return errorsmod.Wrap(err, "invalid destination channel ID") } if p.Sequence == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") + return errorsmod.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") } if p.TimeoutHeight.IsZero() && p.TimeoutTimestamp == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet timeout height and packet timeout timestamp cannot both be 0") + return errorsmod.Wrap(ErrInvalidPacket, "packet timeout height and packet timeout timestamp cannot both be 0") } if len(p.Data) == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet data bytes cannot be empty") + return errorsmod.Wrap(ErrInvalidPacket, "packet data bytes cannot be empty") } return nil } @@ -115,15 +115,15 @@ func (p Packet) ValidateBasic() error { // Validates a PacketId func (p PacketId) Validate() error { if err := host.PortIdentifierValidator(p.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(p.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } if p.Sequence == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") + return errorsmod.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") } return nil diff --git a/modules/core/05-port/types/errors.go b/modules/core/05-port/types/errors.go index 23a2776f59d..1348dfc83b4 100644 --- a/modules/core/05-port/types/errors.go +++ b/modules/core/05-port/types/errors.go @@ -1,13 +1,13 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC port sentinel errors var ( - ErrPortExists = sdkerrors.Register(SubModuleName, 2, "port is already binded") - ErrPortNotFound = sdkerrors.Register(SubModuleName, 3, "port not found") - ErrInvalidPort = sdkerrors.Register(SubModuleName, 4, "invalid port") - ErrInvalidRoute = sdkerrors.Register(SubModuleName, 5, "route not found") + ErrPortExists = errorsmod.Register(SubModuleName, 2, "port is already binded") + ErrPortNotFound = errorsmod.Register(SubModuleName, 3, "port not found") + ErrInvalidPort = errorsmod.Register(SubModuleName, 4, "invalid port") + ErrInvalidRoute = errorsmod.Register(SubModuleName, 5, "route not found") ) diff --git a/modules/core/23-commitment/types/errors.go b/modules/core/23-commitment/types/errors.go index 7191baef1cc..140ec912b00 100644 --- a/modules/core/23-commitment/types/errors.go +++ b/modules/core/23-commitment/types/errors.go @@ -1,7 +1,7 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // SubModuleName is the error codespace @@ -9,7 +9,7 @@ const SubModuleName string = "commitment" // IBC connection sentinel errors var ( - ErrInvalidProof = sdkerrors.Register(SubModuleName, 2, "invalid proof") - ErrInvalidPrefix = sdkerrors.Register(SubModuleName, 3, "invalid prefix") - ErrInvalidMerkleProof = sdkerrors.Register(SubModuleName, 4, "invalid merkle proof") + ErrInvalidProof = errorsmod.Register(SubModuleName, 2, "invalid proof") + ErrInvalidPrefix = errorsmod.Register(SubModuleName, 3, "invalid prefix") + ErrInvalidMerkleProof = errorsmod.Register(SubModuleName, 4, "invalid merkle proof") ) diff --git a/modules/core/23-commitment/types/merkle.go b/modules/core/23-commitment/types/merkle.go index 33c6f51dba7..7d15b00a318 100644 --- a/modules/core/23-commitment/types/merkle.go +++ b/modules/core/23-commitment/types/merkle.go @@ -5,7 +5,7 @@ import ( "fmt" "net/url" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/gogoproto/proto" ics23 "github.com/cosmos/ics23/go" tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" @@ -121,7 +121,7 @@ func (mp MerklePath) Empty() bool { // with the given path. func ApplyPrefix(prefix exported.Prefix, path MerklePath) (MerklePath, error) { if prefix == nil || prefix.Empty() { - return MerklePath{}, sdkerrors.Wrap(ErrInvalidPrefix, "prefix can't be empty") + return MerklePath{}, errorsmod.Wrap(ErrInvalidPrefix, "prefix can't be empty") } return NewMerklePath(append([]string{string(prefix.Bytes())}, path.KeyPath...)...), nil } @@ -138,14 +138,14 @@ func (proof MerkleProof) VerifyMembership(specs []*ics23.ProofSpec, root exporte // VerifyMembership specific argument validation mpath, ok := path.(MerklePath) if !ok { - return sdkerrors.Wrapf(ErrInvalidProof, "path %v is not of type MerklePath", path) + return errorsmod.Wrapf(ErrInvalidProof, "path %v is not of type MerklePath", path) } if len(mpath.KeyPath) != len(specs) { - return sdkerrors.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", + return errorsmod.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", len(mpath.KeyPath), len(specs)) } if len(value) == 0 { - return sdkerrors.Wrap(ErrInvalidProof, "empty value in membership proof") + return errorsmod.Wrap(ErrInvalidProof, "empty value in membership proof") } // Since every proof in chain is a membership proof we can use verifyChainedMembershipProof from index 0 @@ -167,10 +167,10 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo // VerifyNonMembership specific argument validation mpath, ok := path.(MerklePath) if !ok { - return sdkerrors.Wrapf(ErrInvalidProof, "path %v is not of type MerkleProof", path) + return errorsmod.Wrapf(ErrInvalidProof, "path %v is not of type MerkleProof", path) } if len(mpath.KeyPath) != len(specs) { - return sdkerrors.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", + return errorsmod.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", len(mpath.KeyPath), len(specs)) } @@ -180,14 +180,14 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo // of all subroots up to final root subroot, err := proof.Proofs[0].Calculate() if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0, merkle tree is likely empty. %v", err) + return errorsmod.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0, merkle tree is likely empty. %v", err) } key, err := mpath.GetKey(uint64(len(mpath.KeyPath) - 1)) if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key: %s", mpath.KeyPath[len(mpath.KeyPath)-1]) + return errorsmod.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key: %s", mpath.KeyPath[len(mpath.KeyPath)-1]) } if ok := ics23.VerifyNonMembership(specs[0], subroot, proof.Proofs[0], key); !ok { - return sdkerrors.Wrapf(ErrInvalidProof, "could not verify absence of key %s. Please ensure that the path is correct.", string(key)) + return errorsmod.Wrapf(ErrInvalidProof, "could not verify absence of key %s. Please ensure that the path is correct.", string(key)) } // Verify chained membership proof starting from index 1 with value = subroot @@ -195,10 +195,10 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo return err } case *ics23.CommitmentProof_Exist: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "got ExistenceProof in VerifyNonMembership. If this is unexpected, please ensure that proof was queried with the correct key.") default: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "expected proof type: %T, got: %T", &ics23.CommitmentProof_Exist{}, proof.Proofs[0].Proof) } return nil @@ -207,13 +207,13 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo // BatchVerifyMembership verifies a group of key value pairs against the given root // NOTE: Currently left unimplemented as it is unused func (proof MerkleProof) BatchVerifyMembership(specs []*ics23.ProofSpec, root exported.Root, path exported.Path, items map[string][]byte) error { - return sdkerrors.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") + return errorsmod.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") } // BatchVerifyNonMembership verifies absence of a group of keys against the given root // NOTE: Currently left unimplemented as it is unused func (proof MerkleProof) BatchVerifyNonMembership(specs []*ics23.ProofSpec, root exported.Root, path exported.Path, items [][]byte) error { - return sdkerrors.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") + return errorsmod.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") } // verifyChainedMembershipProof takes a list of proofs and specs and verifies each proof sequentially ensuring that the value is committed to @@ -235,35 +235,35 @@ func verifyChainedMembershipProof(root []byte, specs []*ics23.ProofSpec, proofs case *ics23.CommitmentProof_Exist: subroot, err = proofs[i].Calculate() if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not calculate proof root at index %d, merkle tree may be empty. %v", i, err) + return errorsmod.Wrapf(ErrInvalidProof, "could not calculate proof root at index %d, merkle tree may be empty. %v", i, err) } // Since keys are passed in from highest to lowest, we must grab their indices in reverse order // from the proofs and specs which are lowest to highest key, err := keys.GetKey(uint64(len(keys.KeyPath) - 1 - i)) if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key %s: %v", keys.KeyPath[len(keys.KeyPath)-1-i], err) + return errorsmod.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key %s: %v", keys.KeyPath[len(keys.KeyPath)-1-i], err) } // verify membership of the proof at this index with appropriate key and value if ok := ics23.VerifyMembership(specs[i], subroot, proofs[i], key, value); !ok { - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "chained membership proof failed to verify membership of value: %X in subroot %X at index %d. Please ensure the path and value are both correct.", value, subroot, i) } // Set value to subroot so that we verify next proof in chain commits to this subroot value = subroot case *ics23.CommitmentProof_Nonexist: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "chained membership proof contains nonexistence proof at index %d. If this is unexpected, please ensure that proof was queried from a height that contained the value in store and was queried with the correct key. The key used: %s", i, keys) default: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "expected proof type: %T, got: %T", &ics23.CommitmentProof_Exist{}, proofs[i].Proof) } } // Check that chained proof root equals passed-in root if !bytes.Equal(root, subroot) { - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "proof did not commit to expected root: %X, got: %X. Please ensure proof was submitted with correct proofHeight and to the correct chain.", root, subroot) } @@ -293,22 +293,22 @@ func (proof MerkleProof) ValidateBasic() error { // validateVerificationArgs verifies the proof arguments are valid func (proof MerkleProof) validateVerificationArgs(specs []*ics23.ProofSpec, root exported.Root) error { if proof.Empty() { - return sdkerrors.Wrap(ErrInvalidMerkleProof, "proof cannot be empty") + return errorsmod.Wrap(ErrInvalidMerkleProof, "proof cannot be empty") } if root == nil || root.Empty() { - return sdkerrors.Wrap(ErrInvalidMerkleProof, "root cannot be empty") + return errorsmod.Wrap(ErrInvalidMerkleProof, "root cannot be empty") } if len(specs) != len(proof.Proofs) { - return sdkerrors.Wrapf(ErrInvalidMerkleProof, + return errorsmod.Wrapf(ErrInvalidMerkleProof, "length of specs: %d not equal to length of proof: %d", len(specs), len(proof.Proofs)) } for i, spec := range specs { if spec == nil { - return sdkerrors.Wrapf(ErrInvalidProof, "spec at position %d is nil", i) + return errorsmod.Wrapf(ErrInvalidProof, "spec at position %d is nil", i) } } return nil diff --git a/modules/core/23-commitment/types/utils.go b/modules/core/23-commitment/types/utils.go index e2c4317a9fc..2ad3bcf57dc 100644 --- a/modules/core/23-commitment/types/utils.go +++ b/modules/core/23-commitment/types/utils.go @@ -1,7 +1,7 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ics23 "github.com/cosmos/ics23/go" crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) @@ -9,7 +9,7 @@ import ( // ConvertProofs converts crypto.ProofOps into MerkleProof func ConvertProofs(tmProof *crypto.ProofOps) (MerkleProof, error) { if tmProof == nil { - return MerkleProof{}, sdkerrors.Wrapf(ErrInvalidMerkleProof, "tendermint proof is nil") + return MerkleProof{}, errorsmod.Wrapf(ErrInvalidMerkleProof, "tendermint proof is nil") } // Unmarshal all proof ops to CommitmentProof proofs := make([]*ics23.CommitmentProof, len(tmProof.Ops)) @@ -17,7 +17,7 @@ func ConvertProofs(tmProof *crypto.ProofOps) (MerkleProof, error) { var p ics23.CommitmentProof err := p.Unmarshal(op.Data) if err != nil || p.Proof == nil { - return MerkleProof{}, sdkerrors.Wrapf(ErrInvalidMerkleProof, "could not unmarshal proof op into CommitmentProof at index %d: %v", i, err) + return MerkleProof{}, errorsmod.Wrapf(ErrInvalidMerkleProof, "could not unmarshal proof op into CommitmentProof at index %d: %v", i, err) } proofs[i] = &p } diff --git a/modules/core/24-host/errors.go b/modules/core/24-host/errors.go index fe8129bde86..742f1779311 100644 --- a/modules/core/24-host/errors.go +++ b/modules/core/24-host/errors.go @@ -1,7 +1,7 @@ package host import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // SubModuleName defines the ICS 24 host @@ -9,7 +9,7 @@ const SubModuleName = "host" // IBC client sentinel errors var ( - ErrInvalidID = sdkerrors.Register(SubModuleName, 2, "invalid identifier") - ErrInvalidPath = sdkerrors.Register(SubModuleName, 3, "invalid path") - ErrInvalidPacket = sdkerrors.Register(SubModuleName, 4, "invalid packet") + ErrInvalidID = errorsmod.Register(SubModuleName, 2, "invalid identifier") + ErrInvalidPath = errorsmod.Register(SubModuleName, 3, "invalid path") + ErrInvalidPacket = errorsmod.Register(SubModuleName, 4, "invalid packet") ) diff --git a/modules/core/24-host/parse.go b/modules/core/24-host/parse.go index ad8f8af90e9..81074bbfcca 100644 --- a/modules/core/24-host/parse.go +++ b/modules/core/24-host/parse.go @@ -4,7 +4,7 @@ import ( "strconv" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // ParseIdentifier parses the sequence from the identifier using the provided prefix. This function @@ -12,22 +12,22 @@ import ( // are required to use this format. func ParseIdentifier(identifier, prefix string) (uint64, error) { if !strings.HasPrefix(identifier, prefix) { - return 0, sdkerrors.Wrapf(ErrInvalidID, "identifier doesn't contain prefix `%s`", prefix) + return 0, errorsmod.Wrapf(ErrInvalidID, "identifier doesn't contain prefix `%s`", prefix) } splitStr := strings.Split(identifier, prefix) if len(splitStr) != 2 { - return 0, sdkerrors.Wrapf(ErrInvalidID, "identifier must be in format: `%s{N}`", prefix) + return 0, errorsmod.Wrapf(ErrInvalidID, "identifier must be in format: `%s{N}`", prefix) } // sanity check if splitStr[0] != "" { - return 0, sdkerrors.Wrapf(ErrInvalidID, "identifier must begin with prefix %s", prefix) + return 0, errorsmod.Wrapf(ErrInvalidID, "identifier must begin with prefix %s", prefix) } sequence, err := strconv.ParseUint(splitStr[1], 10, 64) if err != nil { - return 0, sdkerrors.Wrap(err, "failed to parse identifier sequence") + return 0, errorsmod.Wrap(err, "failed to parse identifier sequence") } return sequence, nil } @@ -48,19 +48,19 @@ func MustParseClientStatePath(path string) string { func parseClientStatePath(path string) (string, error) { split := strings.Split(path, "/") if len(split) != 3 { - return "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse client state path %s", path) + return "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse client state path %s", path) } if split[0] != string(KeyClientStorePrefix) { - return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not begin with client store prefix: expected %s, got %s", KeyClientStorePrefix, split[0]) + return "", errorsmod.Wrapf(ErrInvalidPath, "path does not begin with client store prefix: expected %s, got %s", KeyClientStorePrefix, split[0]) } if split[2] != KeyClientState { - return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not end with client state key: expected %s, got %s", KeyClientState, split[2]) + return "", errorsmod.Wrapf(ErrInvalidPath, "path does not end with client state key: expected %s, got %s", KeyClientState, split[2]) } if strings.TrimSpace(split[1]) == "" { - return "", sdkerrors.Wrap(ErrInvalidPath, "clientID is empty") + return "", errorsmod.Wrap(ErrInvalidPath, "clientID is empty") } return split[1], nil @@ -71,7 +71,7 @@ func parseClientStatePath(path string) (string, error) { func ParseConnectionPath(path string) (string, error) { split := strings.Split(path, "/") if len(split) != 2 { - return "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse connection path %s", path) + return "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse connection path %s", path) } return split[1], nil @@ -82,11 +82,11 @@ func ParseConnectionPath(path string) (string, error) { func ParseChannelPath(path string) (string, string, error) { split := strings.Split(path, "/") if len(split) < 5 { - return "", "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) + return "", "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) } if split[1] != KeyPortPrefix || split[3] != KeyChannelPrefix { - return "", "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) + return "", "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) } return split[2], split[4], nil diff --git a/modules/core/24-host/validate.go b/modules/core/24-host/validate.go index 23341cec543..e6219d99b40 100644 --- a/modules/core/24-host/validate.go +++ b/modules/core/24-host/validate.go @@ -4,7 +4,7 @@ import ( "regexp" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // DefaultMaxCharacterLength defines the default maximum character length used @@ -38,19 +38,19 @@ type ValidateFn func(string) error func defaultIdentifierValidator(id string, min, max int) error { if strings.TrimSpace(id) == "" { - return sdkerrors.Wrap(ErrInvalidID, "identifier cannot be blank") + return errorsmod.Wrap(ErrInvalidID, "identifier cannot be blank") } // valid id MUST NOT contain "/" separator if strings.Contains(id, "/") { - return sdkerrors.Wrapf(ErrInvalidID, "identifier %s cannot contain separator '/'", id) + return errorsmod.Wrapf(ErrInvalidID, "identifier %s cannot contain separator '/'", id) } // valid id must fit the length requirements if len(id) < min || len(id) > max { - return sdkerrors.Wrapf(ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", id, len(id), min, max) + return errorsmod.Wrapf(ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", id, len(id), min, max) } // valid id must contain only lower alphabetic characters if !IsValidID(id) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidID, "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", id, @@ -95,13 +95,13 @@ func NewPathValidator(idValidator ValidateFn) ValidateFn { return func(path string) error { pathArr := strings.Split(path, "/") if len(pathArr) > 0 && pathArr[0] == path { - return sdkerrors.Wrapf(ErrInvalidPath, "path %s doesn't contain any separator '/'", path) + return errorsmod.Wrapf(ErrInvalidPath, "path %s doesn't contain any separator '/'", path) } for _, p := range pathArr { // a path beginning or ending in a separator returns empty string elements. if p == "" { - return sdkerrors.Wrapf(ErrInvalidPath, "path %s cannot begin or end with '/'", path) + return errorsmod.Wrapf(ErrInvalidPath, "path %s cannot begin or end with '/'", path) } if err := idValidator(p); err != nil { @@ -109,7 +109,7 @@ func NewPathValidator(idValidator ValidateFn) ValidateFn { } // Each path element must either be a valid identifier or constant number if err := defaultIdentifierValidator(p, 1, DefaultMaxCharacterLength); err != nil { - return sdkerrors.Wrapf(err, "path %s contains an invalid identifier: '%s'", path, p) + return errorsmod.Wrapf(err, "path %s contains an invalid identifier: '%s'", path, p) } } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 1fd8ec8dcdb..2bf694e1e2f 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -3,10 +3,10 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -102,7 +102,7 @@ func (k Keeper) ConnectionOpenInit(goCtx context.Context, msg *connectiontypes.M ctx := sdk.UnwrapSDKContext(goCtx) if _, err := k.ConnectionKeeper.ConnOpenInit(ctx, msg.ClientId, msg.Counterparty, msg.Version, msg.DelayPeriod); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open init failed") + return nil, errorsmod.Wrap(err, "connection handshake open init failed") } return &connectiontypes.MsgConnectionOpenInitResponse{}, nil @@ -122,7 +122,7 @@ func (k Keeper) ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.Ms connectiontypes.ProtoVersionsToExported(msg.CounterpartyVersions), msg.ProofInit, msg.ProofClient, msg.ProofConsensus, msg.ProofHeight, msg.ConsensusHeight, ); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open try failed") + return nil, errorsmod.Wrap(err, "connection handshake open try failed") } return &connectiontypes.MsgConnectionOpenTryResponse{}, nil @@ -141,7 +141,7 @@ func (k Keeper) ConnectionOpenAck(goCtx context.Context, msg *connectiontypes.Ms msg.ProofTry, msg.ProofClient, msg.ProofConsensus, msg.ProofHeight, msg.ConsensusHeight, ); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open ack failed") + return nil, errorsmod.Wrap(err, "connection handshake open ack failed") } return &connectiontypes.MsgConnectionOpenAckResponse{}, nil @@ -154,7 +154,7 @@ func (k Keeper) ConnectionOpenConfirm(goCtx context.Context, msg *connectiontype if err := k.ConnectionKeeper.ConnOpenConfirm( ctx, msg.ConnectionId, msg.ProofAck, msg.ProofHeight, ); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open confirm failed") + return nil, errorsmod.Wrap(err, "connection handshake open confirm failed") } return &connectiontypes.MsgConnectionOpenConfirmResponse{}, nil @@ -169,15 +169,15 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan // Lookup module by port capability module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortId) if err != nil { - ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification @@ -186,15 +186,15 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan portCap, msg.Channel.Counterparty, msg.Channel.Version, ) if err != nil { - ctx.Logger().Error("channel open init callback failed", "error", sdkerrors.Wrap(err, "channel handshake open init failed")) - return nil, sdkerrors.Wrap(err, "channel handshake open init failed") + ctx.Logger().Error("channel open init callback failed", "error", errorsmod.Wrap(err, "channel handshake open init failed")) + return nil, errorsmod.Wrap(err, "channel handshake open init failed") } // Perform application logic callback version, err := cbs.OnChanOpenInit(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, cap, msg.Channel.Counterparty, msg.Channel.Version) if err != nil { ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "channel-id", channelID, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open init callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) + return nil, errorsmod.Wrapf(err, "channel open init callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) } // Write channel into state @@ -217,15 +217,15 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann // Lookup module by port capability module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortId) if err != nil { - ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification @@ -233,15 +233,15 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann portCap, msg.Channel.Counterparty, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight, ) if err != nil { - ctx.Logger().Error("channel open try callback failed", "error", sdkerrors.Wrap(err, "channel handshake open try failed")) - return nil, sdkerrors.Wrap(err, "channel handshake open try failed") + ctx.Logger().Error("channel open try callback failed", "error", errorsmod.Wrap(err, "channel handshake open try failed")) + return nil, errorsmod.Wrap(err, "channel handshake open try failed") } // Perform application logic callback version, err := cbs.OnChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, cap, msg.Channel.Counterparty, msg.CounterpartyVersion) if err != nil { ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "channel-id", channelID, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open try callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) + return nil, errorsmod.Wrapf(err, "channel open try callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) } // Write channel into state @@ -264,15 +264,15 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification @@ -280,7 +280,7 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann ctx, msg.PortId, msg.ChannelId, cap, msg.CounterpartyVersion, msg.CounterpartyChannelId, msg.ProofTry, msg.ProofHeight, ); err != nil { ctx.Logger().Error("channel open ack callback failed", "error", err.Error()) - return nil, sdkerrors.Wrap(err, "channel handshake open ack failed") + return nil, errorsmod.Wrap(err, "channel handshake open ack failed") } // Write channel into state @@ -289,7 +289,7 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann // Perform application logic callback if err = cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelId, msg.CounterpartyVersion); err != nil { ctx.Logger().Error("channel handshake open ack callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open ack callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel open ack callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } ctx.Logger().Info("channel open ack callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -306,21 +306,21 @@ func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgC // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification if err = k.ChannelKeeper.ChanOpenConfirm(ctx, msg.PortId, msg.ChannelId, cap, msg.ProofAck, msg.ProofHeight); err != nil { - ctx.Logger().Error("channel open confirm callback failed", "error", sdkerrors.Wrap(err, "channel handshake open confirm failed")) - return nil, sdkerrors.Wrap(err, "channel handshake open confirm failed") + ctx.Logger().Error("channel open confirm callback failed", "error", errorsmod.Wrap(err, "channel handshake open confirm failed")) + return nil, errorsmod.Wrap(err, "channel handshake open confirm failed") } // Write channel into state @@ -329,7 +329,7 @@ func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgC // Perform application logic callback if err = cbs.OnChanOpenConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel handshake open confirm callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel open confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } ctx.Logger().Info("channel open confirm callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -343,26 +343,26 @@ func (k Keeper) ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgCha // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } if err = cbs.OnChanCloseInit(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel close init callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel close init callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } err = k.ChannelKeeper.ChanCloseInit(ctx, msg.PortId, msg.ChannelId, cap) if err != nil { ctx.Logger().Error("channel handshake close init callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrap(err, "channel handshake close init failed") + return nil, errorsmod.Wrap(err, "channel handshake close init failed") } ctx.Logger().Info("channel close init callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -377,26 +377,26 @@ func (k Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Msg // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } if err = cbs.OnChanCloseConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel close confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel close confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } err = k.ChannelKeeper.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, cap, msg.ProofInit, msg.ProofHeight) if err != nil { ctx.Logger().Error("channel handshake close confirm callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrap(err, "channel handshake close confirm failed") + return nil, errorsmod.Wrap(err, "channel handshake close confirm failed") } ctx.Logger().Info("channel close confirm callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -410,22 +410,22 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("receive packet failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("receive packet failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.DestinationPort, msg.Packet.DestinationChannel) if err != nil { - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -442,8 +442,8 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke // no-ops do not need event emission as they will be ignored return &channeltypes.MsgRecvPacketResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "receive packet verification failed")) - return nil, sdkerrors.Wrap(err, "receive packet verification failed") + ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "receive packet verification failed")) + return nil, errorsmod.Wrap(err, "receive packet verification failed") } // Perform application logic callback @@ -493,22 +493,22 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("timeout failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("timeout failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -525,15 +525,15 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c // no-ops do not need event emission as they will be ignored return &channeltypes.MsgTimeoutResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout packet verification failed")) - return nil, sdkerrors.Wrap(err, "timeout packet verification failed") + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet verification failed")) + return nil, errorsmod.Wrap(err, "timeout packet verification failed") } // Perform application logic callback err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) if err != nil { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout packet callback failed")) - return nil, sdkerrors.Wrap(err, "timeout packet callback failed") + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet callback failed")) + return nil, errorsmod.Wrap(err, "timeout packet callback failed") } // Delete packet commitment @@ -566,22 +566,22 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("timeout on close failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("timeout on close failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -598,8 +598,8 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo // no-ops do not need event emission as they will be ignored return &channeltypes.MsgTimeoutOnCloseResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout on close packet verification failed")) - return nil, sdkerrors.Wrap(err, "timeout on close packet verification failed") + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout on close packet verification failed")) + return nil, errorsmod.Wrap(err, "timeout on close packet verification failed") } // Perform application logic callback @@ -608,8 +608,8 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo // application logic callback. err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) if err != nil { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout packet callback failed")) - return nil, sdkerrors.Wrap(err, "timeout packet callback failed") + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet callback failed")) + return nil, errorsmod.Wrap(err, "timeout packet callback failed") } // Delete packet commitment @@ -642,22 +642,22 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("acknowledgement failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("acknowledgement failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -674,15 +674,15 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn // no-ops do not need event emission as they will be ignored return &channeltypes.MsgAcknowledgementResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "acknowledge packet verification failed")) - return nil, sdkerrors.Wrap(err, "acknowledge packet verification failed") + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "acknowledge packet verification failed")) + return nil, errorsmod.Wrap(err, "acknowledge packet verification failed") } // Perform application logic callback err = cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement, relayer) if err != nil { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "acknowledge packet callback failed")) - return nil, sdkerrors.Wrap(err, "acknowledge packet callback failed") + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "acknowledge packet callback failed")) + return nil, errorsmod.Wrap(err, "acknowledge packet callback failed") } defer func() { diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 24346407da7..2c316dacaec 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -3,12 +3,13 @@ package solomachine import ( "reflect" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -63,10 +64,10 @@ func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) // Validate performs basic validation of the client state fields. func (cs ClientState) Validate() error { if cs.Sequence == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "sequence cannot be 0") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "sequence cannot be 0") } if cs.ConsensusState == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be nil") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be nil") } return cs.ConsensusState.ValidateBasic() } @@ -80,7 +81,7 @@ func (cs ClientState) ZeroCustomFields() exported.ClientState { // sets the client state in the provided client store. func (cs ClientState) Initialize(_ sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, consState exported.ConsensusState) error { if !reflect.DeepEqual(cs.ConsensusState, consState) { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "consensus state in initial client does not equal initial consensus state. expected: %s, got: %s", + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "consensus state in initial client does not equal initial consensus state. expected: %s, got: %s", cs.ConsensusState, consState) } @@ -99,7 +100,7 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientState, _ exported.ConsensusState, _, _ []byte, ) error { - return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade solomachine client") + return errorsmod.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade solomachine client") } // VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the latest sequence. @@ -122,11 +123,11 @@ func (cs *ClientState) VerifyMembership( merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if merklePath.Empty() { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "path is empty") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "path is empty") } signBytes := &SignBytes{ @@ -172,7 +173,7 @@ func (cs *ClientState) VerifyNonMembership( merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } signBytes := &SignBytes{ @@ -208,17 +209,17 @@ func produceVerificationArgs( proof []byte, ) (cryptotypes.PubKey, signing.SignatureData, uint64, uint64, error) { if proof == nil { - return nil, nil, 0, 0, sdkerrors.Wrap(ErrInvalidProof, "proof cannot be empty") + return nil, nil, 0, 0, errorsmod.Wrap(ErrInvalidProof, "proof cannot be empty") } var timestampedSigData TimestampedSignatureData if err := cdc.Unmarshal(proof, ×tampedSigData); err != nil { - return nil, nil, 0, 0, sdkerrors.Wrapf(err, "failed to unmarshal proof into type %T", timestampedSigData) + return nil, nil, 0, 0, errorsmod.Wrapf(err, "failed to unmarshal proof into type %T", timestampedSigData) } timestamp := timestampedSigData.Timestamp if len(timestampedSigData.SignatureData) == 0 { - return nil, nil, 0, 0, sdkerrors.Wrap(ErrInvalidProof, "signature data cannot be empty") + return nil, nil, 0, 0, errorsmod.Wrap(ErrInvalidProof, "signature data cannot be empty") } sigData, err := UnmarshalSignatureData(cdc, timestampedSigData.SignatureData) @@ -227,7 +228,7 @@ func produceVerificationArgs( } if cs.ConsensusState.GetTimestamp() > timestamp { - return nil, nil, 0, 0, sdkerrors.Wrapf(ErrInvalidProof, "the consensus state timestamp is greater than the signature timestamp (%d >= %d)", cs.ConsensusState.GetTimestamp(), timestamp) + return nil, nil, 0, 0, errorsmod.Wrapf(ErrInvalidProof, "the consensus state timestamp is greater than the signature timestamp (%d >= %d)", cs.ConsensusState.GetTimestamp(), timestamp) } sequence := cs.GetLatestHeight().GetRevisionHeight() diff --git a/modules/light-clients/06-solomachine/codec.go b/modules/light-clients/06-solomachine/codec.go index 591c94c51c4..e18cd8b563c 100644 --- a/modules/light-clients/06-solomachine/codec.go +++ b/modules/light-clients/06-solomachine/codec.go @@ -1,9 +1,9 @@ package solomachine import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -33,7 +33,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { func UnmarshalSignatureData(cdc codec.BinaryCodec, data []byte) (signing.SignatureData, error) { protoSigData := &signing.SignatureDescriptor_Data{} if err := cdc.Unmarshal(data, protoSigData); err != nil { - return nil, sdkerrors.Wrapf(err, "failed to unmarshal proof into type %T", protoSigData) + return nil, errorsmod.Wrapf(err, "failed to unmarshal proof into type %T", protoSigData) } sigData := signing.SignatureDataFromProto(protoSigData) diff --git a/modules/light-clients/06-solomachine/consensus_state.go b/modules/light-clients/06-solomachine/consensus_state.go index 9aadc567082..ed3bfa55d37 100644 --- a/modules/light-clients/06-solomachine/consensus_state.go +++ b/modules/light-clients/06-solomachine/consensus_state.go @@ -3,8 +3,8 @@ package solomachine import ( "strings" + errorsmod "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -27,12 +27,12 @@ func (cs ConsensusState) GetTimestamp() uint64 { // is not a PubKey. func (cs ConsensusState) GetPubKey() (cryptotypes.PubKey, error) { if cs.PublicKey == nil { - return nil, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey cannot be nil") + return nil, errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey cannot be nil") } publicKey, ok := cs.PublicKey.GetCachedValue().(cryptotypes.PubKey) if !ok { - return nil, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey is not cryptotypes.PubKey") + return nil, errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey is not cryptotypes.PubKey") } return publicKey, nil @@ -41,15 +41,15 @@ func (cs ConsensusState) GetPubKey() (cryptotypes.PubKey, error) { // ValidateBasic defines basic validation for the solo machine consensus state. func (cs ConsensusState) ValidateBasic() error { if cs.Timestamp == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be 0") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be 0") } if cs.Diversifier != "" && strings.TrimSpace(cs.Diversifier) == "" { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "diversifier cannot contain only spaces") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "diversifier cannot contain only spaces") } publicKey, err := cs.GetPubKey() if err != nil || publicKey == nil || len(publicKey.Bytes()) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "public key cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "public key cannot be empty") } return nil diff --git a/modules/light-clients/06-solomachine/errors.go b/modules/light-clients/06-solomachine/errors.go index 5f5726d42da..91c22286241 100644 --- a/modules/light-clients/06-solomachine/errors.go +++ b/modules/light-clients/06-solomachine/errors.go @@ -1,13 +1,13 @@ package solomachine import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) var ( - ErrInvalidHeader = sdkerrors.Register(ModuleName, 2, "invalid header") - ErrInvalidSequence = sdkerrors.Register(ModuleName, 3, "invalid sequence") - ErrInvalidSignatureAndData = sdkerrors.Register(ModuleName, 4, "invalid signature and data") - ErrSignatureVerificationFailed = sdkerrors.Register(ModuleName, 5, "signature verification failed") - ErrInvalidProof = sdkerrors.Register(ModuleName, 6, "invalid solo machine proof") + ErrInvalidHeader = errorsmod.Register(ModuleName, 2, "invalid header") + ErrInvalidSequence = errorsmod.Register(ModuleName, 3, "invalid sequence") + ErrInvalidSignatureAndData = errorsmod.Register(ModuleName, 4, "invalid signature and data") + ErrSignatureVerificationFailed = errorsmod.Register(ModuleName, 5, "signature verification failed") + ErrInvalidProof = errorsmod.Register(ModuleName, 6, "invalid solo machine proof") ) diff --git a/modules/light-clients/06-solomachine/header.go b/modules/light-clients/06-solomachine/header.go index badfa08c62c..e9dd883f2fd 100644 --- a/modules/light-clients/06-solomachine/header.go +++ b/modules/light-clients/06-solomachine/header.go @@ -3,8 +3,8 @@ package solomachine import ( "strings" + errorsmod "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -25,12 +25,12 @@ func (Header) ClientType() string { // is not a PubKey. func (h Header) GetPubKey() (cryptotypes.PubKey, error) { if h.NewPublicKey == nil { - return nil, sdkerrors.Wrap(ErrInvalidHeader, "header NewPublicKey cannot be nil") + return nil, errorsmod.Wrap(ErrInvalidHeader, "header NewPublicKey cannot be nil") } publicKey, ok := h.NewPublicKey.GetCachedValue().(cryptotypes.PubKey) if !ok { - return nil, sdkerrors.Wrap(ErrInvalidHeader, "header NewPublicKey is not cryptotypes.PubKey") + return nil, errorsmod.Wrap(ErrInvalidHeader, "header NewPublicKey is not cryptotypes.PubKey") } return publicKey, nil @@ -40,20 +40,20 @@ func (h Header) GetPubKey() (cryptotypes.PubKey, error) { // been initialized. func (h Header) ValidateBasic() error { if h.Timestamp == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "timestamp cannot be zero") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "timestamp cannot be zero") } if h.NewDiversifier != "" && strings.TrimSpace(h.NewDiversifier) == "" { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "diversifier cannot contain only spaces") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "diversifier cannot contain only spaces") } if len(h.Signature) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "signature cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "signature cannot be empty") } newPublicKey, err := h.GetPubKey() if err != nil || newPublicKey == nil || len(newPublicKey.Bytes()) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "new public key cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "new public key cannot be empty") } return nil diff --git a/modules/light-clients/06-solomachine/misbehaviour.go b/modules/light-clients/06-solomachine/misbehaviour.go index 6075c63f8b6..8533f0b4fb3 100644 --- a/modules/light-clients/06-solomachine/misbehaviour.go +++ b/modules/light-clients/06-solomachine/misbehaviour.go @@ -3,7 +3,7 @@ package solomachine import ( "bytes" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -24,26 +24,26 @@ func (misbehaviour Misbehaviour) Type() string { // ValidateBasic implements Misbehaviour interface. func (misbehaviour Misbehaviour) ValidateBasic() error { if misbehaviour.Sequence == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "sequence cannot be 0") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "sequence cannot be 0") } if err := misbehaviour.SignatureOne.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "signature one failed basic validation") + return errorsmod.Wrap(err, "signature one failed basic validation") } if err := misbehaviour.SignatureTwo.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "signature two failed basic validation") + return errorsmod.Wrap(err, "signature two failed basic validation") } // misbehaviour signatures cannot be identical. if bytes.Equal(misbehaviour.SignatureOne.Signature, misbehaviour.SignatureTwo.Signature) { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signatures cannot be equal") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signatures cannot be equal") } // message data signed cannot be identical if both paths are the same. if bytes.Equal(misbehaviour.SignatureOne.Path, misbehaviour.SignatureTwo.Path) && bytes.Equal(misbehaviour.SignatureOne.Data, misbehaviour.SignatureTwo.Data) { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signature data must be signed over different messages") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signature data must be signed over different messages") } return nil @@ -52,16 +52,16 @@ func (misbehaviour Misbehaviour) ValidateBasic() error { // ValidateBasic ensures that the signature and data fields are non-empty. func (sd SignatureAndData) ValidateBasic() error { if len(sd.Signature) == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "signature cannot be empty") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "signature cannot be empty") } if len(sd.Data) == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "data for signature cannot be empty") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "data for signature cannot be empty") } if len(sd.Path) == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "path for signature cannot be empty") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "path for signature cannot be empty") } if sd.Timestamp == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "timestamp cannot be 0") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "timestamp cannot be 0") } return nil diff --git a/modules/light-clients/06-solomachine/misbehaviour_handle.go b/modules/light-clients/06-solomachine/misbehaviour_handle.go index 1f4aec41489..7e8b3822410 100644 --- a/modules/light-clients/06-solomachine/misbehaviour_handle.go +++ b/modules/light-clients/06-solomachine/misbehaviour_handle.go @@ -3,8 +3,8 @@ package solomachine import ( "github.com/cosmos/cosmos-sdk/codec" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -24,12 +24,12 @@ func (cs ClientState) verifyMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, // misbehaviour.ValidateBasic which is called by the 02-client keeper. // verify first signature if err := cs.verifySignatureAndData(cdc, misbehaviour, misbehaviour.SignatureOne); err != nil { - return sdkerrors.Wrap(err, "failed to verify signature one") + return errorsmod.Wrap(err, "failed to verify signature one") } // verify second signature if err := cs.verifySignatureAndData(cdc, misbehaviour, misbehaviour.SignatureTwo); err != nil { - return sdkerrors.Wrap(err, "failed to verify signature two") + return errorsmod.Wrap(err, "failed to verify signature two") } return nil diff --git a/modules/light-clients/06-solomachine/proof.go b/modules/light-clients/06-solomachine/proof.go index 386830340cf..aab15c17d3c 100644 --- a/modules/light-clients/06-solomachine/proof.go +++ b/modules/light-clients/06-solomachine/proof.go @@ -1,9 +1,9 @@ package solomachine import ( + errorsmod "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" ) @@ -17,7 +17,7 @@ func VerifySignature(pubKey cryptotypes.PubKey, signBytes []byte, sigData signin case multisig.PubKey: data, ok := sigData.(*signing.MultiSignatureData) if !ok { - return sdkerrors.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.MultiSignatureData)(nil), data) + return errorsmod.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.MultiSignatureData)(nil), data) } // The function supplied fulfills the VerifyMultisignature interface. No special @@ -31,7 +31,7 @@ func VerifySignature(pubKey cryptotypes.PubKey, signBytes []byte, sigData signin default: data, ok := sigData.(*signing.SingleSignatureData) if !ok { - return sdkerrors.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.SingleSignatureData)(nil), data) + return errorsmod.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.SingleSignatureData)(nil), data) } if !pubKey.VerifySignature(signBytes, data.Signature) { diff --git a/modules/light-clients/06-solomachine/proposal_handle.go b/modules/light-clients/06-solomachine/proposal_handle.go index 86276180147..2e6fdfd7ed8 100644 --- a/modules/light-clients/06-solomachine/proposal_handle.go +++ b/modules/light-clients/06-solomachine/proposal_handle.go @@ -3,9 +3,9 @@ package solomachine import ( "reflect" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -24,21 +24,21 @@ func (cs ClientState) CheckSubstituteAndUpdateState( ) error { substituteClientState, ok := substituteClient.(*ClientState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "substitute client state type %T, expected %T", substituteClient, &ClientState{}) + return errorsmod.Wrapf(clienttypes.ErrInvalidClientType, "substitute client state type %T, expected %T", substituteClient, &ClientState{}) } subjectPublicKey, err := cs.ConsensusState.GetPubKey() if err != nil { - return sdkerrors.Wrap(err, "failed to get consensus public key") + return errorsmod.Wrap(err, "failed to get consensus public key") } substitutePublicKey, err := substituteClientState.ConsensusState.GetPubKey() if err != nil { - return sdkerrors.Wrap(err, "failed to get substitute client public key") + return errorsmod.Wrap(err, "failed to get substitute client public key") } if reflect.DeepEqual(subjectPublicKey, substitutePublicKey) { - return sdkerrors.Wrapf(clienttypes.ErrInvalidHeader, "subject and substitute have the same public key") + return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "subject and substitute have the same public key") } // update to substitute parameters diff --git a/modules/light-clients/06-solomachine/update.go b/modules/light-clients/06-solomachine/update.go index 9f8078f4cb2..8d044e0a2e9 100644 --- a/modules/light-clients/06-solomachine/update.go +++ b/modules/light-clients/06-solomachine/update.go @@ -3,9 +3,9 @@ package solomachine import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -21,14 +21,14 @@ func (cs ClientState) VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec case *Misbehaviour: return cs.verifyMisbehaviour(ctx, cdc, clientStore, msg) default: - return sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type of %T or %T, got type %T", Header{}, Misbehaviour{}, msg) + return errorsmod.Wrapf(clienttypes.ErrInvalidClientType, "expected type of %T or %T, got type %T", Header{}, Misbehaviour{}, msg) } } func (cs ClientState) verifyHeader(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, header *Header) error { // assert update timestamp is not less than current consensus state timestamp if header.Timestamp < cs.ConsensusState.Timestamp { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( clienttypes.ErrInvalidHeader, "header timestamp is less than to the consensus state timestamp (%d < %d)", header.Timestamp, cs.ConsensusState.Timestamp, ) @@ -69,7 +69,7 @@ func (cs ClientState) verifyHeader(ctx sdk.Context, cdc codec.BinaryCodec, clien } if err := VerifySignature(publicKey, data, sigData); err != nil { - return sdkerrors.Wrap(ErrInvalidHeader, err.Error()) + return errorsmod.Wrap(ErrInvalidHeader, err.Error()) } return nil diff --git a/modules/light-clients/07-tendermint/client_state.go b/modules/light-clients/07-tendermint/client_state.go index 9a74834a299..78b947124eb 100644 --- a/modules/light-clients/07-tendermint/client_state.go +++ b/modules/light-clients/07-tendermint/client_state.go @@ -4,13 +4,14 @@ import ( "strings" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ics23 "github.com/cosmos/ics23/go" "github.com/tendermint/tendermint/light" tmtypes "github.com/tendermint/tendermint/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -63,7 +64,7 @@ func (cs ClientState) GetTimestampAtHeight( // get consensus state at height from clientStore to check for expiry consState, found := GetConsensusState(clientStore, cdc, height) if !found { - return 0, sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "height (%s)", height) + return 0, errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "height (%s)", height) } return consState.GetTimestamp(), nil } @@ -110,7 +111,7 @@ func (cs ClientState) IsExpired(latestTimestamp, now time.Time) bool { // Validate performs a basic validation of the client state fields. func (cs ClientState) Validate() error { if strings.TrimSpace(cs.ChainId) == "" { - return sdkerrors.Wrap(ErrInvalidChainID, "chain id cannot be empty string") + return errorsmod.Wrap(ErrInvalidChainID, "chain id cannot be empty string") } // NOTE: the value of tmtypes.MaxChainIDLen may change in the future. @@ -119,49 +120,49 @@ func (cs ClientState) Validate() error { // and the tendermint version used by this light client. // https://github.com/cosmos/ibc-go/issues/177 if len(cs.ChainId) > tmtypes.MaxChainIDLen { - return sdkerrors.Wrapf(ErrInvalidChainID, "chainID is too long; got: %d, max: %d", len(cs.ChainId), tmtypes.MaxChainIDLen) + return errorsmod.Wrapf(ErrInvalidChainID, "chainID is too long; got: %d, max: %d", len(cs.ChainId), tmtypes.MaxChainIDLen) } if err := light.ValidateTrustLevel(cs.TrustLevel.ToTendermint()); err != nil { return err } if cs.TrustingPeriod <= 0 { - return sdkerrors.Wrap(ErrInvalidTrustingPeriod, "trusting period must be greater than zero") + return errorsmod.Wrap(ErrInvalidTrustingPeriod, "trusting period must be greater than zero") } if cs.UnbondingPeriod <= 0 { - return sdkerrors.Wrap(ErrInvalidUnbondingPeriod, "unbonding period must be greater than zero") + return errorsmod.Wrap(ErrInvalidUnbondingPeriod, "unbonding period must be greater than zero") } if cs.MaxClockDrift <= 0 { - return sdkerrors.Wrap(ErrInvalidMaxClockDrift, "max clock drift must be greater than zero") + return errorsmod.Wrap(ErrInvalidMaxClockDrift, "max clock drift must be greater than zero") } // the latest height revision number must match the chain id revision number if cs.LatestHeight.RevisionNumber != clienttypes.ParseChainID(cs.ChainId) { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "latest height revision number must match chain id revision number (%d != %d)", cs.LatestHeight.RevisionNumber, clienttypes.ParseChainID(cs.ChainId)) } if cs.LatestHeight.RevisionHeight == 0 { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "tendermint client's latest height revision height cannot be zero") + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "tendermint client's latest height revision height cannot be zero") } if cs.TrustingPeriod >= cs.UnbondingPeriod { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidTrustingPeriod, "trusting period (%s) should be < unbonding period (%s)", cs.TrustingPeriod, cs.UnbondingPeriod, ) } if cs.ProofSpecs == nil { - return sdkerrors.Wrap(ErrInvalidProofSpecs, "proof specs cannot be nil for tm client") + return errorsmod.Wrap(ErrInvalidProofSpecs, "proof specs cannot be nil for tm client") } for i, spec := range cs.ProofSpecs { if spec == nil { - return sdkerrors.Wrapf(ErrInvalidProofSpecs, "proof spec cannot be nil at index: %d", i) + return errorsmod.Wrapf(ErrInvalidProofSpecs, "proof spec cannot be nil at index: %d", i) } } // UpgradePath may be empty, but if it isn't, each key must be non-empty for i, k := range cs.UpgradePath { if strings.TrimSpace(k) == "" { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "key in upgrade path at index %d cannot be empty", i) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "key in upgrade path at index %d cannot be empty", i) } } @@ -193,7 +194,7 @@ func (cs ClientState) ZeroCustomFields() exported.ClientState { func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, consState exported.ConsensusState) error { consensusState, ok := consState.(*ConsensusState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T", + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T", &ConsensusState{}, consState) } @@ -219,16 +220,16 @@ func (cs ClientState) VerifyMembership( value []byte, ) error { if height.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be non-zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "proof height must be non-zero") } if len(proof) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if cs.GetLatestHeight().LT(height) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "client state height < proof height (%d < %d), please ensure the client has been updated", cs.GetLatestHeight(), height, ) } @@ -239,17 +240,17 @@ func (cs ClientState) VerifyMembership( var merkleProof commitmenttypes.MerkleProof if err := cdc.Unmarshal(proof, &merkleProof); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") } if err := merkleProof.VerifyMembership(cs.ProofSpecs, consensusState.GetRoot(), merklePath, value); err != nil { @@ -273,16 +274,16 @@ func (cs ClientState) VerifyNonMembership( path exported.Path, ) error { if height.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be non-zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "proof height must be non-zero") } if len(proof) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if cs.GetLatestHeight().LT(height) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "client state height < proof height (%d < %d), please ensure the client has been updated", cs.GetLatestHeight(), height, ) } @@ -293,17 +294,17 @@ func (cs ClientState) VerifyNonMembership( var merkleProof commitmenttypes.MerkleProof if err := cdc.Unmarshal(proof, &merkleProof); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") } if err := merkleProof.VerifyNonMembership(cs.ProofSpecs, consensusState.GetRoot(), merklePath); err != nil { @@ -320,7 +321,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // check that executing chain's timestamp has passed consensusState's processed time + delay time period processedTime, ok := GetProcessedTime(store, proofHeight) if !ok { - return sdkerrors.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight) + return errorsmod.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight) } currentTimestamp := uint64(ctx.BlockTime().UnixNano()) @@ -328,7 +329,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // NOTE: delay time period is inclusive, so if currentTimestamp is validTime, then we return no error if currentTimestamp < validTime { - return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until time: %d, current time: %d", + return errorsmod.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until time: %d, current time: %d", validTime, currentTimestamp) } @@ -338,7 +339,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // check that executing chain's height has passed consensusState's processed height + delay block period processedHeight, ok := GetProcessedHeight(store, proofHeight) if !ok { - return sdkerrors.Wrapf(ErrProcessedHeightNotFound, "processed height not found for height: %s", proofHeight) + return errorsmod.Wrapf(ErrProcessedHeightNotFound, "processed height not found for height: %s", proofHeight) } currentHeight := clienttypes.GetSelfHeight(ctx) @@ -346,7 +347,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // NOTE: delay block period is inclusive, so if currentHeight is validHeight, then we return no error if currentHeight.LT(validHeight) { - return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until height: %s, current height: %s", + return errorsmod.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until height: %s, current height: %s", validHeight, currentHeight) } } diff --git a/modules/light-clients/07-tendermint/consensus_state.go b/modules/light-clients/07-tendermint/consensus_state.go index 6656bb5ad4c..065c2dfa250 100644 --- a/modules/light-clients/07-tendermint/consensus_state.go +++ b/modules/light-clients/07-tendermint/consensus_state.go @@ -3,7 +3,7 @@ package tendermint import ( "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" @@ -46,13 +46,13 @@ func (cs ConsensusState) GetTimestamp() uint64 { // as opposed to a consensus state constructed by the chain. func (cs ConsensusState) ValidateBasic() error { if cs.Root.Empty() { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "root cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "root cannot be empty") } if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil { - return sdkerrors.Wrap(err, "next validators hash is invalid") + return errorsmod.Wrap(err, "next validators hash is invalid") } if cs.Timestamp.Unix() <= 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time") } return nil } diff --git a/modules/light-clients/07-tendermint/errors.go b/modules/light-clients/07-tendermint/errors.go index 7e2b37e59b2..8bbb58ec33a 100644 --- a/modules/light-clients/07-tendermint/errors.go +++ b/modules/light-clients/07-tendermint/errors.go @@ -1,22 +1,22 @@ package tendermint import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC tendermint client sentinel errors var ( - ErrInvalidChainID = sdkerrors.Register(ModuleName, 2, "invalid chain-id") - ErrInvalidTrustingPeriod = sdkerrors.Register(ModuleName, 3, "invalid trusting period") - ErrInvalidUnbondingPeriod = sdkerrors.Register(ModuleName, 4, "invalid unbonding period") - ErrInvalidHeaderHeight = sdkerrors.Register(ModuleName, 5, "invalid header height") - ErrInvalidHeader = sdkerrors.Register(ModuleName, 6, "invalid header") - ErrInvalidMaxClockDrift = sdkerrors.Register(ModuleName, 7, "invalid max clock drift") - ErrProcessedTimeNotFound = sdkerrors.Register(ModuleName, 8, "processed time not found") - ErrProcessedHeightNotFound = sdkerrors.Register(ModuleName, 9, "processed height not found") - ErrDelayPeriodNotPassed = sdkerrors.Register(ModuleName, 10, "packet-specified delay period has not been reached") - ErrTrustingPeriodExpired = sdkerrors.Register(ModuleName, 11, "time since latest trusted state has passed the trusting period") - ErrUnbondingPeriodExpired = sdkerrors.Register(ModuleName, 12, "time since latest trusted state has passed the unbonding period") - ErrInvalidProofSpecs = sdkerrors.Register(ModuleName, 13, "invalid proof specs") - ErrInvalidValidatorSet = sdkerrors.Register(ModuleName, 14, "invalid validator set") + ErrInvalidChainID = errorsmod.Register(ModuleName, 2, "invalid chain-id") + ErrInvalidTrustingPeriod = errorsmod.Register(ModuleName, 3, "invalid trusting period") + ErrInvalidUnbondingPeriod = errorsmod.Register(ModuleName, 4, "invalid unbonding period") + ErrInvalidHeaderHeight = errorsmod.Register(ModuleName, 5, "invalid header height") + ErrInvalidHeader = errorsmod.Register(ModuleName, 6, "invalid header") + ErrInvalidMaxClockDrift = errorsmod.Register(ModuleName, 7, "invalid max clock drift") + ErrProcessedTimeNotFound = errorsmod.Register(ModuleName, 8, "processed time not found") + ErrProcessedHeightNotFound = errorsmod.Register(ModuleName, 9, "processed height not found") + ErrDelayPeriodNotPassed = errorsmod.Register(ModuleName, 10, "packet-specified delay period has not been reached") + ErrTrustingPeriodExpired = errorsmod.Register(ModuleName, 11, "time since latest trusted state has passed the trusting period") + ErrUnbondingPeriodExpired = errorsmod.Register(ModuleName, 12, "time since latest trusted state has passed the unbonding period") + ErrInvalidProofSpecs = errorsmod.Register(ModuleName, 13, "invalid proof specs") + ErrInvalidValidatorSet = errorsmod.Register(ModuleName, 14, "invalid validator set") ) diff --git a/modules/light-clients/07-tendermint/header.go b/modules/light-clients/07-tendermint/header.go index 5db68127d10..e158eaab5d1 100644 --- a/modules/light-clients/07-tendermint/header.go +++ b/modules/light-clients/07-tendermint/header.go @@ -4,7 +4,7 @@ import ( "bytes" "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" tmtypes "github.com/tendermint/tendermint/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -49,34 +49,34 @@ func (h Header) GetTime() time.Time { // with MsgCreateClient func (h Header) ValidateBasic() error { if h.SignedHeader == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "tendermint signed header cannot be nil") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "tendermint signed header cannot be nil") } if h.Header == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "tendermint header cannot be nil") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "tendermint header cannot be nil") } tmSignedHeader, err := tmtypes.SignedHeaderFromProto(h.SignedHeader) if err != nil { - return sdkerrors.Wrap(err, "header is not a tendermint header") + return errorsmod.Wrap(err, "header is not a tendermint header") } if err := tmSignedHeader.ValidateBasic(h.Header.GetChainID()); err != nil { - return sdkerrors.Wrap(err, "header failed basic validation") + return errorsmod.Wrap(err, "header failed basic validation") } // TrustedHeight is less than Header for updates and misbehaviour if h.TrustedHeight.GTE(h.GetHeight()) { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "TrustedHeight %d must be less than header height %d", + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "TrustedHeight %d must be less than header height %d", h.TrustedHeight, h.GetHeight()) } if h.ValidatorSet == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "validator set is nil") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "validator set is nil") } tmValset, err := tmtypes.ValidatorSetFromProto(h.ValidatorSet) if err != nil { - return sdkerrors.Wrap(err, "validator set is not tendermint validator set") + return errorsmod.Wrap(err, "validator set is not tendermint validator set") } if !bytes.Equal(h.Header.ValidatorsHash, tmValset.Hash()) { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "validator set does not match hash") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "validator set does not match hash") } return nil } diff --git a/modules/light-clients/07-tendermint/migrations/migrations.go b/modules/light-clients/07-tendermint/migrations/migrations.go index 2c35ecd2b9e..f5d28fe468f 100644 --- a/modules/light-clients/07-tendermint/migrations/migrations.go +++ b/modules/light-clients/07-tendermint/migrations/migrations.go @@ -1,9 +1,9 @@ package migrations import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -28,12 +28,12 @@ func PruneExpiredConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, clientK clientState, ok := clientKeeper.GetClientState(ctx, clientID) if !ok { - return 0, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) } tmClientState, ok := clientState.(*ibctm.ClientState) if !ok { - return 0, sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + return 0, errorsmod.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") } totalPruned += ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) diff --git a/modules/light-clients/07-tendermint/misbehaviour.go b/modules/light-clients/07-tendermint/misbehaviour.go index 89722ae415b..827518f6f74 100644 --- a/modules/light-clients/07-tendermint/misbehaviour.go +++ b/modules/light-clients/07-tendermint/misbehaviour.go @@ -3,7 +3,7 @@ package tendermint import ( "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -45,56 +45,56 @@ func (misbehaviour Misbehaviour) GetTime() time.Time { // ValidateBasic implements Misbehaviour interface func (misbehaviour Misbehaviour) ValidateBasic() error { if misbehaviour.Header1 == nil { - return sdkerrors.Wrap(ErrInvalidHeader, "misbehaviour Header1 cannot be nil") + return errorsmod.Wrap(ErrInvalidHeader, "misbehaviour Header1 cannot be nil") } if misbehaviour.Header2 == nil { - return sdkerrors.Wrap(ErrInvalidHeader, "misbehaviour Header2 cannot be nil") + return errorsmod.Wrap(ErrInvalidHeader, "misbehaviour Header2 cannot be nil") } if misbehaviour.Header1.TrustedHeight.RevisionHeight == 0 { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header1 cannot have zero revision height") + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header1 cannot have zero revision height") } if misbehaviour.Header2.TrustedHeight.RevisionHeight == 0 { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header2 cannot have zero revision height") + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header2 cannot have zero revision height") } if misbehaviour.Header1.TrustedValidators == nil { - return sdkerrors.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header1 cannot be empty") + return errorsmod.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header1 cannot be empty") } if misbehaviour.Header2.TrustedValidators == nil { - return sdkerrors.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header2 cannot be empty") + return errorsmod.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header2 cannot be empty") } if misbehaviour.Header1.Header.ChainID != misbehaviour.Header2.Header.ChainID { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "headers must have identical chainIDs") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "headers must have identical chainIDs") } if err := host.ClientIdentifierValidator(misbehaviour.ClientId); err != nil { - return sdkerrors.Wrap(err, "misbehaviour client ID is invalid") + return errorsmod.Wrap(err, "misbehaviour client ID is invalid") } // ValidateBasic on both validators if err := misbehaviour.Header1.ValidateBasic(); err != nil { - return sdkerrors.Wrap( + return errorsmod.Wrap( clienttypes.ErrInvalidMisbehaviour, - sdkerrors.Wrap(err, "header 1 failed validation").Error(), + errorsmod.Wrap(err, "header 1 failed validation").Error(), ) } if err := misbehaviour.Header2.ValidateBasic(); err != nil { - return sdkerrors.Wrap( + return errorsmod.Wrap( clienttypes.ErrInvalidMisbehaviour, - sdkerrors.Wrap(err, "header 2 failed validation").Error(), + errorsmod.Wrap(err, "header 2 failed validation").Error(), ) } // Ensure that Height1 is greater than or equal to Height2 if misbehaviour.Header1.GetHeight().LT(misbehaviour.Header2.GetHeight()) { - return sdkerrors.Wrapf(clienttypes.ErrInvalidMisbehaviour, "Header1 height is less than Header2 height (%s < %s)", misbehaviour.Header1.GetHeight(), misbehaviour.Header2.GetHeight()) + return errorsmod.Wrapf(clienttypes.ErrInvalidMisbehaviour, "Header1 height is less than Header2 height (%s < %s)", misbehaviour.Header1.GetHeight(), misbehaviour.Header2.GetHeight()) } blockID1, err := tmtypes.BlockIDFromProto(&misbehaviour.Header1.SignedHeader.Commit.BlockID) if err != nil { - return sdkerrors.Wrap(err, "invalid block ID from header 1 in misbehaviour") + return errorsmod.Wrap(err, "invalid block ID from header 1 in misbehaviour") } blockID2, err := tmtypes.BlockIDFromProto(&misbehaviour.Header2.SignedHeader.Commit.BlockID) if err != nil { - return sdkerrors.Wrap(err, "invalid block ID from header 2 in misbehaviour") + return errorsmod.Wrap(err, "invalid block ID from header 2 in misbehaviour") } if err := validCommit(misbehaviour.Header1.Header.ChainID, *blockID1, @@ -112,15 +112,15 @@ func (misbehaviour Misbehaviour) ValidateBasic() error { func validCommit(chainID string, blockID tmtypes.BlockID, commit *tmproto.Commit, valSet *tmproto.ValidatorSet) (err error) { tmCommit, err := tmtypes.CommitFromProto(commit) if err != nil { - return sdkerrors.Wrap(err, "commit is not tendermint commit type") + return errorsmod.Wrap(err, "commit is not tendermint commit type") } tmValset, err := tmtypes.ValidatorSetFromProto(valSet) if err != nil { - return sdkerrors.Wrap(err, "validator set is not tendermint validator set type") + return errorsmod.Wrap(err, "validator set is not tendermint validator set type") } if err := tmValset.VerifyCommitLight(chainID, blockID, tmCommit.Height, tmCommit); err != nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "validator set did not commit to header") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "validator set did not commit to header") } return nil diff --git a/modules/light-clients/07-tendermint/misbehaviour_handle.go b/modules/light-clients/07-tendermint/misbehaviour_handle.go index 2ef567b70c1..ef3e654179d 100644 --- a/modules/light-clients/07-tendermint/misbehaviour_handle.go +++ b/modules/light-clients/07-tendermint/misbehaviour_handle.go @@ -5,9 +5,9 @@ import ( "reflect" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" tmtypes "github.com/tendermint/tendermint/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -94,12 +94,12 @@ func (cs *ClientState) verifyMisbehaviour(ctx sdk.Context, clientStore sdk.KVSto // Retrieve trusted consensus states for each Header in misbehaviour tmConsensusState1, found := GetConsensusState(clientStore, cdc, misbehaviour.Header1.TrustedHeight) if !found { - return sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header1 at TrustedHeight: %s", misbehaviour.Header1.TrustedHeight) + return errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header1 at TrustedHeight: %s", misbehaviour.Header1.TrustedHeight) } tmConsensusState2, found := GetConsensusState(clientStore, cdc, misbehaviour.Header2.TrustedHeight) if !found { - return sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header2 at TrustedHeight: %s", misbehaviour.Header2.TrustedHeight) + return errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header2 at TrustedHeight: %s", misbehaviour.Header2.TrustedHeight) } // Check the validity of the two conflicting headers against their respective @@ -110,12 +110,12 @@ func (cs *ClientState) verifyMisbehaviour(ctx sdk.Context, clientStore sdk.KVSto if err := checkMisbehaviourHeader( cs, tmConsensusState1, misbehaviour.Header1, ctx.BlockTime(), ); err != nil { - return sdkerrors.Wrap(err, "verifying Header1 in Misbehaviour failed") + return errorsmod.Wrap(err, "verifying Header1 in Misbehaviour failed") } if err := checkMisbehaviourHeader( cs, tmConsensusState2, misbehaviour.Header2, ctx.BlockTime(), ); err != nil { - return sdkerrors.Wrap(err, "verifying Header2 in Misbehaviour failed") + return errorsmod.Wrap(err, "verifying Header2 in Misbehaviour failed") } return nil @@ -128,12 +128,12 @@ func checkMisbehaviourHeader( ) error { tmTrustedValset, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) if err != nil { - return sdkerrors.Wrap(err, "trusted validator set is not tendermint validator set type") + return errorsmod.Wrap(err, "trusted validator set is not tendermint validator set type") } tmCommit, err := tmtypes.CommitFromProto(header.Commit) if err != nil { - return sdkerrors.Wrap(err, "commit is not tendermint commit type") + return errorsmod.Wrap(err, "commit is not tendermint commit type") } // check the trusted fields for the header against ConsensusState @@ -143,7 +143,7 @@ func checkMisbehaviourHeader( // assert that the age of the trusted consensus state is not older than the trusting period if currentTimestamp.Sub(consState.Timestamp) >= clientState.TrustingPeriod { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrTrustingPeriodExpired, "current timestamp minus the latest consensus state timestamp is greater than or equal to the trusting period (%d >= %d)", currentTimestamp.Sub(consState.Timestamp), clientState.TrustingPeriod, @@ -164,7 +164,7 @@ func checkMisbehaviourHeader( if err := tmTrustedValset.VerifyCommitLightTrusting( chainID, tmCommit, clientState.TrustLevel.ToTendermint(), ); err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidMisbehaviour, "validator set in header has too much change from trusted validator set: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidMisbehaviour, "validator set in header has too much change from trusted validator set: %v", err) } return nil } diff --git a/modules/light-clients/07-tendermint/proposal_handle.go b/modules/light-clients/07-tendermint/proposal_handle.go index f3a1f4838f2..98b37ebf019 100644 --- a/modules/light-clients/07-tendermint/proposal_handle.go +++ b/modules/light-clients/07-tendermint/proposal_handle.go @@ -4,9 +4,9 @@ import ( "reflect" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -30,11 +30,11 @@ func (cs ClientState) CheckSubstituteAndUpdateState( ) error { substituteClientState, ok := substituteClient.(*ClientState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "expected type %T, got %T", &ClientState{}, substituteClient) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "expected type %T, got %T", &ClientState{}, substituteClient) } if !IsMatchingClientState(cs, *substituteClientState) { - return sdkerrors.Wrap(clienttypes.ErrInvalidSubstitute, "subject client state does not match substitute client state") + return errorsmod.Wrap(clienttypes.ErrInvalidSubstitute, "subject client state does not match substitute client state") } if cs.Status(ctx, subjectClientStore, cdc) == exported.Frozen { @@ -48,7 +48,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState( consensusState, found := GetConsensusState(substituteClientStore, cdc, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "unable to retrieve latest consensus state for substitute client") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "unable to retrieve latest consensus state for substitute client") } setConsensusState(subjectClientStore, cdc, consensusState, height) @@ -56,12 +56,12 @@ func (cs ClientState) CheckSubstituteAndUpdateState( // set metadata stored for the substitute consensus state processedHeight, found := GetProcessedHeight(substituteClientStore, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed height for substitute client latest height") + return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed height for substitute client latest height") } processedTime, found := GetProcessedTime(substituteClientStore, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed time for substitute client latest height") + return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed time for substitute client latest height") } setConsensusMetadataWithValues(subjectClientStore, height, processedHeight, processedTime) diff --git a/modules/light-clients/07-tendermint/update.go b/modules/light-clients/07-tendermint/update.go index 2ed995ceb40..fbd70e0fb27 100644 --- a/modules/light-clients/07-tendermint/update.go +++ b/modules/light-clients/07-tendermint/update.go @@ -4,9 +4,9 @@ import ( "bytes" "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/light" tmtypes "github.com/tendermint/tendermint/types" @@ -48,7 +48,7 @@ func (cs *ClientState) verifyHeader( // Retrieve trusted consensus states for each Header in misbehaviour consState, found := GetConsensusState(clientStore, cdc, header.TrustedHeight) if !found { - return sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header at TrustedHeight: %s", header.TrustedHeight) + return errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header at TrustedHeight: %s", header.TrustedHeight) } if err := checkTrustedHeader(header, consState); err != nil { @@ -58,7 +58,7 @@ func (cs *ClientState) verifyHeader( // UpdateClient only accepts updates with a header at the same revision // as the trusted consensus state if header.GetHeight().GetRevisionNumber() != header.TrustedHeight.RevisionNumber { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidHeaderHeight, "header height revision %d does not match trusted header revision %d", header.GetHeight().GetRevisionNumber(), header.TrustedHeight.RevisionNumber, @@ -67,22 +67,22 @@ func (cs *ClientState) verifyHeader( tmTrustedValidators, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) if err != nil { - return sdkerrors.Wrap(err, "trusted validator set in not tendermint validator set type") + return errorsmod.Wrap(err, "trusted validator set in not tendermint validator set type") } tmSignedHeader, err := tmtypes.SignedHeaderFromProto(header.SignedHeader) if err != nil { - return sdkerrors.Wrap(err, "signed header in not tendermint signed header type") + return errorsmod.Wrap(err, "signed header in not tendermint signed header type") } tmValidatorSet, err := tmtypes.ValidatorSetFromProto(header.ValidatorSet) if err != nil { - return sdkerrors.Wrap(err, "validator set in not tendermint validator set type") + return errorsmod.Wrap(err, "validator set in not tendermint validator set type") } // assert header height is newer than consensus state if header.GetHeight().LTE(header.TrustedHeight) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( clienttypes.ErrInvalidHeader, "header height ≤ consensus state height (%s ≤ %s)", header.GetHeight(), header.TrustedHeight, ) @@ -112,7 +112,7 @@ func (cs *ClientState) verifyHeader( cs.TrustingPeriod, currentTimestamp, cs.MaxClockDrift, cs.TrustLevel.ToTendermint(), ) if err != nil { - return sdkerrors.Wrap(err, "failed to verify header") + return errorsmod.Wrap(err, "failed to verify header") } return nil @@ -175,7 +175,7 @@ func (cs ClientState) pruneOldestConsensusState(ctx sdk.Context, cdc codec.Binar consState, found := GetConsensusState(clientStore, cdc, height) // this error should never occur if !found { - panic(sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "failed to retrieve consensus state at height: %s", height)) + panic(errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "failed to retrieve consensus state at height: %s", height)) } if cs.IsExpired(consState.Timestamp, ctx.BlockTime()) { @@ -206,14 +206,14 @@ func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.Binar func checkTrustedHeader(header *Header, consState *ConsensusState) error { tmTrustedValidators, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) if err != nil { - return sdkerrors.Wrap(err, "trusted validator set in not tendermint validator set type") + return errorsmod.Wrap(err, "trusted validator set in not tendermint validator set type") } // assert that trustedVals is NextValidators of last trusted header // to do this, we check that trustedVals.Hash() == consState.NextValidatorsHash tvalHash := tmTrustedValidators.Hash() if !bytes.Equal(consState.NextValidatorsHash, tvalHash) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidValidatorSet, "trusted validators %s, does not hash to latest trusted validators. Expected: %X, got: %X", header.TrustedValidators, consState.NextValidatorsHash, tvalHash, diff --git a/modules/light-clients/07-tendermint/upgrade.go b/modules/light-clients/07-tendermint/upgrade.go index 5e137dad0c5..abbeca91b90 100644 --- a/modules/light-clients/07-tendermint/upgrade.go +++ b/modules/light-clients/07-tendermint/upgrade.go @@ -3,11 +3,12 @@ package tendermint import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -30,14 +31,14 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( proofUpgradeClient, proofUpgradeConsState []byte, ) error { if len(cs.UpgradePath) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade client, no upgrade path set") + return errorsmod.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade client, no upgrade path set") } // last height of current counterparty chain must be client's latest height lastHeight := cs.GetLatestHeight() if !upgradedClient.GetLatestHeight().GT(lastHeight) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s", + return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s", upgradedClient.GetLatestHeight(), lastHeight) } @@ -46,22 +47,22 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( // counterparty must also commit to the upgraded consensus state at a sub-path under the upgrade path specified tmUpgradeClient, ok := upgradedClient.(*ClientState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "upgraded client must be Tendermint client. expected: %T got: %T", + return errorsmod.Wrapf(clienttypes.ErrInvalidClientType, "upgraded client must be Tendermint client. expected: %T got: %T", &ClientState{}, upgradedClient) } tmUpgradeConsState, ok := upgradedConsState.(*ConsensusState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "upgraded consensus state must be Tendermint consensus state. expected %T, got: %T", + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "upgraded consensus state must be Tendermint consensus state. expected %T, got: %T", &ConsensusState{}, upgradedConsState) } // unmarshal proofs var merkleProofClient, merkleProofConsState commitmenttypes.MerkleProof if err := cdc.Unmarshal(proofUpgradeClient, &merkleProofClient); err != nil { - return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal client merkle proof: %v", err) + return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal client merkle proof: %v", err) } if err := cdc.Unmarshal(proofUpgradeConsState, &merkleProofConsState); err != nil { - return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal consensus state merkle proof: %v", err) + return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal consensus state merkle proof: %v", err) } // Must prove against latest consensus state to ensure we are verifying against latest upgrade plan @@ -69,29 +70,29 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( // at this consensus state consState, found := GetConsensusState(clientStore, cdc, lastHeight) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "could not retrieve consensus state for lastHeight") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "could not retrieve consensus state for lastHeight") } // Verify client proof bz, err := cdc.MarshalInterface(upgradedClient.ZeroCustomFields()) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "could not marshal client state: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "could not marshal client state: %v", err) } // construct clientState Merkle path upgradeClientPath := constructUpgradeClientMerklePath(cs.UpgradePath, lastHeight) if err := merkleProofClient.VerifyMembership(cs.ProofSpecs, consState.GetRoot(), upgradeClientPath, bz); err != nil { - return sdkerrors.Wrapf(err, "client state proof failed. Path: %s", upgradeClientPath.Pretty()) + return errorsmod.Wrapf(err, "client state proof failed. Path: %s", upgradeClientPath.Pretty()) } // Verify consensus state proof bz, err = cdc.MarshalInterface(upgradedConsState) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "could not marshal consensus state: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "could not marshal consensus state: %v", err) } // construct consensus state Merkle path upgradeConsStatePath := constructUpgradeConsStateMerklePath(cs.UpgradePath, lastHeight) if err := merkleProofConsState.VerifyMembership(cs.ProofSpecs, consState.GetRoot(), upgradeConsStatePath, bz); err != nil { - return sdkerrors.Wrapf(err, "consensus state proof failed. Path: %s", upgradeConsStatePath.Pretty()) + return errorsmod.Wrapf(err, "consensus state proof failed. Path: %s", upgradeConsStatePath.Pretty()) } // Construct new client state and consensus state @@ -104,7 +105,7 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( ) if err := newClientState.Validate(); err != nil { - return sdkerrors.Wrap(err, "updated client state failed basic validation") + return errorsmod.Wrap(err, "updated client state failed basic validation") } // The new consensus state is merely used as a trusted kernel against which headers on the new diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 4a792900527..c00a8d27155 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -3,10 +3,11 @@ package localhost import ( "bytes" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -40,7 +41,7 @@ func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) // Validate performs a basic validation of the client state fields. func (cs ClientState) Validate() error { if cs.LatestHeight.RevisionHeight == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "local revision height cannot be zero") + return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "local revision height cannot be zero") } return nil @@ -54,7 +55,7 @@ func (cs ClientState) ZeroCustomFields() exported.ClientState { // Initialize ensures that initial consensus state for localhost is nil. func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, consState exported.ConsensusState) error { if consState != nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "initial consensus state for localhost must be nil.") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "initial consensus state for localhost must be nil.") } clientState := ClientState{ @@ -88,26 +89,26 @@ func (cs ClientState) VerifyMembership( ) error { // ensure the proof provided is the expected sentintel localhost client proof if !bytes.Equal(proof, SentinelProof) { - return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) + return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) } merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { - return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) + return errorsmod.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store bz := store.Get([]byte(merklePath.KeyPath[1])) if bz == nil { - return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) + return errorsmod.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) } if !bytes.Equal(bz, value) { - return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value provided does not equal value stored at path: %s", path) + return errorsmod.Wrapf(clienttypes.ErrFailedMembershipVerification, "value provided does not equal value stored at path: %s", path) } return nil @@ -128,21 +129,21 @@ func (cs ClientState) VerifyNonMembership( ) error { // ensure the proof provided is the expected sentintel localhost client proof if !bytes.Equal(proof, SentinelProof) { - return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) + return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) } merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { - return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) + return errorsmod.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store if store.Has([]byte(merklePath.KeyPath[1])) { - return sdkerrors.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) + return errorsmod.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) } return nil @@ -150,7 +151,7 @@ func (cs ClientState) VerifyNonMembership( // VerifyClientMessage is unsupported by the 09-localhost client type and returns an error. func (cs ClientState) VerifyClientMessage(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage) error { - return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "client message verification is unsupported by the localhost client") + return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "client message verification is unsupported by the localhost client") } // CheckForMisbehaviour is unsupported by the 09-localhost client type and performs a no-op, returning false. @@ -181,7 +182,7 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { // CheckSubstituteAndUpdateState returns an error. The localhost cannot be modified by // proposals. func (cs ClientState) CheckSubstituteAndUpdateState(_ sdk.Context, _ codec.BinaryCodec, _, _ sdk.KVStore, _ exported.ClientState) error { - return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") + return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") } // VerifyUpgradeAndUpdateState returns an error since localhost cannot be upgraded @@ -194,5 +195,5 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( _, _ []byte, ) error { - return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") + return errorsmod.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") } diff --git a/scripts/linting/lint-changed-go-files.sh b/scripts/linting/lint-changed-go-files.sh new file mode 100755 index 00000000000..286c4b772d0 --- /dev/null +++ b/scripts/linting/lint-changed-go-files.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# lint_modified_go_files runs the linter only if changes have been made to any go files. +function lint_modified_go_files() { + local go_files="$(git diff --name-only | grep \.go$)" + for f in $go_files; do + local dir_name="$(dirname $f)" + golangci-lint run "${dir_name}" --fix --out-format=tab --issues-exit-code=0 + done +} + +lint_modified_go_files diff --git a/scripts/linting/lint-changed-md-files.sh b/scripts/linting/lint-changed-md-files.sh new file mode 100755 index 00000000000..214ec70f622 --- /dev/null +++ b/scripts/linting/lint-changed-md-files.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# lint_modified_markdown_files runs the linter only if changes have been made to any md files. +function lint_modified_markdown_files() { + local markdown_files="$(git diff --name-only | grep \.md$)" + for f in $markdown_files; do + markdownlint "${f}" --fix + done +} + +lint_modified_markdown_files diff --git a/testing/chain.go b/testing/chain.go index e1449029811..b82e2cd9823 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -5,12 +5,12 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" @@ -421,7 +421,7 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa // NextValidatorsHash tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight + 1)) if !ok { - return nil, sdkerrors.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) + return nil, errorsmod.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) } } // inject trusted fields into last header diff --git a/testing/simapp/ante_handler.go b/testing/simapp/ante_handler.go index 5bd7bb567db..1fee5a3a529 100644 --- a/testing/simapp/ante_handler.go +++ b/testing/simapp/ante_handler.go @@ -1,10 +1,11 @@ package simapp import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" "github.com/cosmos/ibc-go/v7/modules/core/keeper" ) @@ -19,13 +20,13 @@ type HandlerOptions struct { // NewAnteHandler creates a new ante handler func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + return nil, errorsmod.Wrap(ibcerrors.ErrLogic, "account keeper is required for AnteHandler") } if options.BankKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + return nil, errorsmod.Wrap(ibcerrors.ErrLogic, "bank keeper is required for AnteHandler") } if options.SignModeHandler == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for AnteHandler") + return nil, errorsmod.Wrap(ibcerrors.ErrLogic, "sign mode handler is required for AnteHandler") } anteDecorators := []sdk.AnteDecorator{ diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 76575485ff1..39cf18c527b 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -64,7 +64,6 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" @@ -908,14 +907,8 @@ func BlockedAddresses() map[string]bool { func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) - paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable()) - paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable()) - paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable()) - paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable()) - paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable()) - paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) - paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) + // TODO: ibc module subspaces can be removed after migration of params + // https://github.com/cosmos/ibc-go/issues/2010 paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) @@ -933,8 +926,7 @@ func (app *SimApp) setupUpgradeHandlers() { // NOTE: The moduleName arg of v6.CreateUpgradeHandler refers to the auth module ScopedKeeper name to which the channel capability should be migrated from. // This should be the same string value provided upon instantiation of the ScopedKeeper with app.CapabilityKeeper.ScopeToModule() - // TODO: update git tag in link below - // See: https://github.com/cosmos/ibc-go/blob/v5.0.0-rc2/testing/simapp/app.go#L304 + // See: https://github.com/cosmos/ibc-go/blob/v6.1.0/testing/simapp/app.go#L310 app.UpgradeKeeper.SetUpgradeHandler( upgrades.V6, upgrades.CreateV6UpgradeHandler( From 5a9e1847db389ded77b70b2095e1ae188b27dd3d Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 1 Mar 2023 10:12:26 +0100 Subject: [PATCH 40/52] removing unnecessary defensive checks in 07-tendermint (#3218) --- .../light-clients/07-tendermint/client_state.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/modules/light-clients/07-tendermint/client_state.go b/modules/light-clients/07-tendermint/client_state.go index 78b947124eb..53daf119393 100644 --- a/modules/light-clients/07-tendermint/client_state.go +++ b/modules/light-clients/07-tendermint/client_state.go @@ -219,14 +219,6 @@ func (cs ClientState) VerifyMembership( path exported.Path, value []byte, ) error { - if height.IsZero() { - return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "proof height must be non-zero") - } - - if len(proof) == 0 { - return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") - } - if cs.GetLatestHeight().LT(height) { return errorsmod.Wrapf( ibcerrors.ErrInvalidHeight, @@ -273,14 +265,6 @@ func (cs ClientState) VerifyNonMembership( proof []byte, path exported.Path, ) error { - if height.IsZero() { - return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "proof height must be non-zero") - } - - if len(proof) == 0 { - return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") - } - if cs.GetLatestHeight().LT(height) { return errorsmod.Wrapf( ibcerrors.ErrInvalidHeight, From 868d0e4ab58e39bde466803c7087083a3d0663ef Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 1 Mar 2023 11:30:57 +0100 Subject: [PATCH 41/52] register localhost types in ibc core, remove AppModuleBasic (#3220) * register localhost types in ibc core, remove AppModuleBasic * updating godoc --- modules/core/types/codec.go | 5 +- modules/light-clients/09-localhost/module.go | 56 -------------------- testing/simapp/app.go | 2 - 3 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 modules/light-clients/09-localhost/module.go diff --git a/modules/core/types/codec.go b/modules/core/types/codec.go index 447b05c849b..e2c67424026 100644 --- a/modules/core/types/codec.go +++ b/modules/core/types/codec.go @@ -7,12 +7,15 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" + localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ) -// RegisterInterfaces registers x/ibc interfaces into protobuf Any. +// RegisterInterfaces registers ibc types against interfaces using the global InterfaceRegistry. +// Note: The localhost client is created by ibc core and thus requires explicit type registration. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { clienttypes.RegisterInterfaces(registry) connectiontypes.RegisterInterfaces(registry) channeltypes.RegisterInterfaces(registry) commitmenttypes.RegisterInterfaces(registry) + localhost.RegisterInterfaces(registry) } diff --git a/modules/light-clients/09-localhost/module.go b/modules/light-clients/09-localhost/module.go deleted file mode 100644 index bca3360a4ca..00000000000 --- a/modules/light-clients/09-localhost/module.go +++ /dev/null @@ -1,56 +0,0 @@ -package localhost - -import ( - "encoding/json" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" -) - -var _ module.AppModuleBasic = AppModuleBasic{} - -// AppModuleBasic defines the basic application module used by the localhost light client. -// Only the RegisterInterfaces function needs to be implemented. All other function perform -// a no-op. -type AppModuleBasic struct{} - -// Name returns the localhost module name. -func (AppModuleBasic) Name() string { - return ModuleName -} - -// RegisterLegacyAminoCodec performs a no-op. The localhost client does not support amino. -func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} - -// RegisterInterfaces registers module concrete types into protobuf Any. This allows core IBC -// to unmarshal localhost light client types. -func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - RegisterInterfaces(registry) -} - -// DefaultGenesis performs a no-op. Genesis is not supported for the localhost light client. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return nil -} - -// ValidateGenesis performs a no-op. Genesis is not supported for the localhost light cilent. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { - return nil -} - -// RegisterGRPCGatewayRoutes performs a no-op. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {} - -// GetTxCmd performs a no-op. Please see the 02-client cli commands. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -// GetQueryCmd performs a no-op. Please see the 02-client cli commands. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 39cf18c527b..d10d601b1fb 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -117,7 +117,6 @@ import ( ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost" ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" simappparams "github.com/cosmos/ibc-go/v7/testing/simapp/params" "github.com/cosmos/ibc-go/v7/testing/simapp/upgrades" @@ -161,7 +160,6 @@ var ( slashing.AppModuleBasic{}, ibc.AppModuleBasic{}, ibctm.AppModuleBasic{}, - localhost.AppModuleBasic{}, solomachine.AppModuleBasic{}, feegrantmodule.AppModuleBasic{}, upgrade.AppModuleBasic{}, From 7303ce371464a3d234b9f0b6edd9dbbba89295bb Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 1 Mar 2023 16:20:22 +0100 Subject: [PATCH 42/52] adding site docs for 09-localhost client (#3147) --- docs/.vuepress/config.js | 32 ++++++++++ .../light-clients/localhost/client-state.md | 60 +++++++++++++++++++ .../ibc/light-clients/localhost/connection.md | 25 ++++++++ .../light-clients/localhost/integration.md | 16 +++++ docs/ibc/light-clients/localhost/overview.md | 40 +++++++++++++ .../localhost/state-verification.md | 18 ++++++ 6 files changed, 191 insertions(+) create mode 100644 docs/ibc/light-clients/localhost/client-state.md create mode 100644 docs/ibc/light-clients/localhost/connection.md create mode 100644 docs/ibc/light-clients/localhost/integration.md create mode 100644 docs/ibc/light-clients/localhost/overview.md create mode 100644 docs/ibc/light-clients/localhost/state-verification.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 0fe317a7322..ee649dd9a81 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -398,6 +398,38 @@ module.exports = { }, ] }, + { + title: "Localhost", + directory: true, + path: "/ibc/light-clients/localhost", + children: [ + { + title: "Overview", + directory: false, + path: "/ibc/light-clients/localhost/overview.html", + }, + { + title: "Integration", + directory: false, + path: "/ibc/light-clients/localhost/integration.html", + }, + { + title: "ClientState", + directory: false, + path: "/ibc/light-clients/localhost/client-state.html", + }, + { + title: "Connection", + directory: false, + path: "/ibc/light-clients/localhost/connection.html", + }, + { + title: "State Verification", + directory: false, + path: "/ibc/light-clients/localhost/state-verification.html", + }, + ], + }, { title: "Solomachine", directory: true, diff --git a/docs/ibc/light-clients/localhost/client-state.md b/docs/ibc/light-clients/localhost/client-state.md new file mode 100644 index 00000000000..9a67fa89396 --- /dev/null +++ b/docs/ibc/light-clients/localhost/client-state.md @@ -0,0 +1,60 @@ + + +# `ClientState` + +The 09-localhost `ClientState` maintains a single field used to track the latest sequence of the state machine i.e. the height of the blockchain. + +```go +type ClientState struct { + // the latest height of the blockchain + LatestHeight clienttypes.Height +} +``` + +The 09-localhost `ClientState` is instantiated in the `InitGenesis` handler of the 02-client submodule in core IBC. +It calls `CreateLocalhostClient`, declaring a new `ClientState` and initializing it with its own client prefixed store. + +```go +func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error { + var clientState localhost.ClientState + return clientState.Initialize(ctx, k.cdc, k.ClientStore(ctx, exported.LocalhostClientID), nil) +} +``` + +It is possible to disable the localhost client by removing the `09-localhost` entry from the `allowed_clients` list through governance. + +## Client updates + +The latest height is updated periodically through the ABCI [`BeginBlock`](https://docs.cosmos.network/v0.47/building-modules/beginblock-endblock) interface of the 02-client submodule in core IBC. + +[See `BeginBlocker` in abci.go.](https://github.com/cosmos/ibc-go/blob/09-localhost/modules/core/02-client/abci.go#L12) + +```go +func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + // ... + + if clientState, found := k.GetClientState(ctx, exported.Localhost); found { + if k.GetClientStatus(ctx, clientState, exported.Localhost) == exported.Active { + k.UpdateLocalhostClient(ctx, clientState) + } + } +} +``` + +The above calls into the the 09-localhost `UpdateState` method of the `ClientState` . +It retrieves the current block height from the application context and sets the `LatestHeight` of the 09-localhost client. + +```go +func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { + height := clienttypes.GetSelfHeight(ctx) + cs.LatestHeight = height + + clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &cs)) + + return []exported.Height{height} +} +``` + +Note that the 09-localhost `ClientState` is not updated through the 02-client interface leveraged by conventional IBC light clients. diff --git a/docs/ibc/light-clients/localhost/connection.md b/docs/ibc/light-clients/localhost/connection.md new file mode 100644 index 00000000000..d76b44a68ae --- /dev/null +++ b/docs/ibc/light-clients/localhost/connection.md @@ -0,0 +1,25 @@ + + +# Localhost connections + +The 09-localhost light client module integrates with core IBC through a single sentinel localhost connection. +The sentinel `ConnectionEnd` is stored by default in the core IBC store. + +This enables channel handshakes to be initiated out of the box by supplying the localhost connection identifier (`connection-localhost`) in the `connectionHops` parameter of `MsgChannelOpenInit`. + +The `ConnectionEnd` is created and set in store via the `InitGenesis` handler of the 03-connection submodule in core IBC. +The `ConnectionEnd` and its `Counterparty` both reference the `09-localhost` client identifier, and share the localhost connection identifier `connection-localhost`. + +```go +// CreateSentinelLocalhostConnection creates and sets the sentinel localhost connection end in the IBC store. +func (k Keeper) CreateSentinelLocalhostConnection(ctx sdk.Context) { + counterparty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) + connectionEnd := types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) + + k.SetConnection(ctx, exported.LocalhostConnectionID, connectionEnd) +} +``` + +Note that connection handshakes are disallowed when using the `09-localhost` client type. \ No newline at end of file diff --git a/docs/ibc/light-clients/localhost/integration.md b/docs/ibc/light-clients/localhost/integration.md new file mode 100644 index 00000000000..a818507f1fd --- /dev/null +++ b/docs/ibc/light-clients/localhost/integration.md @@ -0,0 +1,16 @@ + + +# Integration + +The 09-localhost light client module registers codec types within the core IBC module. This differs from other light client module implementations which are expected to register codec types using the `AppModuleBasic` interface. + +The localhost client is added to the 02-client submodule param [`allowed_clients`](https://github.com/cosmos/ibc-go/blob/v7.0.0-rc0/proto/ibc/core/client/v1/client.proto#L102) by default in ibc-go. + +```go +var ( + // DefaultAllowedClients are the default clients for the AllowedClients parameter. + DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Localhost} +) +``` \ No newline at end of file diff --git a/docs/ibc/light-clients/localhost/overview.md b/docs/ibc/light-clients/localhost/overview.md new file mode 100644 index 00000000000..eca758e0221 --- /dev/null +++ b/docs/ibc/light-clients/localhost/overview.md @@ -0,0 +1,40 @@ + + +# `09-localhost` + +## Overview + +Learn about the 09-localhost light client module. {synopsis} + +The 09-localhost light client module implements a localhost loopback client with the ability to send and receive IBC packets to and from the same state machine. + +### Context + +In a multichain environment, application developers will be used to developing cross-chain applications through IBC. From their point of view, whether or not they are interacting with multiple modules on the same chain or on different chains should not matter. The localhost client module enables a unified interface to interact with different applications on a single chain, using the familiar IBC application layer semantics. + +### Implementation + +There exists a [single sentinel `ClientState`](./client-state.md) instance with the client identifier `09-localhost`. + +To supplement this, a [sentinel `ConnectionEnd` is stored in core IBC](./connection.md) state with the connection identifier `connection-localhost`. This enables IBC applications to create channels directly on top of the sentinel connection which leverage the 09-localhost loopback functionality. + +[State verification](./state-verification.md) for channel state in handshakes or processing packets is reduced in complexity, the `09-localhost` client can simply compare bytes stored under the standardized key paths. + +### Localhost vs *regular* client + +The localhost client aims to provide a unified approach to interacting with applications on a single chain, as the IBC application layer provides for cross-chain interactions. To achieve this unified interface though, there are a number of differences under the hood compared to a 'regular' IBC client (excluding `06-solomachine` and `09-localhost` itself). + +The table below lists some important differences: + +| | Regular client | Localhost | +| -------------------------------------------- | --------------------------------------------------------------------------- | --------- | +| Number of clients | Many instances of a client *type* corresponding to different counterparties | A single sentinel client with the client identifier `09-localhost`| +| Client creation | Relayer (permissionless) | `ClientState` is instantiated in the `InitGenesis` handler of the 02-client submodule in core IBC | +| Client updates | Relayer submits headers using `MsgUpdateClient` | Latest height is updated periodically through the ABCI [`BeginBlock`](https://docs.cosmos.network/v0.47/building-modules/beginblock-endblock) interface of the 02-client submodule in core IBC | +| Number of connections | Many connections, 1 (or more) per client | A single sentinel connection with the connection identifier `connection-localhost` | +| Connection creation | Connection handshake, provided underlying client | Sentinel `ConnectionEnd` is created and set in store in the `InitGenesis` handler of the 03-connection submodule in core IBC | +| Counterparty | Underlying client, representing another chain | Client with identifier `09-localhost` in same chain | +| `VerifyMembership` and `VerifyNonMembership` | Performs proof verification using consensus state roots | Performs state verification using key-value lookups in the core IBC store | +| Integration | Expected to register codec types using the `AppModuleBasic` interface | Registers codec types within the core IBC module | diff --git a/docs/ibc/light-clients/localhost/state-verification.md b/docs/ibc/light-clients/localhost/state-verification.md new file mode 100644 index 00000000000..a208c8734c3 --- /dev/null +++ b/docs/ibc/light-clients/localhost/state-verification.md @@ -0,0 +1,18 @@ + + +# State verification + +The localhost client handles state verification through the `ClientState` interface methods `VerifyMembership` and `VerifyNonMembership` by performing read-only operations directly on the core IBC store. + +When verifying channel state in handshakes or processing packets the `09-localhost` client can simply compare bytes stored under the standardized key paths defined by [ICS-24](https://github.com/cosmos/ibc/tree/main/spec/core/ics-024-host-requirements). + +For existence proofs via `VerifyMembership` the 09-localhost client will retrieve the value stored under the provided key path and compare it against the value provided by the caller. In contrast, non-existence proofs via `VerifyNonMembership` assert the absence of a value at the provided key path. + +Relayers are expected to provide a sentinel proof when sending IBC messages. Submission of nil or empty proofs is disallowed in core IBC messaging. +The 09-localhost light client module defines a `SentinelProof` as a single byte. Localhost client state verification will fail if the sentintel proof value is not provided. + +```go +var SentinelProof = []byte{0x01} +``` From b1c4f4d397bcc131a10f69e91345bf8856eb26b2 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 2 Mar 2023 13:21:06 +0100 Subject: [PATCH 43/52] sync localhost with main to prep feat branch for PR (#3228) --- .github/workflows/proto-registry.yml | 2 +- docs/apps/interchain-accounts/messages.md | 3 +- e2e/README.md | 47 ++++++- e2e/go.mod | 26 ++-- e2e/go.sum | 51 ++++---- go.mod | 22 ++-- go.sum | 43 +++--- .../controller/keeper/msg_server.go | 1 + .../controller/types/tx.pb.go | 122 +++++++++++++----- modules/apps/29-fee/keeper/escrow.go | 6 +- modules/apps/29-fee/keeper/events.go | 16 +-- modules/apps/29-fee/keeper/msg_server.go | 4 +- modules/core/02-client/keeper/client.go | 8 +- modules/core/02-client/keeper/events.go | 24 ++-- modules/core/02-client/keeper/proposal.go | 4 +- modules/core/03-connection/keeper/events.go | 16 +-- .../core/03-connection/keeper/handshake.go | 8 +- modules/core/04-channel/keeper/events.go | 48 +++---- modules/core/04-channel/keeper/handshake.go | 12 +- modules/core/04-channel/keeper/packet.go | 14 +- modules/core/04-channel/keeper/timeout.go | 8 +- .../controller/v1/tx.proto | 1 + 22 files changed, 294 insertions(+), 192 deletions(-) diff --git a/.github/workflows/proto-registry.yml b/.github/workflows/proto-registry.yml index dd9e685af42..ff8fc08acb8 100644 --- a/.github/workflows/proto-registry.yml +++ b/.github/workflows/proto-registry.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: bufbuild/buf-setup-action@v1.14.0 + - uses: bufbuild/buf-setup-action@v1.15.0 - uses: bufbuild/buf-push-action@v1 with: input: "proto" diff --git a/docs/apps/interchain-accounts/messages.md b/docs/apps/interchain-accounts/messages.md index 5486e6c5f97..0f4475818fe 100644 --- a/docs/apps/interchain-accounts/messages.md +++ b/docs/apps/interchain-accounts/messages.md @@ -29,10 +29,11 @@ If the `Version` string is omitted, the controller submodule will construct a de ```go type MsgRegisterInterchainAccountResponse struct { ChannelID string + PortId string } ``` -The `ChannelID` is returned in the message response. +The `ChannelID` and `PortID` are returned in the message response. ## `MsgSendTx` diff --git a/e2e/README.md b/e2e/README.md index 1080f6a41a4..56463c219be 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -18,6 +18,7 @@ 3. [Github Workflows](#github-workflows) 4. [Running Compatibility Tests](#running-compatibility-tests) 5. [Troubleshooting](#troubleshooting) +6. [Importable Workflow](#importable-workflow) # How to write tests @@ -307,7 +308,7 @@ This string is used to generate a test matrix in the Github Action that runs the All tests will be run on different hosts. -### Misceleneous: +### Misceleneous ## GitHub Workflows @@ -352,3 +353,47 @@ json matrix files under .github/compatibility-test-matrices and is equivalent to ``` This issue doesn't seem to occur on other operating systems. + +## Importable Workflow + +This repository contains an [importable workflow](https://github.com/cosmos/ibc-go/blob/bc963bcfd115a0e06b8196b114496db5ea011247/.github/workflows/e2e-compatibility-workflow-call.yaml) that can be used from any other repository to test chain upgrades. The workflow +can be used to test both non-IBC chains, and also IBC-enabled chains. + +### Prerequisites + +- In order to run this workflow, a docker container is required with tags for the versions you want to test. + +- Have an upgrade handler in the chain binary which is being upgraded to. + +> It's worth noting that all github repositories come with a built-in docker registry that makes it convenient to build and push images to. + +[This workflow](https://github.com/cosmos/ibc-go/blob/1da651e5e117872499e3558c2a92f887369ae262/.github/workflows/release.yml#L35-L61) can be used as a reference for how to build a docker image +whenever a git tag is pushed. + +### How to import the workflow + +You can refer to [this example](https://github.com/cosmos/ibc-go/blob/2933906d1ed25ae6dce7b7d93aa429dfa94c5a23/.github/workflows/e2e-upgrade.yaml#L9-L19) when including this workflow in your repo. + +The referenced job will do the following: + +- Create two chains using the image found at `ghcr.io/cosmos/ibc-go-simd:v4.3.0`. +- Perform IBC transfers verifying core functionality. +- Upgrade chain A to `ghcr.io/cosmos/ibc-go-simd:v5.1.0` by executing a governance proposal and using the plan name `normal upgrade`. +- Perform additional IBC transfers and verifies the upgrade and migrations ran successfully. + +> Note: The plan name will always be specific to your chain. In this instance `normal upgrade` is referring to [this upgrade handler](https://github.com/cosmos/ibc-go/blob/e9bc0bac38e84e1380ec08552cae15821143a6b6/testing/simapp/app.go#L923) + +### Workflow Options + +| Workflow Field | Purpose | +|-------------------|---------------------------------------------------| +| chain-image | The docker image to use for the test | +| chain-a-tag | The tag of chain A to use | +| chain-b-tag | The tag of chain B to use | +| chain-upgrade-tag | The tag chain A should be upgraded to | +| chain-binary | The chain binary name | +| upgrade-plan-name | The name of the upgrade plan to execute | +| test-entry-point | Always TestUpgradeTestSuite | +| test | Should be TestIBCChainUpgrade or TestChainUpgrade | + +> TestIBCChainUpgrade should be used for ibc tests, while TestChainUpgrade should be used for single chain tests. diff --git a/e2e/go.mod b/e2e/go.mod index c414e455b95..cb2b3872974 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -4,15 +4,15 @@ go 1.19 require ( github.com/cosmos/cosmos-sdk v0.47.0-rc2 - github.com/cosmos/gogoproto v1.4.4 + github.com/cosmos/gogoproto v1.4.6 github.com/cosmos/ibc-go/v7 v7.0.0-20230120105519-ae96bf3d5ee9 github.com/cosmos/interchain-accounts v0.4.1-0.20230116203650-08d2a4529a5d github.com/docker/docker v20.10.19+incompatible github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230201060741-e0e4e0f9283b - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.8.2 github.com/tendermint/tendermint v0.37.0-rc2 go.uber.org/zap v1.23.0 - golang.org/x/mod v0.6.0 + golang.org/x/mod v0.8.0 google.golang.org/grpc v1.53.0 ) @@ -22,7 +22,7 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v0.8.0 // indirect cloud.google.com/go/storage v1.27.0 // indirect - cosmossdk.io/api v0.2.6 // indirect + cosmossdk.io/api v0.3.1 // indirect cosmossdk.io/core v0.3.2 // indirect cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect @@ -53,7 +53,7 @@ require ( github.com/cockroachdb/apd/v2 v2.0.2 // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-proto v1.0.0-beta.1 // indirect + github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect @@ -190,18 +190,18 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect golang.org/x/crypto v0.4.0 // indirect - golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect - golang.org/x/net v0.5.0 // indirect + golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 // indirect + golang.org/x/net v0.6.0 // indirect golang.org/x/oauth2 v0.4.0 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.4.0 // indirect - golang.org/x/term v0.4.0 // indirect - golang.org/x/text v0.6.0 // indirect - golang.org/x/tools v0.2.0 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/term v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect + golang.org/x/tools v0.6.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.107.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect + google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 // indirect google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect @@ -219,7 +219,7 @@ require ( modernc.org/strutil v1.1.1 // indirect modernc.org/token v1.0.0 // indirect nhooyr.io/websocket v1.8.6 // indirect - pgregory.net/rapid v0.5.3 // indirect + pgregory.net/rapid v0.5.5 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/e2e/go.sum b/e2e/go.sum index d4474cdff02..f6490f008d2 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -46,8 +46,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= -cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= +cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= +cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= @@ -182,8 +182,8 @@ github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= -github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0= -github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE= +github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/AzgIWR2wZ8Nua8= +github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0= github.com/cosmos/cosmos-sdk v0.47.0-rc2 h1:BwQC41zQXG/pN9DdLaWzYJrC911St5lYOQIoW4Hf5wQ= github.com/cosmos/cosmos-sdk v0.47.0-rc2/go.mod h1:e0ZEpY/nhVoXAkijdHPdFOJNOXCddfvyFrFLp2QmCCY= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= @@ -192,8 +192,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI= github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= -github.com/cosmos/gogoproto v1.4.4 h1:nVAsgLlAf5jeN0fV7hRlkZvf768zU+dy4pG+hxc2P34= -github.com/cosmos/gogoproto v1.4.4/go.mod h1:/yl6/nLwsZcZ2JY3OrqjRqvqCG9InUMcXRfRjQiF9DU= +github.com/cosmos/gogoproto v1.4.6 h1:Ee7z15dWJaGlgM2rWrK8N2IX7PQcuccu8oG68jp5RL4= +github.com/cosmos/gogoproto v1.4.6/go.mod h1:VS/ASYmPgv6zkPKLjR9EB91lwbLHOzaGCirmKKhncfI= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.5-rc.1 h1:4PjF2PdScyPbN1WbXpiQU21YtyonnrMU31xN74g8Rkg= @@ -842,8 +842,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= @@ -940,8 +941,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE= +golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -966,8 +967,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I= -golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1018,8 +1019,8 @@ golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1126,13 +1127,13 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= -golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1142,8 +1143,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1207,8 +1208,8 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= -golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= -golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1290,8 +1291,8 @@ google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20220314164441-57ef72a4c106/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 h1:vArvWooPH749rNHpBGgVl+U9B9dATjiEhJzcWGlovNs= +google.golang.org/genproto v0.0.0-20230202175211-008b39050e57/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -1417,8 +1418,8 @@ modernc.org/z v1.5.1 h1:RTNHdsrOpeoSeOF4FbzTo8gBYByaJ5xT7NgZ9ZqRiJM= modernc.org/z v1.5.1/go.mod h1:eWFB510QWW5Th9YGZT81s+LwvaAs3Q2yr4sP0rmLkv8= nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -pgregory.net/rapid v0.5.3 h1:163N50IHFqr1phZens4FQOdPgfJscR7a562mjQqeo4M= -pgregory.net/rapid v0.5.3/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v0.5.5 h1:jkgx1TjbQPD/feRoK+S/mXw9e1uj6WilpHrXJowi6oA= +pgregory.net/rapid v0.5.5/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/go.mod b/go.mod index 9309933950c..6de91cb4622 100644 --- a/go.mod +++ b/go.mod @@ -3,15 +3,15 @@ go 1.19 module github.com/cosmos/ibc-go/v7 require ( - cosmossdk.io/api v0.2.6 + cosmossdk.io/api v0.3.1 cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0-beta.6 cosmossdk.io/simapp v0.0.0-20221216140705-ee8890cf30e7 cosmossdk.io/tools/rosetta v0.2.0 github.com/armon/go-metrics v0.4.1 - github.com/cosmos/cosmos-proto v1.0.0-beta.1 + github.com/cosmos/cosmos-proto v1.0.0-beta.2 github.com/cosmos/cosmos-sdk v0.47.0-rc2 - github.com/cosmos/gogoproto v1.4.4 + github.com/cosmos/gogoproto v1.4.6 github.com/cosmos/ics23/go v0.9.1-0.20221207100636-b1abd8678aab github.com/golang/protobuf v1.5.2 github.com/gorilla/mux v1.8.0 @@ -20,10 +20,10 @@ require ( github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.6.1 github.com/spf13/viper v1.15.0 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.8.2 github.com/tendermint/tendermint v0.37.0-rc2 github.com/tendermint/tm-db v0.6.7 - google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f + google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 google.golang.org/grpc v1.53.0 google.golang.org/protobuf v1.28.1 gopkg.in/yaml.v2 v2.4.0 @@ -146,18 +146,18 @@ require ( go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.4.0 // indirect - golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect - golang.org/x/net v0.5.0 // indirect + golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 // indirect + golang.org/x/net v0.6.0 // indirect golang.org/x/oauth2 v0.4.0 // indirect - golang.org/x/sys v0.4.0 // indirect - golang.org/x/term v0.4.0 // indirect - golang.org/x/text v0.6.0 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/term v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.107.0 // indirect google.golang.org/appengine v1.6.7 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect - pgregory.net/rapid v0.5.3 // indirect + pgregory.net/rapid v0.5.5 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 956441ec485..8178c79db9b 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.6 h1:AoNwaLLapcLsphhMK6+o0kZl+D6MMUaHVqSdwinASGU= -cosmossdk.io/api v0.2.6/go.mod h1:u/d+GAxil0nWpl1XnQL8nkziQDIWuBDhv8VnDm/s6dI= +cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= +cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= @@ -167,8 +167,8 @@ github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= -github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0= -github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE= +github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/AzgIWR2wZ8Nua8= +github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0= github.com/cosmos/cosmos-sdk v0.47.0-rc2 h1:BwQC41zQXG/pN9DdLaWzYJrC911St5lYOQIoW4Hf5wQ= github.com/cosmos/cosmos-sdk v0.47.0-rc2/go.mod h1:e0ZEpY/nhVoXAkijdHPdFOJNOXCddfvyFrFLp2QmCCY= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= @@ -177,8 +177,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI= github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= -github.com/cosmos/gogoproto v1.4.4 h1:nVAsgLlAf5jeN0fV7hRlkZvf768zU+dy4pG+hxc2P34= -github.com/cosmos/gogoproto v1.4.4/go.mod h1:/yl6/nLwsZcZ2JY3OrqjRqvqCG9InUMcXRfRjQiF9DU= +github.com/cosmos/gogoproto v1.4.6 h1:Ee7z15dWJaGlgM2rWrK8N2IX7PQcuccu8oG68jp5RL4= +github.com/cosmos/gogoproto v1.4.6/go.mod h1:VS/ASYmPgv6zkPKLjR9EB91lwbLHOzaGCirmKKhncfI= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.5-rc.1 h1:4PjF2PdScyPbN1WbXpiQU21YtyonnrMU31xN74g8Rkg= @@ -745,8 +745,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= @@ -830,8 +831,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE= +golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -905,8 +906,8 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1006,12 +1007,12 @@ golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= -golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1021,8 +1022,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1163,8 +1164,8 @@ google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20220314164441-57ef72a4c106/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 h1:vArvWooPH749rNHpBGgVl+U9B9dATjiEhJzcWGlovNs= +google.golang.org/genproto v0.0.0-20230202175211-008b39050e57/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -1250,8 +1251,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -pgregory.net/rapid v0.5.3 h1:163N50IHFqr1phZens4FQOdPgfJscR7a562mjQqeo4M= -pgregory.net/rapid v0.5.3/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v0.5.5 h1:jkgx1TjbQPD/feRoK+S/mXw9e1uj6WilpHrXJowi6oA= +pgregory.net/rapid v0.5.5/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go index a41eae140a3..0495d0490b6 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -47,6 +47,7 @@ func (s msgServer) RegisterInterchainAccount(goCtx context.Context, msg *types.M return &types.MsgRegisterInterchainAccountResponse{ ChannelId: channelID, + PortId: portID, }, nil } diff --git a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go index b2ea19032a2..b15979a713e 100644 --- a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go +++ b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go @@ -72,6 +72,7 @@ var xxx_messageInfo_MsgRegisterInterchainAccount proto.InternalMessageInfo // MsgRegisterInterchainAccountResponse defines the response for Msg/RegisterAccount type MsgRegisterInterchainAccountResponse struct { ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` + PortId string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` } func (m *MsgRegisterInterchainAccountResponse) Reset() { *m = MsgRegisterInterchainAccountResponse{} } @@ -114,6 +115,13 @@ func (m *MsgRegisterInterchainAccountResponse) GetChannelId() string { return "" } +func (m *MsgRegisterInterchainAccountResponse) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + // MsgSendTx defines the payload for Msg/SendTx type MsgSendTx struct { Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` @@ -214,42 +222,43 @@ func init() { } var fileDescriptor_7def041328c84a30 = []byte{ - // 546 bytes of a gzipped FileDescriptorProto + // 570 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0xed, 0x34, 0x94, 0xe6, 0x0a, 0x82, 0x5a, 0x41, 0x18, 0x83, 0xec, 0xca, 0x62, 0xe8, - 0x92, 0x3b, 0x25, 0x54, 0xaa, 0x54, 0xd4, 0x81, 0xa8, 0x20, 0x65, 0x88, 0x14, 0x99, 0x0e, 0x08, - 0x21, 0x45, 0x97, 0xf3, 0xc9, 0x39, 0x70, 0xee, 0x8c, 0xef, 0x62, 0xda, 0x91, 0x8d, 0x09, 0xb1, - 0xb1, 0xf6, 0xaf, 0xe0, 0x5f, 0xa0, 0x63, 0x47, 0xa6, 0xa8, 0x4a, 0x16, 0xe6, 0xfc, 0x05, 0xc8, - 0x76, 0xe2, 0x04, 0x28, 0x55, 0xf9, 0xb5, 0xf9, 0xdd, 0xdd, 0xe7, 0xbd, 0xef, 0xfb, 0xe1, 0x07, - 0x1e, 0xb2, 0x1e, 0x41, 0x38, 0x8a, 0x42, 0x46, 0xb0, 0x62, 0x82, 0x4b, 0xc4, 0xb8, 0xa2, 0x31, - 0xe9, 0x63, 0xc6, 0xbb, 0x98, 0x10, 0x31, 0xe4, 0x4a, 0x22, 0x22, 0xb8, 0x8a, 0x45, 0x18, 0xd2, - 0x18, 0x25, 0x75, 0xa4, 0x0e, 0x61, 0x14, 0x0b, 0x25, 0x8c, 0x06, 0xeb, 0x11, 0xb8, 0x0c, 0xc3, - 0x73, 0x60, 0xb8, 0x80, 0x61, 0x52, 0xb7, 0xaa, 0x81, 0x08, 0x44, 0x86, 0xa3, 0xf4, 0x2b, 0xf7, - 0x64, 0x6d, 0x5f, 0x4a, 0x46, 0x52, 0x47, 0x11, 0x26, 0xaf, 0xa8, 0xca, 0x29, 0xf7, 0xa3, 0x0e, - 0xee, 0xb5, 0x65, 0xe0, 0xd1, 0x80, 0x49, 0x45, 0xe3, 0x56, 0x81, 0x3c, 0xca, 0x09, 0xa3, 0x0a, - 0xae, 0x88, 0x37, 0x9c, 0xc6, 0xa6, 0xbe, 0xa9, 0x6f, 0x55, 0xbc, 0xdc, 0x30, 0xf6, 0xc0, 0x75, - 0x22, 0x38, 0xa7, 0x24, 0x8d, 0xd4, 0x65, 0xbe, 0x59, 0x4a, 0x6f, 0x9b, 0xe6, 0x74, 0xe4, 0x54, - 0x8f, 0xf0, 0x20, 0xdc, 0x75, 0xbf, 0xbb, 0x76, 0xbd, 0x6b, 0x0b, 0xbb, 0xe5, 0x1b, 0x26, 0xb8, - 0x9a, 0xd0, 0x58, 0x32, 0xc1, 0xcd, 0x95, 0xcc, 0xed, 0xdc, 0xdc, 0x5d, 0x7b, 0x77, 0xec, 0x68, - 0x5f, 0x8f, 0x1d, 0xcd, 0x7d, 0x01, 0xee, 0x5f, 0x24, 0xcc, 0xa3, 0x32, 0x12, 0x5c, 0x52, 0x63, - 0x1b, 0x00, 0xd2, 0xc7, 0x9c, 0xd3, 0x30, 0xd5, 0x91, 0xa9, 0x6c, 0xde, 0x9a, 0x8e, 0x9c, 0x8d, - 0x99, 0x8e, 0xe2, 0xce, 0xf5, 0x2a, 0x33, 0xa3, 0xe5, 0xbb, 0x9f, 0x4a, 0xa0, 0xd2, 0x96, 0xc1, - 0x53, 0xca, 0xfd, 0x83, 0xc3, 0xff, 0x93, 0xe4, 0x5b, 0x1d, 0xac, 0xe7, 0xb5, 0xee, 0xfa, 0x58, - 0xe1, 0x2c, 0xd3, 0xf5, 0xc6, 0x3e, 0xbc, 0x54, 0xc7, 0x93, 0x3a, 0xfc, 0x29, 0xe5, 0x4e, 0xe6, - 0x6c, 0x1f, 0x2b, 0xdc, 0xb4, 0x4e, 0x46, 0x8e, 0x36, 0x1d, 0x39, 0x46, 0xae, 0x63, 0x29, 0x8c, - 0xeb, 0x81, 0xa8, 0x78, 0x67, 0x3c, 0x01, 0x37, 0x63, 0x1a, 0x62, 0xc5, 0x12, 0xda, 0x55, 0x6c, - 0x40, 0xc5, 0x50, 0x99, 0xe5, 0x4d, 0x7d, 0xab, 0xdc, 0xbc, 0x3b, 0x1d, 0x39, 0xb7, 0x73, 0xfa, - 0xc7, 0x17, 0xae, 0x77, 0x63, 0x7e, 0x74, 0x90, 0x9f, 0x2c, 0xb5, 0x05, 0x81, 0x8d, 0xa2, 0x6e, - 0x45, 0x0f, 0x2c, 0xb0, 0x26, 0xe9, 0xeb, 0x21, 0xe5, 0x84, 0x66, 0x25, 0x2c, 0x7b, 0x85, 0xdd, - 0x38, 0x2b, 0x81, 0x95, 0xb6, 0x0c, 0x8c, 0xcf, 0x3a, 0xb8, 0xf3, 0xeb, 0x31, 0xeb, 0xc0, 0xdf, - 0xff, 0x11, 0xe0, 0x45, 0xf3, 0x61, 0x3d, 0xfb, 0xd7, 0x1e, 0x8b, 0x6c, 0xdf, 0xeb, 0x60, 0x75, - 0x36, 0x38, 0x7b, 0x7f, 0x18, 0x24, 0xc7, 0xad, 0xc7, 0x7f, 0x85, 0xcf, 0x05, 0x35, 0x5f, 0x9e, - 0x8c, 0x6d, 0xfd, 0x74, 0x6c, 0xeb, 0x67, 0x63, 0x5b, 0xff, 0x30, 0xb1, 0xb5, 0xd3, 0x89, 0xad, - 0x7d, 0x99, 0xd8, 0xda, 0xf3, 0x4e, 0xc0, 0x54, 0x7f, 0xd8, 0x83, 0x44, 0x0c, 0x10, 0x11, 0x72, - 0x20, 0x24, 0x62, 0x3d, 0x52, 0x0b, 0x04, 0x4a, 0x76, 0xd0, 0x40, 0xf8, 0xc3, 0x90, 0xca, 0x74, - 0x69, 0x48, 0xd4, 0xd8, 0xa9, 0x2d, 0x42, 0xd7, 0xce, 0x5b, 0x5b, 0xea, 0x28, 0xa2, 0xb2, 0xb7, - 0x9a, 0xed, 0x8d, 0x07, 0xdf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x17, 0x12, 0x8c, 0xf0, 0xf6, 0x04, - 0x00, 0x00, + 0x14, 0xc7, 0xed, 0x34, 0xa4, 0xcd, 0x95, 0x5f, 0xb5, 0x82, 0x30, 0x06, 0xd9, 0x95, 0xc5, 0x50, + 0x09, 0xc5, 0xa7, 0x84, 0x4a, 0x95, 0x8a, 0x3a, 0x10, 0x15, 0xa4, 0x0c, 0x91, 0x22, 0xd3, 0x01, + 0xb1, 0x44, 0x97, 0xf3, 0xc9, 0x39, 0x70, 0xee, 0x8c, 0xef, 0x62, 0xda, 0x91, 0x0d, 0x16, 0xc4, + 0xc6, 0xda, 0xbf, 0x82, 0x7f, 0x81, 0x8e, 0x1d, 0x99, 0xac, 0x2a, 0x59, 0x98, 0xf3, 0x17, 0x20, + 0xdb, 0x89, 0x53, 0xa0, 0x54, 0xe5, 0x47, 0x37, 0xbf, 0x7b, 0xf7, 0x79, 0xef, 0x7b, 0xef, 0x3d, + 0x3f, 0xf0, 0x88, 0xf6, 0x31, 0x44, 0x61, 0x18, 0x50, 0x8c, 0x24, 0xe5, 0x4c, 0x40, 0xca, 0x24, + 0x89, 0xf0, 0x00, 0x51, 0xd6, 0x43, 0x18, 0xf3, 0x11, 0x93, 0x02, 0x62, 0xce, 0x64, 0xc4, 0x83, + 0x80, 0x44, 0x30, 0x6e, 0x40, 0xb9, 0xef, 0x84, 0x11, 0x97, 0x5c, 0x6b, 0xd2, 0x3e, 0x76, 0x4e, + 0xc3, 0xce, 0x19, 0xb0, 0xb3, 0x80, 0x9d, 0xb8, 0x61, 0xd4, 0x7c, 0xee, 0xf3, 0x0c, 0x87, 0xe9, + 0x57, 0x1e, 0xc9, 0xd8, 0xbc, 0x90, 0x8c, 0xb8, 0x01, 0x43, 0x84, 0x5f, 0x11, 0x99, 0x53, 0xf6, + 0x27, 0x15, 0xdc, 0xeb, 0x08, 0xdf, 0x25, 0x3e, 0x15, 0x92, 0x44, 0xed, 0x02, 0x79, 0x9c, 0x13, + 0x5a, 0x0d, 0x5c, 0xe1, 0x6f, 0x18, 0x89, 0x74, 0x75, 0x5d, 0xdd, 0xa8, 0xba, 0xb9, 0xa1, 0xed, + 0x80, 0x6b, 0x98, 0x33, 0x46, 0x70, 0x9a, 0xa9, 0x47, 0x3d, 0xbd, 0x94, 0x7a, 0x5b, 0xfa, 0x34, + 0xb1, 0x6a, 0x07, 0x68, 0x18, 0x6c, 0xdb, 0x3f, 0xb8, 0x6d, 0xf7, 0xea, 0xc2, 0x6e, 0x7b, 0x9a, + 0x0e, 0x96, 0x63, 0x12, 0x09, 0xca, 0x99, 0xbe, 0x94, 0x85, 0x9d, 0x9b, 0xdb, 0x2b, 0xef, 0x0e, + 0x2d, 0xe5, 0xdb, 0xa1, 0xa5, 0xd8, 0xef, 0x55, 0x70, 0xff, 0x3c, 0x65, 0x2e, 0x11, 0x21, 0x67, + 0x82, 0x68, 0x9b, 0x00, 0xe0, 0x01, 0x62, 0x8c, 0x04, 0xa9, 0x90, 0x4c, 0x66, 0xeb, 0xd6, 0x34, + 0xb1, 0xd6, 0x66, 0x42, 0x0a, 0x9f, 0xed, 0x56, 0x67, 0x46, 0xdb, 0xd3, 0x1e, 0x80, 0xe5, 0x90, + 0x47, 0x72, 0xa1, 0x5d, 0x9b, 0x26, 0xd6, 0xf5, 0x1c, 0x99, 0x39, 0x6c, 0xb7, 0x92, 0x7e, 0xb5, + 0x3d, 0xfb, 0x73, 0x09, 0x54, 0x3b, 0xc2, 0x7f, 0x46, 0x98, 0xb7, 0xb7, 0x7f, 0x39, 0x25, 0x79, + 0xab, 0x82, 0xd5, 0xbc, 0x33, 0x3d, 0x0f, 0x49, 0x94, 0xd5, 0x65, 0xb5, 0xb9, 0xeb, 0x5c, 0x68, + 0x3e, 0xe2, 0x86, 0xf3, 0x4b, 0x7d, 0xba, 0x59, 0xb0, 0x5d, 0x24, 0x51, 0xcb, 0x38, 0x4a, 0x2c, + 0x65, 0x9a, 0x58, 0xda, 0xec, 0x79, 0x8b, 0x34, 0xb6, 0x0b, 0xc2, 0xe2, 0x9e, 0xf6, 0x14, 0xdc, + 0x8c, 0x48, 0x80, 0x24, 0x8d, 0x49, 0x4f, 0xd2, 0x21, 0xe1, 0x23, 0xa9, 0x97, 0xd7, 0xd5, 0x8d, + 0x72, 0xeb, 0xee, 0x34, 0xb1, 0x6e, 0xe7, 0xf4, 0xcf, 0x37, 0x6c, 0xf7, 0xc6, 0xfc, 0x68, 0x2f, + 0x3f, 0x39, 0xd5, 0x44, 0x08, 0xd6, 0x8a, 0xba, 0x15, 0x0d, 0x33, 0xc0, 0x8a, 0x20, 0xaf, 0x47, + 0x84, 0x61, 0x92, 0x95, 0xb0, 0xec, 0x16, 0x76, 0xf3, 0xa4, 0x04, 0x96, 0x3a, 0xc2, 0xd7, 0xbe, + 0xa8, 0xe0, 0xce, 0xef, 0x87, 0xb2, 0xeb, 0xfc, 0xf9, 0x6f, 0xe3, 0x9c, 0x37, 0x4c, 0xc6, 0xf3, + 0xff, 0x1d, 0xb1, 0x78, 0xed, 0x07, 0x15, 0x54, 0x66, 0x83, 0xb3, 0xf3, 0x97, 0x49, 0x72, 0xdc, + 0x78, 0xf2, 0x4f, 0xf8, 0x5c, 0x50, 0xeb, 0xe5, 0xd1, 0xd8, 0x54, 0x8f, 0xc7, 0xa6, 0x7a, 0x32, + 0x36, 0xd5, 0x8f, 0x13, 0x53, 0x39, 0x9e, 0x98, 0xca, 0xd7, 0x89, 0xa9, 0xbc, 0xe8, 0xfa, 0x54, + 0x0e, 0x46, 0x7d, 0x07, 0xf3, 0x21, 0xc4, 0x5c, 0x0c, 0xb9, 0x80, 0xb4, 0x8f, 0xeb, 0x3e, 0x87, + 0xf1, 0x16, 0x1c, 0x72, 0x6f, 0x14, 0x10, 0x91, 0xae, 0x18, 0x01, 0x9b, 0x5b, 0xf5, 0x45, 0xea, + 0xfa, 0x59, 0x4b, 0x4e, 0x1e, 0x84, 0x44, 0xf4, 0x2b, 0xd9, 0x96, 0x79, 0xf8, 0x3d, 0x00, 0x00, + 0xff, 0xff, 0xf0, 0x81, 0x7c, 0xb2, 0x24, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -436,6 +445,13 @@ func (m *MsgRegisterInterchainAccountResponse) MarshalToSizedBuffer(dAtA []byte) _ = i var l int _ = l + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintTx(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0x12 + } if len(m.ChannelId) > 0 { i -= len(m.ChannelId) copy(dAtA[i:], m.ChannelId) @@ -568,6 +584,10 @@ func (m *MsgRegisterInterchainAccountResponse) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -818,6 +838,38 @@ func (m *MsgRegisterInterchainAccountResponse) Unmarshal(dAtA []byte) error { } m.ChannelId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index b526bdfcea1..8f3f8bd417f 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -39,7 +39,7 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, packetFees := types.NewPacketFees(fees) k.SetFeesInEscrow(ctx, packetID, packetFees) - EmitIncentivizedPacketEvent(ctx, packetID, packetFees) + emitIncentivizedPacketEvent(ctx, packetID, packetFees) return nil } @@ -168,9 +168,9 @@ func (k Keeper) distributeFee(ctx sdk.Context, receiver, refundAccAddress sdk.Ac return // if sending to the refund address fails, no-op } - EmitDistributeFeeEvent(ctx, refundAccAddress.String(), fee) + emitDistributeFeeEvent(ctx, refundAccAddress.String(), fee) } else { - EmitDistributeFeeEvent(ctx, receiver.String(), fee) + emitDistributeFeeEvent(ctx, receiver.String(), fee) } // write the cache diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index 310421d24dc..e367482649e 100644 --- a/modules/apps/29-fee/keeper/events.go +++ b/modules/apps/29-fee/keeper/events.go @@ -9,9 +9,9 @@ import ( channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) -// EmitIncentivizedPacketEvent emits an event containing information on the total amount of fees incentivizing +// emitIncentivizedPacketEvent emits an event containing information on the total amount of fees incentivizing // a specific packet. It should be emitted on every fee escrowed for the given packetID. -func EmitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId, packetFees types.PacketFees) { +func emitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId, packetFees types.PacketFees) { var ( totalRecvFees sdk.Coins totalAckFees sdk.Coins @@ -44,8 +44,8 @@ func EmitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId }) } -// EmitRegisterPayeeEvent emits an event containing information of a registered payee for a relayer on a particular channel -func EmitRegisterPayeeEvent(ctx sdk.Context, relayer, payee, channelID string) { +// emitRegisterPayeeEvent emits an event containing information of a registered payee for a relayer on a particular channel +func emitRegisterPayeeEvent(ctx sdk.Context, relayer, payee, channelID string) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterPayee, @@ -60,8 +60,8 @@ func EmitRegisterPayeeEvent(ctx sdk.Context, relayer, payee, channelID string) { }) } -// EmitRegisterCounterpartyPayeeEvent emits an event containing information of a registered counterparty payee for a relayer on a particular channel -func EmitRegisterCounterpartyPayeeEvent(ctx sdk.Context, relayer, counterpartyPayee, channelID string) { +// emitRegisterCounterpartyPayeeEvent emits an event containing information of a registered counterparty payee for a relayer on a particular channel +func emitRegisterCounterpartyPayeeEvent(ctx sdk.Context, relayer, counterpartyPayee, channelID string) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterCounterpartyPayee, @@ -76,8 +76,8 @@ func EmitRegisterCounterpartyPayeeEvent(ctx sdk.Context, relayer, counterpartyPa }) } -// EmitDistributeFeeEvent emits an event containing a distribution fee and receiver address -func EmitDistributeFeeEvent(ctx sdk.Context, receiver string, fee sdk.Coins) { +// emitDistributeFeeEvent emits an event containing a distribution fee and receiver address +func emitDistributeFeeEvent(ctx sdk.Context, receiver string, fee sdk.Coins) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeDistributeFee, diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 8fe0aed2f04..943ee0453fc 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -43,7 +43,7 @@ func (k Keeper) RegisterPayee(goCtx context.Context, msg *types.MsgRegisterPayee k.Logger(ctx).Info("registering payee address for relayer", "relayer", msg.Relayer, "payee", msg.Payee, "channel", msg.ChannelId) - EmitRegisterPayeeEvent(ctx, msg.Relayer, msg.Payee, msg.ChannelId) + emitRegisterPayeeEvent(ctx, msg.Relayer, msg.Payee, msg.ChannelId) return &types.MsgRegisterPayeeResponse{}, nil } @@ -69,7 +69,7 @@ func (k Keeper) RegisterCounterpartyPayee(goCtx context.Context, msg *types.MsgR k.Logger(ctx).Info("registering counterparty payee for relayer", "relayer", msg.Relayer, "counterparty payee", msg.CounterpartyPayee, "channel", msg.ChannelId) - EmitRegisterCounterpartyPayeeEvent(ctx, msg.Relayer, msg.CounterpartyPayee, msg.ChannelId) + emitRegisterCounterpartyPayeeEvent(ctx, msg.Relayer, msg.CounterpartyPayee, msg.ChannelId) return &types.MsgRegisterCounterpartyPayeeResponse{}, nil } diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index 1fe4ea733f1..4935cc13299 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -43,7 +43,7 @@ func (k Keeper) CreateClient( []metrics.Label{telemetry.NewLabel(types.LabelClientType, clientState.ClientType())}, ) - EmitCreateClientEvent(ctx, clientID, clientState) + emitCreateClientEvent(ctx, clientID, clientState) return clientID, nil } @@ -81,7 +81,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exporte }, ) - EmitSubmitMisbehaviourEvent(ctx, clientID, clientState) + emitSubmitMisbehaviourEvent(ctx, clientID, clientState) return nil } @@ -101,7 +101,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exporte ) // emitting events in the keeper emits for both begin block and handler client updates - EmitUpdateClientEvent(ctx, clientID, clientState.ClientType(), consensusHeights, k.cdc, clientMsg) + emitUpdateClientEvent(ctx, clientID, clientState.ClientType(), consensusHeights, k.cdc, clientMsg) return nil } @@ -139,7 +139,7 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e }, ) - EmitUpgradeClientEvent(ctx, clientID, upgradedClient) + emitUpgradeClientEvent(ctx, clientID, upgradedClient) return nil } diff --git a/modules/core/02-client/keeper/events.go b/modules/core/02-client/keeper/events.go index 6c08858648e..9b0bb6841ba 100644 --- a/modules/core/02-client/keeper/events.go +++ b/modules/core/02-client/keeper/events.go @@ -14,8 +14,8 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/exported" ) -// EmitCreateClientEvent emits a create client event -func EmitCreateClientEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { +// emitCreateClientEvent emits a create client event +func emitCreateClientEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeCreateClient, @@ -30,8 +30,8 @@ func EmitCreateClientEvent(ctx sdk.Context, clientID string, clientState exporte }) } -// EmitUpdateClientEvent emits an update client event -func EmitUpdateClientEvent(ctx sdk.Context, clientID string, clientType string, consensusHeights []exported.Height, cdc codec.BinaryCodec, clientMsg exported.ClientMessage) { +// emitUpdateClientEvent emits an update client event +func emitUpdateClientEvent(ctx sdk.Context, clientID string, clientType string, consensusHeights []exported.Height, cdc codec.BinaryCodec, clientMsg exported.ClientMessage) { // Marshal the ClientMessage as an Any and encode the resulting bytes to hex. // This prevents the event value from containing invalid UTF-8 characters // which may cause data to be lost when JSON encoding/decoding. @@ -65,8 +65,8 @@ func EmitUpdateClientEvent(ctx sdk.Context, clientID string, clientType string, }) } -// EmitUpdateClientEvent emits an upgrade client event -func EmitUpgradeClientEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { +// emitUpgradeClientEvent emits an upgrade client event +func emitUpgradeClientEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeUpgradeClient, @@ -81,8 +81,8 @@ func EmitUpgradeClientEvent(ctx sdk.Context, clientID string, clientState export }) } -// EmitUpdateClientProposalEvent emits an update client proposal event -func EmitUpdateClientProposalEvent(ctx sdk.Context, clientID, clientType string) { +// emitUpdateClientProposalEvent emits an update client proposal event +func emitUpdateClientProposalEvent(ctx sdk.Context, clientID, clientType string) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeUpdateClientProposal, @@ -96,8 +96,8 @@ func EmitUpdateClientProposalEvent(ctx sdk.Context, clientID, clientType string) }) } -// EmitUpgradeClientProposalEvent emits an upgrade client proposal event -func EmitUpgradeClientProposalEvent(ctx sdk.Context, title string, height int64) { +// emitUpgradeClientProposalEvent emits an upgrade client proposal event +func emitUpgradeClientProposalEvent(ctx sdk.Context, title string, height int64) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeUpgradeClientProposal, @@ -111,8 +111,8 @@ func EmitUpgradeClientProposalEvent(ctx sdk.Context, title string, height int64) }) } -// EmitSubmitMisbehaviourEvent emits a client misbehaviour event -func EmitSubmitMisbehaviourEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { +// emitSubmitMisbehaviourEvent emits a client misbehaviour event +func emitSubmitMisbehaviourEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeSubmitMisbehaviour, diff --git a/modules/core/02-client/keeper/proposal.go b/modules/core/02-client/keeper/proposal.go index 2b30b89ba99..1dc7edd33e0 100644 --- a/modules/core/02-client/keeper/proposal.go +++ b/modules/core/02-client/keeper/proposal.go @@ -63,7 +63,7 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo }() // emitting events in the keeper for proposal updates to clients - EmitUpdateClientProposalEvent(ctx, p.SubjectClientId, substituteClientState.ClientType()) + emitUpdateClientProposalEvent(ctx, p.SubjectClientId, substituteClientState.ClientType()) return nil } @@ -96,7 +96,7 @@ func (k Keeper) HandleUpgradeProposal(ctx sdk.Context, p *types.UpgradeProposal) } // emitting an event for handling client upgrade proposal - EmitUpgradeClientProposalEvent(ctx, p.Title, p.Plan.Height) + emitUpgradeClientProposalEvent(ctx, p.Title, p.Plan.Height) return nil } diff --git a/modules/core/03-connection/keeper/events.go b/modules/core/03-connection/keeper/events.go index cf7eefb69bc..e9e5a575990 100644 --- a/modules/core/03-connection/keeper/events.go +++ b/modules/core/03-connection/keeper/events.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ) -// EmitConnectionOpenInitEvent emits a connection open init event -func EmitConnectionOpenInitEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { +// emitConnectionOpenInitEvent emits a connection open init event +func emitConnectionOpenInitEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenInit, @@ -23,8 +23,8 @@ func EmitConnectionOpenInitEvent(ctx sdk.Context, connectionID string, clientID }) } -// EmitConnectionOpenTryEvent emits a connection open try event -func EmitConnectionOpenTryEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { +// emitConnectionOpenTryEvent emits a connection open try event +func emitConnectionOpenTryEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenTry, @@ -40,8 +40,8 @@ func EmitConnectionOpenTryEvent(ctx sdk.Context, connectionID string, clientID s }) } -// EmitConnectionOpenAckEvent emits a connection open acknowledge event -func EmitConnectionOpenAckEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { +// emitConnectionOpenAckEvent emits a connection open acknowledge event +func emitConnectionOpenAckEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenAck, @@ -57,8 +57,8 @@ func EmitConnectionOpenAckEvent(ctx sdk.Context, connectionID string, connection }) } -// EmitConnectionOpenConfirmEvent emits a connection open confirm event -func EmitConnectionOpenConfirmEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { +// emitConnectionOpenConfirmEvent emits a connection open confirm event +func emitConnectionOpenConfirmEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenConfirm, diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index acfde3183b1..523296194d3 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -57,7 +57,7 @@ func (k Keeper) ConnOpenInit( telemetry.IncrCounter(1, "ibc", "connection", "open-init") }() - EmitConnectionOpenInitEvent(ctx, connectionID, clientID, counterparty) + emitConnectionOpenInitEvent(ctx, connectionID, clientID, counterparty) return connectionID, nil } @@ -154,7 +154,7 @@ func (k Keeper) ConnOpenTry( telemetry.IncrCounter(1, "ibc", "connection", "open-try") }() - EmitConnectionOpenTryEvent(ctx, connectionID, clientID, counterparty) + emitConnectionOpenTryEvent(ctx, connectionID, clientID, counterparty) return connectionID, nil } @@ -254,7 +254,7 @@ func (k Keeper) ConnOpenAck( connection.Counterparty.ConnectionId = counterpartyConnectionID k.SetConnection(ctx, connectionID, connection) - EmitConnectionOpenAckEvent(ctx, connectionID, connection) + emitConnectionOpenAckEvent(ctx, connectionID, connection) return nil } @@ -304,7 +304,7 @@ func (k Keeper) ConnOpenConfirm( telemetry.IncrCounter(1, "ibc", "connection", "open-confirm") }() - EmitConnectionOpenConfirmEvent(ctx, connectionID, connection) + emitConnectionOpenConfirmEvent(ctx, connectionID, connection) return nil } diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index 78dfdbe1644..07b105f363a 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/ibc-go/v7/modules/core/exported" ) -// EmitChannelOpenInitEvent emits a channel open init event -func EmitChannelOpenInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { +// emitChannelOpenInitEvent emits a channel open init event +func emitChannelOpenInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenInit, @@ -29,8 +29,8 @@ func EmitChannelOpenInitEvent(ctx sdk.Context, portID string, channelID string, }) } -// EmitChannelOpenTryEvent emits a channel open try event -func EmitChannelOpenTryEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { +// emitChannelOpenTryEvent emits a channel open try event +func emitChannelOpenTryEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenTry, @@ -48,8 +48,8 @@ func EmitChannelOpenTryEvent(ctx sdk.Context, portID string, channelID string, c }) } -// EmitChannelOpenAckEvent emits a channel open acknowledge event -func EmitChannelOpenAckEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { +// emitChannelOpenAckEvent emits a channel open acknowledge event +func emitChannelOpenAckEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenAck, @@ -66,8 +66,8 @@ func EmitChannelOpenAckEvent(ctx sdk.Context, portID string, channelID string, c }) } -// EmitChannelOpenConfirmEvent emits a channel open confirm event -func EmitChannelOpenConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { +// emitChannelOpenConfirmEvent emits a channel open confirm event +func emitChannelOpenConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenConfirm, @@ -84,8 +84,8 @@ func EmitChannelOpenConfirmEvent(ctx sdk.Context, portID string, channelID strin }) } -// EmitChannelCloseInitEvent emits a channel close init event -func EmitChannelCloseInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { +// emitChannelCloseInitEvent emits a channel close init event +func emitChannelCloseInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelCloseInit, @@ -102,8 +102,8 @@ func EmitChannelCloseInitEvent(ctx sdk.Context, portID string, channelID string, }) } -// EmitChannelCloseConfirmEvent emits a channel close confirm event -func EmitChannelCloseConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { +// emitChannelCloseConfirmEvent emits a channel close confirm event +func emitChannelCloseConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelCloseConfirm, @@ -120,9 +120,9 @@ func EmitChannelCloseConfirmEvent(ctx sdk.Context, portID string, channelID stri }) } -// EmitSendPacketEvent emits an event with packet data along with other packet information for relayer +// emitSendPacketEvent emits an event with packet data along with other packet information for relayer // to pick up and relay to other chain -func EmitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, timeoutHeight exported.Height) { +func emitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, timeoutHeight exported.Height) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeSendPacket, @@ -148,9 +148,9 @@ func EmitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types }) } -// EmitRecvPacketEvent emits a receive packet event. It will be emitted both the first time a packet +// emitRecvPacketEvent emits a receive packet event. It will be emitted both the first time a packet // is received for a certain sequence and for all duplicate receives. -func EmitRecvPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +func emitRecvPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRecvPacket, @@ -176,8 +176,8 @@ func EmitRecvPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types }) } -// EmitWriteAcknowledgementEvent emits an event that the relayer can query for -func EmitWriteAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, acknowledgement []byte) { +// emitWriteAcknowledgementEvent emits an event that the relayer can query for +func emitWriteAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, acknowledgement []byte) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeWriteAck, @@ -204,9 +204,9 @@ func EmitWriteAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, cha }) } -// EmitAcknowledgePacketEvent emits an acknowledge packet event. It will be emitted both the first time +// emitAcknowledgePacketEvent emits an acknowledge packet event. It will be emitted both the first time // a packet is acknowledged for a certain sequence and for all duplicate acknowledgements. -func EmitAcknowledgePacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +func emitAcknowledgePacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeAcknowledgePacket, @@ -230,9 +230,9 @@ func EmitAcknowledgePacketEvent(ctx sdk.Context, packet exported.PacketI, channe }) } -// EmitTimeoutPacketEvent emits a timeout packet event. It will be emitted both the first time a packet +// emitTimeoutPacketEvent emits a timeout packet event. It will be emitted both the first time a packet // is timed out for a certain sequence and for all duplicate timeouts. -func EmitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +func emitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeTimeoutPacket, @@ -253,8 +253,8 @@ func EmitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel ty }) } -// EmitChannelClosedEvent emits a channel closed event. -func EmitChannelClosedEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +// emitChannelClosedEvent emits a channel closed event. +func emitChannelClosedEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelClosed, diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 72765182d26..cfca1efd00d 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -99,7 +99,7 @@ func (k Keeper) WriteOpenInitChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-init") }() - EmitChannelOpenInitEvent(ctx, portID, channelID, channel) + emitChannelOpenInitEvent(ctx, portID, channelID, channel) } // ChanOpenTry is called by a module to accept the first step of a channel opening @@ -212,7 +212,7 @@ func (k Keeper) WriteOpenTryChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-try") }() - EmitChannelOpenTryEvent(ctx, portID, channelID, channel) + emitChannelOpenTryEvent(ctx, portID, channelID, channel) } // ChanOpenAck is called by the handshake-originating module to acknowledge the @@ -297,7 +297,7 @@ func (k Keeper) WriteOpenAckChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-ack") }() - EmitChannelOpenAckEvent(ctx, portID, channelID, channel) + emitChannelOpenAckEvent(ctx, portID, channelID, channel) } // ChanOpenConfirm is called by the counterparty module to close their end of the @@ -377,7 +377,7 @@ func (k Keeper) WriteOpenConfirmChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-confirm") }() - EmitChannelOpenConfirmEvent(ctx, portID, channelID, channel) + emitChannelOpenConfirmEvent(ctx, portID, channelID, channel) } // Closing Handshake @@ -436,7 +436,7 @@ func (k Keeper) ChanCloseInit( channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) - EmitChannelCloseInitEvent(ctx, portID, channelID, channel) + emitChannelCloseInitEvent(ctx, portID, channelID, channel) return nil } @@ -501,7 +501,7 @@ func (k Keeper) ChanCloseConfirm( channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) - EmitChannelCloseConfirmEvent(ctx, portID, channelID, channel) + emitChannelCloseConfirmEvent(ctx, portID, channelID, channel) return nil } diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 726df04c3aa..59be12b73ec 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -101,7 +101,7 @@ func (k Keeper) SendPacket( k.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1) k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) - EmitSendPacketEvent(ctx, packet, channel, timeoutHeight) + emitSendPacketEvent(ctx, packet, channel, timeoutHeight) k.Logger(ctx).Info( "packet sent", @@ -209,7 +209,7 @@ func (k Keeper) RecvPacket( // check if the packet receipt has been received already for unordered channels _, found := k.GetPacketReceipt(ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) if found { - EmitRecvPacketEvent(ctx, packet, channel) + emitRecvPacketEvent(ctx, packet, channel) // This error indicates that the packet has already been relayed. Core IBC will // treat this error as a no-op in order to prevent an entire relay transaction // from failing and consuming unnecessary fees. @@ -233,7 +233,7 @@ func (k Keeper) RecvPacket( } if packet.GetSequence() < nextSequenceRecv { - EmitRecvPacketEvent(ctx, packet, channel) + emitRecvPacketEvent(ctx, packet, channel) // This error indicates that the packet has already been relayed. Core IBC will // treat this error as a no-op in order to prevent an entire relay transaction // from failing and consuming unnecessary fees. @@ -268,7 +268,7 @@ func (k Keeper) RecvPacket( ) // emit an event that the relayer can query for - EmitRecvPacketEvent(ctx, packet, channel) + emitRecvPacketEvent(ctx, packet, channel) return nil } @@ -343,7 +343,7 @@ func (k Keeper) WriteAcknowledgement( "dst_channel", packet.GetDestChannel(), ) - EmitWriteAcknowledgementEvent(ctx, packet, channel, bz) + emitWriteAcknowledgementEvent(ctx, packet, channel, bz) return nil } @@ -416,7 +416,7 @@ func (k Keeper) AcknowledgePacket( commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) if len(commitment) == 0 { - EmitAcknowledgePacketEvent(ctx, packet, channel) + emitAcknowledgePacketEvent(ctx, packet, channel) // This error indicates that the acknowledgement has already been relayed // or there is a misconfigured relayer attempting to prove an acknowledgement // for a packet never sent. Core IBC will treat this error as a no-op in order to @@ -478,7 +478,7 @@ func (k Keeper) AcknowledgePacket( ) // emit an event marking that we have processed the acknowledgement - EmitAcknowledgePacketEvent(ctx, packet, channel) + emitAcknowledgePacketEvent(ctx, packet, channel) return nil } diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index fd6686b35b9..a0151520cbf 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -75,7 +75,7 @@ func (k Keeper) TimeoutPacket( commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) if len(commitment) == 0 { - EmitTimeoutPacketEvent(ctx, packet, channel) + emitTimeoutPacketEvent(ctx, packet, channel) // This error indicates that the timeout has already been relayed // or there is a misconfigured relayer attempting to prove a timeout // for a packet never sent. Core IBC will treat this error as a no-op in order to @@ -168,10 +168,10 @@ func (k Keeper) TimeoutExecuted( ) // emit an event marking that we have processed the timeout - EmitTimeoutPacketEvent(ctx, packet, channel) + emitTimeoutPacketEvent(ctx, packet, channel) if channel.Ordering == types.ORDERED && channel.State == types.CLOSED { - EmitChannelClosedEvent(ctx, packet, channel) + emitChannelClosedEvent(ctx, packet, channel) } return nil @@ -224,7 +224,7 @@ func (k Keeper) TimeoutOnClose( commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) if len(commitment) == 0 { - EmitTimeoutPacketEvent(ctx, packet, channel) + emitTimeoutPacketEvent(ctx, packet, channel) // This error indicates that the timeout has already been relayed // or there is a misconfigured relayer attempting to prove a timeout // for a packet never sent. Core IBC will treat this error as a no-op in order to diff --git a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto index ab97914fe5d..284ffe70576 100644 --- a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto @@ -28,6 +28,7 @@ message MsgRegisterInterchainAccount { // MsgRegisterInterchainAccountResponse defines the response for Msg/RegisterAccount message MsgRegisterInterchainAccountResponse { string channel_id = 1 [(gogoproto.moretags) = "yaml:\"channel_id\""]; + string port_id = 2 [(gogoproto.moretags) = "yaml:\"port_id\""]; } // MsgSendTx defines the payload for Msg/SendTx From 0ec6aad9107c9985944fe582973e99f541579df4 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 2 Mar 2023 16:01:19 +0100 Subject: [PATCH 44/52] chore: client state key nit (#3226) --- docs/ibc/light-clients/localhost/client-state.md | 2 +- modules/light-clients/09-localhost/client_state.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/ibc/light-clients/localhost/client-state.md b/docs/ibc/light-clients/localhost/client-state.md index 9a67fa89396..789200534e1 100644 --- a/docs/ibc/light-clients/localhost/client-state.md +++ b/docs/ibc/light-clients/localhost/client-state.md @@ -51,7 +51,7 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client height := clienttypes.GetSelfHeight(ctx) cs.LatestHeight = height - clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &cs)) + clientStore.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(cdc, &cs)) return []exported.Height{height} } diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index c00a8d27155..c950c106f7f 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -62,7 +62,7 @@ func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientS LatestHeight: clienttypes.GetSelfHeight(ctx), } - clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &clientState)) + clientStore.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(cdc, &clientState)) return nil } @@ -169,7 +169,7 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client height := clienttypes.GetSelfHeight(ctx) cs.LatestHeight = height - clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &cs)) + clientStore.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(cdc, &cs)) return []exported.Height{height} } From 51451875248de3287257f00c6adcf5c6f441f0a1 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 6 Mar 2023 09:49:07 +0100 Subject: [PATCH 45/52] indentation --- docs/ibc/light-clients/localhost/client-state.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/ibc/light-clients/localhost/client-state.md b/docs/ibc/light-clients/localhost/client-state.md index 789200534e1..15c6e1c4b8a 100644 --- a/docs/ibc/light-clients/localhost/client-state.md +++ b/docs/ibc/light-clients/localhost/client-state.md @@ -18,8 +18,8 @@ It calls `CreateLocalhostClient`, declaring a new `ClientState` and initializing ```go func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error { - var clientState localhost.ClientState - return clientState.Initialize(ctx, k.cdc, k.ClientStore(ctx, exported.LocalhostClientID), nil) + var clientState localhost.ClientState + return clientState.Initialize(ctx, k.cdc, k.ClientStore(ctx, exported.LocalhostClientID), nil) } ``` @@ -36,10 +36,10 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { // ... if clientState, found := k.GetClientState(ctx, exported.Localhost); found { - if k.GetClientStatus(ctx, clientState, exported.Localhost) == exported.Active { - k.UpdateLocalhostClient(ctx, clientState) - } - } + if k.GetClientStatus(ctx, clientState, exported.Localhost) == exported.Active { + k.UpdateLocalhostClient(ctx, clientState) + } + } } ``` From 9a41fe192f78e45291a58b0a363ee935c63ead74 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 6 Mar 2023 09:51:30 +0100 Subject: [PATCH 46/52] indentation --- docs/ibc/light-clients/localhost/connection.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/ibc/light-clients/localhost/connection.md b/docs/ibc/light-clients/localhost/connection.md index d76b44a68ae..33251bde432 100644 --- a/docs/ibc/light-clients/localhost/connection.md +++ b/docs/ibc/light-clients/localhost/connection.md @@ -15,11 +15,11 @@ The `ConnectionEnd` and its `Counterparty` both reference the `09-localhost` cli ```go // CreateSentinelLocalhostConnection creates and sets the sentinel localhost connection end in the IBC store. func (k Keeper) CreateSentinelLocalhostConnection(ctx sdk.Context) { - counterparty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) - connectionEnd := types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) + counterparty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) + connectionEnd := types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) - k.SetConnection(ctx, exported.LocalhostConnectionID, connectionEnd) + k.SetConnection(ctx, exported.LocalhostConnectionID, connectionEnd) } ``` -Note that connection handshakes are disallowed when using the `09-localhost` client type. \ No newline at end of file +Note that connection handshakes are disallowed when using the `09-localhost` client type. From 1e131c79cd5aa9158b0932da4695eeaf6817e9a9 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 6 Mar 2023 09:58:35 +0100 Subject: [PATCH 47/52] add 09-locahost to default list --- docs/ibc/params.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ibc/params.md b/docs/ibc/params.md index 3040eea50b7..dcf60692695 100644 --- a/docs/ibc/params.md +++ b/docs/ibc/params.md @@ -10,7 +10,7 @@ The 02-client submodule contains the following parameters: | Key | Type | Default Value | |------------------|------|---------------| -| `AllowedClients` | []string | `"06-solomachine","07-tendermint"` | +| `AllowedClients` | []string | `"06-solomachine","07-tendermint","09-localhost"` | ### AllowedClients From 5c0fc8ba7acd0c6d25373299ab8850cdc2c7a9d0 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 6 Mar 2023 10:25:28 +0100 Subject: [PATCH 48/52] update events.md --- docs/ibc/events.md | 129 +++++++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 51 deletions(-) diff --git a/docs/ibc/events.md b/docs/ibc/events.md index 080c284deaa..d01c1b37649 100644 --- a/docs/ibc/events.md +++ b/docs/ibc/events.md @@ -185,63 +185,90 @@ callbacks to IBC applications. ### SendPacket (application module call) -| Type | Attribute Key | Attribute Value | -|-------------|--------------------------|----------------------------------| -| send_packet | packet_data | {data} | -| send_packet | packet_timeout_height | {timeoutHeight} | -| send_packet | packet_timeout_timestamp | {timeoutTimestamp} | -| send_packet | packet_sequence | {sequence} | -| send_packet | packet_src_port | {sourcePort} | -| send_packet | packet_src_channel | {sourceChannel} | -| send_packet | packet_dst_port | {destinationPort} | -| send_packet | packet_dst_channel | {destinationChannel} | -| send_packet | packet_channel_ordering | {channel.Ordering} | -| message | action | application-module-defined-field | -| message | module | ibc-channel | +| Type | Attribute Key | Attribute Value | Status | +|-------------|--------------------------|----------------------------------|------------| +| send_packet | packet_data | {data} | Deprecated | +| send_packet | packet_data_hex | {hex.Encode(data)} | | +| send_packet | packet_timeout_height | {timeoutHeight} | | +| send_packet | packet_timeout_timestamp | {timeoutTimestamp} | | +| send_packet | packet_sequence | {sequence} | | +| send_packet | packet_src_port | {sourcePort} | | +| send_packet | packet_src_channel | {sourceChannel} | | +| send_packet | packet_dst_port | {destinationPort} | | +| send_packet | packet_dst_channel | {destinationChannel} | | +| send_packet | packet_channel_ordering | {channel.Ordering} | | +| send_packet | packet_connection | {channel.ConnectionHops[0]} | Deprecated | +| send_packet | connection_id | {channel.ConnectionHops[0]} | | +| message | action | application-module-defined-field | | +| message | module | ibc-channel | | ### MsgRecvPacket -| Type | Attribute Key | Attribute Value | -|-------------|--------------------------|----------------------| -| recv_packet | packet_data | {data} | -| recv_packet | packet_ack | {acknowledgement} | -| recv_packet | packet_timeout_height | {timeoutHeight} | -| recv_packet | packet_timeout_timestamp | {timeoutTimestamp} | -| recv_packet | packet_sequence | {sequence} | -| recv_packet | packet_src_port | {sourcePort} | -| recv_packet | packet_src_channel | {sourceChannel} | -| recv_packet | packet_dst_port | {destinationPort} | -| recv_packet | packet_dst_channel | {destinationChannel} | -| recv_packet | packet_channel_ordering | {channel.Ordering} | -| message | action | recv_packet | -| message | module | ibc-channel | +| Type | Attribute Key | Attribute Value | Status | +|-------------|--------------------------|-------------------------------|------------| +| recv_packet | packet_data | {data} | Deprecated | +| recv_packet | packet_data_hex | {hex.Encode(data)} | | +| recv_packet | packet_timeout_height | {timeoutHeight} | | +| recv_packet | packet_timeout_timestamp | {timeoutTimestamp} | | +| recv_packet | packet_sequence | {sequence} | | +| recv_packet | packet_src_port | {sourcePort} | | +| recv_packet | packet_src_channel | {sourceChannel} | | +| recv_packet | packet_dst_port | {destinationPort} | | +| recv_packet | packet_dst_channel | {destinationChannel} | | +| recv_packet | packet_channel_ordering | {channel.Ordering} | | +| recv_packet | packet_connection | {channel.ConnectionHops[0]} | Deprecated | +| recv_packet | connection_id | {channel.ConnectionHops[0]} | | +| message | action | recv_packet | | +| message | module | ibc-channel | | + +| Type | Attribute Key | Attribute Value | Status | +|-----------------------|--------------------------|-------------------------------|------------| +| write_acknowledgement | packet_data | {data} | Deprecated | +| write_acknowledgement | packet_data_hex | {hex.Encode(data)} | | +| write_acknowledgement | packet_timeout_height | {timeoutHeight} | | +| write_acknowledgement | packet_timeout_timestamp | {timeoutTimestamp} | | +| write_acknowledgement | packet_sequence | {sequence} | | +| write_acknowledgement | packet_src_port | {sourcePort} | | +| write_acknowledgement | packet_src_channel | {sourceChannel} | | +| write_acknowledgement | packet_dst_port | {destinationPort} | | +| write_acknowledgement | packet_dst_channel | {destinationChannel} | | +| write_acknowledgement | packet_ack | {ack} | Deprecated | +| write_acknowledgement | packet_ack_hex | {hex.Encode(ack)} | | +| write_acknowledgement | packet_channel_ordering | {channel.Ordering} | | +| write_acknowledgement | packet_connection | {channel.ConnectionHops[0]} | Deprecated | +| write_acknowledgement | connection_id | {channel.ConnectionHops[0]} | | +| message | action | write_acknowledgement | | +| message | module | ibc-channel | | ### MsgAcknowledgePacket -| Type | Attribute Key | Attribute Value | -|--------------------|--------------------------|----------------------| -| acknowledge_packet | packet_timeout_height | {timeoutHeight} | -| acknowledge_packet | packet_timeout_timestamp | {timeoutTimestamp} | -| acknowledge_packet | packet_sequence | {sequence} | -| acknowledge_packet | packet_src_port | {sourcePort} | -| acknowledge_packet | packet_src_channel | {sourceChannel} | -| acknowledge_packet | packet_dst_port | {destinationPort} | -| acknowledge_packet | packet_dst_channel | {destinationChannel} | -| acknowledge_packet | packet_channel_ordering | {channel.Ordering} | -| message | action | acknowledge_packet | -| message | module | ibc-channel | +| Type | Attribute Key | Attribute Value | Status | +|--------------------|--------------------------|-------------------------------|------------| +| acknowledge_packet | packet_timeout_height | {timeoutHeight} | | +| acknowledge_packet | packet_timeout_timestamp | {timeoutTimestamp} | | +| acknowledge_packet | packet_sequence | {sequence} | | +| acknowledge_packet | packet_src_port | {sourcePort} | | +| acknowledge_packet | packet_src_channel | {sourceChannel} | | +| acknowledge_packet | packet_dst_port | {destinationPort} | | +| acknowledge_packet | packet_dst_channel | {destinationChannel} | | +| acknowledge_packet | packet_channel_ordering | {channel.Ordering} | | +| acknowledge_packet | packet_connection | {channel.ConnectionHops[0]} | Deprecated | +| acknowledge_packet | connection_id | {channel.ConnectionHops[0]} | | +| message | action | acknowledge_packet | | +| message | module | ibc-channel | | ### MsgTimeoutPacket & MsgTimeoutOnClose -| Type | Attribute Key | Attribute Value | -|----------------|--------------------------|----------------------| -| timeout_packet | packet_timeout_height | {timeoutHeight} | -| timeout_packet | packet_timeout_timestamp | {timeoutTimestamp} | -| timeout_packet | packet_sequence | {sequence} | -| timeout_packet | packet_src_port | {sourcePort} | -| timeout_packet | packet_src_channel | {sourceChannel} | -| timeout_packet | packet_dst_port | {destinationPort} | -| timeout_packet | packet_dst_channel | {destinationChannel} | -| timeout_packet | packet_channel_ordering | {channel.Ordering} | -| message | action | timeout_packet | -| message | module | ibc-channel | +| Type | Attribute Key | Attribute Value | +|----------------|--------------------------|-------------------------------| +| timeout_packet | packet_timeout_height | {timeoutHeight} | +| timeout_packet | packet_timeout_timestamp | {timeoutTimestamp} | +| timeout_packet | packet_sequence | {sequence} | +| timeout_packet | packet_src_port | {sourcePort} | +| timeout_packet | packet_src_channel | {sourceChannel} | +| timeout_packet | packet_dst_port | {destinationPort} | +| timeout_packet | packet_dst_channel | {destinationChannel} | +| timeout_packet | packet_channel_ordering | {channel.Ordering} | +| timeout_packet | connection_id | {channel.ConnectionHops[0]} | +| message | action | timeout_packet | +| message | module | ibc-channel | From 78cdc696058c2b8d6bd480eb5305235069794f84 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 7 Mar 2023 17:39:09 +0100 Subject: [PATCH 49/52] adding migration doc for v7.1 localhost client (#3210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Carlos Rodriguez --- docs/.vuepress/config.js | 5 ++++ docs/migrations/v7-to-v7_1.md | 40 ++++++++++++++++++++++++----- testing/simapp/upgrades/upgrades.go | 2 +- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index ee649dd9a81..90e172b6cf4 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -545,6 +545,11 @@ module.exports = { directory: false, path: "/migrations/v6-to-v7.html", }, + { + title: "IBC-Go v7 to v7.1", + directory: false, + path: "/migrations/v7-to-v7_1.html", + }, ], }, { diff --git a/docs/migrations/v7-to-v7_1.md b/docs/migrations/v7-to-v7_1.md index 00a233a0ac4..c01c8a05375 100644 --- a/docs/migrations/v7-to-v7_1.md +++ b/docs/migrations/v7-to-v7_1.md @@ -1,19 +1,47 @@ # Migrating from v7 to v7.1 -This guide provides instructions for migrating to a new version of ibc-go. +This guide provides instructions for migrating to version `v7.1.0` of ibc-go. There are four sections based on the four potential user groups of this document: -- [Chains](#chains) -- [IBC Apps](#ibc-apps) -- [Relayers](#relayers) -- [IBC Light Clients](#ibc-light-clients) +- [Migrating from v7 to v7.1](#migrating-from-v7-to-v71) + - [Chains](#chains) + - [IBC Apps](#ibc-apps) + - [Relayers](#relayers) + - [IBC Light Clients](#ibc-light-clients) **Note:** ibc-go supports golang semantic versioning and therefore all imports must be updated on major version releases. ## Chains -- No relevant changes were made in this release. +In the previous release of ibc-go, the localhost `v1` light client module was deprecated and removed. The ibc-go `v7.1.0` release introduces `v2` of the 09-localhost light client module. + + +An [automatic migration handler](https://github.com/cosmos/ibc-go/blob/09-localhost/modules/core/module.go#L133-L145) is configured in the core IBC module to set the localhost `ClientState` and sentintel `ConnectionEnd` in state. + +In order to use the 09-localhost client chains must update the `AllowedClients` parameter in the 02-client submodule of core IBC. This can be configured directly in the application upgrade handler or alternatively updated via the legacy governance parameter change proposal. +We __strongly__ recommend chains to perform this action. + +See the upgrade handler code sample provided below or [follow this link](https://github.com/cosmos/ibc-go/blob/09-localhost/testing/simapp/upgrades/upgrades.go#L85) for the upgrade handler used by the ibc-go simapp. + +```go +func CreateV7LocalhostUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + clientKeeper clientkeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // explicitly update the IBC 02-client params, adding the localhost client type + params := clientKeeper.GetParams(ctx) + params.AllowedClients = append(params.AllowedClients, exported.Localhost) + clientKeeper.SetParams(ctx, params) + + return mm.RunMigrations(ctx, configurator, vm) + } +} +``` + +[For more information please refer to the 09-localhost light client module documentation](../ibc/light-clients/localhost/overview.md). ## IBC Apps diff --git a/testing/simapp/upgrades/upgrades.go b/testing/simapp/upgrades/upgrades.go index 40535eba24a..1adf5eb3e68 100644 --- a/testing/simapp/upgrades/upgrades.go +++ b/testing/simapp/upgrades/upgrades.go @@ -88,7 +88,7 @@ func CreateV7LocalhostUpgradeHandler( clientKeeper clientkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - // explicitly update the IBC 02-client params with the new default allowed clients + // explicitly update the IBC 02-client params, adding the localhost client type params := clientKeeper.GetParams(ctx) params.AllowedClients = append(params.AllowedClients, exported.Localhost) clientKeeper.SetParams(ctx, params) From 38f7d99e6466a868025fdab566ebfa6502f8c760 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 7 Mar 2023 16:41:30 +0000 Subject: [PATCH 50/52] ran go mod tidy --- e2e/go.mod | 1 + e2e/go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/e2e/go.mod b/e2e/go.mod index 80a38700da6..933b8eee8c3 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -11,6 +11,7 @@ require ( github.com/docker/docker v20.10.19+incompatible github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230302213153-84ec330a137b github.com/stretchr/testify v1.8.2 + github.com/tendermint/tendermint v0.37.0-rc2 go.uber.org/zap v1.24.0 golang.org/x/mod v0.8.0 google.golang.org/grpc v1.53.0 diff --git a/e2e/go.sum b/e2e/go.sum index f4d07b0db6b..fdeb4f4c7d3 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -1004,6 +1004,8 @@ github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzH github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/tendermint/tendermint v0.37.0-rc2 h1:2n1em+jfbhSv6QnBj8F6KHCpbIzZCB8KgcjidJUQNlY= +github.com/tendermint/tendermint v0.37.0-rc2/go.mod h1:uYQO9DRNPeZROa9X3hJOZpYcVREDC2/HST+EiU5g2+A= github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg= github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= From 12bd5b89a875212dbc58dabc0907ea00d9c72a77 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 7 Mar 2023 16:50:55 +0000 Subject: [PATCH 51/52] changed tendermint to cometbft --- e2e/go.mod | 1 - e2e/go.sum | 2 -- e2e/testsuite/events.go | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/e2e/go.mod b/e2e/go.mod index 933b8eee8c3..80a38700da6 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -11,7 +11,6 @@ require ( github.com/docker/docker v20.10.19+incompatible github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230302213153-84ec330a137b github.com/stretchr/testify v1.8.2 - github.com/tendermint/tendermint v0.37.0-rc2 go.uber.org/zap v1.24.0 golang.org/x/mod v0.8.0 google.golang.org/grpc v1.53.0 diff --git a/e2e/go.sum b/e2e/go.sum index fdeb4f4c7d3..f4d07b0db6b 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -1004,8 +1004,6 @@ github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzH github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= -github.com/tendermint/tendermint v0.37.0-rc2 h1:2n1em+jfbhSv6QnBj8F6KHCpbIzZCB8KgcjidJUQNlY= -github.com/tendermint/tendermint v0.37.0-rc2/go.mod h1:uYQO9DRNPeZROa9X3hJOZpYcVREDC2/HST+EiU5g2+A= github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg= github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= diff --git a/e2e/testsuite/events.go b/e2e/testsuite/events.go index feb79372123..49a76aebe26 100644 --- a/e2e/testsuite/events.go +++ b/e2e/testsuite/events.go @@ -2,7 +2,7 @@ package testsuite import ( sdk "github.com/cosmos/cosmos-sdk/types" - abci "github.com/tendermint/tendermint/abci/types" + abci "github.com/cometbft/cometbft/abci/types" ) // ABCIToSDKEvents converts a list of ABCI events to Cosmos SDK events. From b67680ff65d753214ef5330fcc7200d091c4d6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 8 Mar 2023 16:51:40 +0100 Subject: [PATCH 52/52] chore: add in-code comment --- modules/core/02-client/genesis.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/02-client/genesis.go b/modules/core/02-client/genesis.go index 269eb7f6bd7..7a38683ea03 100644 --- a/modules/core/02-client/genesis.go +++ b/modules/core/02-client/genesis.go @@ -47,6 +47,8 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { k.SetNextClientSequence(ctx, gs.NextClientSequence) + // if the localhost already exists in state (included in the genesis file), + // it must be overwritten to ensure its stored height equals the context block height if err := k.CreateLocalhostClient(ctx); err != nil { panic(fmt.Sprintf("failed to initialise localhost client: %s", err.Error())) }