Skip to content

interchain-indexer: Cap concurrency in kickoff_token_fetch_for_stats_enrichment #1654

@coderabbitai

Description

@coderabbitai

Problem

In interchain-indexer/interchain-indexer-logic/src/token_info/service.rs, the kickoff_token_fetch_for_stats_enrichment method (introduced in PR #1650) spawns one unbounded tokio::spawn per unique token key. A large startup backfill or a big flush batch can fan out into thousands of concurrent RPC calls and DB writes, which risks overwhelming RPC providers and starving normal indexing traffic.

Affected code: kickoff_token_fetch_for_stats_enrichment (~lines 272–312)

Suggested Fix

Limit concurrency by introducing a bounded semaphore or a buffered stream, for example:

  • A tokio::sync::Semaphore — acquire a permit before calling fetch_token_info_from_chain_and_persist, releasing it after the call.
  • Or futures::stream::iter(uniq).map(...).buffer_unordered(MAX_CONCURRENCY) — run the fetches inside the buffered stream so no more than MAX_CONCURRENCY concurrent RPC/DB tasks are active at once.

The existing in_flight_fetches deduplication should be kept; the bound is an additional guard on top of it.

References

Reported by @EvgenKor

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions