Consensus = mutual agreement
Algorithm = a set of defined rules and procedures.
A consensus algorithm defines the criteria, procedure and a logic to be satisfied in order for the nodes in the networks to agree on how a new block is added to the blockchain network. A consensus algorithm makes a network to be more reliable without the presence of central authority. This helps to establish trust among the peers in the distributed computer network. There are different types of consensus algorithms, but the first implemented in a blockchain network and used vastly by many blockchains is proof of work (poW) consensus.
The concept was invented by Cynthia Dwork and Moni Naor in 1993 as a way to prevent denial-of-service attacks and other service abuses such as spam on a network by requiring some computational effort and time. In 2009 Satoshi Nakamoto surprised the world by implementing the poW consensus in the bitcoin blockchain.How does it work?
The purpose of a consensus algorithm is to validate transactions and broadcast new blocks to the blockchain.
Hence, the miners in the blockchain network will compete against each other to solve a complex mathematical puzzle. The beauty here is, these puzzles are very difficult to solve but very easy to verify the correct answer. Once a miner has solved the puzzle, he will be able to add a new block to the blockchain. Then all the other nodes will verify that it is a right solution.
As an example,
The miners are responsibly for adding a new bock to the blockchain. to do so the miners need to try and guess a random number with a low probability, which is known as a nonce.
This nonce when combined with the data in the block is passed through a hash function. The derived solution should match with a given condition accordingly.
The condition: the first four digits of the hash should be 1234.
When the miner finds a solution (block hash) that is matched to the condition, he will be allowed to add a new block to the blockchain, while the other nodes in the network will verify the validity of the solution which is found by the successful miner. Then the successful miner’s node is rewarded with some rewards as a proof for the computational effort and time that he/she has spent (as the name suggests it is a “proof of work”).
It is not possible to add a new block without a miner finding a valid nonce. So, the solution which is known as the block hash is present in every block representing the work done by the miner.
The PoW is a consensus that creates a relatively healthy and transparent closed economy in a blockchain, it also encourages the users in the network to continue to sustain the ecosystem. In the poW requires huge amount of computational power by the miners. While poW may not be the known as the most efficient solution but it is one of the most popular consensus methods in a blockchain.