Bitcoind

從數據庫讀取後,Chainstate LevelDB 損壞

  • July 11, 2017

我已經使用 LevelDB 工作了幾個星期,編寫了一些工具來訪問數據庫並將數據解析為人類可讀的。

但是,每次我從鏈狀態讀取數據時,數據都會損壞(要求我在執行 bitcoind 時重建它)。我決定在第一次發生後複製數據庫作為解決方法,但是每次我想更新數據時都這樣做很煩人。

我正在使用 plyvel 和 Python 2.8,每次閱讀完畢時我都會關閉數據庫。

例子

# Open the LevelDB
db = plyvel.DB(".bitcoin/chainstate")

for key, o_value in db:
# do stuff

# Close the LevelDB
db.close()

有誰知道可能是什麼原因?bitcoind 是否通過以某種方式標記最後一次訪問來阻止其他軟體訪問數據庫?

執行程式碼、檢索混淆密鑰並關閉數據庫後的鏈狀態日誌:

2017/03/22-11:03:45.746702 7f3c18a39700 Recovering log #394423
2017/03/22-11:03:45.854583 7f3c18a39700 Delete type=0 #394423
2017/03/22-11:03:45.854711 7f3c18a39700 Delete type=3 #394422

範常式式碼

db = plyvel.DB(".bitcoin/chainstate")
o_key = db.get((a2b_hex("0e00") + "obfuscate_key"))
db.close()

打開 bitcoind 後的debug.log(只是引用 LevelDB 的部分):

2017-03-22 10:03:45 Cache configuration:
2017-03-22 10:03:45 * Using 2.0MiB for block index database
2017-03-22 10:03:45 * Using 8.0MiB for chain state database
2017-03-22 10:03:45 * Using 290.0MiB for in-memory UTXO set
2017-03-22 10:03:45 init message: Loading block index...
2017-03-22 10:03:45 Opening LevelDB in /home/sdelgado/.bitcoin/blocks/index
2017-03-22 10:03:45 Opened LevelDB successfully
2017-03-22 10:03:45 Using obfuscation key for /home/sdelgado/.bitcoin/blocks/index: 0000000000000000
2017-03-22 10:03:45 Opening LevelDB in /home/sdelgado/.bitcoin/chainstate
2017-03-22 10:03:45 Opened LevelDB successfully
2017-03-22 10:03:45 Using obfuscation key for /home/sdelgado/.bitcoin/chainstate: 27c78118b7316105
2017-03-22 10:03:48 LoadBlockIndexDB: last block file = 810
2017-03-22 10:03:48 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=53, size=51783543, heights=457770...458279, time=2017-03-18...2017-03-21)
2017-03-22 10:03:48 Checking all blk files are present...
2017-03-22 10:03:49 LoadBlockIndexDB: transaction index disabled
2017-03-22 10:03:49 LevelDB read failure: Corruption: corrupted compressed block contents
2017-03-22 10:03:49 Corruption: corrupted compressed block contents
2017-03-22 10:03:51 Aborted block database rebuild. Exiting.
2017-03-22 10:03:51 scheduler thread interrupt
2017-03-22 10:03:51 Shutdown: In progress...
2017-03-22 10:03:51 StopNode()
2017-03-22 10:03:51 Shutdown: done

Plyvel預設啟用Snappy 壓縮。您是否嘗試在打開數據庫時禁用它?

# Open the LevelDB
db = plyvel.DB(".bitcoin/chainstate", compression=None)

使用此程式碼,我的 bitcoind 在使用 python 打開數據庫後似乎沒有抱怨。

引用自:https://bitcoin.stackexchange.com/questions/52257