Add Block Number Cache to Staged Stream Sync#4942
Merged
GheisMohammadi merged 17 commits intodevfrom Feb 20, 2026
Merged
Conversation
f90ed09 to
6207229
Compare
6207229 to
96ad6c7
Compare
…lock number cache
96ad6c7 to
c27e6d2
Compare
… panic in block number cache
…berRequest, invalidated stream, and double-Stop
…ound cleanup goroutine and prevent leaks on shutdown
mur-me
approved these changes
Feb 20, 2026
Collaborator
|
Devnet is looking good, let's put it on the testnet |
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.
During staged stream sync, the node repeatedly queries every connected peer for their current block height — both in
identifySyncedStreams(to filter peers that are synced past the target) and inestimateCurrentNumber(to determine the sync target).For long-range syncs, these queries are almost entirely redundant. If a peer reports block 1,200,000 and our current target is 500,000, there is no reason to ask that peer again until we actually catch up to 1,200,000.
This PR introduces a per-stream block number cache that eliminates those repeated round-trips, significantly reducing network load on both the syncing node and its peers.
The
BlockNumberCachestores each peer's last-reported block height keyed by stream ID.To support querying a specific peer on cache miss, the p2p request manager's
pickAvailableStreamwas updated to properly respect whitelists:SafeMapfor thread safety.The integration touches three files in the staged sync pipeline:
stage_bodies.go,identifySyncedStreamsnow callsbnCache.GetBlockNumber()per stream instead of making a direct protocol request.syncing.go,estimateCurrentNumberroutes throughbnCache.doGetCurrentNumberRequest()which queries any available stream with high priority and caches the responding stream's result.staged_stream_sync.goand lives on theStagedStreamSyncstruct.Comprehensive unit tests cover cache hits, misses, threshold logic, eviction, expiry, invalidation, and reset.