In a previous post about consensus mechanism, I gave a quick introduction to proof of work. Proof of work is the consensus mechanism implemented in many blockchain projects.
Proof of work is used to secure the Bitcoin network. The computers involved in the proof of work process are called miners. In this post, I would like to explain in details how this consensus mechanism works for Bitcoin and how it’s implemented.
The proof of work algorithm
In order to explain how blockchain works and how mining is applied to add blocks to the blockchain, I will provide detailed drawings with clear explanations.
The blockchain is a data structure. This data structure contains blocks that are cryptographically linked together using hash functions.
The block in the blockchain contains 4 components. The ID of the block. The nonce which is a random number. The list of BTC transactions. And the hash of the previous block. The following drawing gives a few more details about this concept.
The Mining Process
In the following drawing, I show how the mining process works.
This structure is what gives the network its security and immutability. Because any change in the chain will break the links and one has to re-mine everything from the block that has been modified until the end of the chain. That’s a lot of computing power and it’s very expensive to do.
Additionally, Miners are incentivized to play by the rules with block rewards and transactions fees.
There are 21 million bitcoins in total that will ever be mined. And the block rewards halve every 210000 blocks. The block interval which is the time interval between two blocks is 10 minutes. The target is adjusted and the difficulty is increased the more miners join the network in order to keep the block interval at 10 minutes. If more miners leave, the difficulty decreases to keep the 10 minutes interval.
Since the network is decentralized, every time a block is added to the blockchain, the new block has to be broadcast to the other nodes. So It’s necessary to have a long enough block interval in order to leave time for all the nodes to update their version of the blockchain.
Wa can understand from this post, how the network is secured. Mining is an important part of the ecosystem and it’s what keeps everything together.