A candidate block is a temporary block created by a participant in a blockchain network with the intention of adding it to the blockchain. It is then mined by the miners in order to gain rewards. It contains a number of unverified transactions from the node's memory pool and serves as a basis for mining.
The mining process for a candidate block involves multiple steps to validate and add the block to the blockchain. These steps are described below:
The mining process starts with the population of the candidate block with unverified transactions, sourced from the node's memory pool, which are subsequently organized and structured.
Once the candidate block is constructed, a block header is created to summarize the block's data. It consists of the following properties:
Previous block reference: It contains a reference to a previous block in the blockchain that the candidate block aims to build upon.
Merkle root: It represents a summary of all the transactions included in the candidate block, calculated using a Merkle tree structure.
Nonce field: It is a value that miners adjust to find a hash that is below the target value.
Target: It represents the difficulty level that the block hash must be below to be included in the blockchain.
Additional metadata: There may also be other metadata depending upon specific blockchain implementation, such as version number, timestamp, etc.
To mine the candidate block, miners subject the block header to the SHA256 hash function in an effort to discover a hash value that falls below the network's specified target. Miners perform repeated hashing of the block header, adjusting the nonce field to generate different hash results for the same block header.
If a miner successfully discovers a block hash below the target, they broadcast the mined block to the network. Other nodes in the network verify that the block header's hash is indeed below the target before adding the mined block to their blockchain. This consensus-based approach ensures the integrity and consistency of the blockchain across the network.
After successfully mining a block, each node stops working on its previous candidate block and constructs a new one. Fresh transactions from the memory pool are incorporated into the new candidate block, and miners continue the process of mining and extending the blockchain.
The mining process, often referred to as proof-of-work, requires substantial computational effort to find a block hash that meets the required criteria. Miners work independently and collaboratively at the same time to expand the blockchain by adding new blocks of transactions. The hash function serves as a means to demonstrate that a necessary amount of computational work has been carried out on a block.