Consensus and Mining on the Blockchain - https://blockgeeks.com/
What is consensus on the blockchain? Consensus basically means that all nodes in a decentralized network must come to an agreement on what is the truth. For bitcoin, all nodes must agree on the transaction history. In a centralized system, all the participants trust that the authority will behave honestly and share the truth with the rest of the members. Since only the trusted party has the power to modify the data, it is straightforward to achieve consensus. Everyone simply accepts and believes what the central authority says. For example, you simply trust your bank will put the correct balance for your account whenever you send and receive money. However, in a decentralized network, there is no central authority and each node does not trust any other nodes. The challenge is how can all the nodes agree on what is the correct state of the shared data? In other words, how can they all achieve consensus with mutual distrust? In computer science, this is known as the Byzantine Generals’ problem, which was originally presented in 1982.
The Byzantine Generals’ problem is a description of consensus problems in computer networks. More specifically, how can distributed computer systems handle malfunctioning parts that give conflicting information to different parts of the system? This problem is abstractly described as a group of generals of the Byzantine army camped with their troops surrounding an enemy city. The generals must agree upon a common battle plan and they can only communicate with each other using messengers. However, one or more of the generals may be traitors who will try to confuse the others. The problem is to find an algorithm that ensures the loyal generals will all reach an agreement on the battle plan regardless of what the traitors do.
In the case of bitcoin, each general could be thought of as a node in the network and all the honest nodes must agree on what is the true history of transactions. A malicious node can send conflicting transactions to different parts of the network. For example, Bob is a traitor and he sends a transaction stating he sent 10 bitcoins to Alice to one part of the network while sending another transaction stating he sent 10 bitcoins to Carroll to other parts of the network. Let’s assume that Bob only has 10 bitcoins in total, so he is trying to double spend his bitcoins. So what algorithm can be used in the bitcoin network to ensure all the honest nodes recognize Bob sent 10 bitcoins to Alice but reject that he sent 10 bitcoins to Carroll?
Bitcoin uses the proof-of-work (PoW) algorithm to ensure all the honest nodes reach a consensus on the true history of transactions. The PoW algorithm concept was first developed in the early 90s to prevent email spamming. It required computers that want to send an email to do some computation work which took some time to complete before sending out the email. This reduced the amount of spam an email server could get in a given period of time. In bitcoin, PoW is used to govern the mechanics of how a new block is added to the blockchain. In the previous lesson, we learned that blockchain is append-only and once a block is added, it cannot be modified. Therefore, we need to ensure that all the honest nodes in the system will add the exact same block to their local copy of the blockchain to achieve consensus.
So how does PoW achieve this? First, let’s imagine that all the nodes in the network are allowed to create a new block at anytime instantly. If this were the case, the network would get flooded with too many new blocks, and no one would be able to agree on which of the new blocks should be added to the blockchain.
However, in reality, in order for a node to create a new block and broadcast that to the other nodes, it must do some computation work. The computation work is quite intensive and for bitcoin it takes roughly 10 minutes on average for any node to complete. Once a node completes this work, it broadcasts the block to other nodes who verify it. Therefore, all the nodes in the network that want to create a new block must race against each other to be the first one to complete this computation and broadcast their block. This way all the other honest nodes will receive the new block and verify that the proof of work was valid and the transactions inside the block are also correct and then add the block to their local copy of the blockchain.
To read more, visit us at https://blockgeeks.com/