How does it work?
The first step of mining a block is to individually hash each transaction taken from the memory pool, but before starting the process, the miner node adds a transaction where they send themselves the mining reward (block reward). This transaction is referred to as the coinbase transaction, which is a transaction where coins get created ‘out of thin air’ and, in most cases, is the first transaction to be recorded in a new block.
In order to be considered valid, the output (block hash) must be less than a certain target value that is determined by the protocol. In other words, the block hash must start with a certain number of zeros.
The target value - also known as the hashing difficulty - is regularly adjusted by the protocol, ensuring that the rate at which new blocks are created remains constant and proportional to the amount of hashing power devoted to the network.
Therefore, every time new miners join the network and competition increases, the hashing difficulty will raise, preventing the average block time from decreasing. In contrast, if miners decide to leave the network, the hashing difficulty will go down, keeping the block time constant even though there is less computational power dedicated to the network.
However, it sometimes happens that two miners broadcast a valid block at the same time and the network ends up with two competing blocks. Miners start to mine the next block based on the block they received first. The competition between these blocks will continue until the next block is mined based on either one of the competing blocks. The block that gets abandoned is called an orphan block or a stale block. The miners of this block will switch back to mining the chain of the winner block.
While the block reward is granted to the miner who discovers the valid hash first, the probability of finding the hash is equal to the portion of the total mining power on the network. Miners with a small percentage of the mining power stand a very small chance of discovering the next block on their own. Mining pools are created to solve this problem. It means pooling of resources by miners, who share their processing power over a network, to split the reward equally among everyone in the pool, according to the amount of work they contribute to the probability of finding a block.
Stay tuned for more content and don’t forget to check our other videos at Binance Academy!