Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix state based relaying for acknowledgements #488

Merged
merged 5 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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.
* [\#456](https://github.com/cosmos/relayer/pull/456) Fix bug which incorrectly set the timeout on a transfer.
* [\#455](https://github.com/cosmos/relayer/pull/455) Set default client parameter to allow governance to update the client if expiry or misbehaviour freezing occurs.
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