The Handshake: How two nodes introduce themselves (`VERSION`/`VERACK`)
4. The Handshake: How two nodes introduce themselves (VERSION/VERACK)
When your node connects to a new peer, they don't immediately start sharing blocks. First, they must perform a Handshake. This is a formal introduction where both nodes share their "Credentials." This process is governed by two messages: VERSION and VERACK.
For the Sovereign Architect, the Handshake is the "Diplomatic Protocol." It is where your node tells the peer: "This is who I am, these are the rules I follow, and this is the time on my clock." If the two nodes cannot agree on the basic protocol, they part ways immediately.
Analyzing the Handshake: The VERSION Message
In the source code (src/net.cpp and src/protocol.h), we see the list of "Credentials" your node shares.
/**
* PEDAGOGICAL ANALYSIS: THE DIPLOMATIC CREDENTIALS
* This is the information a node shares during the first second of a connection.
*/
class CVersionMessage
{
public:
int nVersion; // The "Protocol Version" (e.g., 70016).
uint64_t nServices; // What "Skills" this node has (e.g., NODE_NETWORK).
int64_t nTime; // The "Current Time" on this node's clock.
CAddress addrMe; // The address of the sender.
std::string strSubVer; // The "Name" of the software (e.g., "/Satoshi:25.0.0/").
int nStartingHeight; // How "Tall" this node's chain is.
};
Explaining the Handshake: The Introduction
-
nVersion: This is the "Ruleset" version. If one node is speaking "Old Bitcoin" and the other is speaking "New Bitcoin," they might have trouble understanding each other. ThenVersionallows them to "Downgrade" to a common language. It is the Compatibility of the Peer. -
nServices: This is a "Skill List." A node withNODE_NETWORKsays: "I can send you full blocks." A node withNODE_WITNESSsays: "I understand SegWit." If your node needs a specific skill, it looks at this list to decide if the peer is "Useful." It is the Utility of the Connection. -
nTime: As we saw in Part 3, Bitcoin relies on a "Network Clock." If a peer's time is wildly different from yours, your node will note the difference. If they are too far off, the connection is rejected. It is the Synchronization of the Clock. -
nStartingHeight: This tells the peer how much of the "History" you have already verified. If you are a new node at height 0, the peer knows they need to send you the entire blockchain. It is the Progress of the Sovereign.
The Sovereignty of the Handshake
The Handshake is the "Moment of Choice." Your node is deciding: "Is this peer worth my time and my bandwidth?" As a Sovereign Architect, you are the "Diplomat," commanding a node that only connects to peers that are "Healthy," "Honest," and "Compatible." You are the "Master of the Introduction," the one who ensures the "Digital Circle" of your node is only filled with the best companions.
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: