区块链:比特币数据存储

完整的比特币系列笔记收藏于IT老兵驿站

区块链:比特币数据存储。

前言

研究一下比特币的数据存储的格式。

正文

There are basically four pieces of data that are maintained:
blocks/blk*.dat: the actual Bitcoin blocks, in network format, dumped in raw on disk. They are only needed for rescanning missing transactions in a wallet, reorganizing to a different part of the chain, and serving the block data to other nodes that are synchronizing.

简单翻译: blocks/blk*.dat,实际的区块数据,使用网络格式,直接存储在磁盘上。他们仅仅被用于:一个钱包重新扫描丢失的交易,重新组织去区块链的一部分,给另外的节点进行同步提供区块数据。

blocks/index/*: this is a LevelDB database that contains metadata about all known blocks, and where to find them on disk. Without this, finding a block would be very slow.

简单翻译: blocks/index/*,这是一个LevelDB数据库,包含了所有知道的区块的元数据,和在磁盘的哪里可以找到它们。没有这个,寻找一个区块是非常慢的。

chainstate/*: this is a LevelDB database with a compact representation of all currently unspent transaction outputs and some metadata about the transactions they are from. The data here is necessary for validating new incoming blocks and transactions. It can theoretically be rebuilt from the block data (see the -reindex command line option), but this takes a rather long time. Without it, you could still theoretically do validation indeed, but it would mean a full scan through the blocks (7 GB as of may 2013) for every output being spent.

简单翻译: 这是一个levelDB数据库,以压缩的形式存储所有当前未花费的交易输出(UTXO)以及关于这些交易来源的一些元数据。这里的数据对于验证新传入的块和交易是必要的。这些数据理论上可以从区块数据中重建(参看-reindex 命令选项),但是这需要花费很长时间。没有这些数据,理论上你也可以进行验证,但是它意味着一个全面地对区块 (2013年5月已经达到7GB ) 的扫描,来检查每一笔输出是否被花费。

blocks/rev*.dat: these contain “undo” data. You can see blocks as ‘patches’ to the chain state (they consume some unspent outputs, and produce new ones), and see the undo data as reverse patches. They are necessary for rolling back the chainstate, which is necessary in case of reorganisations.
Note that the LevelDB’s are redundant in the sense that they can be rebuilt from the block data. But validation and other operations would become intolerably slow without them.

简单翻译: blocks/rev*.dat,包含着“undo”数据。你可以把区块数据看成是区块链状态(它们消费一些未花费的输出,然后产生新的一些)的补丁,可以把这些undo数据看做是反向的补丁。它们对于回滚区块状态非常重要,而回滚对于重新组织构建这种情况又是非常重要的。

参考

Data_Storage”>https://en.bitcoin.it/wiki/Bitcoin_Core_0.11(ch_2):_Data_Storage

没有更多推荐了,返回首页