indexer-reorg-idempotent

Enforces reorg-aware, idempotent blockchain event indexing with stable identity keys and consistency tiers.

Updated Jun 2, 2026
One-click install
npx skills add https://github.com/IagoPrandi/ai-dealer --skill indexer-reorg-idempotent-iagoprandi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: indexer-reorg-idempotent
Source: https://github.com/IagoPrandi/ai-dealer/tree/main/.claude/skills/indexer-reorg-idempotent
Command: npx skills add https://github.com/IagoPrandi/ai-dealer --skill indexer-reorg-idempotent-iagoprandi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Blockchain indexers break when events are replayed or chain reorganizations occur, producing duplicate rows, ghost aggregates, and corrupted payout history. This Skill provides a checklist and rules for building indexers that survive replays and reorgs without data corruption. ## Core Features & Use Cases - Stable Event Identity: Mandates unique keys like (txHash, logIndex) so every event is written exactly once via idempotent upserts. - Reorg Rollback Strategy: Guides reverting projections from orphaned blocks using managed rollback or confirmed-depth tables. - Consistency Tiers: Separates optimistic data for fast UX from confirmed data used for final rankings and payouts. - Use Case: When adding a new event handler for lottery claims, apply this Skill to ensure replaying the same events twice yields identical database state and a simulated reorg rolls back aggregates correctly. ## Quick Start Review my new event handler and database schema changes to confirm they are idempotent and safe against chain reorganizations.

Frequently Asked Questions about indexer-reorg-idempotent

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a blockchain indexer idempotent?▼

Make an indexer idempotent by using a unique event identity key such as (txHash, logIndex) and writing with upserts instead of plain inserts. Replaying the same events twice must produce identical database state, which you verify with a replay test.

How to handle chain reorgs in an event indexer?▼

Handle reorgs by reverting all projections derived from orphaned blocks, either through framework-managed rollback combined with idempotent upserts or through explicit confirmed-depth tables. Never assume finality at the head block.

What unique key should I use for blockchain event identity?▼

Use (txHash, logIndex) as the primary event identity key since it uniquely identifies every log. Fall back to (blockNumber, logIndex) only when the transaction hash is unavailable, which is rare.

Why does my indexer create duplicate rows after re-syncing?▼

Duplicates appear when handlers use INSERT without unique constraints, so replayed events are written again. Add a unique constraint on the event identity key and switch to upserts so a unique violation never crashes the indexer.

When should I separate optimistic and confirmed data tiers?▼

Separate tiers when your UI needs fast feedback but final results must be stable. Serve optimistic data for UX that may change on reorg, and only use confirmed data after N confirmations for final rankings and payout history.