開始之前,建議先閱讀 節點log簡介 ,了解log的格式,比較容易看懂本文。

 

 

如果新裝的節點,或是按了Remove all blockchain data,要怎麼知道區塊同步的進度?

 

查看 %appdata%\Pi Network\docker_volumes\supervisor_logs\stellar-core-stdout---supervisor-xxx_.log ,找"History"訊息。

(不知道 %appdata% 是什麼的人,請看這篇 https://yuanrui919.github.io/mvappdata/ )

 

1.    首先會檢查本地跟網路上的區塊編號,發現有所落差,會看到類似這樣的log,狀態進入到catchup

[Ledger INFO] Lost sync, local LCL is 1, network closed ledger 7204156

[Ledger INFO] Changing state LM_BOOTING_STATE -> LM_CATCHING_UP_STATE

 

2.    接著要向History Archives下載資料,但歷史檔每64個區塊(大約5分鐘)才會更新一次,所以會等最新的歷史檔更新,才會開始下載(7204161-1=7204160,可以被64整除),於是會看到這樣的log

[History INFO] Waiting for trigger ledger: 7204156/7204161, ETA: 25s

[History INFO] Waiting for trigger ledger: 7204157/7204161, ETA: 20s

...

[History INFO] Waiting for trigger ledger: 7204160/7204161, ETA: 5s

 

3.    確定區塊7204161檢查點已經關閉了,就可以開始追趕了,但只往回追256個區塊(7203903~7204159),並不會下載全部的區塊。這是由CATCHUP_COMPLETECATCHUP_RECENT兩個參數所控制的。

[History INFO] Starting catchup after ensuring checkpoint ledger 7204161 was closed on network

[History INFO] Starting catchup with configuration:

  lastClosedLedger: 1

  toLedger: 7204159

  count: 256

 

4.    下載狀態文件,是json格式。

[History INFO] Catching up to ledger 7204159: Downloading state file history/00/6d/ed/history-006ded3f.json for ledger 7204159

[History INFO] Downloading history archive state: history/00/6d/ed/history-006ded3f.json

[History INFO] Catching up to ledger 7204159: Downloading state file history/00/6d/ec/history-006dec3f.json for ledger 7203903

[History INFO] Downloading history archive state: history/00/6d/ec/history-006dec3f.json

 

5.    下載區塊XDR檔。

[History INFO] Catching up to ledger 7204159: downloading ledger files 1/5 (20%)

[History INFO] Catching up to ledger 7204159: downloading ledger files 5/5 (100%)

[History INFO] Catching up to ledger 7204159: Succeeded: batch-download-ledger-006dec3f-006ded7f : 5/5 children completed

 

6.    驗證剛下載內容(注意這裡的中括號和小括號,中括號有包含,小括號沒有包含)

[History INFO] Verifying ledgers [7203903,7204160)

[History INFO] Verifying ledger [seq=7204159, hash=b60608] against SCP hash

[History INFO] Catching up to ledger 7204159: verifying checkpoint 1/5 (20%)

[History INFO] History chain [7203903,7204159] verified

[History INFO] Catching up to ledger 7204159: Succeeded: verify-ledger-chain

 

7.    如果本地區塊是從1開始,又會下載一個很大的檔案,有2GB。我不確定是怎麼回事,應該跟歷史檔歸檔的方式有關,XDR檔總是會不斷合併,可能是下載最近一段完整的檔案。

[History INFO] Catching up to ledger 7204159: downloading and verifying buckets: 0/21 (0%)

[History INFO] Catching up to ledger 7204159: downloading and verifying buckets: 1/21 (4%)

...

[History INFO] Catching up to ledger 7204159: Succeeded: download-verify-buckets : 21/21 children completed

 

8.    寫入本地的bucket

[History INFO] Applying buckets

[History INFO] Catching up to ledger 7204159: Applying buckets 0%. Currently on level 10

[Bucket INFO] Bucket-apply: 12288 entries in 1.17MB/2.05GB in 0/21 files (0%)

...

[Bucket INFO] Bucket-apply: 22027837 entries in 2.05GB/2.05GB in 21/21 files (100%)

[History INFO] Catching up to ledger 7204159: Applying buckets 100%. Currently on level 0

 

9.    Apply Buckets完成。

[History INFO] ApplyBuckets : done, restarting merges

[History INFO] Catching up to ledger 7204159: Succeeded: download-verify-apply-buckets

 

10.  這邊4checkpoint256個區塊(64*4=256)(7203904~7203967, 7203968~7204031, 7204032~7204095, 7204096~7204159)

[History INFO] Downloading, unzipping and applying transactions for checkpoint 7203967

[History INFO] Downloading, unzipping and applying transactions for checkpoint 7204031

[History INFO] Downloading, unzipping and applying transactions for checkpoint 7204095

[History INFO] Downloading, unzipping and applying transactions for checkpoint 7204159

 

11.  開始把區塊寫入DBXDR(7203904~7204159,共256個區塊)

[History INFO] Catching up to ledger 7204159: Download & apply checkpoints: num checkpoints left to apply:4 (0% done)

[Tx INFO] applying ledger 7203904 (txs:28, ops:66)

[Tx INFO] applying ledger 7203905 (txs:31, ops:31)

...

[Tx INFO] applying ledger 7204159 (txs:23, ops:41)

[History INFO] Catching up to ledger 7204159: Download & apply checkpoints: num checkpoints left to apply:0 (100% done)

 

12.  但是在下載與驗證歷史檔的過程中,網路上仍有新的區塊產生,這些都在buffer裡面,也要寫下來。

[History INFO] Catching up to ledger 7204159: Applying buffered ledgers: Running: apply-buffered-ledgers

[History INFO] Scheduling buffered ledger-close: [seq=7204160, prev=b60608, txs=24, ops=49, sv: [ SIGNED@testnet2 txH: fa44fb, ct: 1651505354, upgrades: [ ] ]]

[History INFO] Catching up to ledger 7204159: Applying buffered ledgers: Waiting before starting apply ledger 7204160

[Tx INFO] applying ledger 7204160 (txs:24, ops:49)

...

[History INFO] Scheduling buffered ledger-close: [seq=7204454, prev=eb1aee, txs=18, ops=41, sv: [ SIGNED@testnet3 txH: a22be3, ct: 1651507075, upgrades: [ ] ]]

[History INFO] Catching up to ledger 7204159: Applying buffered ledgers: Waiting before starting apply ledger 7204454

[Tx INFO] applying ledger 7204454 (txs:18, ops:41)

 

13.  在處理buffer裡的區塊的過程中,網路上仍有新的區塊產生。如果某些因素造成buffer跟網路的最新區塊仍有延遲,Catchup會失敗,要再重複一次下載歷史檔的程序。

[History INFO]  (discontiguous; will fail and restart): Catching up to ledger 7204159: Applying buffered ledgers: apply ledger 7204454

[History WARNING] Expected buffered ledger=7204455, actual=7204456

[History INFO] Catching up to ledger 7204159: Applying buffered ledgers: Failed: apply-buffered-ledgers

[History WARNING] Catchup failed

 

14.  如果步驟12沒問題,就同步完全了。若結果像步驟13這樣,會不斷重複步驟2,3,4,5,6,10,11,12,直到同步完成。

[History INFO] Catching up to ledger 7204159: Applying buffered ledgers: apply ledger 7204454

[History INFO] Catchup finished

[Ledger INFO] Changing state LM_CATCHING_UP_STATE -> LM_SYNCED_STATE

 

15.  當其他狀況造成區塊延遲,如網路斷線、停電、重開機等等,Catchup的作業也是跟上面相同。

 

回首頁