A Byte of Blockchain - Week 22 Chaining the Blocks

·

4 min read

A Byte of Blockchain - Week 22
Chaining the Blocks

Photo by Tezos on Unsplash

Recap

Last week we explained how nodes validate & verify transactions in a blockchain. In a blockchain, the transactions are added to the public ledger by nodes in the below order:

  1. Nodes independently verify each transaction
  2. Nodes independently aggregate or group transactions into new blocks
  3. Nodes independently verify the new blocks
  4. Nodes independently add these blocks to a "chain"

We explained step 1 & started with step 2 on blocks which we will elaborate below.

(Before reading further, it is recommended that you read Weeks 12 & 13 related to Hashing & Public Key cryptography).

Block

**A block is a data structure (like an excel sheet with fields for data) where transactions are included and aggregated. It contains fields for

  1. Identifying the block (Block Hash & Block Header)
  2. Incorporating transactions to the block (Block Body)

Block Identification

The fields under this are :

  1. Block Hash
  2. Block Header

Block Hash

Last week, I mentioned that blocks are akin to transaction batches where multiple transactions are bunched or grouped together to form a batch. This batch is normally represented by a batch transaction ID which is a unique set of characters generated by the system automatically to identify that batch. No two batches can have the same transaction ID.

Similarly, for a block, there is a cryptographic hash which is uniquely identifiable only to that block which is generated using hashing algorithms. This hash is always unique and like a fingerprint. No two blocks will have the same hash and a hash is generated as soon as a block is created.

If a block is tampered with, it's hash changes and hence the block hash is a powerful detector to identify any block tampering.

BlockHash.jpg

Block Header

A Block header consists of below fields (also called metadata) :

  1. The previous block hash
  2. Fields related to mining
  3. Merkle Root Tree - a unique hash of all the transactions in the block combined

The below diagram makes it more clear :

BlockHash-1.jpg

Let us deep dive into each of the above :

Reference to previous block hash

In a core banking system, transactions are passed in an environment where ledgers, transactions and data are stored in one platform. This creates a linkage between the data in the system where transactions link to the relevant ledgers, the balances of which gets updated due to transactions being passed from time to time. Hence, movement of funds can be kept track of from the beginning till its current state by checking all the prior entries passed.

In a blockchain, the underlying platform and ledgers are all decentralized and maintained at individual nodes. However, that does not lessen the importance of keeping track of funds and movement of value & ownership. Now, how are transactions which are passed at various points in time in different blocks linked to previous transactions? This is done by linking these blocks to each other. A simple example will make it clear :

Assume Sender sends 10 BTC to Beneficiary & this transaction is passed in Block 1 in January 2022.

Then in February 2022, Beneficiary then sends 10 BTC to Accountant for their services. Assume this transaction is passed in Block 2 in March 2022.

Now, unless these two transactions are linked with each other, there is no way to keep track of the movement of 10 BTC from Sender to Beneficiary and then to Accountant. So, the way this is implemented in a blockchain is by linking Block 1 & Block 2. So how are these blocks linked?

We saw above that blocks are identified through their block hash. So, to link Block 1 to Block 2, Block 2 has a field in the block header called "Previous Block Hash" where the hash of Block 1 will be filled in. This ensures that the block header of Block 2 contains the Hash of Block 1. This is how blocks are "chained with each other" and hence the name BLOCKCHAIN.

Let us visualize the above example :

BlockHash-2.jpg

One thing to note is that the decentralized ledger doesn't keep track of account balances at all. It only records each and every transaction that is verified & approved. It only keeps track of each and every transaction broadcasted within the blockchain network. But how does the wallet show our balances?

The wallet identifies all the transactions that ever took place on the network connected to that wallet & consolidates them into the data structure of the wallet and shows the balance. This balance consolidation & verification is performed based on the links to previous transactions.

To summarize,

  1. The blockchain network orders transactions by grouping them into blocks.

  2. Each block contains a definite number of transactions and a link to the previous block (through the "previous block hash" in the block header).

Next week we will explore

  1. Mining related fields &
  2. Merkle Tree