Skip to content

Add On-Chain Portfolio Reconciliation and Indexer Repair Jobs #562

Description

@grantfox-oss

Package: packages/backend

Complexity: High

Problem

BACKit uses PostgreSQL as the frontend read model and Soroban events as the source of on-chain activity. RPC interruptions, parsing failures, reprocessing, or a deployment configuration mistake can leave calls, stakes, resolutions, and payout claims missing or duplicated in PostgreSQL. There is currently no operator workflow that quantifies drift and repairs affected records safely.

Goal

Build an idempotent reconciliation process that compares indexed records with authoritative Soroban events/state and repairs recoverable drift without modifying on-chain state.

Acceptance criteria

  • Introduce a reconciliation service and BullMQ job that can scan a configurable ledger range and selected contract IDs.
  • Compare at least call creation, stake, resolution, and payout claim records using stable event identity (contractId, ledger, transaction hash, and event index or equivalent).
  • Classify discrepancies as MISSING_OFFCHAIN, DUPLICATE_OFFCHAIN, VALUE_MISMATCH, UNKNOWN_CONTRACT, or UNRECOVERABLE.
  • Dry-run mode produces a structured report without database writes.
  • Repair mode upserts missing records transactionally and quarantines unsafe mismatches for admin review; it never submits a Soroban transaction.
  • Re-running the same ledger range creates no duplicate records and no duplicate notifications.
  • Store reconciliation run metadata, range, contract/network, counts, status, duration, and failure reason.
  • Add protected admin endpoints to start a run and inspect runs/discrepancies with pagination and filters.
  • Prevent overlapping runs for the same network and contract set using a distributed lock.
  • Emit metrics/logs for indexer lag, discrepancy count by type, repaired records, and failed repairs.
  • Tests cover an RPC page boundary, retry after interruption, duplicate events, missing records, value mismatch, and idempotent reruns.
  • Add an operator runbook describing dry-run review, repair execution, and rollback/incident steps.

Technical pointers

  • packages/backend/src/indexer
  • packages/backend/src/event-store
  • packages/backend/src/payouts
  • packages/backend/src/common/queues
  • packages/backend/src/admin

Out of scope

  • Replacing the existing indexer
  • Altering contract state
  • Supporting contracts outside the configured BACKit deployment set

Activity

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

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions