Blockchain – Resolving Conflicts
Blockchain is a decentralized system that allows trade (such as Bitcoin transactions) amongst a network of peers. Here, trade is any form of transaction which involves a sender, a receiver, and a currency. But before coming to this aspect, let us first understand the concept of Bitcoin.
What Is Bitcoin?
Bitcoin is essentially a virtual or digital currency that can be traded or exchanged between two peers without involving a third party. In recent years, Blockchain has seen significant growth in various fields such as Medical, Defence, and Finance. There are many Indian YouTubers who, through their channels are promoting cryptocurrency for companies like CoinDCX, which is India’s first Cryptocurrency exchange company where one can buy and sell not just Bitcoin but other cryptocurrencies like Ethereum, Dogecoin, etc.
How Does Blockchain Operate?
Imagine a situation, where two people Steve and Jake want to communicate with each other. Steve sends a confidential message to Jake. While sending, there are chances that a data snooper could easily steal the OTP sent by Steve and use it for malicious purposes as shown in the picture below.
Now let us say Steve and Jake come to know about an advanced network called Blockchain and decide to communicate in this network.
It can be observed that in communication through a blockchain network, the data snooper is unable to decrypt the message.
Now you might be wondering if the data snooper cannot decrypt the message clearly there is something unique that allows only Jake to read the message. It is nothing but a private key which can be further explained through a concept called Public-key cryptography or Asymmetric key cryptography, which is actively used in Blockchain.
In a network, to secure communication between two people, the concept of Asymmetric cryptography was established where you use one key, which is called a public key for encryption, and a different key called a private key for decryption. Here, the public key is made public in the network whereas the private key is known only to the person who owns it. The private key is also referred to as a secret key.
Rule – One can encrypt a piece of data with a public key, but the decryption can be done only with its corresponding private key.
So, coming back to the question of how Jake decrypts the message that Steve has sent. Before sending the message, Steve encrypts the message with Jake’s public key, so that the message can be opened by Jake’s private key which is known only to Jake, making it impossible for any third party like a data snooper to decrypt the message.
Thus, in this way, Blockchain uses cryptography to protect the messages that are sent between the users in a network. Blockchain does not only provide secure communication but also helps in securing financial transactions.
Let’s see how transactions take place in a Blockchain environment.
A blockchain is a dynamic record of information (transactions). These transactions are stored in a block. Just like a college has a database that contains information about its students, likewise, a blockchain is a database where it stores information or transactions in the form of ‘blocks’.
A block has mainly 3 components:
- Transaction: The Bitcoin blockchain stores the details of the transaction such as the sender (sender’s public key), receiver (receiver’s private key), and the number of coins to be sent.
- Hash: A Hash is used to identify a particular block and is unique for each block in the blockchain.
- Hash of the previous block: This is used to create links in blocks.
It is important to know that the first block of the blockchain is called the Genesis Block, which does not have a previous hash value since it is the first block of the chain.
How do these blocks containing transactions get added to the blockchain?
Bitcoin mining is the process of adding transaction records in the form of blocks to the blockchain and the nodes in the network that compete against each other to create a valid block and successfully add it to the blockchain are called miners.
Since the process of creating a valid block requires a lot of processing power, there is an incentive mechanism, in which the miners are rewarded for their work via the Proof-of-Work (PoW) algorithm. The PoW algorithm is a consensus algorithm that is adopted in the blockchain network where the miners have to solve complex puzzles (which require a lot of processing power) and then they are paid in bitcoins for creating a valid block and successfully adding it to the blockchain.
The process of adding blocks (transactions) to the blockchain can be understood with the following diagram and its corresponding steps.
The steps involved in a Bitcoin Transaction are given below:
- Jake initiates a transaction of say 15 BTC that needs to be transferred to Steve.
- A block consisting of the transaction is flooded throughout the P2P network.
- The miners validate the transaction via the proof-of-work consensus algorithm
- An incentive is given for the miners who successfully create a valid block.
- The new block consisting of the transaction gets added to the blockchain.
- Steve receives the 15 BTC that was sent by Jake thereby completing the transaction.
Here is the interesting part and the topic that we have been waiting to address. From the above-given steps, step 5, a conflict can arise where multiple miners create blocks at the same time and try to add them to the last valid block of the blockchain. In this case which block will be appended to the blockchain?
Consider Steve, Jake and Iris are miners in the blockchain and they simultaneously create their respective blocks which are known as candidate blocks (portrayed in green, yellow, and blue respectively). Out of these candidate blocks, a decision has to be made to choose which of these blocks should be put in the chain.
How Does Blockchain Help Resolve Conflicts?
This conflict is resolved using the longest chain rule which is adopted by every node in the network to achieve consensus on the valid structure of the blockchain. To add a node in the blockchain, a miner in the network needs to have a computer with high processing power. In this case, let us say Jake’s computer has more processing power as compared to the computers of Steve and Iris. So, Jake can create a block faster than Steve and Iris.
Meanwhile, other miners are trying to create other valid blocks, so these blocks are created on the block which has occurred first, and since Jake’s block was created faster than Steve’s and Iris’s, it occurs first in the chain and the miners add their blocks (given below in red ) on top of Jake’s blog (given below in yellow).
It can be seen from the above diagram that the unit with Jake’s block is the longest unit and according to the longest chain rule, the unit with the longest length must be accepted as the valid version of the blockchain. Therefore, the updated valid version of the blockchain looks like the one below:
What Happens To The Blocks Created By Steve And Iris?
The blocks created by Steve and Iris are discarded and they become orphan blocks since they are not part of the main chain of blocks anymore.
What Happens To The Transactions Inside These Orphaned Blocks?
It is important to note that the transactions inside these orphan blocks are valid because someone in the network has initiated it, but cannot be included in the blockchain as they do not follow the longest chain rule. So, these transactions are sent back to the transaction pool (which contains those transactions that are not yet mined), where the miners can pick them from the pool and then start mining them again.