In the process of learning blockchain technology, it is necessary to understand some key concepts, such as consensus mechanism, encryption protocol, distributed storage and so on. These are points that need to be understood in the learning process, and then spread from point to surface. So today, I will first talk about the consensus mechanism of blockchain, and then continue to update other understanding about blockchain.

I. What is the consensus mechanism?

In complex terms, consensus mechanism is a multi-party cooperation mechanism, used to coordinate the multi-party, so that the multi-party jointly accept a unique result, this process is difficult to deceive, and continues to operate steadily. Simply speaking, to take an example, when I want to withdraw a sum of money from Alipay and transfer it to my bank card, no matter which bank, it should be recognized that my transaction is valid and the money in Alipay is the general RMB, which is the consensus I understand.

Ii. Categories of blockchain

In the blockchain world, according to consensus algorithms and application scenarios, blockchains are divided into three categories: public, federated and private.

  • The public chain is a completely open distributed system, in which nodes can join and exit freely without audit, such as Bitcoin and Ethereum are the most typical public chains. As a completely open distributed system, consensus mechanism needs to consider not only common nodes, but also fault nodes and evil nodes, and ensure the consistency of the final results.
  • Alliance chain is a relatively open distributed system. If a new node wants to join, it needs to be verified and reviewed. Alliance chains mostly exist between enterprises, which have high requirements for data security. It is necessary to consider faulty nodes and evil nodes to ensure the consistency of final results.
  • Private chain is a closed distributed system, because it is closed, there is no need to consider the failure nodes and evil nodes.

Third, various consensus mechanisms

1. PoW consensus mechanism

A PoW is Proof of Work. Bitcoin uses a consensus mechanism called “mining.”

PoW is the system’s way of proving that you have done the work required to achieve the same goal. Arithmetic power is everything, and whoever has a strong arithmetic power has a higher probability of success in mining

  • PoW of typical application is the currency that all nodes compete, chain need to generate new the block to charge to an account, and the competitor is through the computer calculate force calculation, calculate the specific value of the nonce, who is able to calculate this value first, first began to charge to an account, at the same time to work out the answer to release to other nodes, Once verified, the competitor gets the revenue from the block. Meanwhile, all competitors move on to the next round of competition
  • Pros and cons of PoW

Advantages :(1) complete decentralization (anyone can join mining) (2) nodes can join and exit freely (3) security, low probability of destruction

Disadvantages :(1) low efficiency; (2) high performance environment requirements for nodes; (3) possible forking; (4) gradually reduced mining output of bitcoin, which may lead to problems due to the reduction of the number of miners in the future

2. PoS consensus mechanism

Instead of PoW being wasteful and constantly hashing, people are starting to talk about a better consensus mechanism, PoS.

PoS is Proof of Stake. According to assets, those with more money are getting richer and those with less are getting poorer.

  • Peer Coin is the first digital currency to adopt PoS consensus mechanism. In Peer Coin, the concepts of Coin age and Coin day are introduced. Coin day is the number of days of holding the currency, and Coin age = the number of coins * Coin day

  • Before each round of competition, bet with a certain age to become the verifier, and then a bookkeeper will be randomly selected, while clearing his age, and give certain interest according to the age of the coin. And this “random selection”, in fact, is basically based on who bet more coin age, so as to increase his probability of being selected. That’s why those with more money are getting richer and those with less are getting poorer. Right

  • Advantages and disadvantages of PoS

Advantages :(1) PoS saves the time of useless hash calculation; (2) as PoS is a verification node, it has the mechanism of pledge, so it can timely punish the perpetrators accordingly; (3) PoS has good balance and everyone can mine

Disadvantages :(1) PoS requires certain competitive capital. (2) as the distribution is based on capital, the one who is richer is likely to get more profits, so it is easy for a few people to acquire the majority of assets

3. DPoS consensus mechanism

Although PoS has made corresponding improvements to many shortcomings of PoW, PoS still has various problems. Among them, “power centralism” is the most obvious. In PoS, choosing based on the amount of “principal” leads to the rich account gaining more power and profits, and perhaps even controlling the bookkeeping, resulting in a few “rich” games.

DPoS, another Delegated Proof of Stake, is based on PoS, similar to voting, and the nodes elected to bookkeep the books, similar to a democratic system.

  • Different from PoS consensus, under DPoS mechanism, nodes with low equity can also exercise the right of accounting as long as enough people vote in the election. However, it should be noted that DPoS is based on PoS, so people with more assets can still enjoy more rights. In other words, in the voting process, the more money the candidate owns, the more votes will be taken.

  • At the same time, once the elected nodes abuse their rights, do nothing or do nothing, they will be reported by other nodes and deprived of corresponding rights.

  • Advantages and disadvantages of DPoS

Advantages :(1) fewer bookkeeping nodes, faster transaction speed (2) more security, ensure final consistency (3) more resource saving

Disadvantages: Since nodes are created by voting, there will be bribery and one person manipulating multiple nodes, which seriously affects the nature of decentralization

Raft consensus Mechanism

PoW, PoS, DPoS may not be very suitable for federation and private chains, hence Raft consensus mechanism

  • A Raft cluster typically has 5 nodes, allowing the system to have 2 failed nodes (since at least N/2 +1 nodes vote). Each node has three states: leader, follower, and candidate. In normal state, there is only one Leader and the others are followers. Followers are passive and do not initiate requests actively. They can only respond to the requests of the leader and Candida. The leader handles all client requests, and the candidate state is used for election.

  • Electing a leader only happens in two situations: 1) when Raft cluster is first started; 2) When a known Leader fails;

  • Advantages and disadvantages of Raft

Advantages: (1) High speed, high transmission efficiency, (2) no mining, more energy saving, (3) no bifurcation, simpler disadvantages: Raft relies too much on the leader, it can be said that it lacks the decentralization feature of digital currency, so Raft consensus is generally only used in the federation chain or private chain.