In this article, you will see how the cryptocurrency P2P network works. You will explore different blockchains policies specifically and the P2P network in general by breaking the P2P network into five layers.
- Consensus layer
- Miner layer
- Propagation layer
- Semantic layer
- Application layer
A consensus mechanism is an agreement needed for the network to operate properly even in the event of a failure. it needs to be able to achieve agreement on the data of the network within the distributed p2p network.
In a traditional centralized system such as a bank, there is a master computer that is trusted with the ledger of transactions. The bank can obviously trust its own computer, and therefore it has no problem being the one responsible for the security and integrity of the master computer.
When you are dealing with untrusted peers sharing a ledger, there is a need to place rules that will ensure security and provide integrity of the ledger to prevent double-spending and other potential hacker attacks. These rules and agreements are called a consensus mechanism.
The P2P network works globally using an Internet connection and is able to provide a platform to achieve a globally distributed consensus mechanism. In cryptocurrencies, the consensus/agreement is on whether the blocks are valid or not. If a block is valid, the block will be added to the blockchain. If a block is invalid, it will be rejected from being added to the blockchain.
That’s where a consensus policy comes into play. Most of the peers in the network hold the same blocks in their validated best blockchain and follow the same rules (consensus rules); that’s how blockchain ensures security.
As the blockchain gained popularity, many consensus mechanisms policies were created. The first one was created by bitcoin, and many others were built to solve problems that exist in other mechanisms. Let’s discuss a few popular ones:
- Proof of Work (PoW): It is the first and most popular mechanism; used by bitcoin and Ethereum, which are the most popular cryptocurrencies at the time of writing. PoW is achieved by having a network of miners and presenting the miners with a mathematical problem. When miners solve a problem, they are rewarded with a cryptocurrency. The reward is the proof of the “work” done, and that’s where the name comes from. On PoW, as the difficulty goes up, that means less profit. Fewer profit results in less incentive to mine coins.
- Proof of Stake (PoS): It was created by Sunny King and Scott Nadal in 2012 as an alternative to solve the PoW cons mentioned earlier. PoS relies on how many coins a peer holds. The peer needs to stake the number of coins it wants to mine. Instead of hashing power, we have stake power, and there is no dependency on energy consumption because there is no puzzle to solve. PoS provides a similar hashing block scheme to bitcoin’s PoW, but it limits the number of peers. This provides the needed security yet lowers the cost and power consumption. A network fee is provided to peers instead of giving a reward for solving a mathematical puzzle as in PoW. PoS determines what peer does the work by the size of the stake the peer holds. This achieves a distributed consensus at less energy and less cost. DDOS attacks and frauds are still possible. However, attackers cannot transact more digital currency than they are staking. Otherwise, they would lose their deposits, so the chances are lower for an attack. Keep in mind that attackers can stake other people’s coins and won’t care to lose these coins as they are not theirs, so there are still ways for a DDOS attack. Here is a list of some popular cryptocurrency coins that use PoS:
- Dash: You need 1,000 units to be a master node. It gives an annual return of approximately 7.5 percent per year.
- NEO: Staking wallets return approximately 5.5 percent per year. There’s no need to mine; you get gas coins just by holding coins.
- Others: LSK, PIVX, NAV, RDD, BEAN, Linda, DCR, NEBL, OK, STRAT.
3. Delegated proof of stake (DPoS): Delegated proof of stake is a census algorithm method invented by Dan Larimer discussed in the white paper. DPoS is aimed at improving PoS cons by providing a democracy instead of the random process of selecting a miner.
DPoS achieves a technological democracy by splitting the process of mining into two parts.
- Election: When electing a group of block producers, there are only 21 block producers instead of unlimited as with PoW.
- Scheduling production: Each one of the 21 block producers takes turns producing a block every 3 seconds.
The election process provides a technological democracy and ensures stakeholders are in control because large stakeholders have the most to lose if a network fails.
Each block producer takes a turn at producing a block, and the longest possible chain gets adopted (just like in PoW).
What the miners are doing behind the scenes on networks could be described as competition to do the blockchain’s work, which is really doing the network bookkeeping. For bitcoin and most coins out there that utilize PoW, each peer needs to hold the entire public ledger, which holds a record of all the transactions that were ever conducted. PoW miners are based on computing power and pools, while other networks take into account other considerations.
For bitcoin, transactions must be validated by the miners who check the ledger, ensure the sender is not transferring funds it doesn’t have, and only then add the transaction to the ledger. Finally, to ensure protection from hackers, the miners seal these transactions behind multiple layers of computational work, requiring too much work for a hacker to possibly achieve. This service is rewarded by providing bitcoins as a fee to the miner.
The propagation layer is responsible for deciding how the shared ledger and the blocks are transmitted on the P2P network. This layer is described in detail in the blockchain white papers.
Each of the peers can transmit a new transaction to other nodes on the network. This architecture allows nodes to communicate indirectly. For instance, you can send a transaction affecting two wallets without each wallet being connected directly to the other.
Any node that receives a valid transaction it has not seen before will immediately forward it to all other nodes to which it is connected. This is a propagation technique known as flooding. Thus, the transaction rapidly propagates across the P2P network, reaching a large percentage of the nodes within seconds.
The semantic layer takes care of how new blocks relate to previous blocks and provides the protocol for verifying the consensus rules.
As you have seen, there are different types of consensus mechanisms based on how many trusted machines are connected, staking, speed, hashing power, and more, but they do work similarly to how new blocks are related to previous blocks to ensure security. Every blockchain has specifications. In this layer, transactions happen where coins/tokens are transferred between accounts. The consensus in the blockchain holds the same blocks in their validated best blockchain and follows the same rules (consensus rules). That’s how a blockchain ensures security.
This layer takes care of deploying applications on top of the blockchain. For instance, dapps, smart contracts, exchanges, and sites that provide information about a blockchain are applications built on top of blockchains.
For the application layer, the blockchain needs to expose APIs. Different blockchains are similar as they all provide a way for a client to communicate with the network.
Bitcoin offers a full node, which is currently about 27 GB and includes a fully enforced node and all the rules of the blockchain. That is needed for mining as well as ensuring the peer you run that gets connected to the application layer is synced with the latest blocks.
These full nodes contribute to the functionality of the P2P network and help support the network and its security.
In this article, I covered the blockchain P2P network and the different layers that make up the network: consensus layer, miner layer, propagation layer, semantic layer, and application layer. You also learned about the peer-to-peer network core logic and proof of work (PoW), proof of stake (PoS), and delegated proof of stake blockchain (DPOS).