2

When running bitcoind, it starts downloading the blockchain and validate every block in a row. It stores the blockchain in the ~/.bitcoin/blocks directory. And when we break daemon and restart it, starts downloading from the last block it downloaded from the previous execution and not from the first block again. This was something I understood from logs.

2022-06-11T16:51:56Z dnsseed thread start
2022-06-11T16:51:56Z addcon thread start
2022-06-11T16:51:56Z init message: Done loading
2022-06-11T16:51:56Z opencon thread start
2022-06-11T16:51:56Z msghand thread start
2022-06-11T16:51:56Z Waiting 300 seconds before querying DNS seeds.
2022-06-11T16:51:57Z New outbound peer connected: version: 70016, blocks=740373, peer=0 (outbound-full-relay)
2022-06-11T16:51:58Z Synchronizing blockheaders, height: 740373 (~100.00%)
2022-06-11T16:51:59Z UpdateTip: new best=0000000000000533f02f775db4176ec57012c76c6dc56fa3debf5f307da3d758 height=139238 version=0x00000001 log2_work=65.854192 tx=1188914 date='2011-08-02T05:59:57Z' progress=0.001607 cache=0.0MiB(308txo)
2022-06-11T16:51:59Z UpdateTip: new best=0000000000000264f2835263bdfcae0a8a4185b781fa980d0eae3e88ee4effa9 height=139239 version=0x00000001 log2_work=65.854368 tx=1189040 date='2011-08-02T06:01:53Z' progress=0.001607 cache=0.1MiB(621txo)
2022-06-11T16:51:59Z UpdateTip: new best=00000000000008ae748a17911f5d56ac7e5ede06586d98d7d6aa83ce8bda5237 height=139240 version=0x00000001 log2_work=65.854543 tx=1189100 date='2011-08-02T06:11:42Z' progress=0.001607 cache=0.1MiB(793txo)

As shown in logs above, it's downloading from height 139238. But beside downloading, does it validate the downloaded blocks again? The thing I noticed while running the program step by step using gdb, was that it calls the GetBlockProof from the first block.

(gdb) break GetBlockProof
Breakpoint 1 at 0x31be40: file chain.cpp, line 126.
(gdb) run
Starting program: /usr/local/bin/bitcoind 
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.31-2.fc32.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
2022-06-11T16:58:20Z Bitcoin Core version v23.0 (release build)
2022-06-11T16:58:20Z Assuming ancestors of block 000000000000000000052d314a259755ca65944e68df6b12a067ea8f1f5a7091 have valid signatures.

...

Thread 1 "bitcoind" hit Breakpoint 1, GetBlockProof (block=...) at chain.cpp:126
126 {
Missing separate debuginfos, use: dnf debuginfo-install libevent-2.1.8-8.fc32.x86_64 libgcc-10.3.1-1.fc32.x86_64 openssl-libs-1.1.1d-7.fc32.x86_64 zlib-1.2.11-21.fc32.x86_64
(gdb) p block.nHeight 
$1 = 0
(gdb) continue 
Continuing.

Thread 1 "bitcoind" hit Breakpoint 1, GetBlockProof (block=...) at chain.cpp:126
126 {
(gdb) p block.nHeight 
$2 = 1
(gdb) continue 
Continuing.

Thread 1 "bitcoind" hit Breakpoint 1, GetBlockProof (block=...) at chain.cpp:126
126 {
(gdb) p block.nHeight 
$3 = 2
(gdb) 

Is this true that is starts validating blocks from the genesis block? Or my conclusion is wrong? And if no, why the GetBlockProof is called from the first block?

1 Answer 1

1

IIRC, it validates the best chain of headers it got, and see if this chain is indeed the best chain its peers know about. So, you won't validate blocks entirely (like, all transaction), but only the PoW performed for all headers up to now, and this is very fast.

2
  • You mean it just calculate the hash of the block to check whether it is satisfied the difficulty or not? Jun 11 at 18:26
  • Yes, see if PoW is valid and sanity check (is something corrupted or so?). Jun 12 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.