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`".
Published at
2026-11-10 04:21:59 UTCEvent JSON
{
"id": "52c8cbd78a17d94a0adc1f97ad32cca24ffcb5bf3b65ff21d71fc62a68b9b6b9",
"pubkey": "5538e28a66eb88360f15f8fa95646bdd2daa2999aacfe4faacf43d0c0540b281",
"created_at": 1794284519,
"kind": 1,
"tags": [],
"content": "**Bitcoin Core IBD failure modes (patched locally, v29.5 tree `~/s/bitcoin-core-29-src`)**\n\n1. **No way to compact the chainstate during or after an IBD/reindex**\n - `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.\n - `CCoinsViewDB::CompactFull()` exists and runs async, but has no RPC, no timer, and `-forcecompactdb` only fires at database open.\n - 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.\n - Patch: `-compactonclose`, which after the final `ForceFlushStateToDisk()` at shutdown calls `CoinsDB().CompactFull().wait()` and logs the duration.\n\n2. **LevelDB block caches are hard-capped, independent of `-dbcache`**\n - `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.\n - 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.\n - Patch: caps raised to 1 GiB (coins) and 64 MiB (block index).\n\n**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.\n\n---\n\nand no, none of these problems are fixed in the latest 30+ versions:\n\nCorrect — neither fix is in the latest versions. Verified directly against the sources on this machine:\n\n| | our patched v29.5 | Core v30.3 (`btc-fork-sim/bitcoin-30.3`) | Knots v29.4.3 (`bitcoinknots/bitcoin`) |\n|---|---|---|---|\n| `MAX_COINS_DB_CACHE` | 1024 MiB | **8 MiB** | **8 MiB** |\n| `MAX_BLOCK_DB_CACHE` | 64 MiB | **2 MiB** | **2 MiB** |\n| `ShouldCompactChainstate` | (unchanged) | `!in_ibd \u0026\u0026 1/320 flushes` | `!in_ibd \u0026\u0026 1/320 flushes` |\n| compaction trigger at shutdown | `-compactonclose` | **none** | **none** |\n| `CoinsDB().CompactFull()` | present | present (unused except the 1/320 path) | present (same) |\n| other compaction trigger | — | `-forcecompactdb` at DB open | `-forcecompactdb` at DB open |\n\nSo 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`\".",
"sig": "ab086274e698fed6a7ee2978f91d96e0ce57d106829660acc94ee8c7d6d39e4a9444040b1c828f33105419049c14238318c4a05fdb7095b904828035b47e6270"
}