Reader small image

You're reading from  Foundations of Blockchain

Product typeBook
Published inJan 2019
PublisherPackt
ISBN-139781789139396
Edition1st Edition
Concepts
Right arrow
Author (1)
Koshik Raj
Koshik Raj
author image
Koshik Raj

Koshik Raj is an information security enthusiast who holds a master's degree in computer science and information security. He has a background of working with RSA, a network security company. He has also worked as a senior developer in CoWrks, Bengaluru. Koshik has been studying blockchain technology since he was introduced to Bitcoin while pursuing his master's. He is currently advising an educational start-up looking to implement blockchain technology in the education space. He is also setting up a blockchain incubation center for students and researchers in Bengaluru to aid mentorship and networking, and even the launching and marketing of their ideas.
Read more about Koshik Raj

Right arrow

Networking in Blockchain

In the previous chapters, we covered the cryptography concepts that are essential for blockchain to function in a trustless network. But we haven't discussed what a trustless network is. A decentralized network facilitates a trustless environment. In this chapter, we will explore how blockchain achieves decentralization with peer-to-peer (P2P) networking.

In this chapter, we will cover the following topics:

  • P2P networking
  • Network discovery
  • Block synchronization
  • Building a simple blockchain in a P2P network

We know that blockchain was created to remove the trust in a single central authority by building a trustless network that decentralizes all the tasks that are otherwise centralized in a single entity. P2P networking is an architecture style used to achieve this decentralization in blockchain applications. We'll begin this chapter by exploring...

Peer-to-peer (P2P) networking

The basic definition of a P2P network is a network where groups of independent computers called nodes are interconnected, sharing data without the assistance of any centralized servers. It is an architecture on top of the internet. Participants or nodes in this type of network are called peers because they are all equal and have equal responsibility within the network. Since there are no special nodes in a P2P network, each peer is both a service provider and a consumer.

History of P2P network

The early vision of the World Wide Web was aligned with the concept of P2P networking, where each user would be an active editor of and contributor to the network. USENET, first developed in 1979, enforced...

Network discovery

Network discovery in a P2P network is crucial. No network is defined when a new node boots up. The new node must detect at least one blockchain node to be a part of the network. There are several ways in which a node can identify peers and thus discover a network.

Different blockchain frameworks use their own protocols to perform peer discovery and efficient routing. We're going to start by exploring basic P2P network discovery by taking a look at Bitcoin's original implementation.

The simplest way to find the list of peers to connect to is by hardcoding a few of the well-known peers. Using a central server that maintains a list of peers is another approach. Bitcoin holds information about DNS seeds, which provide a high level of reliability when a node is initially set up, and will respond with a list of the IP addresses of the Bitcoin nodes. Once...

Block synchronization

Each node that joins the blockchain network needs to update its local copy of the blockchain to synchronize its state with the global state of the rest of the network. This is achieved by block synchronization. A node that needs to update its blockchain sends a message consisting of blockchain height information. Any peer that has a longer blockchain sends an inventory consisting of metadata about the fixed number of blocks that needs to be added to the host node. Now the node makes a request to all its peers to fetch individual blocks by referring to the inventory it received. The node should make sure not to flood the network with block requests by maintaining a cap on the number of block requests it sends.

Block synchronization is a long process for a newly-joined node. However, once all the blocks are up to date, it can verify the information in the block...

Building a simple blockchain in a P2P network

In Chapter 3, Cryptography in Blockchain, we explored how a consensus can be achieved in a decentralized network with the help of algorithms such as proof-of-work. Since consensus algorithms ensure that the Byzantine failure problem can be solved, a global truth can be maintained in a decentralized network in which there is no trust between the peers. Although consensus algorithms provide a convenient way to maintain a public ledger, each node has to perform a set of operations to maintain the ledger in a distributed network.

We have already created a simple blockchain application that can continuously enlarge its records whenever we have new data to be inserted. Because our blockchain application was deployed and the blocks were created in a single system, we have not yet added any mechanisms to validate the blocks. But when we deploy...

Summary

This chapter has covered the aspects of P2P networking that are used in blockchain applications by building a simple P2P application with basic functionalities. The basic architectural knowledge that you've gained from this chapter will help you to understand the advanced networking concepts used in some blockchain platforms.

Now that we have a strong background of the blockchain technology after covering several cryptography and networking concepts, we will get introduced to the original and one of the strongest use cases of blockchain technology – Cryptocurrency. In the next chapter, we will apply most of the concepts introduced till now to understand and implement the cryptocurrency use case.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Foundations of Blockchain
Published in: Jan 2019Publisher: PacktISBN-13: 9781789139396
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Koshik Raj

Koshik Raj is an information security enthusiast who holds a master's degree in computer science and information security. He has a background of working with RSA, a network security company. He has also worked as a senior developer in CoWrks, Bengaluru. Koshik has been studying blockchain technology since he was introduced to Bitcoin while pursuing his master's. He is currently advising an educational start-up looking to implement blockchain technology in the education space. He is also setting up a blockchain incubation center for students and researchers in Bengaluru to aid mentorship and networking, and even the launching and marketing of their ideas.
Read more about Koshik Raj