Skip to content

Commit

Permalink
Fix state based relaying for acknowledgements (#488)
Browse files Browse the repository at this point in the history
* fix flipped acknowledgement query for state based relaying

* fix bug

* revert comment

* update changelog
  • Loading branch information
colin-axner committed Apr 14, 2021
1 parent 93cf183 commit 8cd901e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### Relayer

* [\#488](https://github.com/cosmos/relayer/pull/488) Fix state based relaying for acknowledgements.
* [\#474](https://github.com/cosmos/relayer/pull/474) Fix validator set mismatch when updating IBC client.


Expand Down
26 changes: 15 additions & 11 deletions relayer/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,26 +423,30 @@ func (nrs *NaiveStrategy) RelayAcknowledgements(src, dst *Chain, sp *RelaySequen
return err
}

// add messages for sequences on src
for _, seq := range sp.Src {
// SRC wrote ack, so we query packet and send to DST
// add messages for received packets on dst
for _, seq := range sp.Dst {
// dst wrote the ack. acknowledgementFromSequence will query the acknowledgement
// from the counterparty chain (second chain provided in the arguments). The message
// should be sent to src.
relayAckMsgs, err := acknowledgementFromSequence(src, dst, seq)
if err != nil {
return err
}

msgs.Dst = append(msgs.Dst, relayAckMsgs...)
msgs.Src = append(msgs.Src, relayAckMsgs...)
}

// add messages for sequences on dst
for _, seq := range sp.Dst {
// DST wrote ack, so we query packet and send to SRC
// add messages for received packets on src
for _, seq := range sp.Src {
// src wrote the ack. acknowledgementFromSequence will query the acknowledgement
// from the counterparty chain (second chain provided in the arguments). The message
// should be sent to dst.
relayAckMsgs, err := acknowledgementFromSequence(dst, src, seq)
if err != nil {
return err
}

msgs.Src = append(msgs.Src, relayAckMsgs...)
msgs.Dst = append(msgs.Dst, relayAckMsgs...)
}

if !msgs.Ready() {
Expand Down Expand Up @@ -617,7 +621,7 @@ func relayPacketFromSequence(src, dst *Chain, seq uint64) ([]sdk.Msg, []sdk.Msg,

// source is the sending chain, destination is the receiving chain
func acknowledgementFromSequence(src, dst *Chain, seq uint64) ([]sdk.Msg, error) {
txs, err := src.QueryTxs(src.MustGetLatestLightHeight(), 1, 1000, ackPacketQuery(src.PathEnd.ChannelID, int(seq)))
txs, err := dst.QueryTxs(dst.MustGetLatestLightHeight(), 1, 1000, ackPacketQuery(dst.PathEnd.ChannelID, int(seq)))
switch {
case err != nil:
return nil, err
Expand All @@ -627,7 +631,7 @@ func acknowledgementFromSequence(src, dst *Chain, seq uint64) ([]sdk.Msg, error)
return nil, fmt.Errorf("more than one transaction returned with query")
}

acks, err := acknowledgementsFromResultTx(dst.PathEnd, src.PathEnd, txs[0])
acks, err := acknowledgementsFromResultTx(src.PathEnd, dst.PathEnd, txs[0])
switch {
case err != nil:
return nil, err
Expand Down Expand Up @@ -739,7 +743,7 @@ func relayPacketsFromResultTx(src, dst *Chain, res *ctypes.ResultTx) ([]relayPac
}

// acknowledgementsFromResultTx looks through the events in a *ctypes.ResultTx and returns
//relayPackets with the appropriate data
// relayPackets with the appropriate data
func acknowledgementsFromResultTx(src, dst *PathEnd,
res *ctypes.ResultTx) ([]*relayMsgPacketAck, error) {
var ackPackets []*relayMsgPacketAck
Expand Down

0 comments on commit 8cd901e

Please sign in to comment.