Is the data of the blockchain stored on the chain or in the database? (The answer is that this question is not valid, let’s find out together)

Many people want to know when the blockchain data is stored on the chain, and when is it stored in the database of the corresponding node?

Today we will solve this interesting problem! ! !

First of all, we must understand two concepts clearly:

  1. blockchain data;
  2. Data on the chain;

First: blockchain data includes both block data and state data

  1. The block data description is actually the record of every transaction that happened on the blockchain (for example, Xiaoshuai transferred 50 yuan to Xiaowang, and Xiaoshuai recharged 20 yuan, etc.)
  2. The status data records the current status of each account and smart contract (for example, Xiaoshuai has a balance of 200 yuan, and Xiaowang has a balance of 20 yuan).

Both block data and state data are used and stored by our blockchain nodes. Blockchain nodes are a program that allows multiple nodes to pass through the network on our computers, virtual machines, etc. Linking eventually forms a complete blockchain network.

Among them, the most common way to store the data of blockchain nodes is to store it in the middle of our disk, and our blockchain will not directly access our disk, but through specific databases such as LevelIDB, RocksDB, MySQL, etc. An independent and distributed database to operate our data (the other most important technology at present is to add the cache area, reduce the disk seek time, and speed up the use and storage of disk data by the blockchain), and compared to direct access Disk, the specific data access model using the database as an intermediary is more friendly to blockchain nodes.
Therefore, the process of data storage can be explained as Data storage method
the database is divided into independent and embedded: the biggest difference is whether independent deployment is required, the embedded database and blockchain nodes are integrated in the middle of the same process, moving and stopping at the same time, basically There is no sense of independent existence.

And second: on-chain data

Explanation: The data on the chain is the data generated directly or indirectly by the blockchain consensus;

1. Back to our question, we will find that the block data and state data in the middle of the blockchain are not generated out of thin air. The data in the middle of the block is stored and broadcast to all nodes because of the transaction data between different nodes. The consensus state of blockchain nodes, so block data is also one of the data generated due to consensus;

2. On the other hand, state data, due to the generation of transactions and consensus, will eventually cause state changes, so in this perspective, state data can also be considered as on-chain data;

Summary: So back to the original question, blockchain data can be seen as data generated by consensus transactions, which is part of the data on the chain!

Therefore, the issue of on-chain data storage and database storage is untenable, because on-chain data and databases are not concepts at the same level, and all data stored in databases generated due to consensus can be called on-chain data!

Guess you like

Origin blog.csdn.net/gaoyanwangxin/article/details/100026289