Skip to content

Commit

Permalink
fetchcommitresponse_with_targetheight (cosmos#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
songwongtp authored Apr 9, 2021
1 parent 6c13a43 commit f93962f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
19 changes: 9 additions & 10 deletions relayer/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{},
Expand All @@ -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 {
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

0 comments on commit f93962f

Please sign in to comment.