InitError() doesn’t always halt node startup when blockchain state exists #33276

issue l0rinc openend this issue on September 1, 2025
  1. l0rinc commented at 9:54 pm on September 1, 2025: contributor

    As described in #33231 (review), when InitError() is triggered during initialization, the node prints the error but sometimes continues running, if blockchain data already exists in the datadir.

    0rm -rfd demo build && mkdir -p demo && cmake -B build && cmake --build build -j$(nproc)
    1# empty state fails with error
    2build/bin/bitcoind -datadir=demo -stopatheight=100 -i2psam=invalid_addr
    3# init state with 10 blocks
    4build/bin/bitcoind -datadir=demo -stopatheight=1000
    5# error is shown but doesn't stop execution
    6build/bin/bitcoind -datadir=demo -i2psam=invalid_addr
    

    the last command does usually stop, but it seems that if the validation is happening too late, it doesn’t prevent startup:

     02025-09-01T21:46:54Z Bitcoin Core version v29.99.0-7cc9a087069b (release build)
     12025-09-01T21:46:54Z Using the 'arm_shani(1way,2way)' SHA256 implementation
     22025-09-01T21:46:54Z Default data directory /Users/lorinc/Library/Application Support/Bitcoin
     32025-09-01T21:46:54Z Using data directory /Users/lorinc/IdeaProjects/bitcoin/demo
     42025-09-01T21:46:54Z Config file: /Users/lorinc/IdeaProjects/bitcoin/demo/bitcoin.conf (not found, skipping)
     52025-09-01T21:46:54Z Command-line arg: datadir="demo"
     62025-09-01T21:46:54Z Command-line arg: i2psam="invalid_addr"
     72025-09-01T21:46:54Z Using at most 125 automatic connections (1024 file descriptors available)
     82025-09-01T21:46:54Z Warning: relative datadir option 'demo' specified, which will be interpreted relative to the current working directory '/Users/lorinc/IdeaProjects/bitcoin'. This is fragile, because if bitcoin is started in the future from a different location, it will be unable to locate the current data files. There could also be data loss if bitcoin is started while in a temporary directory.
     92025-09-01T21:46:54Z scheduler thread start
    102025-09-01T21:46:54Z Binding RPC on address ::1 port 8332
    112025-09-01T21:46:54Z Binding RPC on address 127.0.0.1 port 8332
    122025-09-01T21:46:54Z Generated RPC authentication cookie /Users/lorinc/IdeaProjects/bitcoin/demo/.cookie
    132025-09-01T21:46:54Z Permissions used for cookie: rw-------
    142025-09-01T21:46:54Z Using random cookie authentication.
    152025-09-01T21:46:54Z Starting HTTP server with 16 worker threads
    162025-09-01T21:46:54Z Using wallet directory /Users/lorinc/IdeaProjects/bitcoin/demo
    172025-09-01T21:46:54Z init message: Verifying wallet(s)
    182025-09-01T21:46:54Z Using /16 prefix for IP bucketing
    192025-09-01T21:46:54Z init message: Loading P2P addresses
    202025-09-01T21:46:54Z Loaded 7172 addresses from peers.dat  9ms
    212025-09-01T21:46:54Z init message: Loading banlist
    222025-09-01T21:46:54Z SetNetworkActive: true
    232025-09-01T21:46:54Z Cache configuration:
    242025-09-01T21:46:54Z * Using 2.0 MiB for block index database
    252025-09-01T21:46:54Z * Using 8.0 MiB for chain state database
    262025-09-01T21:46:54Z * Using 440.0 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space)
    272025-09-01T21:46:54Z Script verification uses 15 additional threads
    282025-09-01T21:46:54Z Using obfuscation key for blocksdir *.dat files (/Users/lorinc/IdeaProjects/bitcoin/demo/blocks): 'b3658ca56bdb3f0c'
    292025-09-01T21:46:54Z Opening LevelDB in /Users/lorinc/IdeaProjects/bitcoin/demo/blocks/index
    302025-09-01T21:46:54Z Opened LevelDB successfully
    312025-09-01T21:46:54Z Using obfuscation key for /Users/lorinc/IdeaProjects/bitcoin/demo/blocks/index: 0000000000000000
    322025-09-01T21:46:54Z Using 16 MiB out of 16 MiB requested for signature cache, able to store 524288 elements
    332025-09-01T21:46:54Z Using 16 MiB out of 16 MiB requested for script execution cache, able to store 524288 elements
    342025-09-01T21:46:54Z init message: Loading block index
    352025-09-01T21:46:54Z Assuming ancestors of block 00000000000000000001b658dd1120e82e66d2790811f89ede9742ada3ed6d77 have valid signatures.
    362025-09-01T21:46:54Z Setting nMinimumChainWork=0000000000000000000000000000000000000000b1f3b93b65b16d035a82be84
    372025-09-01T21:46:56Z Loading block index db: last block file = 0
    382025-09-01T21:46:56Z Loading block index db: last block file info: CBlockFileInfo(blocks=1030, size=236546, heights=0...1041, time=2009-01-03...2009-01-19)
    392025-09-01T21:46:56Z Checking all blk files are present...
    402025-09-01T21:46:57Z Initializing chainstate Chainstate [ibd] @ height -1 (null)
    412025-09-01T21:46:57Z Opening LevelDB in /Users/lorinc/IdeaProjects/bitcoin/demo/chainstate
    422025-09-01T21:46:57Z Opened LevelDB successfully
    432025-09-01T21:46:57Z Using obfuscation key for /Users/lorinc/IdeaProjects/bitcoin/demo/chainstate: 49bb7fb91842528b
    442025-09-01T21:46:57Z Loaded best chain: hashBestChain=00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09 height=1000 date=2009-01-19T06:34:42Z progress=0.000001
    452025-09-01T21:46:57Z init message: Verifying blocks
    462025-09-01T21:46:57Z Verifying last 6 blocks at level 3
    472025-09-01T21:46:57Z Verification progress: 0%
    482025-09-01T21:46:57Z Verification progress: 16%
    492025-09-01T21:46:57Z Verification progress: 33%
    502025-09-01T21:46:57Z Verification progress: 50%
    512025-09-01T21:46:57Z Verification progress: 66%
    522025-09-01T21:46:57Z Verification progress: 83%
    532025-09-01T21:46:57Z Verification progress: 99%
    542025-09-01T21:46:57Z Verification: No coin database inconsistencies in last 6 blocks (6 transactions)
    552025-09-01T21:46:57Z Block index and chainstate loaded
    562025-09-01T21:46:57Z Setting NODE_NETWORK on non-prune mode
    572025-09-01T21:46:57Z block tree size = 912759
    582025-09-01T21:46:57Z nBestHeight = 1000
    592025-09-01T21:46:57Z initload thread start
    602025-09-01T21:46:57Z mapport thread start
    612025-09-01T21:46:57Z torcontrol thread start
    622025-09-01T21:46:57Z Disabling signature validations at block [#1001](/bitcoin-bitcoin/1001/) (00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6).
    632025-09-01T21:46:57Z UpdateTip: new best=00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6 height=1001 version=0x00000001 log2_work=41.968689 tx=1021 date='2009-01-19T06:49:46Z' progress=0.000001 cache=0.3MiB(1txo)
    642025-09-01T21:46:57Z UpdateTip: new best=00000000430a20b3f4f658c153168b6615512dfe1a8362602e44a5e11e83011a height=1002 version=0x00000001 log2_work=41.970128 tx=1022 date='2009-01-19T07:08:26Z' progress=0.000001 cache=0.3MiB(2txo)
    652025-09-01T21:46:57Z UpdateTip: new best=000000002d5d8c3264d9c6e352b76430cda7a1edac661a515dd1445c15168de5 height=1003 version=0x00000001 log2_work=41.971566 tx=1023 date='2009-01-19T07:26:12Z' progress=0.000001 cache=0.3MiB(3txo)
    662025-09-01T21:46:57Z UpdateTip: new best=00000000aded3a9953bb6acd0f51a99ac433369696116a6b72754c672a350a65 height=1004 version=0x00000001 log2_work=41.973002 tx=1024 date='2009-01-19T07:29:12Z' progress=0.000001 cache=0.3MiB(4txo)
    672025-09-01T21:46:57Z UpdateTip: new best=000000006659f6eed8840da4336211802af29eb04453e7e92d0f80a98f3e833c height=1005 version=0x00000001 log2_work=41.974437 tx=1025 date='2009-01-19T07:52:03Z' progress=0.000001 cache=0.3MiB(5txo)
    682025-09-01T21:46:57Z UpdateTip: new best=00000000c88cb61c8093f11df65dbc6633ae783e6f51be9aa8bbc6c624a994e2 height=1006 version=0x00000001 log2_work=41.975870 tx=1026 date='2009-01-19T08:11:43Z' progress=0.000001 cache=0.3MiB(6txo)
    692025-09-01T21:46:57Z UpdateTip: new best=0000000037b9be6143407617d34d7dd70a09aeb68e5da5a092bf5d19d7a06da6 height=1007 version=0x00000001 log2_work=41.977302 tx=1027 date='2009-01-19T08:27:46Z' progress=0.000001 cache=0.3MiB(7txo)
    702025-09-01T21:46:57Z UpdateTip: new best=000000005f7e442c07d918a1f2cd4f594f5e1946c22b06ffd7dfe378f59f70e8 height=1008 version=0x00000001 log2_work=41.978732 tx=1028 date='2009-01-19T08:40:20Z' progress=0.000001 cache=0.3MiB(8txo)
    712025-09-01T21:46:57Z UpdateTip: new best=000000008bb80b928343bc65ea33b2c97b722d7b85f0470d32a7519d2b7e5550 height=1009 version=0x00000001 log2_work=41.980162 tx=1029 date='2009-01-19T08:52:17Z' progress=0.000001 cache=0.3MiB(9txo)
    722025-09-01T21:46:57Z UpdateTip: new best=0000000074679515061a7e8272f315ca6735ee18105e3d4e867cbc87988e2759 height=1010 version=0x00000001 log2_work=41.981589 tx=1030 date='2009-01-19T08:55:07Z' progress=0.000001 cache=0.3MiB(10txo)
    732025-09-01T21:46:57Z UpdateTip: new best=00000000bbafcd3677dc5f3c713f464996e0253a2457828d3e775c83191abefc height=1011 version=0x00000001 log2_work=41.983016 tx=1031 date='2009-01-19T09:09:28Z' progress=0.000001 cache=0.3MiB(11txo)
    742025-09-01T21:46:57Z UpdateTip: new best=000000002048a8c44e5fcc9b0f19b2ed1fe2c63842ef88c9a29f54607087dc32 height=1012 version=0x00000001 log2_work=41.984440 tx=1032 date='2009-01-19T09:31:02Z' progress=0.000001 cache=0.3MiB(12txo)
    752025-09-01T21:46:57Z UpdateTip: new best=00000000f9c20fdda7029f3d5eda156b6b7d4d2b3b8b850b9dea839483e145b6 height=1013 version=0x00000001 log2_work=41.985864 tx=1033 date='2009-01-19T09:46:28Z' progress=0.000001 cache=0.3MiB(13txo)
    762025-09-01T21:46:57Z Loading 0 mempool transactions from file...
    772025-09-01T21:46:57Z Imported mempool transactions from file: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast
    782025-09-01T21:46:57Z initload thread exit
    792025-09-01T21:46:57Z [error] Invalid -i2psam address or hostname: 'invalid_addr'
    80Error: Invalid -i2psam address or hostname: 'invalid_addr'
    812025-09-01T21:46:57Z tor: Thread interrupt
    822025-09-01T21:46:57Z Shutdown in progress...
    832025-09-01T21:46:57Z torcontrol thread exit
    842025-09-01T21:47:00Z mapport thread exit
    852025-09-01T21:47:00Z scheduler thread exit
    862025-09-01T21:47:00Z Writing 0 mempool transactions to file...
    872025-09-01T21:47:00Z Writing 0 unbroadcast transactions to file.
    882025-09-01T21:47:00Z Dumped mempool: 0.000s to copy, 0.009s to dump, 27 bytes dumped to file
    892025-09-01T21:47:00Z Flushed fee estimates to fee_estimates.dat.
    902025-09-01T21:47:00Z Shutdown done
    
  2. maflcko commented at 6:23 am on September 2, 2025: member
    I can’t reproduce this locally, but I guess you are referring to the initload thread doing its work? If yes, I presume the only fix would be to validate the args before starting the initload thread?
  3. yuvicc commented at 5:43 am on September 5, 2025: contributor

    Tried on my local system, I was able to reproduce that.

     02025-09-05T05:39:58Z UpdateTip: new best=000000004b6da5bbb89d6602b47021c817837330c94c92ffdf0fe7a3fc65fa57 height=1057 version=0x00000001 log2_work=42.047146 tx=1079 date='2009-01-19T19:36:59Z' progress=0.000001 cache=0.3MiB(74txo)
     12025-09-05T05:39:58Z UpdateTip: new best=00000000d357309918e1e2586ca15141650f39b8097169274ccdba05991a87b3 height=1058 version=0x00000001 log2_work=42.048509 tx=1080 date='2009-01-19T19:43:41Z' progress=0.000001 cache=0.3MiB(75txo)
     22025-09-05T05:39:58Z UpdateTip: new best=00000000f6e758bff279b5d6c6c557dd1b90511eac1df10652a2a782aa5733b5 height=1059 version=0x00000001 log2_work=42.049871 tx=1081 date='2009-01-19T20:06:49Z' progress=0.000001 cache=0.3MiB(76txo)
     32025-09-05T05:39:58Z UpdateTip: new best=00000000a396bda7ddfea736dc41dc1ff82ab99b391da8b8d8a24147bae0fe51 height=1060 version=0x00000001 log2_work=42.051231 tx=1082 date='2009-01-19T20:08:35Z' progress=0.000001 cache=0.3MiB(77txo)
     42025-09-05T05:39:58Z UpdateTip: new best=0000000062499825b027659fceb5959e09bfb6c2b856533941f6a090a02ce433 height=1061 version=0x00000001 log2_work=42.052590 tx=1083 date='2009-01-19T20:22:32Z' progress=0.000001 cache=0.3MiB(78txo)
     52025-09-05T05:39:58Z UpdateTip: new best=00000000813a89c779e6d6649c4e8f3ccfd4bfd188d7608f8f652f6b4f28d1f3 height=1062 version=0x00000001 log2_work=42.053948 tx=1084 date='2009-01-19T20:27:20Z' progress=0.000001 cache=0.3MiB(79txo)
     62025-09-05T05:39:58Z UpdateTip: new best=000000002d878e299ee9592fa673e49c36fc1b38a5a8021eb3daf19cf85aec07 height=1063 version=0x00000001 log2_work=42.055304 tx=1085 date='2009-01-19T20:30:12Z' progress=0.000001 cache=0.3MiB(80txo)
     72025-09-05T05:39:58Z Loading 0 mempool transactions from file...
     82025-09-05T05:39:58Z Imported mempool transactions from file: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast
     92025-09-05T05:39:58Z initload thread exit
    102025-09-05T05:39:58Z mapport thread exit
    112025-09-05T05:39:58Z scheduler thread exit
    122025-09-05T05:39:58Z Writing 0 mempool transactions to file...
    132025-09-05T05:39:58Z Writing 0 unbroadcast transactions to file.
    142025-09-05T05:39:58Z Dumped mempool: 0.000s to copy, 0.001s to dump, 27 bytes dumped to file
    152025-09-05T05:39:58Z Flushed fee estimates to fee_estimates.dat.
    162025-09-05T05:39:59Z Shutdown done
    
  4. yuvicc commented at 1:49 pm on September 5, 2025: contributor

    I dug into this issue and found that this behavior lies with the -stopatheight argument. This argument only stops validation of blocks until that height but doesn’t stop further downloading of blocks. That might be the reason we see that it validates the remaining blocks from the index and updates the current height next time when it starts.

    Running the same command build/bin/bitcoind -datadir=demo -stopatheight=1000, I see it has blocks till 1520 in the db.

    02025-09-05T13:32:14Z Loading block index db: last block file = 0
    12025-09-05T13:32:14Z Loading block index db: last block file info: CBlockFileInfo(blocks=1461, size=337438, heights=0...1520, time=2009-01-03...2009-01-24)
    
  5. mzumsande commented at 3:09 pm on September 5, 2025: contributor

    Is this maybe more about wording/definitions? I’d say node startup is finished when RPC is enabled and we log “Done Loading” - in the log, the node does halt before that would happen.

    It’s true (and could be unexpected) that initload may do some work connecting blocks before that, but is there a downside to that? It’s not possible to simply delay the initload start without other changes, because initload also connects the Genesis block, which we wait for here - I think to avoid clients like the GUI from crashing that assume a chain exists.


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: 2025-10-10 21:13 UTC

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