Skip to content

Commit

Permalink
Use client and counterparty terminology in packet server (#7195)
Browse files Browse the repository at this point in the history
* Use client and counterparty terminology in packet server rather than channel

* add counterparty not found error

* add ErrCounterpartyNotFound

* improve comment

---------

Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
chandiniv1 and crodriguezvega authored Aug 26, 2024
1 parent ed164c3 commit f4783d1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
1 change: 1 addition & 0 deletions modules/core/02-client/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
6 changes: 3 additions & 3 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -670,7 +670,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacketV2() {
func() {
packet.SourceChannel = "invalid-client"
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
false,
},
{
Expand Down Expand Up @@ -996,7 +996,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacketV2() {

packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
false,
},
}
Expand Down
26 changes: 13 additions & 13 deletions modules/core/packet-server/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, channeltypes.ErrChannelNotFound
return 0, errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, sourceChannel)
}
destChannel := counterparty.ClientId

Expand Down Expand Up @@ -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 the packet was indeed sent by our counterparty.
counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel)
if !ok {
return "", channeltypes.ErrChannelNotFound
return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel)
}
if counterparty.ClientId != packet.SourceChannel {
return "", channeltypes.ErrInvalidChannelIdentifier
Expand Down Expand Up @@ -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 the packet was indeed sent by our counterparty.
counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel)
if !ok {
return channeltypes.ErrChannelNotFound
return errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel)
}
if counterparty.ClientId != packet.SourceChannel {
return channeltypes.ErrInvalidChannelIdentifier
Expand Down Expand Up @@ -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 the packet was indeed sent by our counterparty.
counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel)
if !ok {
return "", channeltypes.ErrChannelNotFound
return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel)
}

if counterparty.ClientId != packet.DestinationChannel {
Expand Down Expand Up @@ -334,11 +334,11 @@ 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 "", channeltypes.ErrChannelNotFound
return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel)
}

if counterparty.ClientId != packet.DestinationChannel {
Expand Down
55 changes: 37 additions & 18 deletions modules/core/packet-server/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,39 @@ func (suite *KeeperTestSuite) TestSendPacket() {
malleate func()
expError error
}{
{"success", func() {}, nil},
{"counterparty not found", func() {
packet.SourceChannel = ibctesting.FirstChannelID
}, channeltypes.ErrChannelNotFound},
{"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 {
Expand Down Expand Up @@ -139,7 +158,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
func() {
packet.DestinationChannel = ibctesting.FirstChannelID
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: client is not active",
Expand Down Expand Up @@ -246,7 +265,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() {
func() {
packet.DestinationChannel = ibctesting.FirstChannelID
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: counterparty client identifier different than source channel",
Expand Down Expand Up @@ -347,7 +366,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
func() {
packet.SourceChannel = ibctesting.FirstChannelID
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: counterparty client identifier different than source channel",
Expand Down Expand Up @@ -489,7 +508,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {

packet.SourceChannel = ibctesting.FirstChannelID
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: counterparty client identifier different than source channel",
Expand Down

0 comments on commit f4783d1

Please sign in to comment.