What are the consensus algorithms in blockchains?

How is the common state for all the nodes in the blockchain achieved?

Vishesh Dhawan
Vishesh Dhawan
April 3, 2022
consensus algorithms

    Share

As we all know that blockchain is a distributed, decentralized and immutable shared ledger of transactions, with nodes spanning across the globe. All the nodes also contain an entire copy of the blockchain on which they perform their operations. These nodes may also suggest different solutions for the new block to be added.

We also know that blockchains also maintain a common state(a common chain of blocks) for all the nodes.

In this scenario, a question that arises is - With the network of millions of globally distributed nodes, each one performing its operations at different time intervals, how does the blockchain network ensure a common state for all these nodes?

This problem is handled by the Consensus Algorithm used by the blockchain.

What exactly are consensus algorithms?

A consensus algorithm is a fault-tolerant procedure used in blockchains, through which all the nodes achieve an agreement for the common present state of the blockchain network.

Consensus algorithms maintain integrity and security in the network. They also help to establish trust among peers in a trustless environment.

They also make sure that any new block being added to the chain during the minting process is the same block being adopted by all the nodes in the network and thus maintaining a single source of truth agreed upon by all the nodes.

Now that we know what consensus algorithms are and what is their role.. let us find out what will happen if no consensus algorithm is used in a blockchain.

What will happen if no consensus algorithm is used?

  • During the minting process, when the nodes make changes to the local copy of the blockchain maintained by them, there will be no communication among their peers.
  • Due to this different nodes will adopt a different version of the new block possibly with different transactional data.
  • This will lead to the formation of many versions of the same blockchain each being different from one others.
  • Due to the formation of these parallel chains, the same address can hold different values in different chains.
  • E.g., let us consider a wallet address that had 5 Bitcoin initially, then spends 3 bitcoins. Now it owns 2 bitcoins on the network that recorded this change, while it may still hold 5 bitcoins on the version of the chain that couldn't record this change. It will give rise to security issues and double-spending problems.
  • Therefore, no single source of truth will exist and the integrity of the blockchain will be broken.

A deep dive into 2 most popular consensus algorithms

There are many standard consensus algorithms used by different blockchains. Blockchain projects sometimes also come up with their own invented algorithm. These algorithms have different working mechanisms and principles but ultimately a common goal.

Proof of Work

Proof-of-Work (PoW) is the oldest consensus algorithm developed by the pseudonymous identity "Satoshi Nakamoto" who is also regarded as the inventor of the Bitcoin blockchain. Proof-of-work is used by some popular blockchain networks such as bitcoin and ethereum.

In PoW algorithm all the nodes compete against each other to find a solution for a complex mathematical problem, the node that solves the problem first eventually adds the block to the blockchain and earn the reward. 

It is the most energy-consuming algorithm because all the power consumed by the rest of the nodes to find the solution is actually wasted.

Proof of Work in depth -

Proof of Stake

Proof-of-Stake (PoS) is a low energy consuming algorithm. It is much more efficient that proof-of-work algorithm. Here, a validator is randomly chosen on the basis of amount of virtual currencies hoarded by the node. Therefore, the nodes that owns more currency has higher probability of receiving the validator responsibility and thus the reward.

This algorithm leads toward the centralization of power and promotes the holding of resources rather than spending.

The Ethereum 2.0 has adopted the PoS algorithm, discarding the PoW algorithm which is used in the previous version of the Ethereum blockchain, to reduce the wastage of electricity and natural resources.

Also ReadWe also know that blockchains also maintain a common state(a common chain of blocks) for all the nodes.

In this scenario, a question that arises is - With the network of millions of globally distributed nodes, each one performing its operations at different time intervals, how does the blockchain network ensure a common state for all these nodes?

This problem is handled by the Consensus Algorithm used by the blockchain.

What exactly are consensus algorithms?

A consensus algorithm is a fault-tolerant procedure used in blockchains, through which all the nodes achieve an agreement for the common present state of the blockchain network.

Consensus algorithms maintain integrity and security in the network. They also help to establish trust among peers in a trustless environment.

They also make sure that any new block being added to the chain during the minting process is the same block being adopted by all the nodes in the network and thus maintaining a single source of truth agreed upon by all the nodes.

Now that we know what consensus algorithms are and what is their role.. let us find out what will happen if no consensus algorithm is used in a blockchain.

What will happen if no consensus algorithm is used?

  • During the minting process, when the nodes make changes to the local copy of the blockchain maintained by them, there will be no communication among their peers.
  • Due to this different nodes will adopt a different version of the new block possibly with different transactional data.
  • This will lead to the formation of many versions of the same blockchain each being different from one others.
  • Due to the formation of these parallel chains, the same address can hold different values in different chains.
  • E.g., let us consider a wallet address that had 5 Bitcoin initially, then spends 3 bitcoins. Now it owns 2 bitcoins on the network that recorded this change, while it may still hold 5 bitcoins on the version of the chain that couldn't record this change. It will give rise to security issues and double-spending problems.
  • Therefore, no single source of truth will exist and the integrity of the blockchain will be broken.

A deep dive into 2 most popular consensus algorithms

There are many standard consensus algorithms used by different blockchains. Blockchain projects sometimes also come up with their own invented algorithm. These algorithms have different working mechanisms and principles but ultimately a common goal.

Proof of Work

Proof-of-Work (PoW) is the oldest consensus algorithm developed by the pseudonymous identity "Satoshi Nakamoto" who is also regarded as the inventor of the Bitcoin blockchain. Proof-of-work is used by some popular blockchain networks such as bitcoin and ethereum.

In PoW algorithm all the nodes compete against each other to find a solution for a complex mathematical problem, the node that solves the problem first eventually adds the block to the blockchain and earn the reward. 

It is the most energy-consuming algorithm because all the power consumed by the rest of the nodes to find the solution is actually wasted.

Proof of Work in depth -

Proof of Stake

Proof-of-Stake (PoS) is a low energy consuming algorithm. It is much more efficient than proof-of-work algorithm. Here, a validator is randomly chosen on the basis of the amount of virtual currencies hoarded by the node. Therefore, the nodes that own more currency have a higher probability of receiving the validator responsibility and thus the reward.

This algorithm leads toward the centralization of power and promotes the holding of resources rather than spending. Ethereum 2.0 has adopted the PoS algorithm, discarding the PoW algorithm which is used in the previous version of the Ethereum blockchain, to reduce the wastage of electricity and natural resources.