Skip to content

[Backend] Event indexer has no cross-instance lock and can double-process ledger ranges #5

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

src/services/eventIndexer.ts persists last_indexed_ledger but two instances can both read the same cursor and fetch the same range; only the ON CONFLICT DO NOTHING insert prevents duplicate rows, wasting RPC calls and risking duplicate webhook/notification dispatch which happen before the conflict is known.

Acceptance criteria

  • Guard each indexer poll cycle with a Postgres advisory lock or Redis lock so only one instance advances the cursor at a time
  • Ensure side effects (webhook dispatch, notifications) only fire for rows this instance actually inserted
  • Confirm a restarted instance still resumes cleanly from the persisted cursor
  • Add a test simulating two concurrent poll cycles processing without duplicate dispatch

Files to touch

  • src/services/eventIndexer.ts
  • src/services/indexerManager.ts

Out of scope

  • Switching off polling to streaming
  • Reorganizing the indexer_state schema

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignenhancementNew feature or requesthardAdvanced / high-difficulty issue

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions