Mansplainings

Mining in blockchain

We looked at Merkle proof in the previous article and that concluded our discussions on blocks and their structure. In this article, we shall look at the process of mining in detail.

There are two main types of nodes that participate in a blockchain network, namely miners and transacting parties. Transacting parties, as the name implies, join the blockchain network to perform transactions using software clients called wallets. Since mining blocks is a CPU-intensive task, the transacting parties don’t engage in mining blocks.

Mempool

Instead, dedicated miners join the network specifically for the task of mining blocks. Once we complete a transaction and broadcast it to the network, miners in the network receive the broadcast transaction and try to verify it. If the transaction can be verified, then miners will add the transaction to a database called mempool.

Mempool consists of all the verified, but not yet confirmed, transactions. A confirmed transaction is a transaction that is a part of a mined block. Miners pick transactions from this mempool and add them to the block they are trying to mine. The transaction fee determines the priority given to a transaction.

Transaction fee

The higher the transaction fee, the higher the priority given to a transaction, and thus the quicker a miner will confirm the transaction. The transaction fee is the difference between the input money and the output money and the transacting party gets to decide the amount. For instance, if the input is 20 Bitcoins, and the output is 19 Bitcoins, 20 – 19 = 1 Bitcoin becomes the transaction fee.

In addition to the transaction fee, the size of the transaction also plays a part. If a transaction has many inputs and outputs, the data carried by that transaction will be high resulting in a larger size. Since blocks have a limited size, miners prefer smaller transactions. So, bigger transactions will have to provide a higher transaction fee in order to have their transactions confirmed faster.

After picking the transactions and adding them to their block, miners try to mine the block. As we saw in earlier articles, mining is the process of trying to produce a block with a hash value less than that of the specified target hash value.

This is a hit-or-miss process and miners have to keep on producing hashes until they get the right hash. When a miner manages to find the right hash, we say the miner has mined a block. When more miners join the network, a miner’s probability of mining the next block decreases.

Probability of mining a block

The probability of a miner mining the next block is the miner’s hash rate over the total hash rate of the entire network. The hash rate is the number of hashes a miner can produce per second. This is dependent on the CPU speed. A powerful CPU will give a higher hash rate.

If a miner’s hash rate is 30 hashes per second and the total hash rate of the network is 100 hashes per second, then this miner has a probability of 30/100 of mining the next block. Suppose two new miners join the network and the total hash rate increases to 200. The probability of the above miner mining the next block will fall to 15/100.

However, when the total hash rate of the network goes up, the rate of mining blocks also goes up. To keep the average time taken to mine a block constant, the difficulty of mining would be increased as we saw in a previous article. Consequently, blocks would be mined at the same rate whereas the hashes produced to mine a block keep on increasing with the total hash rate.

By now, it’s natural for anyone to wonder why anyone would want to mine a block. What’s the incentive? Why would anyone invest so much energy into it? The makers of blockchain did think about this question of economics. And their answer is to reward mining a block with Bitcoins! Yes, a miner gets 12.5 Bitcoins for mining a block.

Reward for mining

But how do they receive Bitcoins? We have seen that every transaction should have at least one input and that every input should be an output of a previous transaction. This means, if someone is to receive Bitcoins, someone should send Bitcoins to them. So, who is going to send Bitcoins to the miners? Well, no one. Bitcoins are actually created to pay the miners for mining a block. And this remains the only way to create Bitcoins.

In fact, mining got its name because it produces Bitcoins. Mining is a term used to describe the process of extracting gold. During the time of the gold standard, to produce new money, people had to mine gold. Thus, mining is used to describe the production of new Bitcoins.

So, how do we create Bitcoins? When a miner creates a block, the first transaction is addressed to the miner themself with no inputs. We call this a coinbase transaction. This is the only transaction that can have no inputs. If the miner manages to mine this block, then the coinbase transaction becomes confirmed and the miner gets their reward.

At the time of writing, a Bitcoin sells for 23, 455 USD, and hence, it is understandable why people want to engage in mining blocks. The incentive is so big that miners invest in expensive mining rigs to mine blocks. Even though miners used CPUs initially, nowadays, they use GPUs as they provide a higher hash rate owing to the higher number of cores they possess.

Mining pools

However, as cryptocurrencies boomed, more miners started engaging in mining. This resulted in the total hash rate of blockchain networks increasing profusely. Consequently, the probability of an individual miner mining a block went down drastically so much so the cost of running the mining rigs outweighed the reward.  To counter this, now, groups of miners work together to mine blocks. We call these groups mining pools.

These mining pools pool their hash rates together to increase their collective hash rates. For example, if 100 miners with a hash rate of 30 form a pool, then the total hash rate of the pool becomes 3000. When the pool mines a block, the pool members share their reward among themselves proportional to their hash rate. This gives miners a better chance of making money.

In this article, we looked at the process of mining and how hash rates determine the probability of a miner mining a block. In the upcoming articles, we shall look at how double-spend attacks can be carried out by possessing more than 50% of the total hash rate of the network.

Theviyanthan Krishnamohan

Tech geek, cricket fan, failing 'writer', attempted coder, and politically incorrect.

View Comments

Recent Posts

Multitask Knowledge Transfer in Genetic Algorithms

The previous article discussed transferring knowledge from one completed problem to a new problem. However,…

7 months ago

A primer on Memetic Automatons

Memetic automatons leverage knowledge gained from solving previous problems to solve new optimization problems faster…

8 months ago

Data-driven meme selection

This article discusses how we can use data to automatically select the best meme from…

9 months ago

An introduction to memetic computation

Memetic computation is an extension of evolutionary computation that combines the use of memes and…

10 months ago

An introduction to evolutionary algorithms for dummies

Evolutionary algorithms are heuristic search and optimization algorithms that imitate the natural evolutionary process. This…

11 months ago

Running multiple containers within virtual hosts in Mininet

Mininet is a popular network emulator that allows us to create virtual networks using virtual…

12 months ago