Skip to content

net: reject headers presync when clock trails chain start#186

Draft
l0rinc wants to merge 3 commits into
masterfrom
pr/35208_alt
Draft

net: reject headers presync when clock trails chain start#186
l0rinc wants to merge 3 commits into
masterfrom
pr/35208_alt

Conversation

@l0rinc
Copy link
Copy Markdown
Owner

@l0rinc l0rinc commented Jun 6, 2026

Problem: Headers presync derives its commitment memory bound from the local node clock relative to the known chain-start MTP. If the local clock is more than MAX_FUTURE_BLOCK_TIME behind that chain-start MTP, the elapsed value becomes negative before it is used to derive m_max_commitments. This condition is relative to the known fork point, not genesis.

Fix: Reject low-work headers presync before constructing HeadersSyncState when the captured local clock is earlier than chain_start_mtp - MAX_FUTURE_BLOCK_TIME. The same captured now is passed into HeadersSyncState, where the derived non-negative bound remains asserted. The tests first characterize the existing behavior, then update it to pin the exact MAX_FUTURE_BLOCK_TIME boundary.

l0rinc added 3 commits June 6, 2026 20:19
Record the current headers presync behavior when the local clock is more than MAX_FUTURE_BLOCK_TIME behind the chain-start MTP.
This is not the intended behavior: presync accepts the first low-work header and requests more even though no locally acceptable extension can exist. Mark the assertion with a TODO so the next behavior-changing commit can update it without making the current expectation look intentional.
Capture the local node clock before constructing HeadersSyncState and pass that value through the constructor.
This keeps the existing behavior while making the later validation use the same time value as the commitment bound calculation.
Low-work headers presync should not start from a chain-start block whose MTP is already too far in the future for the local clock.
Check the chain-start MTP against the captured local clock before constructing HeadersSyncState.
The constructor keeps an internal assertion over the same clock value, and the regression test pins the exact MAX_FUTURE_BLOCK_TIME boundary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant