fix(rpc): report syncing status when starting block header is pruned#3797
Open
Ehsan-saradar wants to merge 1 commit into
Open
fix(rpc): report syncing status when starting block header is pruned#3797Ehsan-saradar wants to merge 1 commit into
Ehsan-saradar wants to merge 1 commit into
Conversation
Syncing() read the starting block's header only to obtain its hash. With history pruning enabled that header can be pruned once the starting block falls outside the retained window, so the read failed and the handler fell back to "not syncing" while the node was still syncing. Decide the sync status from head vs highest block first, then read the starting block hash best-effort. Applies to rpc v8, v9 and v10. Closes NethermindEth#3791
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect starknet_syncing reporting in history-pruning mode by ensuring the syncing decision is made without depending on the starting block header (which may be pruned), and by fetching starting_block_hash only on a best-effort basis afterward.
Changes:
- Reorders
Syncing()logic in rpc v8/v9/v10 to decide syncing fromheadvshighestfirst. - Makes
starting_block_hashoptional (best-effort DB lookup) while always returningstarting_block_numfromStartingBlockNumber(). - Updates and extends tests to reflect the new call order and pruned-header behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rpc/v8/sync.go | Makes starting header lookup best-effort so pruning doesn’t cause false “not syncing”. |
| rpc/v8/sync_test.go | Reworks expectations for new call order; adds pruned-header syncing case. |
| rpc/v9/sync.go | Same best-effort starting header lookup and corrected sync decision order. |
| rpc/v9/sync_test.go | Updates expectations; adds pruned-header syncing case. |
| rpc/v10/sync.go | Same logic update as v8/v9. |
| rpc/v10/sync_test.go | Updates expectations; adds pruned-header syncing case. |
Comments suppressed due to low confidence (3)
rpc/v9/sync_test.go:55
- This subtest is named as if it exercises the
highestBlockHeader.Number <= head.Numberbranch, butHighestBlockHeader()is currently mocked to return nil (via the.Times(2)expectation above), so the handler returns early athighestBlockHeader == nil. This means the head>highest condition isn’t covered and the test name is misleading. Mock a non-nil highest header with a lower number (and adjust the nil expectation count) so the intended branch is actually tested.
t.Run("block height is greater than highest block", func(t *testing.T) {
mockReader.EXPECT().HeadsHeader().Return(&core.Header{Number: 1}, nil)
syncing, err := handler.Syncing()
assert.Nil(t, err)
assert.Equal(t, &rpc.Sync{Syncing: &defaultSyncState}, syncing)
})
rpc/v8/sync_test.go:55
- This subtest is named as if it exercises the
highestBlockHeader.Number <= head.Numberbranch, butHighestBlockHeader()is currently mocked to return nil (via the.Times(2)expectation above), so the handler returns early athighestBlockHeader == nil. This means the head>highest condition isn’t covered and the test name is misleading. Mock a non-nil highest header with a lower number (and adjust the nil expectation count) so the intended branch is actually tested.
t.Run("block height is greater than highest block", func(t *testing.T) {
mockReader.EXPECT().HeadsHeader().Return(&core.Header{Number: 1}, nil)
syncing, err := handler.Syncing()
assert.Nil(t, err)
assert.Equal(t, &rpc.Sync{Syncing: &defaultSyncState}, syncing)
})
rpc/v10/sync_test.go:55
- This subtest is named as if it exercises the
highestBlockHeader.Number <= head.Numberbranch, butHighestBlockHeader()is currently mocked to return nil (via the.Times(2)expectation above), so the handler returns early athighestBlockHeader == nil. This means the head>highest condition isn’t covered and the test name is misleading. Mock a non-nil highest header with a lower number (and adjust the nil expectation count) so the intended branch is actually tested.
t.Run("block height is greater than highest block", func(t *testing.T) {
mockReader.EXPECT().HeadsHeader().Return(&core.Header{Number: 1}, nil)
syncing, err := handler.Syncing()
assert.Nil(t, err)
assert.Equal(t, &rpc.Sync{Syncing: &defaultSyncState}, syncing)
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Fixes #3791.
In pruned mode,
Handler.Syncing(rpcv8/v9/v10) could returnfalse("not syncing") while the node was in fact still syncing.It read the starting block's header only to obtain that block's hash:
With history pruning enabled, once the starting block falls outside the retained window its header no longer exists in the DB. The lookup errors, and the handler falls through to the default "not syncing" response — so a node that is actively syncing reports itself as fully synced.
Fix
The sync decision only depends on
headvshighestblock, so make that decision first. The starting block hash is purely informational metadata (starting_block_hash), so it is now read best-effort afterwards:starting_block_hashis set as before;starting_block_numnow comes fromStartingBlockNumber()(already in memory) rather than the header, so it no longer depends on a DB read that pruning can invalidate.Applied identically to
rpc/v8,rpc/v9andrpc/v10.Testing
TestSyncingin all three versions to match the new call order.syncing with pruned starting block headercase asserting the node still reports syncing whenBlockHeaderByNumberfails.make lintand therpc/v8,rpc/v9,rpc/v10test suites pass locally.