Skip to content

feat(indexer): support multiple contract IDs with per-contract data partitioning - #3

Open
mohadon0 wants to merge 1 commit into
mainfrom
feat/multi-contract-indexer
Open

feat(indexer): support multiple contract IDs with per-contract data partitioning#3
mohadon0 wants to merge 1 commit into
mainfrom
feat/multi-contract-indexer

Conversation

@mohadon0

Copy link
Copy Markdown
Owner

Summary

Extends the indexer so one deployment can track and correctly separate data for multiple TrustLink contract instances simultaneously. Previously only a single CONTRACT_ID was supported; now CONTRACT_IDS (comma-separated) is accepted and each contract gets an independent event-processing loop with fully isolated data.

Changes

indexer/src/indexer.ts

  • New resolveContractIds() reads CONTRACT_IDS (comma-separated, takes precedence) or falls back to CONTRACT_ID for backward compatibility
  • startIndexer spawns a runContractIndexer loop per contract via Promise.all — each loop has its own cursor and checkpoint
  • Every db.attestation and db.multisigProposal write now includes contractId
  • Revocation and subscription publishes include contractId
  • getLastLedger() returns the minimum across all tracked contracts

indexer/src/graphql.ts

  • attestations — new optional contractId filter argument
  • attestationsByIssuer — new optional contractId filter argument
  • issuerStats — new optional contractId filter (returns cross-contract totals when omitted)
  • proposals — new optional contractId filter
  • trackedContracts — new query returning the list of contract IDs the indexer knows about
  • onAttestationCreated subscription — new optional contractId filter
  • onAttestationRevoked subscription — new optional contractId filter

indexer/src/schema.graphql

  • Attestation and MultisigProposal types gain contractId: String!
  • All query/subscription arguments updated to accept optional contractId
  • trackedContracts: [String!]! query added
  • AttestationRevoked event gains contractId: String!

indexer/prisma/schema.prisma

  • Attestation.contractId String (required) with compound indexes
  • MultisigProposal.contractId String (required)
  • Checkpoint table re-keyed by contractId (was singleton id=1)

indexer/prisma/migrations/0003_multi_contract/migration.sql

  • Adds contractId columns to Attestation and MultisigProposal
  • Backfills existing rows from the app.legacy_contract_id Postgres setting
  • Drops the singleton Checkpoint and recreates it keyed by contractId
  • Adds all new composite indexes

indexer/.env.example

  • Documents CONTRACT_IDS alongside the old CONTRACT_ID

Acceptance criteria

  • One deployment can track two or more contract IDs simultaneously
  • Each contract ID has its own checkpoint and event loop (data is correctly partitioned)
  • contractId filter argument on all relevant GraphQL queries
  • Backward compatible: existing single-CONTRACT_ID deployments continue working unchanged

…artitioning

- Accept CONTRACT_IDS (comma-separated) env var; falls back to CONTRACT_ID
  for single-contract deployments (backward compatible)
- Run an independent ledger-tracking loop per contract ID in parallel
- Key Attestation and MultisigProposal records by contractId to keep data
  from separate deployments isolated
- Per-contract Checkpoint rows (keyed by contractId) replace the old
  singleton id=1 row
- Add contractId filter argument to all GraphQL queries:
    attestations, attestationsByIssuer, issuerStats, proposals
- Add contractId filter to onAttestationCreated / onAttestationRevoked
  subscriptions
- Add trackedContracts query to expose which contracts the indexer knows
- New migration 0003_multi_contract backfills existing rows and adds
  contractId indexes for efficient per-contract queries
- Update .env.example to document CONTRACT_IDS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant