Blockchain is a data structure in which blocks containing transaction information are sequentially linked from back to front. It can be stored as a flatfile (a file that contains records that have no relative relationship), or it can be stored in a simple database. The Bitcoin Core client uses Google’s LevelDB database to store blockchain metadata. Blocks are linked in this chain in an orderly manner from back to front, and each block points to the previous block.
The blockchain is often regarded as a vertical stack, with the first block as the first block at the bottom of the stack, and then each block is placed on top of other blocks. After using the stack to visualize the concept of stacking blocks in sequence, we can use some terms, such as: “height” to indicate the distance between the block and the first block; and “top” or “top” to indicate The newly added block.
Perform SHA256 encryption hash on each block to generate a hash value. Through this hash value, the corresponding block in the blockchain can be identified. World-class digital goods-currency exchange-easy. At the same time, each block can refer to the previous block (parent block) through the “parent block hash value” field of its block header. In other words, each block header contains the hash value of its parent block. In this way, the hash value sequence that links each block to its parent block creates a chain that can be traced back to the first block (the genesis block).
Since the block header contains the “parent block hash value” field, the hash value of the current block is also affected by this field. If the identity of the parent block changes, the identity of the child block will also change. When there is any change in the parent block, the hash value of the parent block also changes. A change in the hash value of the parent block will force the “parent block hash value” field of the child block to change, which in turn will cause the hash value of the child block to change. The change of the hash value of the child block will force the “parent block hash value” field of the grandchild block to change, which in turn will change the hash value of the grandchild block, and so on.
Once a block has many generations later, this waterfall effect will ensure that the block will not be changed unless the block is forced to recalculate all subsequent blocks. It is precisely because such recalculation requires a huge amount of calculation, so the existence of a long blockchain can make the history of the blockchain immutable, which is also a key feature of Bitcoin security.
You can think of the blockchain as a geological layer in a geological structure. The surface layer may change with the seasons and may even be blown away by the wind before deposition. But the deeper it goes, the more stable the geological layer becomes. When you reach a depth of a few hundred feet, you will see rock formations that have been preserved for millions of years but still remain intact. In the blockchain, the most recent blocks may be modified due to recalculation caused by the blockchain fork. The latest six blocks are like a few inches of topsoil. However, after exceeding these six blocks, the deeper the position of the block in the blockchain, the less likely it is to be changed. After 100 blocks, the blockchain is stable enough, and at this time, Coinbase transactions (transactions containing newly mined Bitcoin) can be paid. The blockchain, after a few thousand blocks (one month), will become a definite history and will never change.
In the Bitcoin system, the Bitcoin full node saves a local copy of the blockchain from the genesis block. The blocks are connected in the form of chains by referring to the hash value of the block header of the parent block.
With the concepts of transaction, block and blockchain, if we only consider the blockchain as a database, we can use these concepts to construct a blockchain system. We can use the transaction data structure to store transaction data (checks, blogs, etc.), package transaction data through blocks, and finally, connect blocks through block hashes. This is what we usually call blockchain.
But the blockchain designed in this way is just a database, and there is no way to guarantee that the data cannot be tampered with. Therefore, a blockchain that lacks a consensus mechanism is not a blockchain, and a blockchain must be supported by a consensus mechanism. The consensus mechanism in Bitcoin is guaranteed by mining.
In the first chapter, we introduced that digital currency has experienced more than ten years of development history before Bitcoin was born. This period includes e-Cash, HashCash, B-money, and other related digital currencies. This period belongs to the development stage of digital currencies. Although digital currency has undergone more than ten years of development, no one has proposed the realization of a decentralized digital currency system. Since digital currency is a string of strings, the cost of copying is very low, so the difficulty in implementing decentralized electronic currency is how to avoid digital currency being paid twice or more at the same time, which is what I often call double spend. . (I can’t agree with this translation. I personally think that the translation into double payment is closer to the original meaning and easier to understand.)
In the Bitcoin system, mining is a process of increasing the supply of Bitcoin currency, while also protecting the security of the Bitcoin system, preventing fraudulent transactions, and avoiding double payments (double payment refers to spending the same bitcoin multiple times).
Miners provide computing power for the Bitcoin network in exchange for the opportunity to obtain Bitcoin rewards. The miners verify each new transaction and record them in the general ledger. Every 10 minutes, a new block will be “mined.” Each block contains all the transactions that occurred from the previous block to the present, and these transactions are added to the blockchain in turn. We refer to the transactions included in the block and added to the blockchain as “confirmed” transactions. After the transaction is “confirmed,” the new owner can spend the bitcoins he got in the transaction.
Miners receive two types of rewards during the mining process: new currency rewards for creating new blocks and transaction fees for transactions contained in the blocks. In order to get these rewards, miners are vying to complete a mathematical puzzle based on cryptographic hashing algorithms. The answers to these puzzles are included in the new block as a proof of the miner’s computational workload, which is called “Proof of Work.” The competition mechanism of the algorithm and the mechanism by which the winner has the right to trade on the blockchain are the cornerstones of Bitcoin security.
The term “mining” is somewhat misleading. It is easy to cause the association of precious metal mining, so that our attention is focused on the reward generated by each new block. Although the reward brought by mining is an incentive, its main purpose is not the reward itself or the generation of new coins.
If you only think of mining as the process of producing new coins, then you are using means (incentives) as an end. Mining is a process of decentralizing clearing houses. Each clearing house needs to verify and settle transactions processed.
Mining protects the security of the Bitcoin system and enables the entire Bitcoin network to reach a consensus without a central organization.
P2P network and nodes
Bitcoin uses an Internet-based P2P network architecture. Each node in the P2P network is equal to each other, each node provides services together, and there is no special node. There are no servers, centralized services, and hierarchical structures in the P2P network. P2P networks are inherently scalable, decentralized, and open. Bitcoin is designed as a peer-to-peer digital cash system, and its network architecture is not only a reflection of this core feature but also the cornerstone of this feature. Decentralized control is the core principle of the design. It can only be achieved by maintaining a flat and decentralized P2P consensus network.
Although each node in the P2P network is related and equivalent, depending on the function of each node, each node will have a different division of labor. In the Bitcoin system, each Bitcoin node is a routing, blockchain database, mining, and wallet service. A collection of functions, a full node includes wallets, miners, complete blockchains, and network routing nodes.