为广大币圈朋友提供币圈基础入门专业知识!
当前位置首页 > 区块链知识> 正文

区块链现有的共识算法有哪些,区块链现有的共识算法是什么

发布时间:2023-12-06-09:40:00 来源:网络 区块链知识 区块   共识   算法

区块链现有的共识算法有哪些,区块链现有的共识算法是什么


请查看相关英文文档

1. Four consensus mechanisms of blockchain

The consensus mechanism of blockchain can be divided into the following four categories: Proof of Stake mechanism, Proof of Work mechanism, and Pool verification Hechi share authorization certification mechanism.
Blockchain is a chain composed of blocks one after another. Each block stores a certain amount of information, and they are connected into a chain in the order in which they were generated. This chain is saved in all servers. As long as one server in the entire system can work, the entire blockchain is safe. These servers are called nodes in the blockchain system, and they provide storage space and computing power support for the entire blockchain system.

2. Consensus mechanism of blockchain

The so-called "consensus mechanism" is to complete the verification and confirmation of transactions in a very short time through the voting of special nodes; For a transaction, if several nodes with unrelated interests can reach a consensus, we can think that the entire network can also reach a consensus on it. Beijing Muqi Mobile Technology Co., Ltd., a professional blockchain outsourcing development company, welcomes discussions for cooperation. Below we will look at several consensus mechanisms of blockchain, hoping to help everyone understand the basic technology of blockchain.

Due to the development of blockchain technology, everyone is no longer unfamiliar with the term consensus mechanism. With the development of technology, various innovative consensus mechanisms are also developing.

POW proof of work

Bitcoin uses the PoW proof of work mechanism, and later Ethereum used the PoW consensus mechanism. Pow is equivalent to calculating a difficult mathematical problem, which is to calculate the hash value of a new block, and the difficulty of the calculation will be adjusted every period of time. Although PoW is a consensus mechanism that is relatively recognized by everyone, calculations will consume a lot of energy and may pollute the environment.

POS Equity Proof

The probability of obtaining accounting rights is determined by the number and duration of holding Tokens. Compared with POW, POS avoids a large amount of resource waste caused by mining and shortens the time for each node to reach consensus. If the network environment is good, it can be achieved in milliseconds and has low requirements on node performance.

However, the shortcomings of POS are also obvious. Nodes holding more Tokens have a greater chance of obtaining accounting rights. This will lead to the "Matthew Effect", where the rich will get richer, destroying the decentralization of the blockchain. Centralization.

DPOS Proof of Equity

The principle of DPOS Delegated Proof of Equity is the same as that of POS. The main difference is that DPOS Token holders can vote to elect agents as super nodes, responsible for Produce blocks and maintain consensus rules on the network. If these nodes fail to perform their duties, new nodes will be voted in. The same disadvantage also tends to be centralized.

POA authority certificate

POA nodes can reach consensus without communication, so it is extremely efficient. And it can also resist computing power attacks very well and has high security. But POA requires a centralized authoritative node to verify identity, which means it will harm the decentralization of the blockchain, which is also a compromise between decentralization and improved efficiency.

3. In-depth understanding of the consensus mechanism and algorithm principles of the blockchain

The so-called "consensus mechanism" completes transactions in a very short time through the voting of special nodes. Verification and confirmation; for a transaction, if several nodes with unrelated interests can reach a consensus, we can think that the entire network can also reach a consensus on it. To put it more simply, if a Chinese Weibo influencer, a virtual currency player in the United States, an African student and a European traveler do not know each other, but they all agree that you are a good person, then it can basically be concluded that You're not a bad person.

In order for the entire blockchain network node to maintain the same data and ensure the fairness of each participant, all participants in the entire system must have a unified agreement, which is what we have here The consensus algorithm to be used. All Bitcoin nodes follow unified protocol specifications. The protocol specification (consensus algorithm) consists of relevant consensus rules, which can be divided into two major cores: proof of work and the longest chain mechanism. The ultimate expression of all rules (consensus) is the longest chain of Bitcoin. The purpose of the consensus algorithm is to ensure that Bitcoin continues to operate on the longest chain, thereby ensuring the consistency and reliability of the entire accounting system.

Users in the blockchain do not need to consider the credit of the other party when conducting transactions, do not need to trust the other party, and do not need a trusted intermediary or central agency. They only need to follow the blockchain protocol. Realize the transaction. The premise for smooth transactions without the need for a trusted third-party intermediary is the consensus mechanism of the blockchain, that is, in a market environment of mutual understanding and trust, each node participating in the transaction considers its own interests and does not violate any regulations. Motives and behaviors of cheating, so each node will actively and consciously abide by the preset rules to judge the authenticity and reliability of each transaction, and write the record of passing inspection into the blockchain. The interests of each node are different, and logically there is no incentive for them to collude to deceive. This is especially obvious when some nodes in the network have public reputation. Blockchain technology uses a consensus algorithm based on mathematical principles to establish a "trust" network between nodes, and uses technical means to achieve an innovative credit network.

At present, the mainstream consensus algorithm mechanisms in the district industry include: workload proof mechanism, equity proof mechanism, share authorization proof mechanism and Pool verification pool.

The workload proof mechanism is the proof of workload, which must be satisfied when generating a new transaction information (i.e. a new block) to be added to the blockchain.Require. In a blockchain network built based on the proof-of-work mechanism, nodes compete for accounting rights by calculating the numerical solution of random hashing. The ability to obtain the correct numerical solution to generate blocks is a specific manifestation of the node's computing power. The proof-of-work mechanism has the advantage of being completely decentralized. In a blockchain with a proof-of-work mechanism as the consensus, nodes can enter and exit freely. The well-known Bitcoin network uses a proof-of-work mechanism to produce new currencies. However, since the application of the workload proof mechanism in the Bitcoin network has attracted most of the computing power of computers around the world, it is difficult for other blockchain applications that want to try to use this mechanism to obtain the same scale of computing power to maintain their own security. At the same time, mining based on the proof-of-work mechanism also causes a lot of waste of resources, and the period required to reach consensus is also long, so this mechanism is not suitable for commercial applications.

In 2012, a netizen with the pseudonym Sunny King launched Peercoin. This encrypted electronic currency uses a proof-of-work mechanism to issue new coins and a proof-of-stake mechanism to maintain network security. This is the role of the proof-of-stake mechanism in encrypted electronic currency. first application in . Rather than requiring the certifier to perform a certain amount of computational work, Proof of Stake simply requires the certifier to provide ownership of a certain amount of cryptocurrency. The way the proof-of-stake mechanism works is that when a new block is created, the miner needs to create a "coin rights" transaction, which sends a number of coins to the miners themselves according to a preset ratio. The proof-of-stake mechanism reduces the mining difficulty of nodes in equal proportions based on the proportion and time of tokens owned by each node based on the algorithm, thus speeding up the search for random numbers. This consensus mechanism can shorten the time required to reach consensus, but essentially still requires nodes in the network to perform mining operations. Therefore, the PoS mechanism does not fundamentally solve the problem that the PoW mechanism is difficult to apply in the commercial field.

The share authorization certification mechanism is a new consensus mechanism to ensure network security. While trying to solve the problems of the traditional PoW mechanism and PoS mechanism, it can also offset the negative effects of centralization by implementing technological democracy.

The share authorization certification mechanism is similar to board voting. This mechanism has a built-in real-time shareholder voting system, just like the system is convening a never-ending shareholders' meeting at any time, where all shareholders vote. determine company decisions. The decentralization of the blockchain established based on the DPoS mechanism relies on a certain number of representatives rather than all users. In such a blockchain, all nodes vote to elect a certain number of node representatives, who act on behalf of all nodes to confirm blocks and maintain the orderly operation of the system. At the same time, all nodes in the blockchain have the power to remove and appoint representatives at any time. If necessary, all nodes can vote to disqualify the current node representatives and re-elect new representatives to achieve real-time democracy.

The share authorization certification mechanism can greatly reduce participation verificationnumber of certification and accounting nodes, thereby achieving second-level consensus verification. However, this consensus mechanism still cannot perfectly solve the application problems of blockchain in business, because this consensus mechanism cannot get rid of its dependence on tokens, and the existence of tokens is not required in many commercial applications.

The Pool verification pool is established based on traditional distributed consistency technology and is supplemented by a data verification mechanism. It is a consensus mechanism widely used in current blockchains.

The Pool verification pool can work without relying on tokens. Based on mature distributed consensus algorithms (Pasox, Raft), it can achieve second-level consensus verification, which is more suitable for multi-party participation. Polycentric business model. However, the Pool verification pool also has some shortcomings. For example, the degree of distribution that the consensus mechanism can achieve is not as good as the PoW mechanism.

Here we mainly explain some algorithm principles of the blockchain workload proof mechanism and the Bitcoin network. How to prove your workload? I hope everyone can have a basic understanding of the consensus algorithm.

The main feature of the proof-of-work system is that the client has to do a certain amount of difficult work to get a result, and the verifier can easily use the results to check whether the client has done the corresponding work. A core feature of this scheme is asymmetry: the work is modest for the requester and easy to verify for the verifier. It differs from CAPTCHAs, which are easier to solve by humans rather than easier to solve by computers.

The figure below shows the workload proof process.

For example, give a basic character "hello, world!", the workload requirement we give is that you can add a nonce (random number) after this character creation Integer value, perform SHA-256 operation on the changed (nonce added) character creation, if the result (expressed in hexadecimal form) starts with "0000", the verification is passed. In order to achieve this proof-of-work goal, it is necessary to continuously increment the nonce value and perform a SHA-256 hash operation on the resulting character creation. According to this rule, it takes 4251 operations to find the hash with leading 4 zeros.

Through this example, we have a preliminary understanding of the proof-of-work mechanism. Some people may think that if proof of work is just such a process, then it is enough to remember that the nonce is 4521 so that the calculation can pass verification. Of course not, this is just an example.

Next we simply change the input to "Hello, World! + integer value", the integer value ranges from 1 to 1000, that is to say, the input becomesAn array from 1 to 1000: Hello, World! 1; Hello, World! 2; ...; Hello, World! 1000. Then perform the above proof of work on each input in the array in turn - find the hash with leading 4 zeros.

Due to the pseudo-random nature of the hash value, it is easy to calculate based on the relevant knowledge of probability theory. It is expected that it will take 2 to the 16th power of attempts to obtain a hash hash with four leading zeros. List. If you count the actual results of the 1,000 calculations just performed, you will find that the average number of calculations is 66,958, which is very close to 2 to the 16th power (65,536). In this example, the number of calculations expected by mathematics is actually the required "workload". Repeating the workload proof multiple times will be a probability event that conforms to statistical laws.

The actual number of calculations used to count the input characters and obtain the corresponding target result is as follows:

For any node in the Bitcoin network, if you want to generate a new block To join the blockchain, you must solve this puzzle of the Bitcoin network. The key elements of this question are the proof-of-work function, block and difficulty value. The workload proof function is the calculation method of this question, the block is the input data of this question, and the difficulty value determines the amount of calculation required to understand this question.

The proof-of-work function used in the Bitcoin network is the SHA-256 mentioned above. Blocks are actually generated in the proof-of-work process. Kuangong constantly constructs block data and checks whether each calculated result meets the required workload, thereby determining whether the block meets the network difficulty. The block header is the input data of the Bitcoin proof-of-work function.

The difficulty value is an important reference indicator for miners to mine. It determines how many hash operations it takes for miners to generate a legal block. The Bitcoin network generates a block approximately every 10 minutes. If the generation of new blocks basically maintains this speed under different network computing power conditions, the difficulty value must be adjusted according to changes in the computing power of the entire network. The general principle is to ensure that the network always generates a new block in 10 minutes, regardless of the mining power.

The adjustment of the difficulty value occurs independently and automatically in each complete node. Every 2016 blocks, all nodes will automatically adjust the difficulty value according to a unified format. This formula is based on the time spent in the latest 2016 blocks and the expected time (assuming a withdrawal is generated every 10 minutes, the expected time is 20160 minutes) and adjusted according to the ratio of actual duration to expected duration. That is, if blocks are generated faster than 10 minutes, increase the difficulty value; anyway, decrease the difficulty value. The formula is expressed as follows:

New difficulty value = old difficulty value *(20160 minutes/time spent in the past 2016 blocks).

Proof of work requires a target value. The calculation formula of the target value (Target) of Bitcoin's proof of work is as follows:

Target value = maximum target value/difficulty value, where the maximum target value is a constant value

The size of the target value is inversely proportional to the difficulty value. To achieve the Bitcoin workload proof, the block hash value calculated in the mine must be less than the target value.

We can also simply understand the process of Bitcoin workload as performing SHA-256 hash operation by constantly changing the block header (that is, trying different nonce values) and using it as input. Find a process that has a hash value in a specific format (that is, requires a certain number of leading 0s), and the more leading 0s required, the more difficult it becomes.

The steps of Bitcoin’s proof-of-work puzzle can be roughly summarized as follows:

The process can be represented by the following figure:

Bitcoin’s proof of work is the main work we commonly call “mining”. Understanding the workload proof mechanism will lay the foundation for us to further understand the consensus mechanism of the Bitcoin blockchain.

4. POA (Proof of Activity) blockchain consensus algorithm

POA (Proof of Activity) algorithm is a blockchain consensus algorithm. The basic principle is to combine POW (Proof of work) and POS (Proof of stake) algorithms. For the specific content of POW algorithm and POS algorithm, please refer to:

POW algorithm: https://www.jianshu.com/p/ b23cbafbbad2
POS algorithm: https://blog.csdn.net/wgwgnihao/article/details/80635162

Compared with other algorithms, the POA algorithm can improve the network topology and maintain the proportion of online nodes. Requires fewer transaction fees and reduces energy consumption during the consensus algorithm process.
The network required by the POA algorithm also contains two types of nodes, miners and ordinary participants, among which ordinary participants may not always stay online. The POA algorithm first constructs a block header by miners, and selects N coins from the block header. The owners of these N coins participate in the subsequent verification and block generation process.
From here we can see that the POA algorithm is not only related to computing power, but also the subsequent N parameters.The election of participants is entirely determined by the total number of coins owned by participants in the network. Participants with more coins have a greater chance of being selected as N subsequent participants. The necessary condition for the subsequent participation of N participants is that these N participants must be online, which is also the origin of the POA name. The maintenance of the POA algorithm depends on the active nodes (Active) in the network.

An ideal basic process of the POA algorithm is that, similar to the POW protocol, the miner constructs a block header that meets the difficulty requirements, and calculates the number of N coins from the block header obtained by the miner. Traceability in the chain can reveal the current participants of these coins. The miner sends the block header to the N participants, among which the first N-1 participants verify and sign the block, and the last N-th participant verifies and adds the transaction to the block, and the block is Publishing it out means completing the production of a block.
An ideal process is shown in the figure below:

In actual operation, there is no guarantee that all participants on the network are online, and participants who are not online cannot perform checksum signatures. This Block headers that cannot be verified and signed will be discarded.
That is, in actual operation, a miner should construct a block header and broadcast it to each participant for signature, while continuing to reconstruct a new block header to prevent any of the N participants derived from the previous block header from being online. As a result, the block header was abandoned.
Therefore, in this case, whether a block is confirmed is not only related to the computing power of the miner but also to the online ratio on the network.
Compared with pure POW, when a block is produced in the same 10 minutes as Bitcoin (POW), POA will have losses caused by participants not being online. Therefore, the number of blocks that miners can construct within 10 minutes The number will be greater, that is, the difficulty limit of the block will be reduced, and the energy loss caused by miners during the mining process will also be reduced.
Compared with pure POS, it can be seen that the block generation process of POA does not upload the relevant information in the process of constructing the block, which can significantly reduce the redundant information generated by the maintenance protocol on the blockchain. quantity.

This section analyzes some parameter settings in the appeal protocol

After the miner constructs the block header, it verifies the block header and selects the number of N participants in the block construction. The determination is similar to the selection of the block time of each block in Bitcoin. Bitcoin has chosen 10 minutes as the expected block time for each block and adapted it by dynamically adjusting the difficulty.
The value of N here can also be selected or dynamically adjusted. Dynamic adjustment requires more complex protocol content, which may lead to data expansion in the blockchain, and complex protocols also increase the possibility of attackers attacking.In addition, there is currently no way to prove what benefits dynamic adjustment can bring. Static adjustment can obtain a value of N=3 in the subsequent analysis (4 Safety Analysis), which is more appropriate.

As can be seen from the above description, in addition to miners, there are also N currency owners derived from the block header who construct new blocks. After constructing a new block, these participants should also receive certain incentives to keep participants online.
The non-matching ratio between miners and participants is related to the online status of the participants. The incentives given to participants are closely related to their enthusiasm to stay online. The more participants stay online, the better the stability of the network can be maintained. Therefore, when there are not enough online participants on the network, the incentive share ratio that participants receive can be increased, thereby motivating more participants to come online.
How to determine the online status of the current participant? When the last Nth participant constructs a block, the constructed but discarded block headers can be added to the block. If the number of discarded block headers is too large, it means that the number of people online is too low, and the sharing ratio should be adjusted.
At the same time, the final N-th participant’s share with other participants also needs to be considered. The N-th participant needs to add the transaction to the block, that is, the UTXO pool needs to be maintained. At the same time, the N-th participant also needs to add the transaction to the block. The discarded block header is added to the newly constructed block.
In order to encourage them to add abandoned block headers to newly constructed blocks, a small amount of incentives can be appropriately added according to the added block headers. Although adding more block headers can increase the share in the next round, it should be enough to motivate participants to add unused block headers to the block (it is impossible for participants to add more block headers in order to increase their share) , each block header means the workload of a miner).
If a participant does not maintain the UTXO pool, he cannot construct the block, but he can participate in the first N-1 signatures. Therefore, in order to motivate participants to maintain the UTXO pool, as the last participant to construct the block, he must be given More incentives, like twice as much as other participants.

From the description in 3.2, we can know that a user must be online and maintain the UTXO pool to gain as much benefit as possible. This mechanism will inevitably lead some users to entrust their accounts to a centralized organization. This institution remains online at all times and maintains their accounts for users, participating in the construction of blocks and obtaining benefits when they are selected as participants in constructing blocks. Finally, the organization divides the proceeds in some form.
As mentioned above, participants must use their own keys to sign, and after being entrusted to an organization, the organization can use this key to sign and construct blocks, and it is also possible to use this key to consume users' property. A limited-spend key can be used here. This key has two functions. One is to consume part of the property in the account, and the other is to spend it.All property is transferred to a designated account. This key can be used during escrow. After being notified that part of the property has been spent, all properties can be immediately transferred to another account of one's own to ensure the security of the property.

From the above analysis, we can see that the security of POA is related to the computing power owned by the attacker and the equity owned by the attacker. Assuming that the proportion of online equity owned by the attacker is , the attacker's computing power needs to be times that of all other computing powers to achieve a fork. Assuming that the total proportion of the attacker's equity is , and the online proportion of honest users in the network is , then the attacker's computing power needs to be times that of all other computing powers to achieve the attack.
The analysis table of the attack is as follows:

As can be seen from the above analysis, the POA algorithm can improve the network topology, maintain the proportion of online nodes, and require less transaction fees than other algorithms. At the same time, the energy loss during the consensus algorithm process is reduced. At the same time, the attack cost of the PoA protocol is higher than that of Bitcoin's pure PoW protocol.

Reference: Proof of Activity: Extending Bitcoin's Proof of Work via Proof of Stake

5. What consensus mechanisms are currently used in the blockchain, their respective advantages, disadvantages and scope of application What is it

There are currently four main types of consensus mechanisms: Pow, Pos, DPos, Pool
1. Pow workload proof is the familiar mining, which is calculated through AND or operation. A random number that satisfies the rules will obtain the accounting rights of this time, send out the data that needs to be recorded in this round, and store it together after verification by other nodes in the entire network;
Advantages: Complete decentralization, nodes can enter and exit freely;
Disadvantages: At present, Bitcoin has attracted most of the world's computing power. It is difficult for other blockchain applications that use the Pow consensus mechanism to obtain the same computing power to ensure their own security; mining causes a lot of waste of resources; the cycle of reaching consensus It is too long and not suitable for commercial applications

2. PoS Proof of Stake, an upgraded consensus mechanism of POW; according to the proportion and time of tokens held by each node; the mining difficulty is reduced in an equal proportion. This speeds up the search for random numbers.
Advantages: It shortens the time to reach consensus to a certain extent
Disadvantages: It still requires mining, which essentially does not solve the pain points of commercial applications

3. DPos share authorization certification mechanism , similar to board voting, currency holders vote for a certain number of nodes to perform verification and accounting on their behalf.
Advantages: Significantly reduce the number of nodes participating in verification and accounting, and can achieve second-level consensus verification
Disadvantages: The entire consensus mechanism still relies on tokens, and many commercial applications do not require the existence of tokens
br />
4. Pool verification pool, based on traditional distributed consistency technology, plus data verification mechanism; it is the consensus mechanism currently used in a wide range of industry chains
Advantages: It can work without tokens, and it is mature. Based on the distributed consensus algorithm (Pasox, Raft), it achieves second-level consensus verification;
Disadvantages: The degree of decentralization is not as good as bictoin; more suitable for multi-center business models with multi-party participation

There are huge advantages in using the consensus mechanism to ensure data consistency (the consensus mechanism was first proposed by Ripple, a network transaction synchronization mechanism that prioritizes data correctness. In the consensus network, no matter how the software code changes, you cannot enter if you cannot obtain consensus. network, not to mention forks).
————————————————
PS: A little self-deprecating, although the consensus mechanism can definitely ensure that no hard fork will occur at any time. However, the disadvantage of this mechanism is also obvious, that is, it takes much longer to achieve consensus with other nodes than the current Bitcoin network. In extreme cases, the consequences of being disconnected in the Ripple consensus mechanism network are also terrifying.

It is possible that your home has a power outage for one day, and the entire system will no longer be able to achieve consensus with other Rippled nodes the next day (the consensus mechanism actually requires more than 80% of the nodes to recognize your data, your Submission will be accepted by other nodes, otherwise the connection will be exclusively refused), and you can even only clear all more than 500 GB of your data and resynchronize before you can connect to other Ripple nodes.

So currently, the existing Rippled end is not suitable for civilian use (for commercial use, the impact is relatively small. For example, RL's own Rippled node is hosted in the Amazon cloud data center. If it does not respond for a long time, it can be very high. The amount of compensation is claimed, and that kind of place is almost uninterrupted except for major disasters). This is also one of the aspects that RL has always wanted to improve.

6. Blockchain consensus algorithm - (4) PoA consensus (Proof of Activity)

PoA consensus (Proof of Activity) is also called proof of activity, which combines PoW The characteristics of proof of work and proof of stake of PoS have been expanded accordingly. The PoA consensus has more complex accounting node selection and a fairer reward mechanism.

PoA activities prove that the main advantage is to use fair incentives to ensure that nodes remain online and mobilize node enthusiasm. Online miners have a certain probability of earning profits even if they are not mining. Greatly improved the quality of network-wide maintenance.

step1: Each miner first uses its own computing power to pass the workload proof mechanism to obtain the nonce and generate an empty block header. This block header has no transaction information data and other data is consistent with the normal block. .

step2: The node that first generates the empty block broadcasts to the entire network nodes. After receiving the message, the entire network nodes splice the hash value of this block with the hash value of the previous block, and then Add n fixed suffix values ​​for hashing, and finally get n values ​​as input, enter the follow-the-satoshi program, and then output n random equity holders.

step3: The first n-1 random equity holders sign the empty block. The nth random equity holder is the node that has obtained the accounting right. He will be in the empty area. Add transaction data and signatures on a block basis.

step4: The nth random equity holder will broadcast the packaged block to the entire network. After receiving the block, all network nodes will verify it and upload it to the chain after successful verification.

step5: The miner who generated the empty block shares the transaction fee reward with the nth random equity holder and the first n-1 signed random equity holders.

7. Three common consensus mechanisms in blockchain

Blockchain is a distributed ledger system built on P2P network and participated by nodes. Its biggest feature is "decentralization" change". That is to say, in the blockchain system, there is no need to establish trust between users, between users and institutions, and between institutions. Transactions can be realized by relying only on the blockchain protocol system.

But how to ensure the accuracy, authority, and reliability of the ledger? Why do nodes on the blockchain network participate in accounting? What should I do if the node is fake? How to prevent the ledger from being tampered with? How to ensure data consistency between nodes? …These are the problems that blockchain needs to solve when establishing “decentralized” transactions, resulting in the consensus mechanism.

The so-called "consensus mechanism" is to complete the verification and confirmation of transactions in a very short time through the voting of special nodes; when there is a disagreement, without central control, several Nodes participate in decision-making to reach consensus, that is, how to establish a trust relationship between individuals who have no basis for trust in each other.

Blockchain technology uses a set of consensus-based mathematical algorithms to establish a "trust" network between machines, thereby creating new credit through technical endorsement rather than centralized credit institutions.

Different blockchain types require different consensus algorithms to ensure that the last block on the blockchain can reflect the status of the entire network at any time.

So far, the blockchain consensus mechanisms mainly include the following: POW workload proof, POS equity proof, DPOS authorized equity proof, Paxos, PBFT (Practical Byzantine Fault Tolerance Algorithm), dBFT, DAG ( Directed acyclic graph)

Next weMainly talk about the principles and application scenarios of common POW, POS, DPOS consensus mechanisms

Concept:

Proof of work mechanism (Proof of work), the earliest one is an economics A noun that refers to the measurement method set by the system to achieve a certain goal. A simple understanding is a certificate to confirm that you have done a certain amount of work, and to prove that the corresponding amount of work has been completed by certifying the results of the work.

The proof-of-work mechanism has the advantage of complete decentralization. In a blockchain with a proof-of-work mechanism as the consensus, nodes can enter and exit freely and calculate the numerical solution of the random hash. The ability to compete for accounting rights and obtain correct numerical solutions to generate blocks is a concrete manifestation of node computing power.

Applications:

The most famous application of POW is Bitcoin. In the Bitcoin network, during the Block generation process, miners need to solve complex cryptographic mathematical problems to find a Block Hash that meets the requirements, consisting of N leading zeros. The number of zeros depends on the difficulty value of the network. During this period, a lot of trial calculations (workload) are required, and the calculation time depends on the hashing speed of the machine.

Finding a reasonable hash is a probabilistic event. When a node has n% of the computing power of the entire network, the node has an n/100 probability of finding the Block Hash. After the node successfully finds a satisfactory Hash value, it will immediately broadcast the packaged block to the entire network. The nodes in the network will verify it immediately after receiving the broadcast packaged block.

If the verification passes, it means that a node has successfully solved the puzzle, and it will no longer compete for the current block, but choose to accept the block, record it in its own ledger, and then proceed to the next block. Competitive guessing game of blocks. Only the fastest puzzle-solving block in the network will be added to the ledger, and other nodes will copy it, thus ensuring the uniqueness of the entire ledger.

If a node engages in any cheating behavior, it will cause the network node verification to fail and directly discard its packaged block. This block will not be recorded in the general ledger, and the cost of the cheating node will be It is all in vain. Therefore, under the huge mining cost, miners voluntarily comply with the consensus protocol of the Bitcoin system, thus ensuring the security of the entire system.

Advantages and Disadvantages

Advantages: The results can be verified quickly, the system bears a large number of nodes, and the cost of evil is high to ensure the conscious compliance of miners.

Disadvantages: It requires a large amount of algorithms and takes a long time to reach consensus

Concept:

Proof of Stake Mechanisme), requiring the certifier to provide ownership of a certain amount of cryptocurrency.

The way the proof-of-stake mechanism works is that when a new block is created, the miner needs to create a "coin rights" transaction, which will send some coins to the miners themselves according to a preset ratio. The proof-of-stake mechanism reduces the mining difficulty of nodes in equal proportions based on the proportion and time of tokens owned by each node based on the algorithm, thus speeding up the search for random numbers.

Application:

In 2012, a netizen with the pseudonym Sunny King launched Peercoin, which was the first application of the proof-of-stake mechanism in encrypted electronic currency. The biggest innovation of PPC is that its mining method mixes POW and POS methods, uses a proof-of-work mechanism to issue new coins, and uses a proof-of-stake mechanism to maintain network security.

In order to implement POS, Sunny King learned from Satoshi Nakamoto’s Coinbase and designed a special type of transaction called Coinstake.

The picture above shows how Coinstake works. Coin age refers to the holding period of the currency. If you own 10 coins and hold them for 10 days, then you have collected 100 days of coins. age. If you use these 10 coins, the coin age is consumed (destroyed).

Advantages and Disadvantages:

Advantages: Shortens the time required to reach consensus and is more energy-saving than proof of work.

Disadvantages: Essentially, nodes in the network are still required to perform mining operations, and the authenticity of transfers is difficult to guarantee

Concept:

Authorized equity certificate Mechanism (Delegated Proof of Stake) is similar to board voting. This mechanism has a built-in real-time shareholder voting system, just like the system is convening a never-ending shareholders' meeting at any time, where all shareholders vote to decide company decisions.

While trying to solve the problems of traditional PoW and PoS mechanisms, authorized proof of equity can also offset the negative effects of centralization by implementing technological democracy. The decentralization of the blockchain established based on the DPoS mechanism relies on a certain number of representatives rather than all users. In such a blockchain, all nodes vote to elect a certain number of node representatives, who act on behalf of all nodes to confirm blocks and maintain the orderly operation of the system.

At the same time, all nodes in the blockchain have the power to remove and appoint representatives at any time. If necessary, all nodes can vote to disqualify the current node representatives and re-elect new representatives to achieve real-time democracy.

Application:

Bitshare is a type of cryptocurrency that uses the DPOS mechanism. By introducing the concept of witnesses, witnesses can generate blocks, and everyone who holds BitShares can vote for witnesses. Candidates who get the top N (N is usually defined as 101) candidates in the total number of consent votes can be elected as witnesses. The number of elected witnesses (N) must meet: at least half of the participating voters believe that N has been fully decentralized. .

The candidate list of witnesses is updated every maintenance cycle (1 day). The witnesses are then randomly arranged, and each witness has 2 seconds of permission time to generate a block in order. If the witness cannot generate a block in a given time slice, the block generation permission is given to the witness corresponding to the next time slice. . This design of DPoS makes the generation of blocks faster and more energy-saving.

DPOS makes full use of the votes of shareholders to reach consensus in a fair and democratic way. The N witnesses they voted for can be regarded as N mining pools, and these N mining pools Each other's rights are completely equal. Shareholders can change these witnesses (mining pools) at any time by voting, as long as the computing power they provide is unstable, the computer is down, or they try to use their power to do evil.

Advantages and Disadvantages:

Advantages: Reduce the number of nodes participating in verification and accounting, thereby achieving second-level consensus verification

Disadvantages: Centrality Weaker, the security is weaker than POW, and the node agents are artificially selected, and the fairness is lower than POS. At the same time, the entire consensus mechanism still relies on the additional issuance of tokens to maintain the stability of the agent nodes.

8. Introduction to common consensus algorithms

In an asynchronous system, state replication is required between hosts to ensure that each host reaches a consistent state consensus. In an asynchronous system, failures may occur between hosts, so a fault-tolerant protocol needs to be defined in the asynchronous network, which is unreliable by default, to ensure that each host reaches a safe and reliable state consensus.

The consensus algorithm is actually a set of rules, sets a set of conditions, and selects representative nodes. In the blockchain system, there are many such screening solutions, such as POW, Pos, DPOS, etc. in the public chain. In permissioned chains or private chains that do not require a currency system, absolute trust of nodes and high efficiency are the requirements. Public chain consensus algorithms cannot provide this. For such blockchains, traditional consensus algorithms have become the first choice, such as PBFT, PAXOS, RAFT, etc.

Contents

1. BFT (Byzantine Fault Tolerance Technology)

2. PBFT (Practical Byzantine Fault Tolerance Algorithm)

3. PAXOS < /p>

4. Raft

5. POW (Proof of Work)

6. POS (Proof of Equity)

7. DPOS (Delegated Proof of Equity)

8. Ripple

Byzantine error technology is a type of fault-tolerant technology in the field of distributed computing. The Byzantine hypothesis is the unpredictable behavior of computers and networks due to hardware errors, network congestion or outages, and malicious attacks. Byzantine fault tolerance is used to handle this abnormal behavior and meet the specifications of the problem to be solved.

A Byzantine fault-tolerant system is a system with n nodes. The entire system satisfies the following conditions for each request:

1) All non-Byzantine nodes use the same input information to generate The same result;

2) If the input information is correct, then all non-Byzantine nodes must receive this information and calculate the corresponding results.

Commonly used assumptions in Byzantine systems include:

1) The behavior of Byzantine nodes can be arbitrary, and Byzantine nodes can collude with each other;

2 ) Errors between nodes are irrelevant;

3) Nodes are connected through an asynchronous network. Messages in the network may be lost, out of order, and arrive delayed, but most protocols assume that messages are It can be conveyed to the destination within the time;

4) The information transmitted between servers can be sniffed by a third party, but it cannot tamper with, forge the content of the information and verify the integrity of the information.

Byzantine fault tolerance lacks practicality due to its theoretical feasibility. In addition, it also requires additional clock synchronization mechanism support. The complexity of the algorithm also increases exponentially with the increase of nodes.

Practical Byzantine Fault Tolerance reduces the operational complexity of Byzantine protocols from exponential level to polynomial level.

PBFT is a state machine replica replication algorithm, that is, the service is modeled as a state machine, and the state machine replicates at different nodes in the distributed system. PBFT requires joint maintenance of a state. Three basic types of protocols need to be run, including consistency protocols, checkpoint protocols, and view replacement protocols.

Consistency protocol. The consistency protocol contains at least several stages: request, sequence number allocation (pre-prepare) and response (reply), and may include mutual interaction (prepare), sequence number confirmation (commit) and other stages.

In the PBFT communication model, each client's request needs to go through 5 stages. Since the client cannot obtain any server running status information from the server, whether an error occurs on the master node in PBFT can only be monitored by the server. If the server cannot complete the client's request within a period of time, the view replacement protocol will be triggered.

The basic process of the entire protocol is as follows:

1) The client sends a request to activate the service operation of the master node.

2) When the master node receives the request, it starts a three-phase protocol to broadcast the request to each slave node.

[2.1] In the sequence number allocation stage, the master node assigns a sequence number n to the request, broadcasts the sequence number allocation message and the client's request message m, and constructs a PRE-PREPARE message to each slave node;

[2.2] In the interaction phase, the slave node receives the PRE-PREPARE message and broadcasts the PREPARE message to other service nodes;

[2.3] In the sequence number confirmation phase, each node performs the request and sequence in the view After verification, broadcast the COMMIT message, execute the received client request and respond to the client.

3) The client waits for responses from different nodes. If m+1 responses are the same, the response is the result of the operation.

PBFT is generally suitable for private chains and consortium chains that require strong consistency. For example, in the blockchain Hyperledger project led by IBM, PBFT is an optional consensus protocol. In Hyperledger's Fabric project, the consensus module is designed as a pluggable module and supports consensus algorithms such as PBFT and Raft.

In some distributed scenarios, the assumptions do not need to consider Byzantine faults, but only deal with general crash faults. In this case, it will be more efficient to adopt protocols such as Paxos. . PAXOS is a consensus algorithm based on message passing and highly fault-tolerant.

There are three types of roles in PAXOS: Proposer, Acceptor and Learner. The main interaction process is between Proposer and Acceptor. The algorithm process is divided into two stages:

phase 1

a) The proposer sends prepare messages to more than half of the acceptors in the network

b) Under normal circumstances, the acceptor Reply to promise message

phase 2

a) When there are enough acceptors to reply to promise message, proposer sends accept message

b) Under normal circumstances, acceptor replies accepted Message

The flow chart is shown in the figure:

The PAXOS protocol is used in WeChat PaxosStore, and the Paxos protocol process is called billions of times every minute.

Paxos is a protocol designed by Lamport to maintain the consistency of distributed systems. However, because Paxos is very complex and difficult to understand, various implementations and variants have emerged. Raft is a more understandable consensus algorithm proposed by Stanford and is intended to replace the currently widely used Paxos algorithm.

Raft was originally a consensus algorithm for managing replicated logs. It is a strong consensus protocol that achieves consensus under non-Byzantine failures. The consensus process of Raft is as follows: First, a leader is elected. The leader receives accounting requests from the client, completes accounting operations, generates blocks, and copies them to other accounting nodes. The leader has complete management and accounting rights. For example, the leader can decide whether to accept new transaction record items without considering other accounting nodes. The leader may fail or lose contact with other nodes. At this time, a new leader will be re-elected.

In Raft, each node will be in one of the following three states:

(1) Follower: All nodes start in the follower state. If the leader message is not received, it will become the candidate state;

(2) Candidate: It will "solicit votes" from other nodes. If it gets the majority of votes, it will become the leader. This process is called Leader Election;

(3) Leader: All modifications to the system will first go through the leader. A log entry will be written for each modification. The process after the leader receives the modification request is as follows: This process is called Log Replication

1) Copy the log to all follower nodes

2) When most nodes respond Only then submit the log

3) Notify all followers that the log has been submitted

4) All followers also submit the log

5) The entire system is now in a consistent state

The Raft phase is mainly divided into two stages. The first is the leader election process, and then normal operations are performed based on the elected leader, such as log replication, accounting, etc.

(1) Leader election

When the follower does not receive the message from the leader within the election time, it will transition to the candidate state. In RaIn the ft system:

1) Any server can become a candidate as long as it sends a request to other server followers to elect itself.

2) If other servers agree, issue OK. If a follower goes down during this process and does not receive an election request, the candidate can choose himself at this time. As long as a majority of N/2+1 votes is reached, the candidate can still become the leader.

3) In this way, the candidate becomes the leader, and it can issue instructions to voters, namely followers, such as accounting.

4) Notification of accounting in the future through heartbeat messages.

5) Once the leader collapses, one of the followers will become a candidate and issue an invitation to vote.

6) After the follower agrees, it becomes the leader and continues to undertake guidance work such as accounting.

(2) Log replication

The accounting steps are as follows:

1) Assume that the leader has been elected, and the client sends a message to add a log. Requirements;

2) The leader requires followers to comply with his instructions and append this new log content to their respective logs;

3) Most follower servers write transaction records into the ledger After confirming that the addition is successful, a confirmation success message is sent;

4) In the next heartbeat message, the leader will notify all followers to update the confirmed items.

Repeat the above process for each new transaction record.

During this process, if a network communication failure occurs and the leader cannot access most followers, the leader can only update the follower servers it can access normally. Since most server followers do not have a leader, they will re-elect a candidate as leader, and then this leader will deal with the outside world as a representative. If the outside world requires it to add new transaction records, the new leader will notify everyone according to the above steps. Most followers. When network communication is restored, the original leader becomes a follower. During the disconnection stage, any updates from the old leader cannot be considered confirmed and must all be rolled back to receive new updates from the new leader.

In a decentralized ledger system, each node joining the system must keep a complete ledger, but each node cannot keep accounts at the same time because the nodes are in different environments and receive different Information, if it is recorded at the same time, it will inevitably lead to inaccuracies in the account book.consistent. Therefore, it is decided at the same time which node has the accounting right.

In the Bitcoin system, a computing power competition takes place approximately every 10 minutes. The winner of the competition will obtain the right to keep accounts and synchronize new ledger information to other nodes.

The main feature of PoW systems is the asymmetry of computing. The working end has to do a certain amount of difficult work to get a result, but the verifier can easily use the results to check whether the working end has done the corresponding work. The requirement of this workload is to connect an integer value string called nonce after a certain string, and perform a SHA256 hash operation on the connected string. If the hash result obtained (expressed in hexadecimal form ) starts with several 0s, then the verification passes.

If any node in the Bitcoin network wants to generate a new block and write it into the blockchain, it must solve the PoW problem in the Bitcoin network. The three key elements are the workload proof function, block and difficulty value. The workload proof function is the calculation method of this question. The block determines the input data of this question, and the difficulty value determines the amount of calculation required for this question.

(1) The workload proof function is SHA256

Bitcoin blocks consist of block headers and the transaction list included in the block. The block header, which has a fixed length of 80 bytes, is the input string used for Bitcoin’s proof of work.

(2) Difficulty adjustment occurs independently and automatically in each complete node. Every 2016 blocks, all nodes will automatically adjust the difficulty according to a unified formula. If the block generation rate is faster than 10 minutes, the difficulty will be increased, and if the block generation rate is slower than 10 minutes, the difficulty will be decreased.

The formula can be summarized as: new difficulty value = old difficulty value × (time spent in the past 2016 blocks/20160 minutes)

Proof of work needs to have a target value. The calculation formula of the target value (Target) of Bitcoin's proof of work: target value = maximum target value/difficulty value

The maximum target value is a constant value:

The size of the target value is inversely proportional to the difficulty value. The achievement of Bitcoin's proof of work is that the block hash value calculated by the miner must be less than the target value.

(3) Can PoW solve the Byzantine Generals Problem

Bitcoin’s PoW consensus algorithm is a probabilistic Byzantine Agreement (Probabilistic BA)

When When the dishonest computing power is less than 50% of the total computing power of the network, the mining difficulty will increase at the same time.At a relatively high level (with a block in about 10 minutes), the concept of Bitcoin network reaching consistency increases exponentially with the number of confirmed blocks. But when the dishonest computing power reaches a certain scale, not even close to 50%, Bitcoin's consensus algorithm cannot guarantee correctness, that is, it cannot guarantee that most blocks are provided by honest nodes.

Bitcoin’s consensus algorithm is not suitable for private chains and consortium chains. The reason is first of all that it is an eventual consistency consensus algorithm, not a strong consistency consensus algorithm. The second reason is its low consensus efficiency.

Extended knowledge: Consistency

Strict consistency can be achieved under the ideal condition that the system does not experience any failures and communication between all nodes does not require any time. . At this time, the entire system is equivalent to a machine. In reality, it is impossible to achieve.

Strong consistency, when the update operation is completed in the distributed system, any multiple processes or threads accessing the system will obtain the latest value.

Weak consistency means that the system does not guarantee that subsequent accesses by processes or threads will return the latest updated value. After the data is successfully written, the system does not promise that the latest written value can be read immediately, nor does it specifically promise how long it will take to read it. But we will try our best to ensure that it is after a certain time level (seconds). The data can be brought to a consistent state.

Eventual consistency is a specific form of weak consistency. The system guarantees that if there is no subsequent update, the system will eventually return the value of the last update operation. In other words, if it is required to access the updated data after a period of time, it is eventual consistency.

In the PoS mode, there is a term called coin age. Each coin generates 1 coin age every day. For example, if you hold 100 coins for a total of 30 days, then, at this time, you The currency age is 3000. At this time, if you find a PoS block, your currency age will be cleared to 0. Every time you are cleared of 365 coins, you will get 0.05 coins in interest from the block (assuming that the interest can be understood as an annual interest rate of 5%), then in this case, interest = 3000 * 5% / 365 = 0.41 coins Coin, this is very interesting. Holding the currency has interest.

Peercoin is the first currency to adopt proof of stake. , Peitecoin’s proof-of-stake mechanism combines the concepts of randomization and currency age. Coins that have not been used for at least 30 days can participate in the competition for the next block. The longer and larger the currency set, the greater the possibility of signing the next block. . Once the equity of the coin is used to sign a block, the coin age will be reset to zero, so that you must wait at least 30 days before signing another block.

Although the PoS mechanism takes into account the shortcomings of PoW, it is based on the equity settlementThe choice of Yu Lai will result in the richest man's account having greater power and possibly controlling the accounting rights. The emergence of the Delegated Proof of Stake (DPoS) mechanism is precisely based on solving the shortcomings of the PoW mechanism and the PoS mechanism.

Bitshare is a type of cryptocurrency that uses the DPoS mechanism. Its principle is to let everyone who holds BitShares vote, resulting in 101 representatives. We can understand it as 101 super nodes or mining pools, and the rights of these 101 super nodes are completely equal to each other. of. If a representative fails to perform their duties (fails to generate a block when it is their turn), they will be removed from the list and a new supernode will be elected to replace them.

BitShares introduces the concept of witnesses. Witnesses can generate blocks, and everyone who holds BitShares can vote for witnesses. Candidates who get the top N (N is usually defined as 101) candidates in the total number of consent votes can be elected as witnesses. The number of elected witnesses (N) must meet: at least half of the participating voters believe that N has been fully decentralized. .

The candidate list of witnesses is updated every maintenance cycle (1 day). The witnesses are then randomly arranged, and each witness has 2 seconds of permission time to generate a block in order. If the witness cannot generate a block in a given time slice, the block generation permission is given to the witness corresponding to the next time slice. .

BitShares has also designed another type of election, the representative election. Elected representatives have the privilege of proposing changes to network parameters, including transaction fees, block sizes, witness fees, and block intervals. If a majority of representatives agree to the proposed changes, shareholders have a two-week review period during which they can remove the representatives and annul the proposed changes. This design ensures that representatives technically do not have the right to directly modify parameters and that all changes to network parameters ultimately require the consent of shareholders.

Ripple is an open source payment protocol based on the Internet. In Ripple's network, transactions are initiated by the client (application) and pass through the tracking node or validating node. Broadcast the transaction to the entire network.

The main function of the tracking node is to distribute transaction information and respond to the client’s ledger requests. In addition to all the functions of the tracking node, the verification node can also add new ledger instance data to the ledger through the consensus protocol.

Ripple's consensus occurs between verification nodes. Each verification node is pre-configured with a list of trusted nodes, called UNL (Unique Node List). Nodes on the list can vote on the transaction. Every few seconds, RippleThe network will carry out the following consensus process:

1) Each verification node will continuously receive transactions sent from the network. After verification with the local ledger data, illegal transactions will be discarded directly, and legal transactions will be Summarized into a transaction candidate set (candidate set). The transaction candidate set also includes transactions left over from the previous consensus process that could not be confirmed.

2) Each verification node sends its own transaction candidate set as a proposal to other verification nodes.

3) After the verification node receives a proposal from other nodes, if it is not from a node on UNL, it will ignore the proposal; if it is from a node on UNL, it will compare the transactions in the proposal If there is the same transaction as the local transaction candidate set, the transaction will receive one vote. Within a certain period of time, when a transaction receives more than 50% of the votes, the transaction enters the next round. Transactions that do not exceed 50% will be left for the next consensus process to be confirmed.

4) The verification node sends transactions with more than 50% of the votes as proposals to other nodes, and at the same time increases the threshold of the required votes to 60%, and repeats steps 3) and 4) until the threshold reaches 80% .

5) The verification node formally writes the transactions confirmed by 80% UNL nodes into the local ledger data, which is called the Last Closed Ledger, which is the last (latest) status of the ledger.

In Ripple's consensus algorithm, the identities of participating voting nodes are known in advance. This consensus algorithm is only suitable for permissioned chain scenarios. The Byzantine Fault Tolerance (BFT) capability of the Ripple consensus algorithm is (n-1)/5, which means it can tolerate Byzantine errors in 20% of the nodes in the entire network without affecting the correct consensus.

In the blockchain network, due to different application scenarios, the design goals are different, and different blockchain systems use different consensus algorithms. Generally speaking, in the case of private chains and consortium chains, there are strong requirements for consistency and correctness. Generally speaking, a consensus algorithm with strong consistency should be used. In the case of public chains, the consistency and correctness are usually not 100%, and the consensus algorithm of eventual consistency (Eventual Consistency) is usually used.

The choice of consensus algorithm is highly related to the application scenario. Trusted environments use paxos or raft, permissioned alliances can use pbft, and non-permissioned chains can be pow, pos, ripple consensus, etc., based on the trust of the counterparty. Degree classification, free choice of consensus mechanism.

9. What are the blockchain consensus mechanisms?

1.pow (Proof of Work) workloadProof
One sentence introduction: The more you work, the more you receive.
2.POS Proof of Stake, Proof of Stake
One sentence introduction: The more you hold, the more you get.
3.PBFT: Practical Byzantine Fault Tolerance, Practical Byzantine Fault Tolerance
Introduction: It provides (n-1)/3 fault tolerance on the premise of ensuring liveness & safety.
4.dBFT: delegated BFT Authorized Byzantine Fault Tolerance Algorithm
Introduction: The dBFT mechanism adopted by Xiaoyi selects bookkeepers based on equity, and then the bookkeepers reach a consensus through the Byzantine Fault Tolerance algorithm. .
5.POOL verification pool
Based on traditional distributed consistency technology, plus data verification mechanism.
ChainNova is a blockchain company. It feels pretty good. Although I don’t know much about hashing algorithms, I still know a little bit about it.

博客主人唯心底涂
男,单身,无聊上班族,闲着没事喜欢研究股票,无时无刻分享股票入门基础知识,资深技术宅。
  • 37288 文章总数
  • 3637265访问次数
  • 3078建站天数