Skip to content

Make the chain indexer reorg safe #52#76

Merged
Lakes41 merged 3 commits into
Adamantine-guild:mainfrom
clintjeff2:Make-the-chain-indexer-reorg-safe-#52
Jun 29, 2026
Merged

Make the chain indexer reorg safe #52#76
Lakes41 merged 3 commits into
Adamantine-guild:mainfrom
clintjeff2:Make-the-chain-indexer-reorg-safe-#52

Conversation

@clintjeff2

Copy link
Copy Markdown
Contributor

This PR implements the reorg-safe chain indexer as requested in issue #52.

Changes:

  • Prisma Schema: Added tokenId to Membership, and new models ProcessedEvent and IndexerState.
  • Event Processing: applyContractEvent now uses transactionHash and logIndex to ensure each event is processed exactly once.
  • Indexer Worker: A new worker scans the chain, respecting a configurable INDEXER_FINALITY_WINDOW. It detects chain reorganizations by verifying the hash of the last processed block and handles them by rewinding the checkpoint.
  • Configuration: Added INDEXER_INTERVAL_MS and INDEXER_FINALITY_WINDOW settings.
  • Testing: Added unit tests in indexerWorker.test.ts covering block scanning, reorg detection/rewind, and idempotency.

The IndexerWorker is wired up in index.ts with a stub provider, ready for injection of a real RPC provider.


Closes #52

google-labs-jules Bot and others added 3 commits June 29, 2026 17:24
- Added `ProcessedEvent` and `IndexerState` models for reorg safety and idempotency.
- Enhanced `applyContractEvent` with idempotency checks and event logging.
- Implemented `IndexerWorker` with configurable finality window and reorg detection logic.
- Updated configuration and environment examples.
- Added comprehensive unit tests for `IndexerWorker`.

Co-authored-by: clintjeff2 <119521983+clintjeff2@users.noreply.github.com>
…fe-#52-6229560644847801002

Make the chain indexer reorg-safe

@Lakes41 Lakes41 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job @clintjeff2

@Lakes41 Lakes41 merged commit 848fc89 into Adamantine-guild:main Jun 29, 2026
0 of 2 checks passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Jun 29, 2026
6 tasks
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.

Make the chain indexer reorg-safe

2 participants