Back to Course

Session 1.5 - Peer-to-Peer Networks

Understanding the network layer that enables decentralized blockchain communication

Module 1 45 minutes Foundation Level

Learning Objectives

By the end of this session, you will be able to:

  • Understand routing mechanisms in peer-to-peer networks
  • Explain how blockchain networks handle node churn
  • Describe different P2P network topologies and their trade-offs
  • Analyze network discovery and bootstrap processes
  • Evaluate the challenges and solutions in P2P network design

What are Peer-to-Peer Networks?

Core Definition

A peer-to-peer (P2P) network is a distributed network where participants (peers) communicate directly with each other without relying on centralized servers or intermediaries.

Traditional Client-Server
  • Central server controls all data
  • Clients request information from server
  • Single point of failure
  • Server bears all computational load
Peer-to-Peer
  • No central authority
  • Peers communicate directly
  • Distributed and resilient
  • Load shared among all peers
Real-World Examples
  • BitTorrent: File sharing without central servers
  • Bitcoin: Cryptocurrency transactions
  • Skype (original): Voice calls through peer connections
  • IPFS: Distributed file storage system

P2P Network Topologies

Unstructured

Random connections between peers

Pros: Simple, robust
Cons: Inefficient routing
Structured

Organized topology (e.g., DHT)

Pros: Efficient routing
Cons: Complex maintenance
Hybrid

Combines structured and unstructured

Pros: Balanced approach
Cons: Increased complexity
Blockchain Networks

Most blockchain networks (like Bitcoin and Ethereum) use unstructured P2P networks because they prioritize robustness and decentralization over routing efficiency.

Routing Mechanisms

Message Propagation Strategies

Flooding

How it works: Each node forwards messages to all its neighbors

Advantages:

  • Simple to implement
  • Guarantees message delivery
  • Highly fault-tolerant

Disadvantages:

  • High network overhead
  • Message duplication
  • Potential network congestion
Random Walk

How it works: Message is forwarded to a randomly selected neighbor

Advantages:

  • Low network overhead
  • No message duplication
  • Scalable approach

Disadvantages:

  • No delivery guarantee
  • Potentially slow propagation
  • May miss some nodes
Bitcoin's Approach

Bitcoin uses a modified flooding approach:

  • Each node forwards transactions to ~8 peers
  • Uses exponential backoff to prevent spam
  • Implements duplicate detection to avoid loops
  • Prioritizes recent and high-fee transactions

Network Discovery and Bootstrap

The Bootstrap Problem

How does a new node joining the network find other peers to connect to? This is the fundamental bootstrap problem in P2P networks.

Common Bootstrap Methods

Seed Nodes

Hardcoded list of well-known nodes

Pros: Simple, reliable initial connection

Cons: Centralization risk, maintenance overhead

DNS Seeds

DNS queries return IP addresses of active nodes

Pros: Dynamic, can return multiple addresses

Cons: Relies on DNS infrastructure

Peer Exchange

Existing peers share addresses of other peers

Pros: Fully decentralized, self-maintaining

Cons: Requires initial connection

DHT Bootstrap

Distributed Hash Table for peer discovery

Pros: Efficient, structured approach

Cons: Complex implementation

Handling Network Churn

What is Churn?

Churn refers to the continuous process of nodes joining and leaving the network. In blockchain networks, nodes may go offline due to:

  • Network connectivity issues
  • Hardware failures
  • Software updates
  • Voluntary disconnection

Churn Management Strategies

Keep-Alive Messages

Regular ping/pong messages to detect node failures

  • Periodic health checks
  • Timeout-based detection
  • Connection maintenance
Connection Redundancy

Maintain multiple connections to different peers

  • Multiple peer connections
  • Automatic reconnection
  • Load balancing
Peer Address Caching

Store addresses of known peers for future connections

  • Local peer database
  • Address freshness tracking
  • Reputation scoring
Ethereum's Approach

Ethereum handles churn through:

  • Kademlia DHT: Structured peer discovery
  • Node Discovery Protocol: UDP-based peer finding
  • Connection Limits: Maximum of 25 outbound connections
  • Peer Scoring: Reputation-based connection management

Security Considerations

Common Attacks
  • Eclipse Attack: Isolating a node from honest peers
  • Sybil Attack: Creating multiple fake identities
  • DDoS: Overwhelming nodes with requests
  • Routing Attacks: Manipulating message paths
Defense Mechanisms
  • Diverse Connections: Connect to peers from different subnets
  • Rate Limiting: Limit requests per peer
  • Proof of Work: Computational cost for participation
  • Reputation Systems: Track peer behavior
Eclipse Attack Example

An attacker controls all of a victim's peer connections, effectively isolating them from the honest network. This can lead to:

  • Double-spending attacks
  • Censorship of transactions
  • Mining on outdated chains

Performance Optimization

Key Performance Metrics

Latency

Time for message propagation

Throughput

Messages processed per second

Scalability

Performance with network size

Resilience

Fault tolerance capability

Optimization Techniques

  • Connection Management: Optimal number of peer connections
  • Message Prioritization: Important messages first
  • Compression: Reduce bandwidth usage
  • Caching: Store frequently accessed data locally
  • Load Balancing: Distribute traffic across peers

Session Summary

Key Takeaways
  • P2P networks enable decentralized communication without central servers
  • Routing mechanisms like flooding ensure message propagation across the network
  • Network churn is handled through redundancy and peer discovery protocols
  • Bootstrap methods help new nodes join the network initially
  • Security threats like eclipse and sybil attacks require specific defenses
  • Performance optimization balances latency, throughput, and resilience

What's Next?

In the next session, we'll explore Proof of Work, diving into the hash-puzzle mechanism that secures Bitcoin and understanding how mining difficulty adjusts to maintain consistent block times.