refactor: Use u64 consistently for flatfile sizes #36725

Manually merged
maflcko merged 3 commits from 2611-file-size-u64 into master 2026-11-05 22:19:02 +00:00 AGit
maflcko commented 2026-11-02 09:47:53 +00:00 (Migrated from github.com)

unsigned is a 32-bit integer (even on 64-bit platforms). File sizes are generally measured in 64-bit integers and using 32-bit integers or architecture-dependent integers is brittle and confusing.

So use u64 consistently for flatfile sizes in this refactor.

Also, use LARGE_INTEGER's QuadPart on Windows, which is recommended since C++11.

Also, unit test VarInt overflow errors.

`unsigned` is a 32-bit integer (even on 64-bit platforms). File sizes are generally measured in 64-bit integers and using 32-bit integers or architecture-dependent integers is brittle and confusing. So use u64 consistently for flatfile sizes in this refactor. Also, use `LARGE_INTEGER`'s `QuadPart` on Windows, which is recommended since C++11. Also, unit test VarInt overflow errors.
DrahtBot commented 2026-11-02 09:48:04 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK darosior, frankomosh, sedited

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35713 (Remove boost as a unit test runner by rustaceanrob)
  • #35646 (RFC: Separate out runtime errors from BlockValidationState using util::Expected by yuvicc)
  • #29700 (kernel, refactor: return error status on all fatal errors by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36725 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36725.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36725#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [darosior](https://github.com/bitcoin/bitcoin/pull/36725#pullrequestreview-5773930759), [frankomosh](https://github.com/bitcoin/bitcoin/pull/36725#pullrequestreview-5783767022), [sedited](https://github.com/bitcoin/bitcoin/pull/36725#pullrequestreview-5792884029) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35713](https://github.com/bitcoin/bitcoin/pull/35713) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35713.svg"></sub> (Remove boost as a unit test runner by rustaceanrob) * [#35646](https://github.com/bitcoin/bitcoin/pull/35646) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35646.svg"></sub> (RFC: Separate out runtime errors from BlockValidationState using `util::Expected` by yuvicc) * [#29700](https://github.com/bitcoin/bitcoin/pull/29700) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/29700.svg"></sub> (kernel, refactor: return error status on all fatal errors by ryanofsky) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · The increment-overflow test leaves 2^39 unexplained

The unexplained constant makes this unit test's connection to the decoder's increment-overflow boundary difficult to verify.

Location: src/test/serialize_tests.cpp:165 (head).

Review coverage was incomplete.


Reviewed: fa2c8df1810f · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:965af1044d9e41839565702e4d9bd0a751eda81f6e8b6402747fa296ef84ebea:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:6c01bd0b2dc201c21e80ac3635828abf854ee5a0 --> <!-- ralph-head:fa2c8df1810f23e1c510e310eb246fd5abd3a066 --> <!-- ralph-case:8fb18b4148f668cf08fee361409eb9c29e176508e8dc2f36076670f15191a24f --> **🔵 Suggestion · The increment-overflow test leaves `2^39` unexplained** The unexplained constant makes this unit test's connection to the decoder's increment-overflow boundary difficult to verify. Location: [`src/test/serialize_tests.cpp:165`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/fa2c8df1810f23e1c510e310eb246fd5abd3a066/src/test/serialize_tests.cpp#L165>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`fa2c8df1810f`](<https://git.fish.foo/bitcoin/bitcoin/commit/fa2c8df1810f23e1c510e310eb246fd5abd3a066>) · [Full review report](<https://review.fish.foo/traces/36725-fa2c8df1810f23e1c510e310eb246fd5abd3a066-1970-1.html>) · [Previous reports](<https://review.fish.foo/traces/36725/>) [permalink](<https://review.fish.foo/traces/36725-fa2c8df1810f23e1c510e310eb246fd5abd3a066-1970-1.html>)
frankomosh (Migrated from github.com) reviewed 2026-11-03 15:30:59 +00:00
frankomosh (Migrated from github.com) left a comment

Concept ACK

Concept ACK
darosior (Migrated from github.com) approved these changes 2026-11-04 18:50:53 +00:00
darosior (Migrated from github.com) left a comment

utACK fa2c8df181

utACK fa2c8df1810f23e1c510e310eb246fd5abd3a066
frankomosh (Migrated from github.com) reviewed 2026-11-05 10:56:57 +00:00
frankomosh (Migrated from github.com) left a comment

ACK fa2c8df181

nPos, nSize and nUndoSize were already u64, so this makes the remaining flatfile sizes match them. I checked that the block and undo size headers on disk stay 4 bytes. Built the PR at this commit and ran serialize_tests, flatfile_tests and blockmanager_tests, which all look good.

ACK fa2c8df1810f23e1c510e310eb246fd5abd3a066 `nPos`, `nSize` and `nUndoSize` were already u64, so this makes the remaining flatfile sizes match them. I checked that the block and undo size headers on disk stay 4 bytes. Built the PR at this commit and ran `serialize_tests`, `flatfile_tests` and `blockmanager_tests`, which all look good.
sedited (Migrated from github.com) approved these changes 2026-11-05 22:12:22 +00:00
sedited (Migrated from github.com) left a comment
ACK fa2c8df1810f23e1c510e310eb246fd5abd3a066
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36725
No description provided.