Successful Mining, Block Validation, Assembly and Selection

In this article, we understand what successful mining is, how blocks are validated and how chains are assembled and selected in Bitcoin.

Table of contents.

  1. Introduction.
  2. Successful Mining.
  3. Validating a Block.
  4. Chain Assembly and Selection.
  5. Summary
  6. References

Prerequisites.

  • Mining a Block

Introduction

Mining is the process of adding new blocks to the blockchain thereby extending the blockchain by one more block. A block is a collection of validated transactions. When a block is added to the blockchain, so are the transactions. Mining is intentionally a computationally demanding task, this is so that the number of blocks being found by miners every 10 minutes remains steady.

For blocks to be considered valid, they have to have a valid proof of work.
Apart from the creation of new blocks, mining also serves as a way to add new Bitcoins into circulation. 21 million is the total number of Bitcoins that can ever be in circulation. This makes Bitcoin resistant to inflation.
The current Bitcoin reward for mining blocks is 6.25 Bitcoins. This value is halved after every 210,000 blocks or after every four years.
Miners also earn incentives for validating transactions paid by participants in form of transaction fees. The mining reward plus the transaction fees are summed up and awarded to the miner as a coinbase transaction. The coinbase transaction is the first transaction in a block. It has no inputs.

Mining can be hardware-based, CPU-based, GPU-based, FPGA-based, ASIC-based, or cloud-based. Mining can also be done by an individual or a collection of miners who form a mining pool.

In this article, we understand what successful mining is, how blocks are validated and how chains are assembled and selected in Bitcoin.

Successful Mining.

A mining rig consists of multiple ASIC (Application-Specific Integrated Circuits) - processors made for mining purposes running the SHA256 hashing algorithms in parallel very fast. These circuits are connected to a mining node using a USB stick or a LAN network. This node transmits the block header to the mining hardware which runs algorithms to find a nonce that will solve the cryptographic puzzle.
In about 10 minutes a solution is found and sent back to the mining node that when inserted into the block header produces a block hash that is less than the target hence solving the puzzle.

The mining node then transmits the block to all peer nodes in the network which validate and then propagate the entire block. Each peer node adds the block to its own copy of the blockchain. This results in the blockchain height increasing. Since the puzzle has been solved, other mining nodes stop mining and start computing the next block in the chain. The competition begins again.
Miners can build on top of the winning block essentially voting with their computational power and endorsing the block and the chain it extends.

Validating a Block.

In order for a block to be added to the chain. Every node in the network has to validate it and make sure it is valid. Remember we said that a winning node cannot change anything for its own benefit since it will lead to loos of the reward since other nodes will reject the block. Validation is the step before the block is propagated to the entire network, meaning if a block is rendered invalid, propagation stops there. therefore saving network bandwidth that would be used to propagate invalid blocks. In addition to this independent mining also ensures that honest miners have their blocks added to the chain hence earning the rewards as compensation for contributing computational power to the blockchain.

During propagation when a node receives a mined block, it validates it according to a list of criteria. This includes;

  • A syntactically valid block data structure
  • A block header hash less than the target
  • A block size within accepted limits.
  • A block timestamp of fewer than two hours in the future.
  • First transaction is a coinbase transaction.
  • All transactions abide by their own criteria for validation.

This ensure miners cannot cheat and if they do risk losing their rewards and fees for processing transactions not to mention computational power that translates into electricity used to power the mining rigs. Therefore, a miner cannot manipulate the coinbase transaction to reward themselves more than expected since its invalidity leads to the invalidity of an entire block.

Chain Assembly and Selection.

This is the last step in decentralized consensus for Bitcoin whereby blocks are assembled into chains and a chain with the most proof of work is selected. This occurs when a node validates a new block. It attempts to assemble a chain by connecting the block to the existing blockchain. This node keeps three sets of blocks, the first set is those connected to the main blockchain, and the second set comprises of blocks forming branches off the main blockchain and blocks that don't have known parents in the known chains, these are referred to as orphan blocks. As mentioned when a block fails a validation criteria it is immediately rejected and not propagated or added to the chain.

At any time in a blockchain, the main chain is a chain with a valid chain of blocks with the most cumulative Proof-of-Work and in most circumstances, this is the chain with the most blocks. An exception occurs when there are two chains with the same length that came as a result of a chain split. This is still valid however Bitcoin has mechanisms to solve this and reconcile the two chains into a single chain forming the longest chain. The extra chains remain valid but are not part of the main chain however, are used as reference points.

When a new block is received, a node tries to add it to the existing blockchain by looking at the block's previous block hash that references the block's parent, it then attempts to find the parent in the existing blockchain. The parent in most cases will be at the tip of the main chain, this means that the new block when added will extend the main chain.

We also have forks, this is whereby a new block extends a secondary chain that is not the main chain. Here, the node attaches the new block to a secondary chain it extends then compares the work of the secondary chain to the work of the main chain., If the secondary chain has more cumulative Proof-of-Work, the node recoverges on the secondary chain and selects it as the main chain making the main chain secondary.

There are cases when the valid block received is an orphan. In this case, it is saved in the orphan block pool where it stays until its parent is received after which it is removed from the pool and linked to the parent incorporating it into the chain.

Selecting the greatest cumulative proof-of-work results in a network-wide decentralized consensus. Mining nodes can vote using their mining power by choosing a chain to extend by mining the next block after which the new block is used to extend the chain. The new block is a result of the voting.

Summary

Mining in blockchains is the process of adding new blocks to the blockchain thereby extending the blockchain by one more block. This extension not only grows the network but makes the network more secure and resistant to mutation or any form of hacking.

Independent validation is a very important component of decentralized consensus. Miners validate blocks according to a list of criteria such as a valid syntax of the block data structure, the block header hash being less than the target, a small enough block size that fits within the accepted limits, a coinbase transaction being the first transaction in the block and all transactions fulfilling their own criteria that ensures they are valid.

References

Bitcoin's Hashing Race and the Extra Nonce Solution
Mining Pools.
Mining Blocks.