Overview

8 Peer to peer network

This chapter replaces the last central bottleneck—the shared folder—with a decentralized peer-to-peer network. In this gossip-style network, full nodes (including miners) connect to several peers and relay information directly, making block and transaction propagation fast and resilient. Because no single administrator decides what gets through, censorship becomes far harder: even if one node withholds data, others forward it. Wallets also benefit by broadcasting transactions to the entire network without knowing who the miners are, removing the need for miner address lists and improving discoverability and speed.

The chapter traces how data moves across the network and how peers communicate. Nodes connect over TCP (commonly to port 8333), perform a version/verack handshake, and then speak a shared protocol: new transactions are announced with inv, fetched with getdata, and sent with tx; new blocks are announced and fetched using headers, getdata, and block (per modern propagation like BIP130). Lightweight wallets use bloom filters to request only relevant data and receive compact merkleblock proofs to verify inclusion without downloading full blocks. This lets recipients learn about pending payments quickly (0-conf) and later confirm them as blocks arrive and accumulate work.

The second half explains how a new node boots up and joins the network. After installing software (e.g., Bitcoin Core) and verifying release signatures, a node discovers peers via manual entries, DNS seeds, or hard-coded seeds, then expands its view with getaddr/addr while maintaining multiple connections for robustness. It synchronizes by downloading headers first (getheaders/headers) to find the best chain, then pulls blocks in parallel (getdata/block), verifies proof of work and transactions, and builds the UTXO set—optionally skipping signature checks on very old blocks to accelerate initial download. Once caught up, the node enters normal operation, validating, relaying, and participating fully on the network; at this point the cookie-token scaffolding is discarded because the model now matches Bitcoin exactly.

   Bitcoin’s peer to peer network
visual toc peer to peer network.png
  The shared folder is a central point of authority
shared folder problem.png
  In a peer to peer network, blocks are being passed on from one node to another. Much like how gossip spreads among people.
basic network.png
  Transactions travel the peer to peer network just like blocks do. Wallets don’t need to know the miners anymore.
transactions over p2p network.png
  Tom’s computer program sets up a TCP connection to Lisa’s computer program. After this they can send and receive data between each other.
tcp connection.png
  Lisa must be able to understand what Tom writes on the channel.
need protocol.png
  Lightweight wallets communicate with nodes using the Bitcoin network protocol.
spv node exchange.png
  Tom’s node is informed about John’s transaction so that Tom can fetch it.
tx john tom.png
  Tom forwards the transaction to his friends.
tom sends tx.png
  Tom’s node sends the transaction to Qi’s node by using the familiar three-step process
tx tom qi.png
2ndcol lisa sends inv.png
  Lisa’s node sends an inv to Qi’s node, but Qi’s node already has the transaction
tx lisa qi.png
2ndcol rashid sends inv.png
  The cafe’s lightweight wallet has a TCP connection to their own full node
cafe connected to node.png
  The cafe’s wallet gets John’s transaction from their trusted node after being checked against the bloom filter.
tx cafenode cafe.png
2ndcol rashid sends inv.png
  Rashid’s block containing John’s transaction
2ndcol rashids block valid.png
  Rashid’s node sends Rashid’s block to Qi’s node
block rashid qi.png
  All but Lisa has the block. Tom, Cafe and Qi send headers messages.
tom cafe qi sends headers.png
  Tom sends a merkleblock containing a merkle proof that John’s transaction is in the block.
john requests merkleblock.png
  The merkleblock contains a block header and a partial merkle tree.
verify merkle proof.png
  The cafe requests a merkleblock from their trusted full node
cafewallet requests merkleblock.png
  As more blocks arrive, John’s transaction becomes safer and safer
further confirmations.png
  The cookie token system evolution.
cookie token evolution.png
26   The Bitcoin network distributes blocks (and transactions) to all participants.
periscope bitcoin network.png
  Running a full node involves, downloading and running the software, connect to other nodes, download old blocks and enter normal operation
running a full node.png
step 1 run software.png
  The Bitcoin Core team signs the released program with their private key
core signs program.png
  Selma verifies the Bitcoin Core signature and that the hash in the signature file matches the hash of the actual program.
selma verifies program.png
  Selma’s full node has three different types of sources to find initial peers
initial peer addresses.png
version selma qi.png
  Selma requests more peer addresses from Rashid’s node. He responds with a bunch.
addr selma rashid.png
  Selma downloads block headers from Tom by repeatedly sending a getheaders message with her latest block id.
getheaders selma tom.png
  Selma downloads blocks from Tom by repeatedly sending a getblocks message with her latest block id.
getblocks selma rashid.png
  Selma is finally an active part of the Bitcoin peer to peer network
selma full blown node.png
  The Bitcoin Core team signs the released program with their private key
core signs program.png
  Johns transaction propagates to all participants
summary tx propagation.png
  Rashid’s block containing John’s transaction propagates to all participants
summary block propagation.png
  Selma goes through four steps to join the network
running a full node.png
ex network lie to lisa.png
ex network badly connected.png
ex getblocks power outage.png

  Recap

In this chapter you learned that

  • The peer to peer network makes blocks censorship resistant
  • A node connects to multiple peers to reduce their vulnerability for information hiding.
  • The Bitcoin network protocol is the "language" nodes speak to communicate.
  • Transactions are broadcast on the Bitcoin peer to peer network to reach both miners and the recipient of the money early.
  • New nodes synchronize with the Bitcoin network to get up to date with the other nodes. Takes hours or days.
  • Nodes do not need to stay on-line 24/7. They can drop out and come back and sync up the latest stuff.
  • Signature verification can be skipped for older blocks to speed up initial synchronization. This is useful if you know that a specific block is valid.

FAQ

Why was the “shared folder” a bad idea, and how does a peer-to-peer (P2P) network fix it?The shared folder is a central point of authority and failure: the admin can censor blocks, and every node downloading the same block from one place creates a propagation bottleneck. A decentralized P2P “gossip” network removes this single choke point—nodes connect to many peers and relay blocks/transactions among themselves, making censorship and slow block propagation far harder.
How do wallets broadcast transactions without knowing who the miners are?Wallets connect to any full node and use the network’s gossip protocol. They first advertise a transaction’s ID with an inv message; interested peers request it with getdata; the wallet (or node) responds with the full tx message. From there, peers repeat the same inv → getdata → tx sequence, reaching miners quickly without the wallet tracking miner addresses.
What network messages advertise and fetch data?- inv: “I have these items” (txids or block headers/hashes)
- getdata: “Send me these items”
- tx: full transaction
- headers: list of new block headers (BIP130 flow for blocks)
- block: full block
- merkleblock: header + partial Merkle tree for SPV wallets, proving inclusion of relevant txs
What does it mean to “relay,” and why does peer diversity matter?Relaying is forwarding a received transaction or block to your peers. If one peer withholds data, others will still deliver it, provided you’re well connected. More, diverse peers improve censorship resistance, reduce the chance of missing data, and speed up propagation.
How do lightweight (SPV) wallets get notified and verify transactions without downloading full blocks?SPV wallets set a Bloom filter with their trusted/full node connection. When a node sees a tx matching the filter, it advertises it (inv); the wallet requests it (getdata). For confirmations, the wallet gets headers and requests merkleblock messages to verify inclusion via a Merkle proof without downloading the entire block. Trusted-node setups can use large (sparse) filters to reduce irrelevant traffic.
How do two nodes connect and agree how to talk?They open a TCP connection to the listening node’s IP:port (default port 8333). They exchange version messages (protocol version, user agent, services, best height, and “my address”) followed by verack acknowledgments. After this handshake, they can relay transactions, headers, and blocks.
How does a brand-new node find peers?A node can use multiple sources: (1) manually configured peers, (2) DNS seeds baked into the software, and (3) a small set of hardcoded fallback addresses. After initial connections, it asks peers for more addresses (getaddr → addr) to expand connectivity. Typical nodes maintain many connections; only a subset are outbound, with the rest inbound if the node is reachable.
What is the initial blockchain download (IBD) process?IBD first downloads and verifies all block headers (in batches, e.g., 2000 at a time) to find the strongest chain, then fetches full blocks—often in parallel from multiple peers—while building the UTXO set. To speed up, nodes may skip signature checks for very old blocks beyond a known-assumed-valid point while still enforcing all other rules.
How are new blocks propagated quickly (and why headers-first)?Per BIP130, a node that finds/learns a new block sends a headers message to peers. Interested peers respond with getdata for the full block, and the sender replies with block. Advertising headers instead of full blocks reduces bandwidth and latency, speeding propagation and lowering the risk of competing blocks overtaking each other.
What are “confirmations,” and why might a merchant wait for them?Each block mined on top of the one containing a transaction adds a confirmation. More confirmations mean more accumulated proof of work, making double-spends increasingly impractical. A merchant may accept a 0-conf payment (riskier) or wait for one or more confirmations (safer). SPV wallets track headers and request merkleblock proofs to verify inclusion.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bitcoin ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bitcoin ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bitcoin ebook for free