You might have read a lot about the Blockchain and its underlying concepts. As the definition says ‘The Blockchain is a public ledger used to record all the transaction happened in a particular network’. Nowadays Blockchain is spreading to different areas like trading, file storage, identity management, medical records management, and education etc. Since Blockchain is growing at such a dynamic speed there must be a strong and secure data structure behind this to support the entire system.
So do you have any idea how exactly a block is implemented? If you are still confused then read on. Let’s explore ‘how exactly blockchain is implemented?’ You might be familiar with the concept of Distributed computing and our famous Linked list Data structure. Seriously….! You don’t have to be a ‘geek’ to understand those two. So well, we can say Blockchain is a well-blended combination of these two concepts.
Blocks are the basic building units of the blockchain. First, we will create a block and then link this block to the chain. There won’t be any isolated blocks in the blockchain. All the blocks are linked together. So let’s see how a block really looks like.
Just like a linked list, the Blockchain is a collection of blocks linked together, where each block will have the following fields.
1) Block: It is used to store the block value
2) Nonce: An arbitrary value used for finding a valid hash value.
3) Data: Store the data (transaction details)
4) Prev: Store the hash of the previous block
5) Hash: Hash value for the current block which can be used to refer this block.
Suppose we are creating the first block in a Blockchain, then consider the example.
• Here Block No is ‘1’
• Nonce string is ‘3522’
• ‘Hello World’ is the Data part
• ‘0000fdgydfs5434hbsdfjndsd’ is the hash value.
• Previous value is ‘000000000000000000000’ (Zero) as it doesn’t have any previous block.
The hash value is the most important thing in a block. The hash value is unique and it represents a single block in a blockchain. It is obtained using a hash function algorithm like SHA 256 or keccak-25. The hash value can be used to determine the validity of the block. A valid block will have a hash value that starts with 4 zeros. The hash value starting without 4 zeros is an invalid block, and further mining should be done on that particular block in order to make that block valid.
The mining process is done by a miner, who is responsible for the validation of the blocks/transactions in a Blockchain. The mining process is based on Merkle Root of the block, timestamp, previous block etc. After the mining process, a valid hash key is generated which is a unique value. The nonce value is the number of Hash outs we have to perform to obtain a valid hash value. So the nonce value will also change after the hashing. Sometimes the miner has to perform a number of Hash outs before getting the desired hash value. Whenever a new block is added to the Blockchain it must contain the hash value of the previous block and a default hash value for that represents the particular block.
As per the distributed nature of the blockchain, all the nodes in the distributed network will have the same copy of the blockchain and whenever a transaction happens in the network it will be updated in its corresponding block (only after verification) and it must be updated in other peers also. But what if two different peers got different hash value and both claim as valid? In this case, a democratic method is applied for verification. The hash value that majority of the peers having will be considered as the original value.
The token is a terminology used in Blockchain to manage financial transactions. All the digital asset movements in the network are recorded in the tokens called ‘tx’. Each block contains a token in which the transactions are recorded and we can see any transactions between two clients here. The Miners dig through the transactions history of the clients to validate a new transaction. Since the miner has the copy of the public ledger, it is very easy to go through different blocks and verify the transactions. For validating a financial transaction, the miner will make sure that the client who transferred the amount does have that much amount in his wallet. He can verify it by checking the transactions history of the client. If the client does not possess that much amount, then the miner won’t validate that transaction.
In the case of the first transaction of a client, it is not possible to validate the amount as he doesn’t have a transaction history to check. In this case, the Blockchain uses a terminology called ‘Coinbase’ to initiate the transaction. Each client will have a ‘Coinbase’ and he can directly put some amount to this Coinbase. Then the other transactions can be continued from here.
Immutable Nature of blocks
Since every node has the copy of the entire Blockchain, the security is a prime concern here. In a Blockchain, the security is maintained by the immutable nature of blocks. Once you added a block in a Blockchain it can’t be changed. You may add a new block, but you can’t make changes in the previously added block. The Blockchain immutability is obtained with the two properties of the hash
1. It is very hard to calculate the original data from the hash.
2. A slight change in the data will make a big change in the hash value.
Being a distributed system, immutable nature of the blocks are essential in blockchains. Since all the nodes in the network have the same copy of the data anybody may make modifications on the block. But due to the immutable nature of the blocks, once a data is entered to the blockchain any changes on the data can be easily identified by its hash value.
This nature is dangerous too since a small change in data can make big changes in the hash value. Furthermore, the possibility of the data loss is very less as every node keeps the copy of entire blocks.
Block Chain Structure
I believe you have got a complete picture of the Blockchain data structure and its actual implementation. We will cover more interesting topics in upcoming blogs.