Skip to content

fix: make event ingestion idempotent by canonical log identity - #740

Merged
dDevAhmed merged 6 commits into
DigiNodes:mainfrom
philipeh:fix/issue-652-prewave-be-052-make-event-ingestion-idempotent
Oct 20, 2026
Merged

dDevAhmed merged 6 commits into
DigiNodes:mainfrom
philipeh:fix/issue-652-prewave-be-052-make-event-ingestion-idempotent

Conversation

@philipeh

Copy link
Copy Markdown

Overview

This PR makes blockchain event ingestion idempotent by introducing a canonical log identity (chain / release / block hash / tx hash / log index / decoder version), enforcing uniqueness at the storage layer, and handling removed logs explicitly through the rollback flow. It also adds a persisted block cursor and decoder-version traceability so reprocessing and overlapping polls cannot duplicate effects.

Related Issue

Changes

🔑 Canonical Event Identity

  • [MODIFY] prisma/schema.prisma

    • Adds a unique constraint on the canonical event identity fields so duplicate ingestion is rejected at the database level.
    • Adds a persisted block cursor model to track ingestion progress per chain/release.
  • [ADD] prisma/migrations/20260924000000_add_chain_event_dedup_and_block_cursor/migration.sql

    • Creates the uniqueness constraint and block cursor table backing the schema changes.
  • [MODIFY] src/blockchain/entities/processed-event.entity.ts

    • Carries the canonical identity fields (chain, release, block hash, tx hash, log index, decoder version) and removed-log state.
  • [MODIFY] src/blockchain/interfaces/blockchain-event.interface.ts

    • Extends the event interface with the identity and removed-log fields required for dedup and rollback.

⚙️ Ingestion and Rollback

  • [MODIFY] src/blockchain/blockchain-indexer.service.ts

    • Derives canonical identity per log, deduplicates within and across batches, and skips already-processed events.
    • Routes removed logs into the rollback flow instead of treating them as new effects.
    • Uses the persisted block cursor to make overlapping polls and restarts safe.
  • [MODIFY] src/blockchain/reorg-detector.service.ts

    • Aligns reorg detection with the canonical identity and removed-log handling.
  • [MODIFY] src/blockchain/abi-version-registry.service.ts

    • Exposes the decoder version used as part of the canonical identity so it is traceable per processed event.

Verification Results

npx prisma validate
✅ schema valid

npm run build
✅ build passed
Acceptance Criteria Status
Reprocessing cannot duplicate effects ✅ Canonical identity + unique constraint reject duplicates across batches, overlapping polls, and restarts
Removed logs enter rollback flow ✅ Removed logs are detected and routed to rollback instead of being applied as new effects
Identity uniqueness is enforced in storage ✅ Unique constraint added via migration on canonical identity fields
Decoder version is traceable ✅ Decoder version stored on each processed event and sourced from the ABI version registry

Closes #652

@philipeh
philipeh requested a review from dDevAhmed as a code owner October 17, 2026 07:23
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: DigiNodes/truthbounty-api/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 11cbe55c-c7ca-4be5-bfca-a5adafc12fc6
📥 Commits

Reviewing files that changed from the base of the PR and between 4dbde1c and a6bbc77.

📒 Files selected for processing: 7
  • prisma/migrations/20260924000000_add_chain_event_dedup_and_block_cursor/migration.sql
  • prisma/schema.prisma
  • src/blockchain/abi-version-registry.service.ts
  • src/blockchain/blockchain-indexer.service.ts
  • src/blockchain/entities/processed-event.entity.ts
  • src/blockchain/interfaces/blockchain-event.interface.ts
  • src/blockchain/reorg-detector.service.ts
+-------------------------+
| Think twice, code once. |
+-------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dDevAhmed

Copy link
Copy Markdown
Contributor

resolve conflicts @philipeh

@dDevAhmed
dDevAhmed merged commit f437c8b into DigiNodes:main Oct 20, 2026
1 check was pending
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.

PREWAVE-BE-052 — Make Event Ingestion Idempotent by Canonical Log Identity

2 participants