檔案結構
資料位置
以bitcoin @ Linux為例:
一般來說在 ~/.bitcoin 目錄,若不是可尋找檔案 wallet.dat
如至家目錄下,
find . -name wallet.dat -print
找到該目錄即可。
目錄分析
.bitcoin/
├── banlist.dat (IP與網段的黑名單)
├── blocks
│ ├── blk00000.dat
│ ├── blk00001.dat
│ ├── blk00002.dat
│ ├── ... ...
│ ├── index
│ │ ├── 000012.log
│ │ ├── 000013.ldb
│ │ ├── 000014.ldb
│ │ ├── ... ...
│ │ ├── CURRENT
│ │ ├── LOCK
│ │ ├── LOG
│ │ ├── LOG.old
│ │ └── MANIFEST-000010
│ ├── rev00000.dat
│ ├── rev00001.dat
│ ├── rev00002.dat
│ ├── ... ...
├── chainstate
│ ├── 000020.log
│ ├── 000025.ldb
│ ├── 000026.ldb
│ ├── ... ...
│ ├── CURRENT
│ ├── LOCK
│ ├── LOG
│ ├── LOG.old
│ └── MANIFEST-000018
├── db.log
├── debug.log
├── fee_estimates.dat
├── peers.dat
└── wallet.dat
banlist.dat: stores the IPs/Subnets of banned nodes
bitcoin.conf: contains configuration settings for bitcoind or bitcoin-qt
bitcoind.pid: stores the process id of bitcoind while running
blocks/blk000??.dat: block data (custom, 128 MiB per file); since 0.8.0
blocks/rev000??.dat; block undo data (custom); since 0.8.0 (format changed since pre-0.8)
blocks/index/*; block index (LevelDB); since 0.8.0
chainstate/*; block chain state database (LevelDB); since 0.8.0
database/*: BDB database environment; only used for wallet since 0.8.0
db.log: wallet database log file
debug.log: contains debug information and general logging generated by bitcoind or bitcoin-qt
fee_estimates.dat: stores statistics used to estimate minimum transaction fees and priorities required for confirmation; since 0.10.0
mempool.dat: dump of the mempool's transactions; since 0.14.0.
peers.dat: peer IP address database (custom format); since 0.7.0
wallet.dat: personal wallet (BDB) with keys and transactions
.cookie: session RPC authentication cookie (written at start when cookie authentication is used, deleted on shutdown): since 0.12.0
onion_private_key: cached Tor hidden service private key for -listenonion: since 0.12.0
以btcd@linux為例
~/.btcd
目錄結構
存取Block實作
#### 將新的block放入block chain的操作
btcd/blockchain/process.go 之 ProcessBlock()
包含:
拒絕重複的區塊、確認blocks是否合法且符合規則(checkpoint)、落單(orphan) block的處理、 以及把區塊插入至block chain的選擇與重整
<pre><code>
check BlockExists\(\) //判斷區塊是否重複
check block.orphans\[\*blockhash\] list //是否為orphan?
checkBlockSanity\(\) //檢查block格式是否合法\(包含block本身以及所有交易\)
blockHeader := &block.MsgBlock().Header //取得block header
checkpointBlock, err := b.findPreviousCheckpoint() //找到上一個檢查點
blockHeader.Timestamp.Before(checkpointTime) //檢查是否是checkpoint之前的區塊,若是,就拒絕整理
block.addOrphanBlock(block) //如果block是落單的孤兒,而且其prev_block又存在,就將其加入
block.maybeAcceptBlock(block, flags) //通過檢查,加入block chain
</code></pre>