What is a Consensus Algorithm?

code-block

5 min

code-block

5 min

This week we’re covering a pretty complex topic with lots of info, so let’s jump right in.

Node operators are incentivized to run nodes on a blockchain that perform the computer work necessary to maintain a distributed ledger and to update it with every new transaction. But how do you ensure that every node updates the blockchain with the CORRECT block of information? A majority of nodes must agree on the update to the blockchain - that’s called consensus.

A consensus algorithm is a group of mathematical formulas or rules written in computer code and designed to solve a very specific problem: how to reach a general agreement among blockchain nodes to approve the addition of a new block to the chain.

The concept of consensus is vital to a distributed ledger because reaching consensus on each block serves as a defensive measure against those nodes with bad intentions and/or those that are unreliable nodes (security threats). A balance exists between security and adding blocks (groups of transactions) to a chain quickly (for example, NASDAQ can process 10,000 transactions per second!). There are lots of different solutions based on whether the priority is speed or security. These solutions are different types of Consensus Algorithms.

It’s tough to have a conversation about blockchain without mentioning Bitcoin, so it makes sense to start with Bitcoin’s consensus algorithm - Proof of Work (PoW).  PoW is an example of a consensus algorithm that favors security over speed. Node operators on the Bitcoin blockchain are called miners. What if one of these miners wants to add a block of information that gives them a bunch of Bitcoin?

Bitcoin blockchain uses an elegant and complicated solution.

First, every new block of information generates a mathematical problem for all the miners using a hash function (we’ll cover this in the future). This problem is similar to guessing a completely random number when you only know how many digits it contains. Miners use their computers to generate random numbers very quickly in the hopes of being the first miner to guess the random number and win Bitcoin. This process is called mining hence why the nodes are miners.

Here’s where PoW becomes interesting.  Other miners must verify every new block of information added to the chain. It is VERY easy for miners to identify an incorrect block of information because of how blockchains fit together and continue a pattern. A new block can ignore the results of a previous block if it believes it to be incorrect (known as forking, we'll come to this later too). To introduce an incorrect block, a malicious miner must know in advance that they have the support of at least 50% of the other miners over a significant period of time. Because mining is costly (hardware, electricity, and so on), the cost of doing this is exceptionally high compared to the potential upside of a malicious transaction.

Join us next week when we discuss the Proof of Stake consensus algorithm!