feat(indexer): support multiple contract IDs with per-contract data partitioning - #3
Open
mohadon0 wants to merge 1 commit into
Open
feat(indexer): support multiple contract IDs with per-contract data partitioning#3mohadon0 wants to merge 1 commit into
mohadon0 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the indexer so one deployment can track and correctly separate data for multiple TrustLink contract instances simultaneously. Previously only a single
CONTRACT_IDwas supported; nowCONTRACT_IDS(comma-separated) is accepted and each contract gets an independent event-processing loop with fully isolated data.Changes
indexer/src/indexer.tsresolveContractIds()readsCONTRACT_IDS(comma-separated, takes precedence) or falls back toCONTRACT_IDfor backward compatibilitystartIndexerspawns arunContractIndexerloop per contract viaPromise.all— each loop has its own cursor and checkpointdb.attestationanddb.multisigProposalwrite now includescontractIdcontractIdgetLastLedger()returns the minimum across all tracked contractsindexer/src/graphql.tsattestations— new optionalcontractIdfilter argumentattestationsByIssuer— new optionalcontractIdfilter argumentissuerStats— new optionalcontractIdfilter (returns cross-contract totals when omitted)proposals— new optionalcontractIdfiltertrackedContracts— new query returning the list of contract IDs the indexer knows aboutonAttestationCreatedsubscription — new optionalcontractIdfilteronAttestationRevokedsubscription — new optionalcontractIdfilterindexer/src/schema.graphqlAttestationandMultisigProposaltypes gaincontractId: String!contractIdtrackedContracts: [String!]!query addedAttestationRevokedevent gainscontractId: String!indexer/prisma/schema.prismaAttestation.contractId String(required) with compound indexesMultisigProposal.contractId String(required)Checkpointtable re-keyed bycontractId(was singletonid=1)indexer/prisma/migrations/0003_multi_contract/migration.sqlcontractIdcolumns toAttestationandMultisigProposalapp.legacy_contract_idPostgres settingCheckpointand recreates it keyed bycontractIdindexer/.env.exampleCONTRACT_IDSalongside the oldCONTRACT_IDAcceptance criteria
contractIdfilter argument on all relevant GraphQL queriesCONTRACT_IDdeployments continue working unchanged