refactor + log: use new CeilDiv helper in UTXO Flushing warning #34436

pull l0rinc wants to merge 2 commits into bitcoin:master from l0rinc:l0rinc/ceildiv-utxo-flush-gib changing 17 files +88 −21
  1. l0rinc commented at 9:47 pm on January 28, 2026: contributor

    Problem

    The Flushing large (... GiB) UTXO set... warning was rounding the target value down (e.g. 1643.7MiB was printed as 1 GiB) which downplayed the warning that is meant to set the user’s expectations.

    Fixes

    This PR starts with introducing a small overflow-safe integer CeilDiv() helper and replaces existing ceiling-division expressions across the codebase as a pure refactor. In the second commit, this method is applied to change the flushing message slightly by rounding the batch size up, amending #31534 which introduced the warning.

    Reproducer:

    killall bitcoind; rm -rfd build demo; mkdir demo && cmake -B build >/dev/null 2>&1 && cmake –build build -j$(nproc) –target bitcoind >/dev/null 2>&1 && build/bin/bitcoind -datadir=demo-dbcache=2000 -stopatheight=300000 | egrep ‘height=300000|Flushing large’

    Before:

    0UpdateTip: new best=000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254 height=300000 version=0x00000002 log2_work=78.499549 tx=38463789 date='2014-05-10T06:32:34Z'
    1progress=0.029457 cache=1643.7MiB(11822004txo)
    2[warning] Flushing large (1 GiB) UTXO set to disk, it may take several minutes
    

    After:

    0UpdateTip: new best=000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254 height=300000 version=0x00000002 log2_work=78.499549 tx=38463789 date='2014-05-10T06:32:34Z'
    1progress=0.029457 cache=1643.7MiB(11822004txo)
    2[warning] Flushing large (2 GiB) UTXO set to disk, it may take several minutes
    

    The cache line shows 1643.7MiB, which now rounds up to 2 GiB instead of down to 1 GiB.

  2. DrahtBot commented at 9:47 pm on January 28, 2026: contributor

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

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34435 (refactor: use _MiB/_GiB consistently for byte conversions by l0rinc)
    • #33512 (coins: use number of dirty cache entries in flush warnings/logs by l0rinc)
    • #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.

  3. DrahtBot added the label CI failed on Jan 28, 2026
  4. DrahtBot commented at 10:44 pm on January 28, 2026: contributor

    🚧 At least one of the CI tasks failed. Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/21456706302/job/61799208927 LLM reason (✨ experimental): Link-time failure: arith_uint256.cpp.o depends on check.cpp.o symbol assertion_fail, triggering an “Unexpected dependencies were detected” error.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  5. l0rinc force-pushed on Jan 28, 2026
  6. l0rinc force-pushed on Jan 29, 2026
  7. l0rinc force-pushed on Jan 29, 2026
  8. fanquake commented at 11:18 am on January 29, 2026: member

    https://github.com/bitcoin/bitcoin/actions/runs/21474548168/job/61856382435?pr=34436#step:11:2456:

    0 fuzz: util/overflow.h:64: auto CeilDiv(const Dividend, const Divisor) [Dividend = long, Divisor = int]: Assertion `dividend >= 0 && divisor > 0' failed.
    
  9. l0rinc force-pushed on Jan 29, 2026
  10. l0rinc commented at 11:44 am on January 29, 2026: contributor
    0 fuzz: util/overflow.h:64: auto CeilDiv(const Dividend, const Divisor) [Dividend = long, Divisor = int]: Assertion `dividend >= 0 && divisor > 0' failed.
    

    Yeah, a few places (e.g. GetVirtualTransactionSize) were replaced originally in the PR, but turns out fuzzers sometimes create negative amounts for these - not sure if that’s possible in reality so I’ve reverted that one. Sorry for all the pushes, the extra validations in the new CeilDiv trigger a lot of these (invalid?) edge cases - so we can investigate and possibly migrate them in follow-up PRs instead.

  11. DrahtBot removed the label CI failed on Jan 29, 2026
  12. DrahtBot added the label Needs rebase on Feb 7, 2026
  13. refactor: add overflow-safe `CeilDiv` helper
    Introduce `CeilDiv()` for integral ceiling division without the typical `(dividend + divisor - 1) / divisor` overflow.
    `CeilDiv()` asserts non-negative arguments and a non-zero divisor.
    
    Replace existing ceiling-division expressions with `CeilDiv()` to centralize the preconditions.
    
    Add unit tests covering return type deduction, max-value behavior, and divisor checks.
    
    A few places (e.g. `GetVirtualTransactionSize`) were replaced originally, but turns out fuzzer creates negative amounts for these so they will be tackled in possible follow-up PRs.
    d09b8c2394
  14. validation: round up UTXO flush GiB warning
    Use `CeilDiv()` when formatting the UTXO cache size so the warning does not under-report near GiB boundaries.
    Use `1024_MiB` for the divisor to keep the units explicit.
    
    Reproducer:
    > killall bitcoind; rm -rfd build demo; mkdir demo && cmake -B build >/dev/null 2>&1 && cmake --build build -j$(nproc) --target bitcoind >/dev/null 2>&1 && build/bin/bitcoind -datadir=demo -dbcache=2000 -stopatheight=300000 | egrep 'height=300000|Flushing large'
    
    Before:
    UpdateTip: new best=000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254 height=300000 version=0x00000002 log2_work=78.499549 tx=38463789 date='2014-05-10T06:32:34Z' progress=0.029457 cache=1643.7MiB(11822004txo)
    [warning] Flushing large (1 GiB) UTXO set to disk, it may take several minutes
    
    After:
    UpdateTip: new best=000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254 height=300000 version=0x00000002 log2_work=78.499549 tx=38463789 date='2014-05-10T06:32:34Z' progress=0.029457 cache=1643.7MiB(11822004txo)
    [warning] Flushing large (2 GiB) UTXO set to disk, it may take several minutes
    
    The cache line shows 1643.7MiB, which now rounds up to 2 GiB instead of down to 1 GiB.
    d9b0708e69
  15. l0rinc force-pushed on Feb 8, 2026
  16. DrahtBot removed the label Needs rebase on Feb 8, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-02-10 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me