From cbc2fe097c947a249fe6dcd3d423afdc0655607b Mon Sep 17 00:00:00 2001 From: chandiniv1 Date: Wed, 21 Aug 2024 16:28:50 +0530 Subject: [PATCH 1/4] Use client and counterparty terminology in packet server rather than channel --- modules/core/packet-server/keeper/keeper.go | 10 +++++----- modules/core/packet-server/keeper/keeper_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index 926905228b9..cc408111fa4 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -60,7 +60,7 @@ func (k Keeper) SendPacket( // Lookup counterparty associated with our source channel to retrieve the destination channel counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, sourceChannel) if !ok { - return 0, channeltypes.ErrChannelNotFound + return 0, clienttypes.ErrClientNotFound } destChannel := counterparty.ClientId @@ -136,7 +136,7 @@ func (k Keeper) RecvPacket( // sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { - return "", channeltypes.ErrChannelNotFound + return "", clienttypes.ErrClientNotFound } if counterparty.ClientId != packet.SourceChannel { return "", channeltypes.ErrInvalidChannelIdentifier @@ -211,7 +211,7 @@ func (k Keeper) WriteAcknowledgement( // sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { - return channeltypes.ErrChannelNotFound + return clienttypes.ErrClientNotFound } if counterparty.ClientId != packet.SourceChannel { return channeltypes.ErrInvalidChannelIdentifier @@ -268,7 +268,7 @@ func (k Keeper) AcknowledgePacket( // sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { - return "", channeltypes.ErrChannelNotFound + return "", clienttypes.ErrClientNotFound } if counterparty.ClientId != packet.DestinationChannel { @@ -339,7 +339,7 @@ func (k Keeper) TimeoutPacket( // is the expected counterparty counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { - return "", channeltypes.ErrChannelNotFound + return "", clienttypes.ErrClientNotFound } if counterparty.ClientId != packet.DestinationChannel { diff --git a/modules/core/packet-server/keeper/keeper_test.go b/modules/core/packet-server/keeper/keeper_test.go index 513a5412dbb..efc1fc8b885 100644 --- a/modules/core/packet-server/keeper/keeper_test.go +++ b/modules/core/packet-server/keeper/keeper_test.go @@ -61,7 +61,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { {"success", func() {}, nil}, {"counterparty not found", func() { packet.SourceChannel = ibctesting.FirstChannelID - }, channeltypes.ErrChannelNotFound}, + }, clienttypes.ErrClientNotFound}, {"packet failed basic validation", func() { // invalid data packet.Data = nil @@ -139,7 +139,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { func() { packet.DestinationChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrClientNotFound, }, { "failure: client is not active", @@ -246,7 +246,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { func() { packet.DestinationChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrClientNotFound, }, { "failure: counterparty client identifier different than source channel", @@ -347,7 +347,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { func() { packet.SourceChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrClientNotFound, }, { "failure: counterparty client identifier different than source channel", @@ -489,7 +489,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet.SourceChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrClientNotFound, }, { "failure: counterparty client identifier different than source channel", From 97b5777335e0b4c8b2c1c863704e98df525e8e4f Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 26 Aug 2024 09:29:11 +0200 Subject: [PATCH 2/4] add counterparty not found error --- modules/core/02-client/types/errors.go | 1 + modules/core/keeper/msg_server_test.go | 6 +- modules/core/packet-server/keeper/keeper.go | 22 ++++---- .../core/packet-server/keeper/keeper_test.go | 55 +++++++++++++------ 4 files changed, 52 insertions(+), 32 deletions(-) diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 116e322ac6d..f663019ab0f 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -39,4 +39,5 @@ var ( ErrRouteNotFound = errorsmod.Register(SubModuleName, 32, "light client module route not found") ErrClientTypeNotSupported = errorsmod.Register(SubModuleName, 33, "client type not supported") ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 34, "invalid counterparty") + ErrCounterpartyNotFound = errorsmod.Register(SubModuleName, 35, "counterparty not found") ) diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 43e59b1c130..4a87d594d09 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -307,7 +307,7 @@ func (suite *KeeperTestSuite) TestRecvPacketV2() { // any non-nil value of packet is valid suite.Require().NotNil(packet) }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, false, false, false, @@ -670,7 +670,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacketV2() { func() { packet.SourceChannel = "invalid-client" }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, false, }, { @@ -996,7 +996,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacketV2() { packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, false, }, } diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index eb06fe2a2b1..5f084ff64f1 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -59,7 +59,7 @@ func (k Keeper) SendPacket( // Lookup counterparty associated with our source channel to retrieve the destination channel counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, sourceChannel) if !ok { - return 0, clienttypes.ErrClientNotFound + return 0, errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, sourceChannel) } destChannel := counterparty.ClientId @@ -131,11 +131,11 @@ func (k Keeper) RecvPacket( return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. + // Lookup counterparty associated with our channel and ensure + // that it was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { - return "", clienttypes.ErrClientNotFound + return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel) } if counterparty.ClientId != packet.SourceChannel { return "", channeltypes.ErrInvalidChannelIdentifier @@ -206,11 +206,11 @@ func (k Keeper) WriteAcknowledgement( return channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. + // Lookup counterparty associated with our channel and ensure + // that it was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { - return clienttypes.ErrClientNotFound + return errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel) } if counterparty.ClientId != packet.SourceChannel { return channeltypes.ErrInvalidChannelIdentifier @@ -263,11 +263,11 @@ func (k Keeper) AcknowledgePacket( return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. + // Lookup counterparty associated with our channel and ensure + // that it was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { - return "", clienttypes.ErrClientNotFound + return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel) } if counterparty.ClientId != packet.DestinationChannel { @@ -338,7 +338,7 @@ func (k Keeper) TimeoutPacket( // is the expected counterparty counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { - return "", clienttypes.ErrClientNotFound + return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel) } if counterparty.ClientId != packet.DestinationChannel { diff --git a/modules/core/packet-server/keeper/keeper_test.go b/modules/core/packet-server/keeper/keeper_test.go index efc1fc8b885..183f32a6be4 100644 --- a/modules/core/packet-server/keeper/keeper_test.go +++ b/modules/core/packet-server/keeper/keeper_test.go @@ -58,20 +58,39 @@ func (suite *KeeperTestSuite) TestSendPacket() { malleate func() expError error }{ - {"success", func() {}, nil}, - {"counterparty not found", func() { - packet.SourceChannel = ibctesting.FirstChannelID - }, clienttypes.ErrClientNotFound}, - {"packet failed basic validation", func() { - // invalid data - packet.Data = nil - }, channeltypes.ErrInvalidPacket}, - {"client status invalid", func() { - path.EndpointA.FreezeClient() - }, clienttypes.ErrClientNotActive}, - {"timeout elapsed", func() { - packet.TimeoutTimestamp = 1 - }, channeltypes.ErrTimeoutElapsed}, + { + "success", + func() {}, + nil, + }, + { + "counterparty not found", + func() { + packet.SourceChannel = ibctesting.FirstChannelID + }, + clienttypes.ErrCounterpartyNotFound, + }, + { + "packet failed basic validation", + func() { + // invalid data + packet.Data = nil + }, + channeltypes.ErrInvalidPacket, + }, + { + "client status invalid", + func() { + path.EndpointA.FreezeClient() + }, + clienttypes.ErrClientNotActive, + }, + { + "timeout elapsed", func() { + packet.TimeoutTimestamp = 1 + }, + channeltypes.ErrTimeoutElapsed, + }, } for i, tc := range testCases { @@ -139,7 +158,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { func() { packet.DestinationChannel = ibctesting.FirstChannelID }, - clienttypes.ErrClientNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: client is not active", @@ -246,7 +265,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { func() { packet.DestinationChannel = ibctesting.FirstChannelID }, - clienttypes.ErrClientNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than source channel", @@ -347,7 +366,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { func() { packet.SourceChannel = ibctesting.FirstChannelID }, - clienttypes.ErrClientNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than source channel", @@ -489,7 +508,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet.SourceChannel = ibctesting.FirstChannelID }, - clienttypes.ErrClientNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than source channel", From c930b3a2a6f1cb000796ddff7e332e1052915de7 Mon Sep 17 00:00:00 2001 From: chandiniv1 Date: Mon, 26 Aug 2024 14:30:47 +0530 Subject: [PATCH 3/4] add ErrCounterpartyNotFound --- modules/core/02-client/types/errors.go | 1 + modules/core/packet-server/keeper/keeper.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 116e322ac6d..f663019ab0f 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -39,4 +39,5 @@ var ( ErrRouteNotFound = errorsmod.Register(SubModuleName, 32, "light client module route not found") ErrClientTypeNotSupported = errorsmod.Register(SubModuleName, 33, "client type not supported") ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 34, "invalid counterparty") + ErrCounterpartyNotFound = errorsmod.Register(SubModuleName, 35, "counterparty not found") ) diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index cc408111fa4..aa2fd5d3664 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -60,7 +60,7 @@ func (k Keeper) SendPacket( // Lookup counterparty associated with our source channel to retrieve the destination channel counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, sourceChannel) if !ok { - return 0, clienttypes.ErrClientNotFound + return 0, errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, sourceChannel) } destChannel := counterparty.ClientId @@ -132,7 +132,7 @@ func (k Keeper) RecvPacket( return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that it was packet was indeed + // Lookup counterparty associated with our channel and ensure that packet was indeed // sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { From d83e77c318b1307a10fbb9b21dc0d50753df8a26 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 26 Aug 2024 12:18:24 +0200 Subject: [PATCH 4/4] improve comment --- modules/core/packet-server/keeper/keeper.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index 48bc7477264..894ebb59b4a 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -131,8 +131,8 @@ func (k Keeper) RecvPacket( return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that packet was indeed - // sent by our counterparty. + // Lookup counterparty associated with our channel and ensure + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel) @@ -207,7 +207,7 @@ func (k Keeper) WriteAcknowledgement( } // Lookup counterparty associated with our channel and ensure - // that it was indeed sent by our counterparty. + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { return errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel) @@ -264,7 +264,7 @@ func (k Keeper) AcknowledgePacket( } // Lookup counterparty associated with our channel and ensure - // that it was indeed sent by our counterparty. + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel) @@ -334,8 +334,8 @@ func (k Keeper) TimeoutPacket( if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that destination channel - // is the expected counterparty + // Lookup counterparty associated with our channel and ensure + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel)