Sitemap

Demystifying Blockchain Part 2: Nodes and Consensus Algorithms -0x00Auditor

6 min readJan 2, 2024

--

Hello this is the 2nd blog of my series “Demystifying Blockchain” but for those who are reading my blog for the first time let me introduce myself, My name is Shashank a.k.a 0x00Auditor and currently I am transitioning from Web2 security to Web3 security.

In the last blog I gave you a brief introduction of blockchain technology is and in this blog I will tell you about two important components of blockchain ecosystem which are miners/nodes and the consensus mechanism.

What are blockchain nodes?

Blockchain nodes are devices (such as computers or servers) that form part of a distributed network. Each node has a copy of the entire blockchain, and they work together to validate and secure transactions. Blockchain nodes are essential components of a blockchain network, playing a crucial role in maintaining the integrity, security, and decentralization of the system. A node, in the context of blockchain, refers to any device that participates in the blockchain.

Roles of node in blockchain

  1. Transaction Validation: Nodes on the blockchain network validate transactions to ensure they meet the consensus rules and are legitimate. This process involves checking the cryptographic signatures and confirming that the sender has sufficient funds.
  2. Consensus Mechanism: Nodes participate in the consensus mechanism to agree on the state of the blockchain. Different blockchain networks use various consensus algorithms (e.g., Proof of Work, Proof of Stake) to achieve agreement among nodes on the validity of transactions and the order in which they are added to the blockchain.
  3. Block Creation: In Proof of Work based blockchains, nodes (miners) compete to solve complex mathematical problems to add a new block to the blockchain. In Proof of Stake or other consensus mechanisms, nodes are chosen to create new blocks based on their stake in the network.
  4. Maintaining a Copy of the Blockchain: Every node on the network maintains a copy of the entire blockchain. This decentralized nature ensures redundancy and security. If one node fails or is compromised, the network can still operate smoothly.
  5. Security and Decentralization: Nodes contribute to the security and decentralization of the blockchain network. The more nodes there are, the more resilient the network is to attacks or failures. Decentralization also helps prevent a single point of control or failure.

How these nodes communicate to each other?

These nodes are connected to each other in a peer-to-peer network.

In a peer-to-peer network, every computer (peer) is equal and can share information directly with others. Unlike a setup with a central server, P2P networks allow direct communication and sharing between these equal peers. This structure is often used for tasks like file sharing and collaboration.

Figure 1.1

In figure 1.1, we can see that each node is connected to other in some manner so that the information can be transmitted to each and every node.

Why do nodes store the latest copy of the blockchain?

Nodes store the copy of blockchain for many purposes which are listed below

  1. Suppose in case a node gets disconnected from the internet and comes back online and in between this time more blocks are mined then it can fetch the latest copy of the chain by requesting it from its connected peers. In case the node works without updating its chain then it would work on the old chain and then 2 version of the same chain will exist on the internet which will cause chaos.
  2. Suppose an attacker i.e. hacker gets control of a node than it could change the data in blocks and precious blocks and then mine it then what he could do, include transactions which are giving less fees, change the address and put it own address and then mine it which will send all the funds to it address pretty scary right, well this isn’t happening because blockchain works on 51%+ approval rate we’ll get to it in the later section of the article.

Consensus algorithm in blockchain

Consensus in blockchain is how all the computers in the network agree on which transactions are valid. It’s like a group decision-making process to keep the information secure and reliable. Different methods, like Proof of Work or Proof of Stake, help them reach an agreement on what goes into the blockchain.

There are mainly 2 types of consensus algorithms present and used which are as follows:

  1. Proof of work — This mechanism is used by bitcoin in this consensus mechanism miners/nodes have to do arithmetic calculation and after successfully completing the calculation it will send the message to other nodes as well that I have completed the block mining calculation and then the other nodes will check that block as well and after approval of more than 51% of the nodes the block will be added to the blockchain and all the miners will add that block on their stored copy of the chain.
  2. Proof of stake — This mechanism is used by bitcoin in this consensus mechanism miners/nodes have to do arithmetic calculation and after successfully completing the calculation it will send the message to other nodes as well that I have completed the block mining calculation and then the other nodes will check that block as well and after approval of more than 51% of the nodes the block will be added to the blockchain and all the miners will add that block on their stored copy of the chain.
Press enter or click to view image in full size

Proof of Stake (PoS) vs Proof of Work (PoW)

Press enter or click to view image in full size

Calculation of creation of new blocks

Press enter or click to view image in full size
Figure 2.1

Step 1 — In step 1 all the miner gets a challenge value, and the challenge is that the hash value of the resulted block should be less than the challenge provided.

Step 2 — The miner picks some transactions from the mempool (mempool is where all the unprocessed transaction are stored).

Step 3 — In the above picture you can see there are many fields in the block, but the miner can only control the nonce and data field. Now the miner will try to add different values in nonce and try to get a hash value less than the challenge value.

Step 4 — Now, if the miner gets the resulted value, it will send the result to other miners for validation and if not, it will pick other transactions and then again perform the same calculation.

Now, after a miner completes the calculation and other nodes will approve then the block will be added to that chain. So, in this manner a block is added to the chain.

Press enter or click to view image in full size
Figure 3.1

In figure 3.1 we can see that after one device completes the calculation and mines a block it will send the details to the other to which that particular device is connected and those device will send the details to other devices as well. In this manner the blockchain is populated to each and every device.

So, that’s all for this blog in the next blog we will discuss about some problems that can happen while adding a block till then adios. If you have any queries reach out to me on LinkedIn or twitter.

Linkedinhttps://www.linkedin.com/in/shashank-mudgal-6b29171a0/

Twitterhttps://twitter.com/0x00Auditor

--

--