You are currently viewing What it means to mine cryptocurrencies and how the mining process works

What does it mean to mine cryptocurrencies and how the mining process works

Reading time: 3 minutes

Mining cryptocurrencies, also called mining of cryptocurrencies, is that process in which transactions between users are verified and added to the register, to that huge, completely public ledger, which is the blockchain.

Il mining process is one of the key elements that allow

  • cryptocurrencies to function as a peer-to-peer decentralized network, without the need for a third central authority
  • to new cryptocurrencies to be born

Bitcoin is the most popular and established example of a mineable cryptocurrency, and the Bitcoin mining is based on a consensus algorithm called Proof of Work.

And not all cryptocurrencies are mineable. Now let's try to understand, from a technical point of view, what it means to mine cryptocurrencies and how the mining process works.

What happens during the mining process?

A miner is a node in the network which collects transactions and organizes them into blocks.

Whenever transactions are made, everyone the nodes of the network they receive them and verify their validity. The very efficient miner nodes then collect these transactions from the memory pool and start assembling them into a block (this is what is called the candidate block).

The first thing the miner node does is to add a transaction where you send the mining reward (block reward), and then start mining: the first thing that happens to the block when it is mined is that they come hashate individually each of the transactions taken from the memory pool. The transaction with which the miner is rewarded is called coinbase transaction, and it's a transaction where coins are created "out of thin air". In most cases, the coinbase transaction is the first transaction to be recorded in a new block.

Organization in the Merkle Tree

As soon as each transaction has been analyzed, the hashes are organized into a Merkle Tree, which is formed by matching the hashes of the two-by-two transactions and analyzing them. The outputs are then organized into other pairs and subjected to a further hash, and so on again and again, until they reach the “top of the tree”. The top of the tree is also called roothash (or Merkle root) and is basically a single hash representing all the previous hashes that were used to generate it.

The root hash along with the hash of the previous block and a random number called nuncio it is then inserted in the block header. The block header is then hashed producing an output based on these elements (hash of the root, hash of the previous block and nonce) plus some other parameters. The resulting output is the hash of the block and will serve as the identifier of the newly generated block (candidate block).
To be considered valid, the output (hash of the block) must be less than a certain target value which is determined by the protocol: the hash of the block must start with a certain number of zeros.

Hashing difficulty

Il target value - also known as hashing difficulty (hashing difficulty) - is regularly adjusted by the protocol, ensuring that the rate of creation of new blocks remains constant and proportional to the amount of hashing power dedicated to the network.

Each time new miners join the network and the competition increases the hashing difficulty will increase, preventing the average block time from decreasing. Conversely, if miners decide to leave the network, the hashing difficulty will drop, keeping the block time constant even if there is less computing power dedicated to the network.

The mining process requires miners to keep hashing the block header over and over, iterating through the nonce until a network miner finally produces a valid block hash. When a valid hash is found the founder node transmits the block to the network. All other nodes will check if the hash is valid and if so, they will add the block into their copy of the blockchain and move on to extracting the next block.
It has already happened and sometimes it happens that two miners transmit a valid block at the same time, and the network found itself with two competing blocks. The miners start mining the next block based on the block they received first. Competition between these blocks will continue until the next block is extracted based on one of the competing blocks. The block that is dropped is called a orphan block o stale block. The miners in this block will return to mine the winning block chain.

Pool of miners

While the block reward is granted to the miner who first discovers the valid hash, the probability of finding the hash is governed by a simple formula: it is equal to the portion of total extraction power on the network. Miners with a small percentage of the mining power have a very small chance of discovering the next block on their own. THE mining pool are created to solve this problem. It means pooling the resources of miners, who share their processing power over a network, to divide the reward equally among all members of the pool, based on the amount of work they contribute to the likelihood of finding a block.