Skip to content

Fix Race Condition in On-Chain Event Ingestion Sequence #157

Description

@AlAfiz

Description: The event ingestion worker occasionally processes Stellar ledgers out of chronological order under heavy network load, leading to race conditions where a Swap event is recorded before the corresponding pool's Mint or initialization event.
Context / Motivation: Out-of-order event ingestion corrupts historical balance tracking and displays inaccurate TVL metrics on the client dashboard. We must guarantee strict sequential processing based on ledger sequence numbers.
Acceptance Criteria:

  • Implement a concurrency lock or sequential queue mechanism (e.g., using a mutex or a job queue like BullMQ) to ensure ledger $N$ is fully processed before ledger $N+1$ begins execution.
  • Add a database constraint to prevent duplicate ingestion of the same ledger sequence.
  • Write integration tests simulating rapid block emissions to verify sequential database writes.
    Technical Pointers: Review the ingestion polling loop. Instead of triggering unawaited async mapping loops over an array of blocks, resolve them sequentially using a strict for...of loop or an ordered transaction pipeline.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions