P2p_networking
Chapter 23: Peer-to-Peer Networking
Section titled “Chapter 23: Peer-to-Peer Networking”Overview
Section titled “Overview”Blockchain nodes communicate through Peer-to-Peer (P2P) networks. Understanding P2P networking is essential for node operators.
23.1 P2P Network Basics
Section titled “23.1 P2P Network Basics”How Blockchain P2P Works
Section titled “How Blockchain P2P Works”┌─────────────────────────────────────────────────────────────────┐│ P2P NETWORK OVERVIEW │├─────────────────────────────────────────────────────────────────┤│ ││ Each node connects to multiple peers ││ ││ Node A ││ / | | \ ││ / | | \ ││ / | | \ ││ B C D E ││ ││ Transactions flow: A → B, C, D, E ││ Blocks propagate: A → B → C → D → E ││ ││ No central server - fully decentralized ││ │└─────────────────────────────────────────────────────────────────┘23.2 Node Discovery
Section titled “23.2 Node Discovery”Discovery Methods
Section titled “Discovery Methods”| Method | Description |
|---|---|
| Bootnodes | Well-known nodes for initial connection |
| DNS Discovery | DNS-based peer discovery |
| DiscV5 | Ethereum’s new discovery protocol |
| Kademlia | DHT-based peer discovery |
Bootnodes in Ethereum
Section titled “Bootnodes in Ethereum”# Mainnet bootnodesenr:-KG4QOtcL...@bootnode.mainnet.ethdisco.net:30303
# Connect to specific peersgeth --bootnodes "enr:-KG4..."23.3 Network Ports
Section titled “23.3 Network Ports”Common Ports
Section titled “Common Ports”| Protocol | Port | Description |
|---|---|---|
| TCP P2P | 30303 | Ethereum mainnet |
| UDP Discovery | 30303 | Peer discovery |
| HTTP RPC | 8545 | JSON-RPC |
| WebSocket | 8546 | WS API |
Firewall Configuration
Section titled “Firewall Configuration”# Allow P2Psudo ufw allow 30303/tcpsudo ufw allow 30303/udp
# Allow RPC (restrict to your IP)sudo ufw allow from YOUR_IP to any port 8545
# Allow WebSocketsudo ufw allow 8546/tcp23.4 Peer Management
Section titled “23.4 Peer Management”Connecting to Peers
Section titled “Connecting to Peers”# In Geth consoleadmin.peers() # List all peersadmin.addPeer("enr:...") # Add specific peer
# Check peer countnet.peerCountStatic Peers
Section titled “Static Peers”# config.toml[Node]StaticNodes = ["enr:...", "enr:..."]23.5 Network Troubleshooting
Section titled “23.5 Network Troubleshooting”Common Issues
Section titled “Common Issues”| Issue | Cause | Solution |
|---|---|---|
| No peers | Firewall, network | Check ports, add bootnodes |
| Peer drops | Network issues | Check connectivity |
| Sync stuck | Peer issues | Try different peers |
Debug Commands
Section titled “Debug Commands”# Check network infocurl http://localhost:8545 -X POST -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":1}'
# Check enodegeth attach http://localhost:8545admin.nodeInfo.enodeSummary
Section titled “Summary”- P2P networks enable decentralized communication
- Bootnodes help new nodes discover peers
- Proper firewall configuration is crucial
- Monitor peer count for network health
Next Chapter
Section titled “Next Chapter”In Chapter 24: Node Discovery Protocols, we’ll explore discovery in detail.
Last Updated: 2026-02-20