fix: prevent massive resyncs when RPC returns stale block number#85
Open
vp993 wants to merge 2 commits intodebridge-finance:masterfrom
Open
fix: prevent massive resyncs when RPC returns stale block number#85vp993 wants to merge 2 commits intodebridge-finance:masterfrom
vp993 wants to merge 2 commits intodebridge-finance:masterfrom
Conversation
When an RPC returns a stale block number (fromBlock > toBlock), the previous fix in PR debridge-finance#80 would query the submissions table for the last event block and reset the chain's sync position to that block. The problem: On chains with low debridge activity (like Zilliqa), the last event could be millions of blocks behind the current sync position, causing massive unnecessary resyncs (e.g., 2.9M blocks on Zilliqa). This fix simply uses toBlock as the fallback, which is the RPC's current confirmed block number. This prevents the resync while maintaining consistency with the RPC's view of the chain. The old code already used toBlock when there were NO events - this fix makes the behavior consistent for all cases. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds a dedicated test that verifies the fix for stale RPC responses: - Simulates scenario where DB has latestBlock=200 but RPC returns block 100 - Verifies no events are fetched when fromBlock > toBlock - Verifies latestBlock is reset to toBlock (99) to prevent massive resync Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
When an RPC returns a stale block number causing
fromBlock > toBlock, the current error handling in PR #80 queries thesubmissionstable for the last event block and resets the chain's sync position to that block.The problem: On chains with low debridge activity (like Zilliqa), the last event could be millions of blocks behind the current sync position, causing massive unnecessary resyncs. For example, on Zilliqa this caused a 2.9 million block resync when the RPC momentarily returned stale data.
Root Cause Analysis
The bug was discovered while debugging validator alerts showing Zilliqa lagging 2.8M blocks behind. Log analysis revealed:
toBlock (18653005) < fromBlock (18653006)The Fix
This PR changes the fallback behavior to use
toBlock(the RPC's current confirmed block) instead of querying the submissions table. This is consistent with what the code already does when there are NO events:Changes
SubmissionEntityrepository injection fromAddNewEventsActiontoBlockas fallbackTest plan
npm run build)npm test -- --testPathPattern="AddNewEventsAction")🤖 Generated with Claude Code