Add internal onRollbackCommit callback API for rollback events#1283
Merged
Conversation
Add `indexer.~internalAndWillBeRemovedSoon_onRollbackCommit`, an unstable internal hook fired once per chain affected by a reorg rollback, after the rollback diff is durably written. A throwing callback bubbles to the write loop's onError, crashing the indexer like a failed write. The whole feature is concentrated in RollbackCommit.res plus three call sites (registration in Main, per-chain block snapshot in GlobalState, fire on a successful rollback write in InMemoryStore) so it can be removed in one piece. https://claude.ai/code/session_01E1JiTmZ9APfXhzDvjEVgX7
Carry per-chain last-valid blocks on `Persistence.rollback` instead of a global pending ref, and guard the fire on a registered callback so an empty registry doesn't schedule an extra microtask. https://claude.ai/code/session_01E1JiTmZ9APfXhzDvjEVgX7
Contributor
Contributor
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches📝 Generate docstrings
Comment |
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
Adds an internal, unstable
~internalAndWillBeRemovedSoon_onRollbackCommitAPI that allows indexers to register callbacks fired once per chain affected by a reorg rollback, after the rollback is durably written to the database.Key Changes
New
RollbackCommitmodule (packages/envio/src/RollbackCommit.res): Manages callback registration and firing for rollback commit events. Callbacks receive the chain ID and the last valid block number for that chain.Integration in
InMemoryStore: After a rollback diff is durably written,RollbackCommit.fireis invoked with the progress block numbers per chain. Throwing callbacks bubble to the write loop's error handler, crashing the indexer like a failed write.Registration in
Main: ExposesonRollbackCommitFnas a property on the indexer object, allowing users to register callbacks during the configuration phase. The method name is marked as internal and will be removed without notice.Type definitions: Updated
index.d.tsto include the callback signature in theIndexerFromConfigtype.Persistence layer: Extended the
rollbacktype to carryprogressBlockNumberByChainId, which is populated during rollback preparation inGlobalStateand read by the callback firing logic.Test coverage: Added test verifying that the callback fires once per affected chain with correct arguments after a rollback write.
Implementation Details
progressBlockNumberByChainIddict is threaded through the rollback preparation pipeline to ensure the callback has access to the last valid block per chain.https://claude.ai/code/session_01E1JiTmZ9APfXhzDvjEVgX7
Summary by CodeRabbit
New Features
Tests