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: use context timeout per paginated query #1395

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion relayer/chains/cosmos/cosmos_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ func (ccp *CosmosChainProcessor) initializeConnectionState(ctx context.Context)

// initializeChannelState will bootstrap the channelStateCache with the open channel state.
func (ccp *CosmosChainProcessor) initializeChannelState(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, queryStateTimeout)
ctx, cancel := context.WithCancel(ctx)
defer cancel()

channels, err := ccp.chainProvider.QueryChannels(ctx)
if err != nil {
return fmt.Errorf("error querying channels: %w", err)
}

for _, ch := range channels {
if len(ch.ConnectionHops) != 1 {
ccp.log.Error("Found channel using multiple connection hops. Not currently supported, ignoring.",
Expand All @@ -322,15 +324,18 @@ func (ccp *CosmosChainProcessor) initializeChannelState(ctx context.Context) err
)
continue
}

ccp.channelConnections[ch.ChannelId] = ch.ConnectionHops[0]
k := processor.ChannelKey{
ChannelID: ch.ChannelId,
PortID: ch.PortId,
CounterpartyChannelID: ch.Counterparty.ChannelId,
CounterpartyPortID: ch.Counterparty.PortId,
}

ccp.channelStateCache.SetOpen(k, ch.State == chantypes.OPEN, ch.Ordering)
}

return nil
}

Expand Down
20 changes: 17 additions & 3 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,24 @@ func (cc *CosmosProvider) QueryChannels(ctx context.Context) ([]*chantypes.Ident
qc := chantypes.NewQueryClient(cc)
p := DefaultPageRequest()
chans := []*chantypes.IdentifiedChannel{}
res := &chantypes.QueryChannelsResponse{}

for {
res, err := qc.Channels(ctx, &chantypes.QueryChannelsRequest{
Pagination: p,
})
err := func() error {
jtieri marked this conversation as resolved.
Show resolved Hide resolved
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()

var err error
res, err = qc.Channels(ctx, &chantypes.QueryChannelsRequest{
Pagination: p,
})
if err != nil {
jtieri marked this conversation as resolved.
Show resolved Hide resolved
return err
}

return nil
}()

if err != nil {
return nil, err
}
Expand All @@ -905,6 +918,7 @@ func (cc *CosmosProvider) QueryChannels(ctx context.Context) ([]*chantypes.Ident
time.Sleep(PaginationDelay)
p.Key = next
}

return chans, nil
}

Expand Down
Loading