Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions modules/core/04-channel/v2/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import (
"github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
)

// getV1Counterparty attempts to retrieve a v1 channel from the channel keeper if it exists, then converts it
// to a v2 counterparty and stores it in the v2 channel keeper for future use
func (k *Keeper) getV1Counterparty(ctx context.Context, port, id string) (channeltypesv2.Counterparty, bool) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not return an err directly? will we ever do anything else other than fail? 🤔 I guess we do the get with a bool return in other places too.

Fine as is though!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I don't have any strong feelings about it. I liked keeping it similar to the original GetCounterparty

if counterparty, ok := k.AliasV1Channel(ctx, port, id); ok {
// we can key on just the channel here since channel ids are globally unique
k.SetCounterparty(ctx, id, counterparty)
return counterparty, true
}

return channeltypesv2.Counterparty{}, false
}

// sendPacket constructs a packet from the input arguments, writes a packet commitment to state
// in order for the packet to be sent to the counterparty.
func (k *Keeper) sendPacket(
Expand All @@ -26,15 +38,9 @@ func (k *Keeper) sendPacket(
// Lookup counterparty associated with our source channel to retrieve the destination channel
counterparty, ok := k.GetCounterparty(ctx, sourceID)
if !ok {
// If the counterparty is not found, attempt to retrieve a v1 channel from the channel keeper
// if it exists, then we will convert it to a v2 counterparty and store it in the packet server keeper
// for future use.
// TODO: figure out how aliasing will work when more than one packet data is sent.
if counterparty, ok = k.AliasV1Channel(ctx, data[0].SourcePort, sourceID); ok {
// we can key on just the source channel here since channel ids are globally unique
k.SetCounterparty(ctx, sourceID, counterparty)
} else {
// if neither a counterparty nor channel is found then simply return an error
counterparty, ok = k.getV1Counterparty(ctx, data[0].SourcePort, sourceID)
if !ok {
return 0, errorsmod.Wrap(types.ErrCounterpartyNotFound, sourceID)
}
}
Expand Down Expand Up @@ -107,16 +113,10 @@ func (k Keeper) recvPacket(
// that the packet was indeed sent by our counterparty.
counterparty, ok := k.GetCounterparty(ctx, packet.DestinationId)
if !ok {
// If the counterparty is not found, attempt to retrieve a v1 channel from the channel keeper
// if it exists, then we will convert it to a v2 counterparty and store it in the packet server keeper
// for future use.
// TODO: figure out how aliasing will work when more than one packet data is sent.
if counterparty, ok = k.AliasV1Channel(ctx, packet.Data[0].SourcePort, packet.SourceId); ok {
// we can key on just the source channel here since channel ids are globally unique
k.SetCounterparty(ctx, packet.SourceId, counterparty)
} else {
// if neither a counterparty nor channel is found then simply return an error
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.SourceId)
counterparty, ok = k.getV1Counterparty(ctx, packet.Data[0].DestinationPort, packet.DestinationId)
if !ok {
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
}
}
if counterparty.ClientId != packet.SourceId {
Expand Down