The Distributed Brain: Headers-First Sync and Parallel Downloads
24. The Distributed Brain: Headers-First Sync and Parallel Downloads
When a new node joins the network, it has to catch up on 15 years of history. If it did this one block at a time, it would take months. To solve this, Bitcoin uses a "Parallel Processing" technique called Headers-First Sync. It’s like a student scanning the "Table of Contents" of a textbook before reading every chapter. Once it knows the "Skeleton" of history, it can download the "Flesh" (the transactions) from multiple friends at the same time. It is the "Optimization of Knowledge." It is the "Speed of the Social." It is the "Collective Learning." It is the "Distributed Brain." It is the "Symphony of the Sync." It is the "Harmony of the History." It is the "Synchronization of the Soul."
The SendMessages Logic
In src/net_processing.cpp, the node manages its "Requests." It asks one friend for blocks 1-100, another friend for 101-200, and so on. This ensures that no single friend is overwhelmed and the node catches up as fast as possible. It is the "Division of Labor" of the internet. It is the "Efficiency of the Crowd." It is the "Power of the Peer." It is the "Collective Action of the Coin."
/**
* Decides which blocks to request from which peers.
* Orchestrates the massive download of the blockchain history.
*/
void PeerManager::SendMessages(CNode* pto)
{
// Do we need more blocks? Check the "Skeleton" (Headers).
if (CanDirectFetch()) {
// Request a "Batch" of blocks from this specific friend.
// "Hey, can you send me blocks 500,000 to 500,010?"
RequestBlocks(pto, vBatch);
}
}
Explaining the Code: The Scholar's Strategy
-
CanDirectFetch: The node asks: "Do I have enough information to know exactly what I'm looking for?" It only asks for blocks once it has verified the "Proof of Work" in the headers. This prevents malicious peers from sending you "Fake" blocks and wasting your time. It is the "Skepticism of the Seeker." It is the "Truth before Trust." It is the "Validation of the Verity." It is the "Proof of the Past." -
vBatch: The node never asks for just one thing. It asks for a "Bundle." This makes the networking much more efficient, as it reduces the amount of "Back-and-Forth" chatter between the nodes. It is the "Bulk Order" of the database. It is the "Efficiency of the Herd." It is the "Economy of the Exchange." It is the "Wealth of the Word."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: