Skip to content

log: correct size output in disk space check - #34305

Closed
fanquake wants to merge 1 commit into
bitcoin:masterfrom
fanquake:fix_space_warning_log
Closed

fanquake wants to merge 1 commit into
bitcoin:masterfrom
fanquake:fix_space_warning_log

Conversation

@fanquake

Copy link
Copy Markdown
Member

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:

./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:

./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 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.
```
@DrahtBot

DrahtBot commented Jan 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34305.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK l0rinc, willcl-ark, bensig

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:

  • #29678 (Bugfix: Correct first-run free space checks by luke-jr)

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 l0rinc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/init.cpp
),
fs::quoted(fs::PathToString(args.GetBlocksDirPath())),
chainparams.AssumedBlockchainSize()
(additional_bytes_needed / 1024 / 1024 / 1024)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth noting that this will be capped to current blockchain max size:

std::min(chainman.m_blockman.GetPruneTarget(), assumed_chain_bytes) :

@willcl-ark willcl-ark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bensig

bensig commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

ACK 2a42d39

Comment thread src/init.cpp
),
fs::quoted(fs::PathToString(args.GetBlocksDirPath())),
chainparams.AssumedBlockchainSize()
(additional_bytes_needed / 1024 / 1024 / 1024)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rounding up sounds more appropriate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add an int ceil rounding and ""_GiB primitive helper, we could do the conversion here as:

Suggested change
(additional_bytes_needed / 1024 / 1024 / 1024)
CeilDiv(additional_bytes_needed, 1_GiB)

Comment thread src/init.cpp
),
fs::quoted(fs::PathToString(args.GetBlocksDirPath())),
chainparams.AssumedBlockchainSize()
(additional_bytes_needed / 1024 / 1024 / 1024)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@fanquake fanquake closed this Jan 29, 2026
@fanquake
fanquake deleted the fix_space_warning_log branch January 29, 2026 09:41
achow101 added a commit that referenced this pull request Apr 22, 2026
…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
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Jun 28, 2026
… 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
BigcoinBGC pushed a commit to BigcoinBGC/bigcoin that referenced this pull request Jun 30, 2026
… 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
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 19, 2026
… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants