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.