To understand the consensus mechanism, you first need to understand what consensus is. We live in a diverse world where there are no two leaves exactly alike, and no two people exactly alike. The so-called consensus is a group of people with differences in various aspects agreeing on something and raising it to a common rule.
The development and prosperity of human civilization cannot be separated from the division of labor among individuals in a social group, and how to divide the work, how to make decisions, how to distribute the results and rewards and punishments, all rely on a recognized rule, or consensus. The so-called consensus mechanism refers to the way a group uses to reach and maintain consensus, and the consensus mechanism often determines the organization of the group. In the early stages of human civilization, force was the main way for groups to establish and maintain consensus rules, and human beings relied on force to establish centralized management authorities such as tribes and states, which set centralized management rules and punished individuals who did not accept them.
Of course, as civilization developed and evolved, we began to make laws, design elections, and introduce negotiation and arbitration mechanisms, which became the way companies, associations, governments, schools, and other social groups reached and maintained consensus, but all of these civilized practices were still supported by a large state apparatus of violence. Human civilizations chose to establish centralized authority by force to build and maintain group consensus not only because it was the fastest way to do so in the early years of civilization, but also because relying on centralized authority was a more efficient and secure way to govern. However, centralization is not the only feasible solution. If we can come up with a consensus mechanism that is equally secure and convenient without relying on centralized authority, we can also establish a new form of organization that corresponds to it.
The emergence of blockchain technology provides such an option, except that the decentralized logic is based not on the real world but on a relatively lightweight network environment. The object of the consensus mechanism is not an individual but a computer with different ownership rights. Through the application of the blockchain consensus mechanism, computers scattered all over the world can be gathered into a unified network to achieve large-scale machine collaboration.
As a peer-to-peer collaboration network, the principle of blockchain is that each node holds an independent ledger and keeps the ledger synchronized to achieve common bookkeeping, but in the absence of a central command and coordination and the complex and changing state of the network, how to ensure that the ledger of each node, which is completely dispersed in space, can be identical, which requires the consensus mechanism of blockchain.
Let's take Bitcoin as an example, and try to discuss the bookkeeping process of a typical blockchain system, where the public ledger records the transfer transactions that are happening in the Bitcoin network every moment, but these transfers are not written into the ledger immediately, but are recorded uniformly every once in a while. Each time a transfer is recorded, a new block is created in the ledger that contains not only a number of transfers, but also the time of birth, a summary of the previous block, etc. In this way, the blocks in the ledger can be chained together in chronological order.
The reason why this block-based bookkeeping method is chosen instead of all nodes recording all information instantly is that in the whole decentralized system, considering the differences in network status and spatial location among different nodes, it is impossible to achieve complete synchronization of data, and the correctness of the results recorded by each node can be ensured by means of structured data packets.
And for each newborn block, the method of each node recording separately is not enough to guarantee the uniqueness of the ledger for almost the same reason. In response to this problem, the chosen method in the blockchain network is to adopt some automatically enforceable competition means to select a unique node to first pack data to generate blocks and record them in its own ledger, and then this selected node will notify other nodes of the newly produced block data through the Internet, and other nodes will record them in their own ledger synchronously after receiving the information and verifying that the blocks are correct, and the above is A complete decentralized distributed bookkeeping process.
The consensus mechanism focuses on solving two problems in this process: one is how to compete for bookkeeping rights between fully peer-to-peer nodes, the chain technology has developed so far, there have been a variety of ways to compete for bookkeeping rights, which we will introduce in detail later. The second possible situation is that in practice, due to network latency and other reasons, occasionally two nodes may think they have obtained the bookkeeping right and go to pack the block and notify other nodes, and the other nodes will record the first notification received and ignore the other one, which will inevitably cause inconsistent writing of all nodes' books considering the small time interval between the two notifications. For this situation, the solution of the blockchain network is to temporarily accept the state of this chain fork, and the records of several subsequent block packing nodes prevail according to them. This way of preserving the longest chain can ensure that multiple nodes can still record an authoritative ledger in a complex network environment.
There are hundreds of existing independent blockchain networks, and the consensus mechanisms used are similar, with the main difference being the competitive bookkeeping method described above, and thus we often use the competitive bookkeeping method to name the different blockchain consensus mechanisms. The most common ones are POW, POS, DPOS, etc.
POW (proof of workload) is used by many coins such as bitcoin and ethereum, and its competitive bookkeeping logic is that each node competes to compute a random number, which must be obtained after a certain amount of work. This method is simple and brutal yet extremely effective, but is often criticized for being energy intensive and prone to node concentration.
POS (proof of stake), on the other hand, allocates bookkeeping rights by multiplying the number of tokens held by the node by the holding time, and the higher the bookkeeping rights the higher the probability of obtaining them. The implementation of this competitive method is technically demanding and can easily become a game for rich nodes.
DPOS (Proof of Share Authority) consensus mechanism's competitive bookkeeping logic is similar to the people's congress system, where token holders have a corresponding amount of voting rights, and the nodes elected by voting have the right to take turns to bookkeeping. The most famous blockchain project using DPOS is EOS. The most significant advantage of this consensus mechanism is that it is highly efficient and more in line with the current acceptance habits, but the disadvantage is also obvious, mainly in the highest degree of centralization, which many people think is against the original purpose of the blockchain.