[statesync] End every client pass at the target
Summary
The statesync client splits each prefix into two passes. A pass that starts below 99% of the target stops there, and the prefix finishes in a second pass [0.99 * target + 1, target] with old_target = target, which asks for no deletions. This PR makes every pass end at the target.
The two passes cover every leaf only when one peer serves both. A pass selects leaves by the serving node's own versions. A node that was state-synced stamps each leaf it received with the version its sync started from (statesync_client_context.cpp), not the block that last wrote it. Suppose the first peer executed every block, the second peer state-synced from an empty database, and a leaf was last written above 0.99 * target. The first peer labels the leaf with that block and leaves it out of pass 1. The second labels it 0 and leaves it out of pass 2. Only the state-root check at finalize catches this. The split is why the bft client keeps each prefix on one peer for the whole sync.
The split no longer saves anything:
- bft hands the client a new target only after the current one is reached, so both passes run at the same target and together serve exactly
[0, target]. - A node restored from a snapshot at block L starts with
[L + 1, target], which needs deletions back to L. Servers keep at most 43,200 blocks of deletions (MAX_ENTRIES), which is under 1% of any target past block 4.32M, so the split never fires on this path.
With every pass ending at the target, a pass has one of two forms. [0, target] selects every leaf. [old_target + 1, target] can only be served by a peer that executed every block in that range, so it selects exactly the leaves written there. Either way, any peer that can serve the pass returns the same leaves, and the bft client no longer needs to pin a prefix to one peer. Removing that pinning is a separate bft change.
Testing
The test harness's request callback, statesync_send_request, now checks that every request the client sends ends at the target. With the split restored, the sync tests fail on that check.
馃 Generated with Claude Code