Cryptocurrency mining is one of the key elements that allow cryptocurrencies to work as a peer-to-peer decentralized network without the need of a third party central authority.
It is a process in which transactions between users are verified and added into the blockchain public ledger and also a process that is used to introduce new coins into the existing circulating supply.
A miner is a node in the network who collects transactions and works to organize them into blocks. Whenever transactions are made, miner nodes receive and verify the transactions, add them to the memory pool and begin assembling them into a block of multiple transactions.
The first step in a process of mining a block is to hash each transaction in the memory pool.
Before starting the process, the miner node adds a transaction where they send themselves the mining reward. This transaction is referred to as the “coinbase” transaction, it’s a transaction where coins get created ‘out of thin air’ and in most cases is the first transaction in a new block.
After every transaction is hashed, these hashes are then organized into something called a Merkle Tree or a hash tree meaning that the hashes are organized into pairs and then hashed again until “the top of the tree” is reached, also called a root hash or a Merkle root.
The root hash along with the hash of the previous block and a random number called a nonce is then placed into the block's header. The blocks header is then hashed producing an output that will serve as the blocks identifier.
The blocks identifier must be less than a certain target value that is set by the protocol. In other words, the block header hash must start with a certain number of zeros.
This target value, also known as the hashing difficulty, scales, ensuring that the rate at which new blocks are created remains proportionate to the amount of hashing power in the network.
The miners keep hashing the header over and over again by iterating through the nonce until one miner in the network eventually produces a valid hash. When a valid hash is found, the founder node will broadcast the block to the network. All other nodes will check if the hash is valid and add the block into their copy of the blockchain and move on to mining a next block.
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!