Join Nostr
2026-11-10 04:21:59 UTC

mleku on Nostr: **Bitcoin Core IBD failure modes (patched locally, v29.5 tree ...

**Bitcoin Core IBD failure modes (patched locally, v29.5 tree `~/s/bitcoin-core-29-src`)**

1. **No way to compact the chainstate during or after an IBD/reindex**
- `ShouldCompactChainstate()` (`src/validation.cpp:115`) returns `false` whenever `in_ibd`, and otherwise compacts with probability 1/320 per full flush. So a from-genesis sync or `-reindex` never compacts, no matter how long it runs.
- `CCoinsViewDB::CompactFull()` exists and runs async, but has no RPC, no timer, and `-forcecompactdb` only fires at database open.
- Result: chainstate reached 445 tables × ~30 MB (13 GB); random UTXO lookups fanned out across all of them. Measured `rchar` 0.3 MB/s against `read_bytes` 250 MB/s — **811× read amplification**, 2–4 blocks/min.
- Patch: `-compactonclose`, which after the final `ForceFlushStateToDisk()` at shutdown calls `CoinsDB().CompactFull().wait()` and logs the duration.

2. **LevelDB block caches are hard-capped, independent of `-dbcache`**
- `src/kernel/caches.h`: `MAX_COINS_DB_CACHE{8_MiB}`, `MAX_BLOCK_DB_CACHE{2_MiB}`. Setting `-dbcache=12000` still yields `Using 8.0 MiB for chain state database`; the rest goes to the in-memory UTXO cache.
- Result: with a multi-GB chainstate every lookup reads index/data blocks from disk — ~1.1 GB/s and 32k IOPS sustained at ~4 blocks/s, ~285 MB read per connected block.
- Patch: caps raised to 1 GiB (coins) and 64 MiB (block index).

**Operational traps that made both worse** (no patch, but they trigger the above): auto-compaction being IBD-gated; restarts resuming from the last chainstate flush and replaying; `assumevalid` being ineffective while its block is not yet on the active chain, silently falling back to full validation; and the UTXO-cache/DB-cache split making a large `-dbcache` look ineffective.

---

and no, none of these problems are fixed in the latest 30+ versions:

Correct — neither fix is in the latest versions. Verified directly against the sources on this machine:

| | our patched v29.5 | Core v30.3 (`btc-fork-sim/bitcoin-30.3`) | Knots v29.4.3 (`bitcoinknots/bitcoin`) |
|---|---|---|---|
| `MAX_COINS_DB_CACHE` | 1024 MiB | **8 MiB** | **8 MiB** |
| `MAX_BLOCK_DB_CACHE` | 64 MiB | **2 MiB** | **2 MiB** |
| `ShouldCompactChainstate` | (unchanged) | `!in_ibd && 1/320 flushes` | `!in_ibd && 1/320 flushes` |
| compaction trigger at shutdown | `-compactonclose` | **none** | **none** |
| `CoinsDB().CompactFull()` | present | present (unused except the 1/320 path) | present (same) |
| other compaction trigger | — | `-forcecompactdb` at DB open | `-forcecompactdb` at DB open |

So the underlying machinery exists in all three, but the two things that made it unusable for a from-genesis IBD are identical upstream: the coin-DB LevelDB cache is capped at 8 MiB regardless of `-dbcache`, and compaction is disabled for the entire duration of IBD with no way to invoke it except the hidden open-time `-forcecompactdb`. The only levers upstream ships are "give the UTXO cache tens of GB so you never flush" or "restart with `-forcecompactdb`".