diff --git a/relayer/naive-strategy.go b/relayer/naive-strategy.go index 696c3e6c9..dd0a55be3 100644 --- a/relayer/naive-strategy.go +++ b/relayer/naive-strategy.go @@ -346,16 +346,6 @@ func relayPacketsFromEventListener(src, dst *PathEnd, events map[string][]string } func (nrs *NaiveStrategy) sendTxFromEventPackets(src, dst *Chain, rlyPackets []relayPacket) { - - // fetch the proofs for the relayPackets - for _, rp := range rlyPackets { - if err := rp.FetchCommitResponse(src, dst); err != nil { - // we don't expect many errors here because of the retry - // in FetchCommitResponse - src.Error(err) - } - } - // send the transaction, retrying if not successful // TODO: have separate retries for different pieces here if err := retry.Do(func() error { @@ -369,6 +359,11 @@ func (nrs *NaiveStrategy) sendTxFromEventPackets(src, dst *Chain, rlyPackets []r return err } + header, err := clienttypes.UnpackHeader(updateMsg.(*clienttypes.MsgUpdateClient).Header) + if err != nil { + return err + } + txs := &RelayMsgs{ Src: []sdk.Msg{updateMsg}, Dst: []sdk.Msg{}, @@ -378,6 +373,10 @@ func (nrs *NaiveStrategy) sendTxFromEventPackets(src, dst *Chain, rlyPackets []r // add the packet msgs to RelayPackets for _, rp := range rlyPackets { + // fetch the proof for the relayPacket + if err := rp.FetchCommitResponse(src, dst, header.GetHeight().GetRevisionHeight()); err != nil { + return err + } msg, err := rp.Msg(src, dst) if err != nil { if src.debug { diff --git a/relayer/relayPackets.go b/relayer/relayPackets.go index da63eab77..f04b5bc88 100644 --- a/relayer/relayPackets.go +++ b/relayer/relayPackets.go @@ -11,7 +11,7 @@ import ( type relayPacket interface { Msg(src, dst *Chain) (sdk.Msg, error) - FetchCommitResponse(src, dst *Chain) error + FetchCommitResponse(src, dst *Chain, queryHeight uint64) error Data() []byte Seq() uint64 Timeout() clienttypes.Height @@ -39,14 +39,13 @@ func (rp *relayMsgTimeout) Timeout() clienttypes.Height { return rp.timeout } -func (rp *relayMsgTimeout) FetchCommitResponse(src, dst *Chain) (err error) { +func (rp *relayMsgTimeout) FetchCommitResponse(src, dst *Chain, queryHeight uint64) (err error) { var dstRecvRes *chantypes.QueryPacketReceiptResponse // retry getting commit response until it succeeds if err = retry.Do(func() error { // NOTE: Timeouts currently only work with ORDERED channels for nwo // NOTE: the proof height uses - 1 due to tendermint's delayed execution model - queryHeight := dst.MustGetLatestLightHeight() - 1 - dstRecvRes, err = dst.QueryPacketReceipt(int64(queryHeight), rp.seq) + dstRecvRes, err = dst.QueryPacketReceipt(int64(queryHeight)-1, rp.seq) switch { case err != nil: return err @@ -128,12 +127,12 @@ func (rp *relayMsgRecvPacket) Timeout() clienttypes.Height { return rp.timeout } -func (rp *relayMsgRecvPacket) FetchCommitResponse(src, dst *Chain) (err error) { +func (rp *relayMsgRecvPacket) FetchCommitResponse(src, dst *Chain, queryHeight uint64) (err error) { var dstCommitRes *chantypes.QueryPacketCommitmentResponse // retry getting commit response until it succeeds if err = retry.Do(func() error { // NOTE: the proof height uses - 1 due to tendermint's delayed execution model - dstCommitRes, err = dst.QueryPacketCommitment(int64(dst.MustGetLatestLightHeight()-1), rp.seq) + dstCommitRes, err = dst.QueryPacketCommitment(int64(queryHeight)-1, rp.seq) switch { case err != nil: return err @@ -228,12 +227,12 @@ func (rp *relayMsgPacketAck) Msg(src, dst *Chain) (sdk.Msg, error) { return msg, nil } -func (rp *relayMsgPacketAck) FetchCommitResponse(src, dst *Chain) (err error) { +func (rp *relayMsgPacketAck) FetchCommitResponse(src, dst *Chain, queryHeight uint64) (err error) { var dstCommitRes *chantypes.QueryPacketAcknowledgementResponse // retry getting commit response until it succeeds if err = retry.Do(func() error { // NOTE: the proof height uses - 1 due to tendermint's delayed execution model - dstCommitRes, err = dst.QueryPacketAcknowledgement(int64(dst.MustGetLatestLightHeight())-1, rp.seq) + dstCommitRes, err = dst.QueryPacketAcknowledgement(int64(queryHeight)-1, rp.seq) switch { case err != nil: return err