3 suggestions
Earlier concerns neither republished nor resolved: 3 minor findings · 1 suggestion. See the Run archive for their assessments.
Optional improvements
[suggestion] · The production-parameter wrapper lacks direct unit coverage
Unit tests do not pin the constants or clamp in ComputeHeadersSyncParams, so a change could alter headers-sync parameters across networks without failing a test.
Location: src/test/headerssync_tests.cpp:236 (head).
Details and suggested fix
Every unit vector calls ComputeHeadersSyncParamsInner with an explicit attack_headers. The wrapper is called only by MakeHeadersSyncParams and the headers_sync_params fuzz target, which checks only broad bounds. It contains the constants that set the attack budget, derives max_headers at six headers per second, and applies the lower clamp. A change to these values could alter the redownload buffer without failing the unit tests. For example, increasing LIMIT_FRACTION would shrink every redownload buffer. The generator comment says its LIMIT_FRACTION must match headerssync.cpp, but C++ does not verify that; before this change, reviewers could check the concrete pairs in chainparams.cpp. Add a few ComputeHeadersSyncParams vectors to pin this path, including mainnet's minchainwork_height of 966143 at a fixed timespan and a negative timespan to exercise the clamp. Use expected values produced by the same script.
[suggestion] · The optimizer fuzz target does not check the attack-rate budget
The fuzz target checks only result shape, so a redownload buffer that exceeds the attack-rate budget outside the 50 unit vectors would pass its assertions.
Location: src/test/fuzz/headerssync.cpp:171 (head).
Details and suggested fix
headers_sync_params_inner samples attack_headers from about 2^-1000 to 2^20, but checks only that the result is in range, the buffer holds at least one header, and the buffer is at least the period when the budget is below 0.5. A result of period 1 and buffer size 1 passes these checks, although the closed form gives 0.5 accepted forged headers per attack, exceeding any budget below 0.5. The budget is checked only for the fixed unit vectors through CheckOptimal. Evaluate the closed-form AttackRate on the returned pair and assert that it is below attack_headers, allowing a small relative tolerance such as 1e-9 for boundary rounding. AttackRate would need to move into a shared test utility.
[suggestion] · The attack budget uses in-memory header size instead of wire size
The value is correct today, but an in-memory-only addition to CBlockHeader would silently loosen the attack budget.
Location: src/headerssync.cpp:579 (head).
Details and suggested fix
The comment describes NET_HEADER_SIZE as the number of bits a header uses in the P2P protocol, but the code calculates it as (sizeof(CBlockHeader) + 1) * 8. Both sizes are 80 bytes today. If a non-serialized member, such as a cached hash, were added to CBlockHeader, NET_HEADER_SIZE would grow while the wire size remained 81 bytes. NET_HEADERRATE would fall, LIMIT_FRACTION and attack_headers would rise, and the optimizer would choose smaller redownload buffers. The unit vectors would not catch this because they pass attack_headers explicitly. Add static_assert(NET_HEADER_SIZE == 81 * 8);, or use the literal, to preserve today's value and make such a layout change a compile error.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [minor]: Avoid overflow when scaling negative timespans
- [minor]: Check header-count bounds before computing the optimizer clamp
- [minor]: Use one clock sample for parameter sizing and the commitment cap
- [suggestion]: Initialize the minimum-chain-work height member