Skip to content

fix(net): correct sync completion and chain summary request timeouts - #7000

Merged
kuny0707 merged 31 commits into
tronprotocol:release_v4.8.3from
317787106:fix/sync_complete
Oct 26, 2026
Merged

kuny0707 merged 31 commits into
tronprotocol:release_v4.8.3from
317787106:fix/sync_complete

Conversation

@317787106

@317787106 317787106 commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fix chain-summary request timeouts and stale remaining-block state at sync completion, and adjust peer request deadlines.

  • Check outstanding syncChainRequested requests in PeerStatusCheck and disconnect the peer with TIME_OUT when its request expires. The deadline uses the original request timestamp; keepalive traffic, other interactions, and block progress do not extend it.
  • Increase SYNC_TIME_OUT from 5 to 10 seconds for both chain-summary requests and requested sync blocks. Reduce ADV_TIME_OUT from 20 to 15 seconds for advertisement inventory requests.
  • Reset remainNum to zero when a validated single-block response identifies a locally known block and completes the local download. Preserve the existing needSyncFromUs upload state and SYNC_COMPLETED state so a later download can restart.
  • Capture the outstanding summary request once during response validation, and explicitly check the last returned block height against the future-height limit alongside the existing declared-height and overflow checks.

Why are these changes required?

Block-progress and interaction timestamps do not provide a deadline for an individual unanswered chain-summary request. Checking the request timestamp closes that gap. A sync fetch can request up to 100 blocks from one peer, so increasing the shared sync timeout gives responsive peers more time to deliver a batch. The shorter advertisement timeout detects overdue inventory requests sooner.

The single-known-block completion path previously left a stale remainNum from an earlier response. Clearing it keeps the remaining-block count consistent with the completed download. Checking the last block height separately also strengthens the future-height validation instead of relying only on the summed declared height.

This PR has been tested by:

  • Expanded ChainInventoryMsgHandlerTest coverage for download completion, preservation of upload state, later sync restarts, unknown queued blocks, pagination, malformed responses rejected before peer-state mutation, and lock-protected fetch decisions.
  • Regression scenarios cover terminal responses below the HELLO head, repeated known terminal responses, a reorganization during summary generation, and the final summary/single-block exchange that clears both peers' sync state and restores block and transaction inventory flow.
  • Expanded PeerStatusCheckMockTest coverage for per-peer request expiry, activity that must not extend the deadline, six-second requests remaining active, completed and subsequent requests, and existing inventory/sync-block timeouts.
  • CI for f40e6d6, checked on 2026-10-26: the Ubuntu 24 / JDK 17 / aarch64 build passed; the full PR Build workflow is still in progress. The single-node smoke test, Checkstyle and PR lint, and Math usage check passed.

Follow up

Cross-request no-progress protection remains a follow-up: repeated valid responses containing only known blocks can trigger further summary exchanges without downloading new blocks.

Extra details

Completion follows the validated response and local block availability. Valid terminal responses below the peer's HELLO head remain accepted, and a multi-block terminal response may end at a block already present in the requested summary. When all returned blocks are locally known, the existing flow requests another summary so the remote peer can return a single common block and clear its upload-sync state. Unknown queued blocks continue through the fetch path.

@github-actions
github-actions Bot requested a review from xxo1shine September 24, 2026 09:15

@SeriousCoding789 SeriousCoding789 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixes here look correct to me: the request snapshot is validated before any state change, the future-height check no longer overflows, negative remainNum is rejected, and the new chain-inventory timeout uses the request's own timestamp.

One gap seems to remain beyond the terminal-response case raised in the review above. Intermediate pages (remainNum > 0) are not covered by the HELLO-head check, and a full page made up only of blocks we already have can pass every check without moving blockBothHave forward; the handler then drains the queue and calls syncNext() again. The underlying reason is that the 30-second progress check in PeerStatusCheck looks at blockBothHaveUpdateTime, which setBlockBothHave() refreshes whether or not the height increased, so activity is counted as progress.

Two possible directions:

  • For remainNum > 0, require the last block of the page to be higher than peer.getBlockBothHave().getNum(). An honest page starts from the highest summary block on the peer's main chain and spans SYNC_FETCH_BATCH_NUM blocks, and fork depth is bounded by the solidified height, so an honest page should always end above blockBothHave.
  • More generally, refresh blockBothHaveUpdateTime only when the shared height increases, so any response shape that does not advance synchronization is caught by the existing 30-second check. The other setBlockBothHave() callers (broadcast handling, serving fetches) would need to be checked against that change.

public static final long ADV_TIME_OUT = 20000L;
public static final long SYNC_TIME_OUT = 5000L;
public static final long SYNC_TIME_OUT = 10000L;
public static final long NET_MAX_TRX_PER_SECOND = 700L;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also consider reducing ADV_TIME_OUT. The current 20-second timeout for block and transaction fetch requests following broadcast announcements is rather long, delaying the handling of unresponsive peers and the rescheduling of outstanding requests.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I reduced ADV_TIME_OUT from 20 seconds to 15 seconds in ae2e246. This timeout currently disconnects the peer, so I chose a conservative reduction rather than 10 seconds without broader network latency data. The focused timeout tests pass. We can revisit the threshold, or separate request retry from peer disconnection, once we have production measurements.

}
}

if (chainInventoryMessage.getRemainNum() == 0 && peer.getSyncBlockToFetch().isEmpty()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synchronization should not be marked complete here solely because remainNum is zero and the fetch queue is empty. When the remote peer returns multiple blocks, it sets needSyncFromUs=true. We still need to send an updated chain summary through syncNext so that the remote peer can return a single common block and clear that state. Local synchronization can then complete through the existing single-block branch.

Please remove this early-completion branch. Repeated responses containing known blocks from a malicious peer should be handled by separately limiting repeated exchanges that make no progress, without skipping the normal final confirmation exchange. Tests should also cover synchronization state on both peers and verify that subsequent announcement exchange resumes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I removed the early completion branch in 82feab3. To prevent the previous no-progress loop, the handler now rejects a multi-block terminal response if its terminal block was already included in the requested summary; at that point, a normal peer should return a single block. A regression test covers the repeated-response case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current summary membership check still allows a no-progress loop by alternating between already-known terminal blocks. Each round refreshes the progress timestamp and restarts the request timeout, allowing the loop to continue indefinitely.

For example, with a sync window lower bound of 98, a HELLO head of 99, and local blocks available through height 101:

Request summary Peer response (remain=0) Next summary
[98,100] [98,99] [98,99]
[98,99] [99,100] [98,100]

Both rounds satisfy the first-block membership, continuity, and HELLO lower-bound checks, but neither downloads any new blocks.

Processing known blocks refreshes the sync progress timestamp (PeerConnection.java:246), and the subsequent summary request receives a new timestamp (SyncService.java:129). As a result, neither timeout check detects this no-progress loop.

@317787106 317787106 Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@3for Thanks for the concrete example. You're right: alternating already-known terminal blocks can refresh the block-progress timestamp and start a new request deadline without making progress. The current check only rejects a terminal block already present in that round's summary.

Preventing this across multiple requests needs separate progress tracking and regression tests. I'll address that in a follow-up rather than expand this PR further. I've updated the PR description to document the remaining limitation.

@317787106
317787106 requested review from 3for and xxo1shine October 19, 2026 05:38

@3for 3for left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, as the known issues will be addressed in a separate PR.

Classify repeated terminal inventories as sync failures to avoid bad-protocol bans during fork switches. Rely on the merged HELLO entry gate instead of a duplicate handler check, and cover the reorg disconnect reason.
BlockId lastBlockId = blockIds.get(blockIds.size() - 1);
long lastNum = lastBlockId.getNum();
long helloHeadNum = hello.getHeadBlockId().getNum();
if (lastNum < helloHeadNum) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These terminal-response checks can disconnect an honest peer during a rollback or concurrent fork switch. A HELLO head is a handshake-time snapshot, not a permanent lower bound on the peer's current chain head.

For example, if a peer advertises height 200 and later rolls back to 198, an otherwise valid terminal response ending at 198 is rejected here. Separately, a fork switch while generating the response can produce a multi-block terminal inventory whose last block is already in the request summary. The new testReorgDuringSummaryResponseDisconnectsWithSyncFail explicitly reproduces and asserts that disconnect.

I see that the PR documents this as an accepted tradeoff. Changing the reason to SYNC_FAIL avoids the one-hour bad-protocol ban, but still closes the connection with the default 60-second cooldown; reconnection is not guaranteed immediately afterward. This can delay recovery precisely while peers are resolving a fork, especially when few synchronization peers are available.

Could we handle these recoverable cases with a bounded summary retry/resynchronization path instead of immediately disconnecting? The response's captured head, common ancestor, and block IDs should also come from a consistent chain view. A separate cross-request no-progress budget can bound retries without treating the original HELLO height as immutable. Please add coverage for successful recovery after rollback/concurrent reorganization, in addition to asserting the disconnect reason.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A normal fork switch in java-tron selects a strictly longer chain. A head change from 200 to 198 would therefore be a transient state during the switch, rather than the resulting stable head. When our node is behind in current sceme, changes near the remote peer’s tip generally do not affect the range we are currently downloading.

Concurrent reads during a fork switch can still produce a response that fails these checks. We now handle this as SYNC_FAILED, avoiding the one-hour protocol-violation ban. The cooldown affects that peer; synchronization can continue through other available peers. Given the multiple sync sources normally available, this does not imply a node-wide recovery delay.

We will retain the current handling to keep this PR focused. Generating responses from a consistent chain view is a useful separate improvement. Bounded retries and a cross-request progress budget would require broader changes.

@waynercheung waynercheung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 85517a5. I found no blocking issue in the production changes. LGTM.

[SHOULD] Please open and link a follow-up issue from the Compatibility notes for:

  • Cross-request no-progress detection (r4295880341).
  • Consistent chain-inventory responses and recovery during concurrent fork switches (r4312910151).

[DISCUSS] #6966 targets the same branch and conflicts in ChainInventoryMsgHandler.java and its test. Please coordinate the merge order, preserve the negative-remain and overflow protections, and rerun the relevant tests after integration.

[NIT] Please refresh the stale #6993 integration note, and change BAD_MESSAGE to SYNC_FAILED in the description of the terminal-summary membership rejection.

Preserve the upstream queue-concurrency regression test and adapt sync test HELLO messages to constructor validation.
Preserve the subtraction-based overflow guard and sync completion checks. Merge release negative-remain validation and retain regression tests from both branches.

Validation: clean build, CI Checkstyle, Math usage and diff checks pass. Full tests: 4986 total, 4969 passed, 16 skipped, 1 failed. All 53 sync-related regression tests pass. RelayServiceTest.testStrictHelloAuthentication also fails in isolation because its unchanged HELLO fixture omits required block hashes; the fixture and HelloMessage validator are unchanged from both parents.
Calculate the declared highest block number explicitly and reject overflow or values above the future height limit.

Validation: all 26 ChainInventoryMsgHandlerTest cases and framework checkstyleMain pass.
@github-actions
github-actions Bot requested a review from xxo1shine October 26, 2026 09:15
@kuny0707
kuny0707 merged commit 632e647 into tronprotocol:release_v4.8.3 Oct 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants