Blockchain Consensus and Consensus Mechanism

Table of contents

consensus definition

Why should there be a consensus mechanism?

the nature of miners

The nature of the consensus mechanism

The nature of the consensus mechanism

PoW mechanism

TPS in PoW

Proof-Of-Stake, Proof of Stake.

DPoS


I believe that the consensus and consensus mechanism of the blockchain is the most talked about, but there may not be too much that can be understood, especially for non-technical personnel. And some people with ulterior motives deliberately confuse the difference between the two in order to achieve some purpose of their own.

consensus definition

First, we can simply define:

Consensus: A result that everyone in the system can agree on.

Consensus mechanism: the method for obtaining consensus in the system.

In the current blockchain:

Consensus: transaction records recognized by everyone

Consensus mechanism: A method for making transaction records everyone agrees on.

reason

Why should there be a consensus mechanism?

In the blockchain, nodes communicate through data communication. Any node can join the blockchain system as long as it conforms to a certain data format agreed by the blockchain. That is to say, each node can use any program written to attack the blockchain to obtain benefits.

the nature of miners

At present, the essence of blockchain miners is bookkeeping. Each miner listens to the transaction information broadcast in the network and records the information. Since there are a large number of miners in the system, a method is needed to confirm which miner's account is valid. Effective bookkeeping is called a block.

The nature of the consensus mechanism

In a decentralized system, each bookkeeping node (miner) will maintain a ledger. When he is doing bookkeeping, he will check whether the previous records are valid. At the same time, he also hopes that his own bookkeeping will be recognized as valid by others- -Because once the recognition is valid, he can get the corresponding reward.

At this time, the way to maximize the interests of each miner is to make their own recorded books recognized by others. From the interests of the miners, it is best to grab the bookkeeping rights as much as possible and let them produce blocks, but from the perspective of the system, this is a huge security problem:

If there is always one or a few nodes that successfully generate blocks, then this or this group of nodes can be fake, for example: delete a previous transaction record, so that the receiver of a certain transaction thought it was received However, after a while, the coins disappeared, and there is no record to find them. Think about the news back then, the story of someone’s bank account suddenly adding hundreds of millions, and then disappearing inexplicably after a while...  

Therefore, if the system wants to be safe, the block producing nodes must be dispersed as much as possible , because in this case, if a certain node records false accounts, it will be overthrown by its bookkeeping nodes.

The nature of the consensus mechanism

The essence of the consensus mechanism is a way to make the nodes that generate blocks as random and decentralized as possible

problem and solution

Seeing this, you may think, it’s so simple, the system will continuously generate a random number, shouldn’t it be enough for everyone to match the block producing node according to this random number? The problem is at this moment, the system does not have a center, so no node can generate random numbers recognized by everyone-who knows if your random numbers are really random, and the possibility of false randomness is greater than the possibility of true randomness.

The essence of the design of the consensus mechanism is to find a way to randomize the block nodes

Common consensus mechanism and its security analysis

PoW mechanism

Randomize the block nodes at all times: So in such a decentralized system, what is credible? Everyone believes in themselves, the moment when the transaction and block generation result data arrives at me cannot be faked: the data may arrive late (due to network delay), but it will never arrive in advance (unless time goes back). We can design a mechanism so that the accounting results of each node must meet a certain condition, and each node will recognize the record of the first node that meets this condition.

Proof-Of-Work, each node finds a random number according to a certain rule while keeping accounts, through which a certain qualified (hash) value can be calculated, whoever finds it first, he will The block was produced successfully . The process of finding random numbers is the process of constantly adjusting random numbers --> calculation, as long as the algorithm can be discrete enough (this time has nothing to do with the next calculation, and the change of random numbers causes the calculation results to change sufficiently discrete), then The randomization of block producing nodes can be realized.

To give a simple example, if the hash value obtained by the algorithm is always between 0-10000, and the algorithm requires the (hash value) to be less than 1, if a machine can calculate once a second, then the average calculation is one 10,000 times, the value may be less than 1 once; or conversely, each calculation, there is a one in ten thousand chance of less than 1. If 10,000 nodes are calculating at the same time, then one node may get The result that meets the conditions, the node that gets the result that meets the conditions is the success of the block. And every second, the machine that gets the result may be different. This achieves sufficiently random results.

Arms race:

Some people say that if I upgrade the machine and increase the computing power of the machine to 10 calculations per second, then the chance of him producing a block becomes 10 out of 10,000. When other people see it, I can do it too, so everyone upgrades the machine . In this way, the arms race begins. It costs money to upgrade the machine, and the computing power provides increased power consumption, but as long as the output is greater than the input, everyone will continue to upgrade.

difficulty value

Some people may have discovered the problem, and everyone’s computing power has increased by ten times. The value that could be calculated in an average of one second is now calculated in 0.1 seconds. Then in the end, everything is done quickly, just for fun. , so that everyone can't stand it, what's the point?

The arithmetic is just to achieve randomness, and the essence is to keep accounts.

In order to solve this problem, the concept of difficulty is introduced. When the computing power increases, everyone originally hoped to produce a block in 1 second. However, someone increased the computing power and produced a block in 0.5 seconds. What should I do? Increase the difficulty. It was originally less than 1, but now everyone requires the result to be less than 0.5, so the computing power has doubled, and the difficulty has doubled. As a result, the block generation time is still close to 1 second. What if the computing power is increased by 10 times? The result is required to be less than 0.1 ah.

With the difficulty value, with the development of the arms race, the computing power is getting higher and higher, but the block generation time remains the same. Satoshi Nakamoto, who was the first to think of this, is awesome!

TPS in PoW

TPS (throughout per second) means throughput, that is, the number of transactions that can be executed per second. Those who are new to the industry will find it strange, why the network bandwidth and CPU performance are constantly improving, but the TPS of Bitcoin and Ethereum are only so much?

Speaking of block generation, the system adjusts the difficulty value. Bitcoin fixes the block generation time at 10-15 minutes, and Ethereum fixes the block generation time at about 12 seconds. And the size of each block is limited, so the number of transactions within each block is limited. TPS = maximum number of transactions per block / block generation time. Therefore, the TPS number is fixed in the algorithm at the beginning of the system design.

Since TPS = maximum number of transactions per block / block generation time, the method of increasing TPS is very simple:

Expand the molecule: expand the capacity of each block, for example, BCH does this.

Reduce the denominator: that is, shorten the block time, and reduce the denominator from Bitcoin to Ethereum.

But this is limited, and the block size is always limited, so it shouldn’t be hundreds of M per block. Shortening the block generation time is also limited, because the network has a delay. When it is reduced to a certain extent, the data between nodes will not be synchronized in time.

Proof-Of-Stake, Proof of Stake.

The PoW mechanism is very useful, but there is a problem. After the arms race, it consumes too much power, and it is all meaningless calculations. Apart from this result and arrival time, what credible data is used as a random value? ? I thought of a new idea, is the amount of coins stored in each person's account different, can it be used as a random number?

It’s okay to think about it, every time a block is produced, whoever has the most coins in the block producing node (account) will be recognized. But there is a problem: isn’t the one with the most coins always producing blocks?

Add a coin age. Once an account (node) successfully produces a block, the coin age will be cleared. If no block is successfully produced, the coin age will be added.

For example, account A has 7 coins, account B has 8 coins, and account C has 3 coins

Initial coin age: A: 7, B: 8, C: 3 The first round: B blocks

Currency age after the first round: A: 14, B: 0, C: 6 The second round of block A

Currency age after the second round: A:0, B:8, C:9 The third round: Block C

Coin age after the third round: A:7 B:16, C:0

Through the above results, it can be seen that the effect of random block generation has been achieved, and there is no additional power consumption calculation, but there are two problems with POS:

1. If the currency is concentrated in some people's mobile phones, the probability of block generation of these people's nodes is very high

2. What if it is the turn of a certain node to produce a block, but he does not finally produce a block?

DPoS

On the basis of PoS, some people thought, oh, decentralization means not to generate blocks on one node, so I can select some nodes and let these nodes generate blocks in turn. So there is DPoS (delegated Proof-Of-Stake), we select some nodes , let these nodes serve everyone, and they come to produce blocks, OK, save trouble and worry.

Wait, this seems a bit wrong. The decentralized method is to disperse the block producing nodes as much as possible to prevent one or some nodes from always producing blocks. Therefore, if they always produce blocks, then they are completely out of control. You can do whatever you want. Doesn’t this dPos run counter to this principle?

This conclusion is partly correct, because the blockchain not only has a public chain, but also an alliance chain . For example, the customs of various countries set up an alliance chain. They represent the interests of their respective countries, so they are in a state of Internet supervision. Besides, if they jointly commit evil, there is no target for evil, so there is no meaning and conditions for joint evil.

So what will be the consequences of dPos on the public chain? dPos has master nodes, candidate nodes, and a large number of coin miners on the public chain. The prerequisite for DPoS master nodes to do evil together is that the benefits of their evil actions are greater than the costs (willing to gamble and admit defeat, the loser may eventually abandon the chain).

Guess you like

Origin blog.csdn.net/qq_38998213/article/details/131415609