Repository navigation
Conversation
The output should be the additional space needed, otherwise we are always warning that 810GB will be stored, even when a user is pruning. For example on machine with ~20GB free disk, pruning to 40GB: ```bash ./build/bin/bitcoind -prune=40000 ... 2026-01-15T11:45:33Z [warning] Disk space for "/root/.bitcoin/blocks" may not accommodate the block files. Approximately 810 GB of data will be stored in this directory. Warning: Disk space for "/root/.bitcoin/blocks" may not accommodate the block files. Approximately 810 GB of data will be stored in this directory. ``` This PR: ```bash ./build/bin/bitcoind -prune=40000 ... 2026-01-15T11:41:49Z [warning] Disk space for "/root/.bitcoin/blocks" may not accommodate the block files. Approximately 39 GB of data will be stored in this directory. Warning: Disk space for "/root/.bitcoin/blocks" may not accommodate the block files. Approximately 39 GB of data will be stored in this directory. ```
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34305. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
l0rinc
left a comment
There was a problem hiding this comment.
tested ACK 2a42d39
With small prune values it shows the pruning value:
mkdir -p demo && cmake -B build && cmake --build build -j$(nproc) && ./build/bin/bitcoind -datadir=demo -prune=400000
2026-01-15T12:33:14Z [warning] Disk space for "[...]/bitcoin/demo/blocks" may not accommodate the block files. Approximately 390 GB of data will be stored in this directory.For very big values it shows the current blocksdir size instead:
mkdir -p demo && cmake -B build && cmake --build build -j$(nproc) && ./build/bin/bitcoind -datadir=demo -prune=4000000
2026-01-15T12:33:45Z [warning] Disk space for "[...]/bitcoin/demo/blocks" may not accommodate the block files. Approximately 810 GB of data will be stored in this directory.| ), | ||
| fs::quoted(fs::PathToString(args.GetBlocksDirPath())), | ||
| chainparams.AssumedBlockchainSize() | ||
| (additional_bytes_needed / 1024 / 1024 / 1024) |
There was a problem hiding this comment.
Might be worth noting that this will be capped to current blockchain max size:
Line 1925 in 2a42d39
willcl-ark
left a comment
There was a problem hiding this comment.
tACK 2a42d39
With 520GB free on /tmp I see:
master:
❯ /run/current-system/sw/bin/bitcoind -daemon=0 -datadir=/tmp/size-warn -prune=600000
<snip>
2026-01-15T13:16:00Z [warning] Disk space for "/tmp/size-warn/blocks" may not accommodate the block files. Approximately 810 GB of data will be stored in this directory.
Warning: Disk space for "/tmp/size-warn/blocks" may not accommodate the block files. Approximately 810 GB of data will be stored in this directory.
PR
❯ ./build/bin/bitcoind -daemon=0 -datadir=/tmp/size-warn -prune=600000
<snip>
2026-01-15T13:13:51Z init message: Pruning blockstore…
2026-01-15T13:13:51Z [warning] Disk space for "/tmp/size-warn/blocks" may not accommodate the block files. Approximately 585 GB of data will be stored in this directory.
Warning: Disk space for "/tmp/size-warn/blocks" may not accommodate the block files. Approximately 585 GB of data will be stored in this directory.
|
ACK 2a42d39 |
| ), | ||
| fs::quoted(fs::PathToString(args.GetBlocksDirPath())), | ||
| chainparams.AssumedBlockchainSize() | ||
| (additional_bytes_needed / 1024 / 1024 / 1024) |
There was a problem hiding this comment.
This now wraps down to zero if a minimal prune target is provided:
Disk space for "/tmp/small_blocks/blocks" may not accommodate the block files. Approximately 0 GB of data will be stored in this directory.
Maybe clamp it to 1?
There was a problem hiding this comment.
Rounding up sounds more appropriate?
There was a problem hiding this comment.
If we add an int ceil rounding and ""_GiB primitive helper, we could do the conversion here as:
| (additional_bytes_needed / 1024 / 1024 / 1024) | |
| CeilDiv(additional_bytes_needed, 1_GiB) |
| ), | ||
| fs::quoted(fs::PathToString(args.GetBlocksDirPath())), | ||
| chainparams.AssumedBlockchainSize() | ||
| (additional_bytes_needed / 1024 / 1024 / 1024) |
There was a problem hiding this comment.
Also, while I love 1024-based units, the codebase does seem to be consistent with 1000-based "GB" vs 1024-based "GiB"
This PR is actually a duplicate of #29678
…rsions af0ee28 refactor: use _MiB consistently for Mebibyte conversions (Lőrinc) b3edd30 util: add _GiB for Gibibyte conversions (Lőrinc) Pull request description: ### Problem Byte-size conversions in the codebase currently show up in many equivalent formats (multiplication/division chains, shifts, hex/binary literals), which creates a maintenance burden and makes review error-prone - especially considering the architectural differences of `size_t`. Inspired by #34305 (comment), it seemed appropriate to unify `Mebibyte` usage across the codebase and add `Gibibyte` support with 32/64 bit `size_t` validation. ### Fix This PR refactors those call sites to use `""_MiB` (existing) and `""_GiB` (new), and adds the encountered value/pattern replacements to unit tests to make review straightforward, and to ensure the conversions remain valid. The literals are overflow-checked when converting to `size_t`, and unit tests cover the 32-bit boundary cases. Concretely, it replaces patterns such as: * `1024*1024`, `1<<20`, `0x100000`, `1048576`, `/ 1024 / 1024`, `* (1.0 / 1024 / 1024)` → `1_MiB` or `double(1_MiB)` * `1024*1024*1024`, `1<<30`, `0x40000000`, `1024_MiB`, `>> 30` → `1_GiB` (added unit tests for each replacement category to ease review) Additionally, declarations whose initializer reads a `_MiB`/`_GiB` literal are switched to braced initialization so a future oversized value is rejected at compile time through the narrowing check instead of silently truncating. ### Note In the few places where arithmetic involves signed values, the result is identical to the previous code assuming those quantities never become negative. ACKs for top commit: achow101: ACK af0ee28 janb84: ACK af0ee28 maflcko: review ACK af0ee28 🖍 hodlinator: re-ACK af0ee28 Tree-SHA512: 55286ce3f833f88335394a74e9e0b95c7d023e5cdc9ded40accbbbcd870101e4dcc05926865d6bef4c1be1ebd648aa3fdf947ef9575633ccfe56691f145d7a2d
… for byte conversions d0ab9c9 refactor: use _MiB consistently for Mebibyte conversions (Lőrinc) b4c845b util: add _GiB for Gibibyte conversions (Lőrinc) Pull request description: ### Problem Byte-size conversions in the codebase currently show up in many equivalent formats (multiplication/division chains, shifts, hex/binary literals), which creates a maintenance burden and makes review error-prone - especially considering the architectural differences of `size_t`. Inspired by bitcoin/bitcoin#34305 (comment), it seemed appropriate to unify `Mebibyte` usage across the codebase and add `Gibibyte` support with 32/64 bit `size_t` validation. ### Fix This PR refactors those call sites to use `""_MiB` (existing) and `""_GiB` (new), and adds the encountered value/pattern replacements to unit tests to make review straightforward, and to ensure the conversions remain valid. The literals are overflow-checked when converting to `size_t`, and unit tests cover the 32-bit boundary cases. Concretely, it replaces patterns such as: * `1024*1024`, `1<<20`, `0x100000`, `1048576`, `/ 1024 / 1024`, `* (1.0 / 1024 / 1024)` → `1_MiB` or `double(1_MiB)` * `1024*1024*1024`, `1<<30`, `0x40000000`, `1024_MiB`, `>> 30` → `1_GiB` (added unit tests for each replacement category to ease review) Additionally, declarations whose initializer reads a `_MiB`/`_GiB` literal are switched to braced initialization so a future oversized value is rejected at compile time through the narrowing check instead of silently truncating. ### Note In the few places where arithmetic involves signed values, the result is identical to the previous code assuming those quantities never become negative. ACKs for top commit: achow101: ACK d0ab9c9 janb84: ACK d0ab9c9 maflcko: review ACK d0ab9c9 🖍 hodlinator: re-ACK d0ab9c9 Tree-SHA512: 55286ce3f833f88335394a74e9e0b95c7d023e5cdc9ded40accbbbcd870101e4dcc05926865d6bef4c1be1ebd648aa3fdf947ef9575633ccfe56691f145d7a2d
… for byte conversions e859dfd refactor: use _MiB consistently for Mebibyte conversions (Lőrinc) e0f46d1 util: add _GiB for Gibibyte conversions (Lőrinc) Pull request description: ### Problem Byte-size conversions in the codebase currently show up in many equivalent formats (multiplication/division chains, shifts, hex/binary literals), which creates a maintenance burden and makes review error-prone - especially considering the architectural differences of `size_t`. Inspired by bitcoin/bitcoin#34305 (comment), it seemed appropriate to unify `Mebibyte` usage across the codebase and add `Gibibyte` support with 32/64 bit `size_t` validation. ### Fix This PR refactors those call sites to use `""_MiB` (existing) and `""_GiB` (new), and adds the encountered value/pattern replacements to unit tests to make review straightforward, and to ensure the conversions remain valid. The literals are overflow-checked when converting to `size_t`, and unit tests cover the 32-bit boundary cases. Concretely, it replaces patterns such as: * `1024*1024`, `1<<20`, `0x100000`, `1048576`, `/ 1024 / 1024`, `* (1.0 / 1024 / 1024)` → `1_MiB` or `double(1_MiB)` * `1024*1024*1024`, `1<<30`, `0x40000000`, `1024_MiB`, `>> 30` → `1_GiB` (added unit tests for each replacement category to ease review) Additionally, declarations whose initializer reads a `_MiB`/`_GiB` literal are switched to braced initialization so a future oversized value is rejected at compile time through the narrowing check instead of silently truncating. ### Note In the few places where arithmetic involves signed values, the result is identical to the previous code assuming those quantities never become negative. ACKs for top commit: achow101: ACK e859dfd janb84: ACK e859dfd maflcko: review ACK e859dfd 🖍 hodlinator: re-ACK e859dfd Tree-SHA512: 55286ce3f833f88335394a74e9e0b95c7d023e5cdc9ded40accbbbcd870101e4dcc05926865d6bef4c1be1ebd648aa3fdf947ef9575633ccfe56691f145d7a2d
… for byte conversions af0ee28eb623a54e7ff8602864f61cab1f23848d refactor: use _MiB consistently for Mebibyte conversions (Lőrinc) b3edd30aa24af3a5f63cbcebb7013e60a6d7b8a4 util: add _GiB for Gibibyte conversions (Lőrinc) Pull request description: ### Problem Byte-size conversions in the codebase currently show up in many equivalent formats (multiplication/division chains, shifts, hex/binary literals), which creates a maintenance burden and makes review error-prone - especially considering the architectural differences of `size_t`. Inspired by bitcoin/bitcoin#34305 (comment), it seemed appropriate to unify `Mebibyte` usage across the codebase and add `Gibibyte` support with 32/64 bit `size_t` validation. ### Fix This PR refactors those call sites to use `""_MiB` (existing) and `""_GiB` (new), and adds the encountered value/pattern replacements to unit tests to make review straightforward, and to ensure the conversions remain valid. The literals are overflow-checked when converting to `size_t`, and unit tests cover the 32-bit boundary cases. Concretely, it replaces patterns such as: * `1024*1024`, `1<<20`, `0x100000`, `1048576`, `/ 1024 / 1024`, `* (1.0 / 1024 / 1024)` → `1_MiB` or `double(1_MiB)` * `1024*1024*1024`, `1<<30`, `0x40000000`, `1024_MiB`, `>> 30` → `1_GiB` (added unit tests for each replacement category to ease review) Additionally, declarations whose initializer reads a `_MiB`/`_GiB` literal are switched to braced initialization so a future oversized value is rejected at compile time through the narrowing check instead of silently truncating. ### Note In the few places where arithmetic involves signed values, the result is identical to the previous code assuming those quantities never become negative. ACKs for top commit: achow101: ACK af0ee28eb623a54e7ff8602864f61cab1f23848d janb84: ACK af0ee28eb623a54e7ff8602864f61cab1f23848d maflcko: review ACK af0ee28eb623a54e7ff8602864f61cab1f23848d 🖍 hodlinator: re-ACK af0ee28eb623a54e7ff8602864f61cab1f23848d Tree-SHA512: 55286ce3f833f88335394a74e9e0b95c7d023e5cdc9ded40accbbbcd870101e4dcc05926865d6bef4c1be1ebd648aa3fdf947ef9575633ccfe56691f145d7a2d
The output should be the additional space needed, otherwise we are always warning that 810GB will be stored, even when a user is pruning.
For example on machine with ~20GB free disk, pruning to 40GB:
This PR: