Skip to content

Commit

Permalink
fix: txs not relayed from hub (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix committed Nov 1, 2023
1 parent 8fcae0a commit 24835c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 12 additions & 4 deletions relayer/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package relayer
import (
"context"
"fmt"
"sort"
"sync"

"github.com/avast/retry-go/v4"
Expand Down Expand Up @@ -508,6 +509,13 @@ func AddMessagesForSequences(
srcChanID, srcPortID, dstChanID, dstPortID string,
order chantypes.Order,
) error {
src.log.Info("Adding messages for sequences", zap.String("src_chain_id", src.ChainID()))
// hack: Iterate in reverse order to get latest packets first. This breaks compatibility with ordered channels, but it's a hack.
// To make sure first packets get priorities as a lot may be stuck in queue.
// Order sequences where the heights sequence is first in the list
sort.Slice(sequences, func(i, j int) bool {
return sequences[i] > sequences[j]
})
for idx, seq := range sequences {
recvMsg, timeoutMsg, err := src.ChainProvider.RelayPacketFromSequence(
ctx,
Expand All @@ -530,18 +538,18 @@ func AddMessagesForSequences(
zap.String("channel_order", order.String()),
zap.Error(err),
)
return err
continue
}

// Depending on the type of message to be relayed, we need to send to different chains
if recvMsg != nil {
*dstMsgs = append(*dstMsgs, recvMsg)
*dstMsgs = append([]provider.RelayerMessage{recvMsg}, *dstMsgs...)
}

if timeoutMsg != nil {
*srcMsgs = append(*srcMsgs, timeoutMsg)
*srcMsgs = append([]provider.RelayerMessage{timeoutMsg}, *srcMsgs...)
}
src.log.Info("Added packet to relay message list", zap.Uint64("sequence", seq), zap.String("src_chain_id", src.ChainID()))
src.log.Info("Added packet to relay message list", zap.Uint64("sequence", seq), zap.String("src_chain_id", src.ChainID()), zap.Uint64("height", uint64(srch)))

// A hack to add batching to queue sequences.
// This is done in order to prevent a situation where 1000's of
Expand Down
5 changes: 4 additions & 1 deletion relayer/provider/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"log"
"strings"
"time"

Expand Down Expand Up @@ -71,7 +72,6 @@ func (cc *CosmosProvider) QueryTxs(ctx context.Context, page, limit int, events
if limit <= 0 {
return nil, errors.New("limit must greater than 0")
}

res, err := cc.RPCClient.TxSearch(ctx, strings.Join(events, " AND "), true, &page, &limit, "")
if err != nil {
return nil, err
Expand Down Expand Up @@ -709,6 +709,7 @@ func (cc *CosmosProvider) QueryPacketCommitments(ctx context.Context, height uin
total := []*chantypes.PacketState{}

for {
log.Printf("Querying packet commitments for channel: %s, page: %s, height: %d", channelid, p.Key, height)
res, err := qc.PacketCommitments(ctxWithHeight, &chantypes.QueryPacketCommitmentsRequest{
PortId: portid,
ChannelId: channelid,
Expand All @@ -717,6 +718,7 @@ func (cc *CosmosProvider) QueryPacketCommitments(ctx context.Context, height uin
if err != nil {
return nil, err
}
log.Printf("Found %d packet commitments for channel %s. Adding them to the total.", len(res.Commitments), channelid)
total = append(total, res.Commitments...)
next := res.GetPagination().GetNextKey()
if len(next) == 0 {
Expand All @@ -726,6 +728,7 @@ func (cc *CosmosProvider) QueryPacketCommitments(ctx context.Context, height uin
time.Sleep(PaginationDelay)
p.Key = next
}
log.Printf("Found %d packet commitments for channel %s", len(total), channelid)
return total, nil
}

Expand Down
3 changes: 2 additions & 1 deletion relayer/provider/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1991,8 +1991,9 @@ func (cc *CosmosProvider) InjectTrustedFields(ctx context.Context, header ibcexp
// place where we need to fix the upstream query proof issue?
var trustedHeader ibcexported.Header
if err := retry.Do(func() error {
trustedHeader, err = cc.GetLightSignedHeaderAtHeight(ctx, int64(latestTrustedHeight.RevisionHeight+1))
trustedHeader, err = cc.GetLightSignedHeaderAtHeight(ctx, int64(latestTrustedHeight.RevisionHeight))
if err != nil {
fmt.Printf("Error: %v, while getting light signed header at height: %d from source chain\n", err, int64(latestTrustedHeight.RevisionHeight))
return err
}
return err
Expand Down

0 comments on commit 24835c7

Please sign in to comment.