# Understanding the BlockChain Network validation concept using simple Java program.
Understanding BlockChain using simple Java Program (It explains the working of block chain network in a simple and easy way using java program)
Here is my another article to understand , why the block chain network is difficult to hack or modify the content of block data.
Added the demonstration (in BlockChainNetwork.java)
for validating Block Chain network
Also, demonstrated what happens, if the data is tampered in
any block.
note: below are some of the conditions to validate the blockchain network
1.The hash of current block is valid.
2.The hash of current block is equal to the previous hash of succeeded block.
So, If the data is tampered in any block
* The hash becomes invalid, this in turn makes the network invalid
* Even if the hash is updated, it is difficult to update the same in previous hash of every succeeded block.
(can be tried if the intruder have the compute power more than 50 % of peers in the block chain network.. definitely not possible.. 😝 😝!!!.. so make your hashing algorithm stronger..)
BlockChain Network Validation Concept:
------------------------------------------------------------------------------------------------------
public String isBlockChainNetworkValid(List<Block> blockChainNetwork){
Block currentBlock=null;
Block previousBlock=null;
String message="";
for(int i=1;i<blockChainNetwork.size();i++){
currentBlock = (Block) blockChainNetwork.toArray()[i];
previousBlock = (Block) blockChainNetwork.toArray()[i-1];
if(currentBlock.getCurrentBlockHash().equals(currentBlock.calculateHash(currentBlock.getBlockData()))){
if(currentBlock.getPreviousBlockHash().equals(previousBlock.getCurrentBlockHash())){
message = "Valid";
}
else{
message = "Invalid...\n Because the previous hash of block index : "+currentBlock.getIndex()+" is not equal to hash of block index "+previousBlock.getIndex();
break;
}
}
else{
message = "Invalid... \n Because the hash of block index : "+currentBlock.getIndex()+ " is not valid. The data might have been tampered..!!"
+"\n The actual valid hash is : "+currentBlock.calculateHash(currentBlock.getBlockData())
+"\n But the available hash in network is : "+currentBlock.getCurrentBlockHash();
break;
}
}
return message;
}
-------------------------------------------------------------------------------------------------------------------------
**** Introducing nonce and proof of work…… [
follow the next posts !!! ]
Hence, Block Chain becomes secure..! It is quite difficult
to hack & update the data in any block and make it valid without the peer's
concern.
Sample output of validation code is also attached..(closely
monitor the previousHash & currentHash of each block)
So, the Questions arise of
- What if the data is tampered & hash is updated in the last block of network. Since, the last block in the network doesn’t have any succeeded block to check the previous hash
Get the complete source code here,
**** Introducing cryptographic nonce and proof of work in my upcoming post.