The Inventory System: The concept of `inv` messages
10. The Inventory System: The concept of inv messages
In the "Forge of the Core," information is the most valuable currency. But if every node "Shouted" every new block and transaction at its neighbors, the internet would "Collapse" under the weight of the data. To solve this, Bitcoin uses the Inventory (inv) System. This is the "Newsletter" of the network.
Instead of sending the "Whole Crate" (the block), a node first sends a "Postcard" (the inv message). The postcard says: "I have a new block with this Hash. Do you want it?" The neighbor then "Requests" the data only if they don't already have it. This is the "Efficiency of the Propagation."
Analyzing the Newsletter: The inv Message
In the source code (src/protocol.h and src/net_processing.cpp), we see the simple structure of the "Postcard."
/**
* PEDAGOGICAL ANALYSIS: THE NEWSLETTER OF THE TRUTH
* This logic allows nodes to announce data without wasting bandwidth.
*/
class CInv
{
public:
int type; // What is it? (MSG_TX or MSG_BLOCK).
uint256 hash; // What is its "Fingerprint"?
// This allows the node to "Sort" its newsletters.
bool operator<(const CInv& a) const;
};
Explaining the Newsletter: The "I Have" Message
-
MSG_TXvsMSG_BLOCK: Theinvmessage is "Agnostic." It doesn't care if it's a tiny transaction or a massive block. It just says: "Here is a piece of data." This simplicity allows the node to handle all "Announcements" with the same code. It is the Generic Pulse of the Network. -
"The Hash (Fingerprint)": As we saw in Part 1, every piece of data in Bitcoin has a unique hash. By sharing only the hash, the node allows its neighbor to check their own "Memory" (their
BlockMap). If they recognize the hash, they say: "No thanks, I already have that." This prevents "Duplication." It is the Smart Gossip of the Sovereign. -
"The Batching": A single
invmessage can contain up to 50,000 hashes. This "Batching" allows a node that is catching up to tell its neighbors about thousands of blocks in a single packet. It is the Speed of the Catch-up. -
"The Trickle": To prevent a hacker from "Timing" your transactions and finding out who you are, Bitcoin Core doesn't send
invmessages immediately. It "Batches" them and sends them out at random intervals (every few hundred milliseconds). This "Trickle" is a key privacy feature. It is the Discretion of the Sovereign.
The Sovereignty of the Announcement
The Inventory System is the "Quiet Confidence" of the network. It is the proof that Bitcoin is designed for "Global Scale." By using inv messages, your node can stay synchronized with the world while using a fraction of the bandwidth. As a Sovereign Architect, you know that "Less is More." You are the "Master of the Newsletter," the one who ensures the "Digital Gossip" of your machine is always efficient, private, and precise. You are the "Guardian of the Inventory."
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: