The Eviction Policy: How the node decides which peers to kick out
9. The Eviction Policy: How the node decides which peers to kick out
As we saw in Chapter 6, your node has a "Room Limit" (usually 125 peers). But what happens when the room is full and a new, potentially better peer wants to connect? The node must perform an Eviction. This is the "Bouncer" of the node. It looks at the current group of peers and decides who is the "Weakest Link" to be kicked out.
For the Sovereign Architect, the Eviction Policy is the "Survival of the Fittest." It ensures that your node's limited memory and bandwidth are always used for the "Highest Quality" peers. It is a ruthless but necessary logic.
Analyzing the Bouncer: SelectNodeToEvict
In the source code (src/net.cpp), we see the "Criteria" for being kicked out. It is a multi-step "Audition."
/**
* PEDAGOGICAL ANALYSIS: THE BOUNCER'S CRITERIA
* This logic protects the "Most Valuable" peers while sacrificing the "Laggards".
*/
std::optional<NodeId> SelectNodeToEvict(std::vector<NodeEvictionCandidate>&& vEvictionCandidates)
{
// [THE AUDITION]
// 1. PROTECT the "Old Friends".
// We favor peers that have been with us for a long time.
// 2. PROTECT the "Net-Work" peers.
// We favor peers that have given us a "Block" recently.
// 3. SACRIFICE the "Slow" peers.
// We kick out peers with the lowest bandwidth or highest "Latency" (delay).
// 4. SACRIFICE the "Duplicates".
// If we have 10 peers from the same "Neighborhood" (IP range),
// we kick one of them out to keep the network "Diverse".
}
Explaining the Bouncer: The Quality Control
-
"Neighborhood Protection": If a hacker wants to attack you, they might start 100 nodes in the same data center and try to "Surround" you. The Bouncer detects this! It says: "I already have enough friends from this part of the internet," and kicks out the duplicates. It is the Defense against the Sybil.
-
"Block Protection": A peer that gives you a block is like a person who "Brings Food to the Party." They are very valuable. The Bouncer will almost never kick out a peer that is actively helping you synchronize. It is the Reward for the Contribution.
-
"Latency Sacrifice": If a peer takes 5 seconds to answer a "Ping," they are "Dead Weight." They are slowing down your node's ability to hear the news. The Bouncer will kick them out to make room for a "Faster" peer. It is the Efficiency of the Sovereign.
-
"Inbound-Only Eviction": Crucially, your node Never evicts its "Outbound Scouts" (Chapter 8). The Bouncer only kicks out "Inbound Guests." This ensures your "Trusted Lifeline" is never broken by a surge of strangers. It is the Stability of the Core.
The Sovereignty of the Selection
Your node is an "Elite Club." Not everyone is allowed to stay. By performing these evictions, your node is constantly "Upgrading" its social circle. As a Sovereign Architect, you know that a "Lean and Fast" network is safer than a "Bloated and Slow" one. You are the "Master of the Bouncer," commanding a node that only speaks to the most reliable, diverse, and helpful peers on the planet. You are the "Guardian of the Quality."
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: