I was contacted by someone who runs a lot of nodes that they see the following issue happen very often: After an unclean shutdown an index reports that it is at an unknown best block and the node can not be restarted unless the index is deactivated or resynced.
02025-08-16T12:34:43Z Verification progress: 99%
12025-08-16T12:34:43Z Verification: No coin database inconsistencies in last 6 blocks (6 transactions)
22025-08-16T12:34:43Z Block index and chainstate loaded
32025-08-16T12:34:43Z Opening LevelDB in /bitcoin/testnet3/indexes/txindex
42025-08-16T12:34:43Z Opened LevelDB successfully
52025-08-16T12:34:43Z Using obfuscation key for /bitcoin/testnet3/indexes/txindex: 0000000000000000
62025-08-16T12:34:43Z Opening LevelDB in /bitcoin/testnet3/indexes/coinstats/db
72025-08-16T12:34:43Z Opened LevelDB successfully
82025-08-16T12:34:43Z Using obfuscation key for /bitcoin/testnet3/indexes/coinstats/db: 0000000000000000
92025-08-16T12:34:43Z [error] txindex: best block of the index not found. Please rebuild the index.
102025-08-16T12:34:43Z Shutdown: In progress...
112025-08-16T12:34:43Z scheduler thread exit
122025-08-16T12:34:43Z Flushed fee estimates to fee_estimates.dat.
132025-08-16T12:34:44Z Shutdown: done
I didn’t find an issue on this problem here but it seems to indeed be happening more widely since I could find similar reports on several forums for node runners:
https://community.umbrel.com/t/bitcoin-core-stuck-starting-rebuild-index/18715 https://community.umbrel.com/t/can-anyone-explain-how-to-rebuild-an-index/23288 https://community.start9.com/t/bitcoin-restart-loop-with-error-txindex-best-block-of-the-index-not-found-please-rebuild-the-index/1589 https://community.start9.com/t/knots-is-looping-in-running-erroring-restarting/3522 (This is knots but I don’t think knots changes much on the indexes) https://bitcoin.stackexchange.com/questions/126304/bitcoind-testnet3-node-fails-with-txindex-best-block-of-the-index-not-found
So far I haven’t been able to reproduce the issue though. I tried through applying targeted asserts and sleeps but either I haven’t found the right spot or this is some deeper issue. I’m waiting to receive more infos/logs that might be helpful for triaging.
In the PR that added this code @mzumsande already anticipated that this could be an issue. From taking a look and considering/sketching out some ideas I think the simplest way to fix this might be to go back to the old behavior in Init
and give the CustomInit
in coinstatsindex the ability to roll back if it is initialized with an older block. It seems like fixing this was the motivation behind #25193 but I haven’t read through all the old conversations yet.