Blockchain nodes and mining, explained

Venkat Kasthala
6 min readAug 21, 2019

--

As discussed in one of my previous articles “Blockchain key characteristics and the conditions to use it as a solution”, there is no central intermediary overseeing the transactions in a blockchain though the transactions are between entities that do not trust each other. What roles can each entity in the blockchain possibly take? Without a third-party, who is responsible for adding transactions to the blockchain? What’s the incentive for someone who works to add transactions to blockchain? I will address these questions in this post.

Blockchain nodes and their types

A node is a computer that runs blockchain software and helps transmit the information across the blockchain network. Laptop, phone, router, etc. are all nodes. Anyone can download blockchain software and run it for free. Nodes are classified into different types based on their role in the blockchain.

  • Mining Nodes (also called miners): These are the nodes that can add transactions to a blockchain. Every node in the blockchain network has an option to become a mining node. The process of adding transactions to a blockchain is called mining.
  • Full Nodes: These nodes hold and distribute copies of the entire blockchain ledger right from the genesis block (i.e., first block in the blockchain) thereby helping in validating the history of the blockchain.
  • Super Nodes: These nodes connect full nodes to each other and spread the information across the network to make sure everyone has the correct copy of the blockchain.
  • Light Nodes: These nodes are similar to the full nodes but hold only a portion of the blockchain ledger instead of the entire blockchain.
Illustration of nodes in a blockchain
Illustration of connected nodes in a blockchain

Once a transaction is created, the node in which transaction originated sends the information to all the nodes that it knows and those nodes will in-turn send the information to all the nodes they know thereby sharing the data with all the nodes in the blockchain network rather quickly. The blockchain data is stored in the nodes in a flat file or in a database.

Who can add transactions to blockchain?

Every node has an option to “mine” and add transactions to a blockchain. But, why would the nodes want to mine transactions? What’s in it for them to do this work? It is because the miners get rewarded for successfully adding transactions to blockchain.

For example, a mining node that adds transactions successfully to a bitcoin blockchain is rewarded with 12.5 bitcoins along with the transaction fees, which is worth over $130,000 today. That’s a big enough reward for a lot of miners to compete and add transactions to blockchain.

Because of numerous mining nodes competing against each other for the reward, blockchain must have a solid method for selection of a mining node that adds transactions to the blockchain. Bitcoin blockchain software provides a mathematical puzzle to all the miners and the node that succeeds in solving this puzzle gets to add the block to the blockchain and win the reward.

How can a miner solve the puzzle?

As illustrated in the picture below and explained in my other article, a block in a blockchain has the following key components: header, data, nonce, previous hash, and hash. Data is a set of transactions, hash is a unique identifier for a block and is analogous to a fingerprint for a human, previous hash is the hash value of the previous block in the blockchain, Nonce, and header has the details such as block number, timestamp, etc.

Nonce is the only field in a block that can be changed by a miner. All the data fields in a block except “Nonce” are predetermined and cannot be altered.

Blockchain program creates a complex puzzle for the miners which is to generate a “Nonce” value which when combined with the other components in the block (i.e., header, data, previous hash) and passed through a hash function, produces a hash value that is less than a target hash value. In the case of bitcoin, the nonce is an integer between 0 and 4,294,967,296.

Hash = function(header, data, nonce, previous hash)

There is no way for the miners to determine which “Nonce” value will work because of avalanche affect of hash function; i.e., even a slight variation in the inputs to a hash function completely changes the hash value. So, the only way for the miners to determine “Nonce” is by guessing at random through trial and error.

The mining node that solves the puzzle first, distributes its blockchain and informs the rest of the nodes in the network so that the other miners can stop working on that block and move onto finding the “Nonce” for a different block. Blockchain program performs a series of checks to determine whether the block should be added to the blockchain or not. Once all the checks are passed, block is added to the blockchain and copied to all the nodes in the network. The miner receives new bitcoins as a reward for its work.

This is referred to as proof of work consensus protocol because the nodes in the blockchain check for proof of work constantly and once found, its blockchain is distributed to all the remaining nodes in the blockchain.

Simultaneous mining of blocks by different nodes

When two or more nodes (let’s say M1 and M2) mine the same or different blocks successfully at the same time, each mining node (i.e., M1 and M2) starts propagating the information to the nodes it knows. During this process, at some point there will be inconsistency in the blockchain data among the nodes because some nodes would have information received from M1 and others nodes would have not information received from M2. At this point, blockchain waits for yet another block to be added and the blockchain that is there in the longest chain or majority of the nodes is accepted and copied to all the other nodes in the network. The block that is successfully mined by the other node but not accepted is ignored and that miner doesn’t get rewarded despite working on it.

Ultimately the chain that has the highest computational power wins because it can solve the puzzle quickly and propagate the information to the network quickly. The longest blockchain is copied to the other nodes as well.

Though the rewards for mining are high, the costs involved are considerable as well. One needs powerful hardware and faster processors than that of competing miners so that multiple iterations can be run quickly to determine the “Nonce” and propagate the information quickly across the network. One block of Bitcoin gets mined every 10 minutes.

It is in the interest of the miners to form a distributed consensus-based on valid block information because of the reward for the miners. Miners have to play fair because any incorrect data will tamper the blockchain and they wouldn’t get their reward.

Mining has become so difficult for a lone miner with limited computation power that it might take years to mine a block. For this reason, miners started pooling their resources to mine a block quickly and receive a portion of the reward based on their hash rate contribution to the process.

To sum up, I illustrated the transaction flow in a bitcoin blockchain in the below diagram.

References:

  1. https://www.udemy.com/build-your-blockchain-az/
  2. https://thenextweb.com/hardfork/2019/03/01/bitcoin-blockchain-nodes-network/

--

--