#Issue 4: Blockchain Consensus Mechanisms and Mining
Hello folks!
With a hiatus of 1 week, we are back! Hope everyone is safe and having a good time.
Till now, we covered some concepts key to how blockchain works - decentralization, cryptography, and hashing. Today we take a dive into Blockchain consensus mechanisms and Mining. Grab a cup of hot chai or coffee and hop on!
What do we mean by Consensus?
Consensus is a dynamic way of reaching an agreement in a group. While democratic voting just settles for a majority rule without any thought for the feelings and well-being of the minority, a consensus on the other hand makes sure that an agreement is reached which could benefit the entire group as a whole.
A consensus algorithm is a procedure through which all the peers of the Blockchain network reach a common agreement about the present state of the Blockchain ledger. In this way, consensus algorithms achieve reliability in the Blockchain network and establish trust between unknown peers(nodes) in a distributed computing environment. Essentially, the consensus mechanism makes sure that every new block that is added to the Blockchain is the one and only version of the truth that is agreed upon by all the nodes in the Blockchain.
Why should Blockchain have Consensus Mechanisms?
As discussed in length in earlier issues, blockchain is a decentralized peer-to-peer system with no central authority figure. Each node in the network validates all transactions and blocks. In effect, each node checks what the other nodes in the network are doing.
While we take away the concentration of power and decision making from a centralized network, this decentralization gives us 2 major problems to solve:
Who would take any decision in the network?
How does one take that decision?
We would try to answer the above questions subsequently.
Think of a normal centralized system - a cricket team or even a company. All the decisions are taken by the captain or the CEO of the company. In case of computer networks, decision making authority lies with the central node.
But this isn’t possible in a decentralized blockchain network because a blockchain has no “leader”. For the blockchain to make decisions, they need to come to a consensus using “consensus mechanisms”. It’s this reason blockchain consensus mechanisms are so essential— the network needs to come to agreement on which transactions to approve and which to deny.
Objective of Blockchain Consensus Mechanisms
The primary function of blockchain consensus mechanisms is to take decisions and provide security to the network. In particular, blockchain consensus mechanisms must overcome 2 core challenges:
Byzantine Generals Problem
Prevent double spending of the network’s currency
Let’s examine each of these objectives:
Byzantine’s General Problem
We all need a Gabbar in our lives to make it interesting!
In an ideal scenario, we can imagine that all nodes are honest, and share complete and truthful information in blocks. But, as a matter of fact, some of the nodes in a blockchain’s network may be dishonest. But, the honest nodes should come to an agreement for the benefit of the network despite the presence of dishonest nodes.
In the world of computer networks, this is what’s known as the ‘Byzantine General’s Problem’.
The concept of the Byzantine Generals Problem was first introduced in 1982. The authors of the essay state the problem as follows:
“[A] group of generals of the Byzantine army [are] camped with their troops around an enemy city. Communicating only by messenger, the generals must agree upon a common battle plan. However, one or more of them may be traitors who will try to confuse the others. The problem is to find an algorithm to ensure that the loyal generals will reach agreement.”
In the analogy, the Byzantine Generals represent the nodes in a decentralized peer to peer network and the messengers would be the packets of information the nodes are sending to one another across the network. There may be traitors among the generals— malicious nodes in the network— so it’s crucial that the honest generals can come to consensus on which battle strategy to pursue, in spite of this uncertainty. Further, it’s essential that each general is confident that each of his peers will be following through with the same plan that he is.
Applying this concept to Blockchains, a majority of nodes on a network have to agree upon the legitimacy of submitted transactions, data, and the state of the network.
Prevent Double Spending
The double spending problem is common to blockchains supporting crypto-currencies. It refers to the same person using the same digital currency from the same wallet multiple times.
To give an example, I spend $10 to buy a coffee. With double spending, I would use the same $10 bill to buy a sandwich and a pastry. This is easily possible with crypto-currencies because digital information can easily be replicated and manipulated by people understanding the concepts behind them.
Double spending is typically made possible as a result of gaining >50% consensus in a network - wherein the malicious nodes can gain control of a majority of a network’s computing power. In Blockchain terms, this is referred to as 51% attack. But, with various solutions and approaches, blockchain consensus mechanisms secure a decentralized network against double spending.
Most Popular Blockchain Consensus Mechanisms:
Now, to answer our earlier questions: “Who would take a decision in a blockchain network and how”, we list down some of the popular consensus mechanisms used today:
Proof of Work (PoW)
Proof of Stake (PoS)
Delegated Proof of Stake (DPoS)
We would just discuss Proof of work in this issue.
Proof of Work:
This consensus mechanism is most popular as it is used to run Bitcoin - the first and the most popular cryptocurrency in use today. The ‘Work’ in '“Proof of Work” refers to a process called as Mining (like mining of gold or other precious metals - in this case mining blocks). Mining is the “work” itself. In order to add blocks to a blockchain or simply put - ‘Mine blocks’, one needs to solve a mathematical problem.
Oh God! I hate mathematics - why does everything has to deal with Mathematics?
Be rest assured, its nothing to do with mathematics but more to do with winning a lottery. Just that, one needs a huge amount of computing power (RAM’s, CPU’s, memory) to solve the lottery. Once a blockchain node solves the lottery puzzle, it broadcasts the result to the other nodes. The other nodes verify whether the answer for the puzzle is correct, and publish the new block in the blockchain.
But what is there for the miners to mine the blocks? To reframe the question, what would be the possible incentives for the ‘miners’ (those who mine blocks)?
For each block mined, the blockchain rewards the miner with the cryptocurrency of the underlying blockchain. And this economic incentive itself helps to achieve the consensus in the completely decentralized network. The miner needs to utilize computing power to mine blocks - which requires huge amount of hardware resources, electricity and time. If it plays by the rules, i.e according to the consensus mechanism, he / she receives the reward. If the miner tries to manipulate data or double-spend, he / she would not receive any reward and just waste resources.
Quick fact : Miners received around $7bn worth of bitcoin in 2020!
Can I become a Miner?
Anyone can apply to become a blockchain miner. These blockchain miners install and run a special blockchain mining software that enables their computers to communicate securely with one another. Once a computer installs the software, joins the network, and begins mining bitcoins, it becomes what is called a ‘node.’ Together, all these nodes communicate with one another and process transactions to add new blocks to the Blockchain which is commonly known as the bitcoin network.
Functions of Blockchain Mining
1. Validating Transactions
Transactions take place in huge figures everyday. With each transaction, new blocks are added to the blockchain in the network and the validation lies in the mining results from the blockchain miners.
2. Confirming Transactions
Miners work the blockchain mining process to confirm whether the transaction is authentic or not. All confirmed transactions are then included in the blockchain.
3. Securing Network
To secure the transaction network, bitcoin miners work together. With more users mining the blockchain, the blockchain network security increases. Network security ensures that there are no fraudulent activities happening with cryptocurrencies.
So just to summarize:
Who would take a decision in a blockchain? The miner who solves the puzzle correctly in the least period of time
How is the decision made? Other miners on the blockchain verify and come to the consensus to add the block
We are suckers for validation. That’s our entire motivation. So help us get more balls and eyeballs. Balls, so that we can write more of these, eyeballs so that you can share these insights with more peeps!
Send this on WhatsApp. Share it on Twitter and Instagram.
Follow me (CJ) on Twitter. Find me (AK) on LinkedIn.
You can just forward this email as well. Duh!
And Do whatever you want to do, man!