Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Bitcoin code analysis 11 Bitcoin storage mechanism

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Bitcoin storage mechanism

Bitcoin storage system consists of two parts: kv database (levelDB) index and ordinary data files. Normal files are used to store blockchain data, and kv databases are used to store blockchain metadata. Ordinary files used to store blockchain data are made up of blk00000.dat and blk00001.dat file names. The index directory store is used to store block metadata.

General block data file

To retrieve chunk data quickly, the size of each file is 128m Bytes. The data in the block (the block header and all transactions in the block) are sequenced into a bytecode and written to the dat file. During serialization, if it is detected that the current write file size plus a chunk size greater than 128m Bytes, a dat file will be regenerated.

Kv data index

The index metadata format of the block is in a format such as format, where xxxxx is the serial number of the dat file and npos is the starting position where the block is written to the dat file.

The metadata format for the transaction is in a format such as the format, where xxxxx and npos are consistent with the above description, and nTxOffset is the starting position where the dat file is written (based on the npos location).

All of the above metadata will be written to the kv database, where blockhash/txHash will be used as an index for subsequent query specific data in the dat file.

LevelDB

Google's LevelDB database stores blockchain metadata. Leveldb is a very efficient kv database implemented by google and is open source.

One of its main features is that the writing performance is very good, which is suitable for application scenarios such as bitcoin clients.

Although levelDB is a database, it does not provide client connection services like other mainstream databases (mysql, oracle, etc.). It is only a C++-based lib library, so it is easy for us to use, directly link the lib library files in the project.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report