TeachMeBitcoin

The Eviction Policy: How the node decides which peers to kick out

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

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

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."


☕ Help support TeachMeBitcoin

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:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!