Open
Conversation
…d latest_blocks inserts
|
@zannis is attempting to deploy a commit to the joshaavecom's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Reactive Reorg Handling for rindexer
rindexer is now reactive to chain reorganizations. Instead of relying solely on safe distance offsets to avoid reorged data, the indexer actively monitors the block hash chain and catches reorgs the moment they happen. When one is detected, indexing pauses, stale state is corrected, and indexing resumes — all within seconds.
The existing
reorg_safe_distanceconfiguration remains fully supported. Users who prefer the conservative approach of only indexing finalized blocks can continue using it as before — the two mechanisms are complementary. Safe distance prevents indexing unconfirmed blocks; reorg handling corrects state if a reorg slips through. They can be used independently or together.This means three operating modes for downstream consumers:
For latency-sensitive streams (webhooks, Kafka, SNS, etc.) — events are delivered instantly as before, but now with a safety net. If a reorg invalidates previously-delivered events, a reorg notification is published through the same channels so consumers can reconcile. This is the
instantdelivery mode (default).For correctness-critical streams — a new
finalizeddelivery mode buffers events until they're past the chain's finality window before publishing. Events that survive the reorg safe distance are guaranteed canonical. No reconciliation needed.For maximum safety — combine
reorg_safe_distanceon the contract withreorg_handlingon the network. The safe distance delays indexing by N blocks, and reorg handling catches anything that slips past that window. Belt and suspenders.How it works
A per-network
ReorgCoordinatorvalidates the parent hash of every new block against a persisted sliding window of recent block hashes. On mismatch:on_reorgcallback fires with invalidated tx hashes for user-side reconciliationThe entire recovery is blocking — no callbacks or dependent events see stale data.
Three detection paths converge on the same recovery flow:
log.removed == truefrom RPC) — catches reorgs surfaced during log fetchingOn restart, startup validation compares the persisted window against the canonical chain and handles any reorgs that occurred while the indexer was offline.
What changed architecturally
The monolithic
reorg.rs(1,790 lines) is replaced by a modularreorg/module:coordinator.rs— Per-network reorg detection and orchestrationtask.rs— Rollback execution (delete, correct, rewind, notify)window.rs— In-memoryBlockChainWindowbacked by a persistedlatest_blockstablepersistence.rs— DB read/write for the block hash windowA
ReorgContextstruct bundles DB clients, callback registry, and stream clients through the detection → recovery chain.Crash recovery
The
latest_blocksupdate is inside the PG rollback transaction. If the process crashes mid-recovery, the transaction rolls back and startup validation re-detects the reorg on next start.New metrics
rindexer_reorg_handling_duration_seconds{network}rindexer_reorg_events_deleted_total{network}rindexer_reorg_events_reindexed_total{network}rindexer_reorg_detection_source_total{network, source}rindexer_reorg_cascade_total{network}Deferred
on_reorgcallback wiring from no-code setup — Types and firing logic implemented, needs registry threading