You have probably heard about PoW, PoS, and DPoS. They are consensus protocols or consensus algorithm. In the article, I will describe what consensus exactly is, how transactions are inserted into blocks and what are the most important properties of a consensus. I will try to explain it easily without deep details and no math. After reading you should know basic principles and requirements for making consensus in a distributed environment.

Consensus definition

Generally speaking, the distributed network consists of a certain number of nodes that have the same rights related to change data. In the crypto world, data are stored in a ledger. The ledger is in most cases a chain of blocks. The very first block of the chain is the so-called genesis block. To add another block behind the genesis block, and thus change the ledger, requires mutual agreement of nodes in the network. The protocol defines all rules which must be followed to achieve the agreement. If the agreement is not achieved then the ledger is not changed. Adding a new block always requires making an agreement upon the block that is to be added at the end of the blockchain.

Copy of the ledger sits on all nodes and they all have the same version at a given time. Once the agreement is achieved a new block is added into the blockchain on all nodes simultaneously. Thus, the ledger is highly protected against tampering. An attacker is not usually able to change the ledger on all nodes at the same time.

Now you know the purpose of making the consensus. Let’s define the consensus:

A protocol consensus is a set of rules that are used for making a decision between mutually distributed parties.

The rules are implemented by protocol developers. You can find source code for a given project on GitHub if the project is an open-source one. It is the so-called implementation of the protocol and a client is built from the source code. The client is a piece of software that is installed on nodes by their owners. Thus nodes can participate in making the agreement.

As stated above, in our case the decision is made about the addition of a new block. Every block consists of new transactions that must be valid in regard to the blockchain history. The important part of the mutual agreement is the verification of transactions in a proposed block.

Rules for a new block creation

Now you understand that nodes must agree upon a block addition. However, not all nodes might agree. Image one deceptive node that would disagree with all proposed blocks. The network would never add a new block so no transaction would not be processed. A new block is added only when the majority of nodes agree with the addition. It is usually 51% of nodes in PoW or some PoS (Cardano Ouroboros PoS). It is 33% in DPoS networks that are often based on the Byzantine Fault Tolerance algorithm.

A protocol must have some set of rules dedicated to a selection of a node with a right to produce a block. The most effective way is to select one node that will produce a new block and let the rest of the nodes to make a decision whether the block will be added into the blockchain or not. The faster the selection is the sooner a block can be added.

Rules for the selection of a node with the right to produce a block are very different in PoW and PoS systems.

In PoW, there is an open competition between a few groups. Each group consists of a pool operator and all miners who dedicate hash-rate to the pool. The winner with the right to produce a block is selected based on the hash-rate of a given group with a little piece of randomness. It might be said that the higher the hash-rate given group has the more often it produces a block. The winner is selected approximately after 10 minutes of searching. It takes 10 minutes to pick one pool operator from approximately 10 biggest pools. It is not a very effective rule, however, hash-rate is used also for security.

In PoS, there might be used more sophisticated cryptographic tools which are able to generate random number in a second. Thus node with the right to produce a block might be found right away. Only one node, not more.

The disadvantage of the PoW approach is that the competition takes 10 minutes. Thus, only one block is added into the blockchain in 10 minutes what is not much and it will be very difficult to scale the protocol on the first layer. Moreover, more nodes might succeed in the competition at nearly the same time since the propagation of the block on the internet takes some time.

P2P networks have some limitations. See time needed for delivering 2Mb block from London via TCP/IP:

  • Paris - 0.1s
  • US East coast - 1.1s
  • US West coast - 2.5s
  • Brazil - 3.0s
  • Korea - 3.4s
  • Australia - 5.3s

So some node e.g. in the USA continues and succeeds in solving math puzzles at the moment there have already been found a block in China. As a result, a fork is created. There are two proposed blocks and both are valid. The addition of other blocks will eventually decide which branch will stay valid (the famous longer chain rule) and which one will be discarded (including all transactions). It is proposed to wait for the next 6 blocks to be absolutely sure that a transaction is finally settled. The advantage is that the addition of the block requires 10 minutes of work so it is difficult to propose deceptive block. However, PoW rule “the longer chain wins” is mostly about the power of hash-rate and the security is based on an assumption that it is not easy for an individual to collect a huge amount of the hash-rate which would be required for the attack. Bitcoin was decentralized at the early stages but it is rather centralized nowadays. It happened within a few years thanks to ASIC miners and pools.