Mining, in the scope of blockchain technology, is the process of adding new blocks of data to the distributed public ledger of existing transactions, or the blockchain.
The people who run mining operations on their computers are awarded for their work with crypto coins.
Mining serves two main purposes.
First, new units of the cryptocurrency are generated at a controlled pace, and second, and most important, the transactions are validated. In the decentralized cryptocurrency blockchain trust is a must.
Validation is key to the functioning of the system.
In the process of mining, the data is encoded using strong encryption and then distributed over the entire network. Each computer keeps an updated copy of the blockchain. The computers (or nodes) communicate using a software protocol that checks for consistency.
If someone tries to manipulate the data in a block, the other nodes would reject the change, in accordance with the consensus protocol.
This is a procedure through which all nodes reach a common agreement about the present state of the distributed ledger. The purpose is to make sure that the new block that is added is the one and only version of the containing data. Mining is employed in many blockchain technologies, but the term is widely associated with Bitcoin.
When a Bitcoin is sent from one address to another, the transaction is taken by the nodes for a checkup. It is compared to previous transactions associated with these addresses, the purpose being to prevent double spending.
Every existing Bitcoin is unique, so it can be identified, and its history can be tracked.
The verification process encrypts the data using an algorithm that produces a number, called a “hash” and compiles it in a new block.
A hash value from the previous block must also be included in the block-to-be in order to link them securely in the blockchain. Then miners need to solve a complex mathematical problem called “Proof of work” (PoW), which is difficult, time-consuming and costly (hardware, energy).
The way the system works, a block is mined once every 10 minutes on average.
This speed is automatically controlled so that the blockchain develops in a predictable fashion. If too many miners join the network, meaning the mining speed increases, a number called “target value” decreases. This increases the mining difficulty, thus reducing the mining speed.
The target value is adjusted once every 2016 blocks, or about once every 2 weeks and is a part of the mathematical problem that miners solve in the Proof of work system.
To solve the complex puzzle, a number (generated using SHA-256) must be found. In short, a nonce is added to the hash of the new block and the header of the latest block of the blockchain. The resulting number must be lower than the target value. If it is not, the computation starts again, using an incremented number for a nonce.
The solution to the puzzle is difficult to find but easy to verify (you compare the target value and the solution value). Once the solution is found, the new block is added to the chain and propagated to the network.
There are other consensus algorithms used with other cryptocurrencies blockchain networks.
Ethereum, for example, has shifted from PoW to PoS (Proof of Stake). In this type of algorithm, miners invest coins instead of buying expensive hardware. These coins are locked up as a stake, giving them the right to mine the blocks. Other protocols include the Proof of Burn, Proof of Capacity, Proof of Elapsed Time, etc.
The decentralized nature of blockchains needs the participants to be able to come to an agreement as to the shared state of the blockchain.
Unanimous consensus amongst the network nodes results in a single blockchain containing verified data (transactions) that the network asserts to be correct. There are times, however, when the nodes in the network can’t reach a unanimous consensus. In such a case more than one valid chain forms.
These are known as “blockchain forks”.
There are three types of blockchain forks: Soft Fork, Hard Fork and Temporary Fork. The first two occur after a software update. The Soft Fork would allow the use of both new and old protocols, while the Hard Fork would mean the new rules are mandatory for all nodes.
When a block is mined by more than one miner (or a group of miners) at approximately the same time, which would result in two or more valid blocks with identical data and height, the network may not agree on the same block. This is eventually resolved when more nodes choose one of the blocks, leading to the other chains to die out. This is the Temporary Fork.
When the new block is added to the blockchain the miner is awarded a certain number of Bitcoins (plus the fees that the users sending the transactions have paid). This is the only way new coins are generated. The size of the reward is determined through a schedule set by Satoshi Nakamoto, meaning there will be a finite amount of coins, 21 million, calculated to be reached by 2140.