Skip to content
Merged
Changes from 5 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
30 changes: 21 additions & 9 deletions testing/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
)

Expand Down Expand Up @@ -39,47 +41,57 @@ func (path *Path) SetChannelOrdered() {
// if EndpointA does not contain a packet commitment for that packet. An error is returned
// if a relay step fails or the packet commitment does not exist on either endpoint.
func (path *Path) RelayPacket(packet channeltypes.Packet) error {
_, _, err := path.RelayPacketWithResults(packet)
return err
}

// RelayPacketWithResults attempts to relay the packet first on EndpointA and then on EndpointB
// if EndpointA does not contain a packet commitment for that packet. The function returns:
// - The result of the packet receive transaction.
// - The acknowledgement written on the receiving chain.
// - An error if a relay step fails or the packet commitment does not exist on either endpoint.
func (path *Path) RelayPacketWithResults(packet channeltypes.Packet) (*sdk.Result, []byte, error) {
pc := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointA.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
Comment thread
crodriguezvega marked this conversation as resolved.
if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointA.Chain.App.AppCodec(), packet)) {

// packet found, relay from A to B
if err := path.EndpointB.UpdateClient(); err != nil {
return err
return nil, nil, err
}

res, err := path.EndpointB.RecvPacketWithResult(packet)
if err != nil {
return err
return nil, nil, err
}

ack, err := ParseAckFromEvents(res.GetEvents())
if err != nil {
return err
return res, ack, err
Comment thread
crodriguezvega marked this conversation as resolved.
Outdated
}

return path.EndpointA.AcknowledgePacket(packet, ack)
return res, ack, path.EndpointA.AcknowledgePacket(packet, ack)
Comment thread
crodriguezvega marked this conversation as resolved.
Outdated
}

pc = path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointB.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointB.Chain.App.AppCodec(), packet)) {

// packet found, relay B to A
if err := path.EndpointA.UpdateClient(); err != nil {
return err
return nil, nil, err
}

res, err := path.EndpointA.RecvPacketWithResult(packet)
if err != nil {
return err
return nil, nil, err
}

ack, err := ParseAckFromEvents(res.GetEvents())
if err != nil {
return err
return res, ack, err
Comment thread
crodriguezvega marked this conversation as resolved.
Outdated
}

return path.EndpointB.AcknowledgePacket(packet, ack)
return res, ack, path.EndpointB.AcknowledgePacket(packet, ack)
}

return fmt.Errorf("packet commitment does not exist on either endpoint for provided packet")
return nil, nil, fmt.Errorf("packet commitment does not exist on either endpoint for provided packet")
}