How Proof of Work (PoW) consensus works
What is a consensus algorithm?
It's the procedure through which all the network's peers agree on the network's present state. For example, blockchain networks use different consensus algorithms to decide on the current state of the global ledger.
Types of consensus algorithms
Different types of consensus algorithms are listed below:
- Proof of Work
- Proof of Stake
- Proof of Capacity
- proof of Burn
Proof of Work (PoW)
To mine the next block, every miner must solve a complex mathematical problem (which takes a lot of computational power). The miners compute the block's hash, and if their hash is less than the current difficulty level set by the network, they have found the correct solution. Otherwise, they can adjust the value of the
Depending on the network's current difficulty, nodes might have to compute millions or even billions of hashes to find the correct solution. Then they will send their block to all the other nodes on the network. Then they all will
Note: All other fields in a
are fixed except the nonce. candidate block A block that a miner is trying to mine
Pseudocode
- Start with an initial value of the nonce.
- Compute the hash of the block.
- While (hash is not less than the difficulty of the network):
a. Nonce = nonce + 1 (or you can randomly assign a new value to nonce)
b. Recompute the hash of the block
- After we've computed the correct hash, we'll send the block to the entire network.
Figure
You can visualize the steps in the following figure:
Free Resources