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

fetchcommitresponse_with_targetheight #490

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
19 changes: 9 additions & 10 deletions relayer/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,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 {
Expand All @@ -367,6 +357,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{},
Expand All @@ -376,6 +371,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 {
Expand Down
15 changes: 7 additions & 8 deletions relayer/relayPackets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down