bitcoin: getbestblockhash is sometimes taking a very long time

Is there an existing issue for this?

  • I have searched the existing issues

Current behaviour

I’m running Bitcoin Core v29 on a RPi v4 with 4GB RAM and 2TB SSD. Sometimes when I run “getbestblockhash” it takes a very long time.

admin@raspibolt2:~ $ time bitcoin-cli getbestblockhash
0000000000000000000208fcdfe388b464d7a7ef9c05b2ad2701488f1eedbe70

real    10m21.332s
user    0m0.000s
sys     0m0.026s
admin@raspibolt2:~ $ time bitcoin-cli getbestblockhash
000000000000000000002f0d8fcab1392628ed73aa18848aa44cb53de6dff349

real    11m34.199s
user    0m0.002s
sys     0m0.044s
admin@raspibolt2:~ $ time bitcoin-cli getbestblockhash
0000000000000000000083ac9f1bc7ae399cd89f84c3058e5e7905a66da66394

real    4m40.592s
user    0m0.008s
sys     0m0.019s
admin@raspibolt2:~ $ time bitcoin-cli getbestblockhash
0000000000000000000083ac9f1bc7ae399cd89f84c3058e5e7905a66da66394

real    0m0.144s
user    0m0.007s
sys     0m0.009s

The last entry I ran immediately after the previous call and it returns the same hash which I guess is cached or easier to read on a subsequent call. I don’t see anything in the logs but I am running the default log settings.

Is there something that I need to tweak to get this to be more performant? Is there any other information needed to debug this?

Expected behaviour

getbestblockhash should return in seconds instead of minutes

Steps to reproduce

bitcoin-cli getbestblockhash …I’m not certain what data or environmental issues would cause it to take minutes to return.

Relevant log output

No response

How did you obtain Bitcoin Core

Compiled from source

What version of Bitcoin Core are you using?

v29

Operating system and version

Debian Bullseye Lite

Machine specifications

RPI 4 4GB RAM 2TB SSD connected via USB

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Looking at these debug logs, it’s taking you ~500s to connect a new block to the chaintip, and the cs_main lock would be held for that time, so that explains why getblockhash takes so long.

2025-06-13T02:32:39Z [bench]       - Connect 2344 transactions: 519962.12ms (221.827ms/tx, 61.266ms/txin) [519.96s (519962.12ms/blk)]
2025-06-13T02:32:39Z [bench]     - Verify 8487 txins: 519968.86ms (61.267ms/txin) [519.97s (519968.86ms/blk)]
From the logs, most of block connection is spent connecting inputs.

https://github.com/bitcoin/bitcoin/blob/2def85847318513afa7765e042567d13f616c54c/src/validation.cpp#L2598-L2707

And that the fact that the Verify bench log comes immediately after means that you were probably blocked on fetching inputs from disk (I/O), not script validation (CPU).

This points to the read performance of the disk your chainstate is stored on being quite slow. Although you may have an SSD, you might be bound by the speed of the USB adapter you are using.

A rough estimate of your read speed could be gleaned by doing the following if your debug.log and chainstate are on the same disk:

# It doesn't matter what input file you use, debug.log is just likely
# to be a good candidate because it's probably on the same disk
# and big enough that the result won't be too noisy.
dd if=/path/to/your/debug.log of=/dev/null bs=4M

txindex=1

I upgraded from v27.x I believe.

* Other than that, I'd check the debug log via the  debug categories `bench, blockstorage, lock, prune, validation`, and possibly `rpc`, if there is a background caller?

I’ll add these into the log and see what comes of it.