How Does the Blockchain Work?

Prerequisite – Introduction to Blockchain technology | Set 1, Set 2
A blockchain is nothing but a chain of blocks that holds some serious properties which are utilised to enable decentralisation over the internet. Decentralisation means nobody has full authority or control over the network but rather the authority is distributed to the users who use it, in the case of blockchain, to the miners, the users.

  • Blockchain provides immutability (it’s theoretically possible to mutate the contents but its practically impossible most of the times because of the computational power required, unless there is a bug, which happened to ethereum once and it resulted in a hard fork, thus creating two versions of it, and thus two currencies, ethereum and ethereum classic).
  • Blockchain provides Transparency and trust. Blockchain is shared, and hence it allows the system to be transparent and everybody can verify the data present in it.
  • Blockchain is secure. The famous and reliable blockchains use cryptographic functions approved and used by cryptographic experts all over the world. However, this may change as quantum computing advances.
  • Blockchain has high availability, since the system is based on thousands of peers in a p2p network.

In the most basic way, we can think of a blockchain as a linked list. Each of the next item in list is dependent on the previous item, except for the first block, also known as the genesis block, which is hardcoded into the blockchain.

So suppose we have a chain of 10 blocks, so the 10th block depends on the 9th block, the 9th block on the 8th block and so on. Thus in a way, the 10th block depends on all the previous blocks and genesis block as well. Thus, if someone tries to change data on the 2nd block, lets say, then he will have to change data on all the later blocks as well, otherwise the blockchain will become invalid since the later blocks depend on data present in the 2nd block and the 2nd block has changed, but not the later blocks. Thus, as the blocks are added, immutability increases as we will see later, changing the block is an expensive operation.



Also, to add/change a block in a blockchain, people have to show some proof. To avoid enormous amount of block to be added to the blockchain, a concept of difficulty is introduced. To add a block, We have to compute the hash of the block. The hash holds certain properties which makes computing the hash time consuming. For ex, someone might keep the difficulty to have a no. of zeroes present in the start of the hash. Thus, by randomly changing the nonce(arbitrary data present so that the properties of the hash hold) we have to find the hash of the block which holds the properties.

The difficulty is adjusted after a certain amount of time to maintain an average constant rate of mining blocks.

Mining a block –
Mining a block refers to adding of the block present in the blockchain network. A miner selects a set of transactions from the pool of transactions and then mines the block, or one can say, computes the hash to add the block to the network. If two or more miners mine the same block at the same time, the block with more difficulty is selected. The others are known as stale blocks. Mining usually rewards miners with blockchain currency.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.