Bitcoin-Core
bitcoind 是否在每次啟動時驗證每個塊?
執行 bitcoind 時,它開始下載區塊鏈並連續驗證每個塊。它將區塊鏈儲存在
~/.bitcoin/blocks
目錄中。當我們中斷守護程序並重新啟動它時,從上次執行下載的最後一個塊開始下載,而不是再次從第一個塊開始下載。這是我從日誌中了解到的。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)
如上日誌所示,它是從139238高度下載的。但是除了下載之外,它是否再次驗證下載的塊?在使用 逐步執行程序時,我注意到它從第一個塊
gdb
呼叫。GetBlockProof
(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)
從創世區塊開始驗證區塊是真的嗎?還是我的結論是錯誤的?如果不是,為什麼
GetBlockProof
從第一個塊呼叫?
IIRC,它驗證它獲得的最佳標頭鏈,並查看該鍊是否確實是其同行所知道的最佳鏈。因此,您不會完全驗證區塊(例如,所有交易),而只會驗證迄今為止對所有標頭執行的 PoW,這非常快。