diff --git a/relayer/chains/cosmos/cosmos_chain_processor.go b/relayer/chains/cosmos/cosmos_chain_processor.go index bb048314a..ea405e8e9 100644 --- a/relayer/chains/cosmos/cosmos_chain_processor.go +++ b/relayer/chains/cosmos/cosmos_chain_processor.go @@ -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.", @@ -322,6 +324,7 @@ func (ccp *CosmosChainProcessor) initializeChannelState(ctx context.Context) err ) continue } + ccp.channelConnections[ch.ChannelId] = ch.ConnectionHops[0] k := processor.ChannelKey{ ChannelID: ch.ChannelId, @@ -329,8 +332,10 @@ func (ccp *CosmosChainProcessor) initializeChannelState(ctx context.Context) err CounterpartyChannelID: ch.Counterparty.ChannelId, CounterpartyPortID: ch.Counterparty.PortId, } + ccp.channelStateCache.SetOpen(k, ch.State == chantypes.OPEN, ch.Ordering) } + return nil } diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index d3684d63e..48886072f 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -882,22 +882,18 @@ func (cc *CosmosProvider) QueryConnectionChannels(ctx context.Context, height in return channels, nil } -// QueryChannels returns all the channels that are registered on a chain +// QueryChannels returns all the channels that are registered on a chain. func (cc *CosmosProvider) QueryChannels(ctx context.Context) ([]*chantypes.IdentifiedChannel, error) { - qc := chantypes.NewQueryClient(cc) p := DefaultPageRequest() chans := []*chantypes.IdentifiedChannel{} for { - res, err := qc.Channels(ctx, &chantypes.QueryChannelsRequest{ - Pagination: p, - }) + res, next, err := cc.QueryChannelsPaginated(ctx, p) if err != nil { return nil, err } - chans = append(chans, res.Channels...) - next := res.GetPagination().GetNextKey() + chans = append(chans, res...) if len(next) == 0 { break } @@ -905,13 +901,19 @@ func (cc *CosmosProvider) QueryChannels(ctx context.Context) ([]*chantypes.Ident time.Sleep(PaginationDelay) p.Key = next } + return chans, nil } -// QueryChannels returns all the channels that are registered on a chain -func (cc *CosmosProvider) QueryChannelsPaginated(ctx context.Context, pageRequest *querytypes.PageRequest) ([]*chantypes.IdentifiedChannel, []byte, error) { +// QueryChannelsPaginated returns all the channels for a particular paginated request that are registered on a chain. +func (cc *CosmosProvider) QueryChannelsPaginated( + ctx context.Context, + pageRequest *querytypes.PageRequest, +) ([]*chantypes.IdentifiedChannel, []byte, error) { qc := chantypes.NewQueryClient(cc) - chans := []*chantypes.IdentifiedChannel{} + + ctx, cancel := context.WithTimeout(ctx, time.Second*10) + defer cancel() res, err := qc.Channels(ctx, &chantypes.QueryChannelsRequest{ Pagination: pageRequest, @@ -920,10 +922,9 @@ func (cc *CosmosProvider) QueryChannelsPaginated(ctx context.Context, pageReques return nil, nil, err } - chans = append(chans, res.Channels...) next := res.GetPagination().GetNextKey() - return chans, next, nil + return res.Channels, next, nil } // QueryPacketCommitments returns an array of packet commitments