Skip to content

Commit

Permalink
feat(pd): raises default peering limits
Browse files Browse the repository at this point in the history
Makes a few changes to `pd`, designed to improve peering behavior on
testnets:

  * raises the default values for inbound/outbound peers
  * limits the number of peers discovered during join to 5, randomized

We originally decided to add node discovery logic to aid in peering.
There's a downside, however, to reusing all peers of the bootstrap node:
the CI deployment nodes get swamped, and the network remains centralized
on the nodes that Penumbra Labs run. Instead, let's just take a handful,
at random, and trust the p2p gossip to discover more over time.

Refs #3056.
  • Loading branch information
conorsch committed Sep 20, 2023
1 parent 4cd7c3e commit 081fe52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 24 additions & 2 deletions crates/bin/pd/src/testnet/join.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Logic for onboarding a new `pd` node onto an existing testnet.
//! Handles generation of config files for `pd` and `tendermint`.
use anyhow::Context;
use rand::seq::SliceRandom;
use rand_core::OsRng;
use std::net::{IpAddr, SocketAddr};
use std::path::PathBuf;
use tendermint_config::net::Address as TendermintAddress;
Expand Down Expand Up @@ -127,7 +129,7 @@ pub async fn fetch_peers(tm_url: &Url) -> anyhow::Result<Vec<TendermintAddress>>
let client = reqwest::Client::new();
let net_info_url = tm_url.join("net_info")?;
tracing::debug!(%net_info_url, "Fetching peers of bootstrap node");
let net_info_peers = client
let mut net_info_peers = client
.get(net_info_url)
.send()
.await?
Expand All @@ -142,9 +144,19 @@ pub async fn fetch_peers(tm_url: &Url) -> anyhow::Result<Vec<TendermintAddress>>
if net_info_peers.len() == 0 {
tracing::warn!(
?net_info_peers,
"Bootstrap node reported 0 peers; we'll have no way to get blocks"
"bootstrap node reported 0 peers; we'll have no way to get blocks"
);
}

// Randomize the ordering of the peer candidates, so that different nodes
// joining are more likely to get different peers, as we select a subset.
net_info_peers.shuffle(&mut OsRng);

// We'll look for a handful of peers and use those in our config.
// We don't want to naively add all of the bootstrap node's peers,
// instead trusting gossip to find peers dynamically over time.
let threshold = 5;

let mut peers = Vec::new();
for raw_peer in net_info_peers {
tracing::debug!(?raw_peer, "Analyzing whether to include candidate peer");
Expand Down Expand Up @@ -183,6 +195,16 @@ pub async fn fetch_peers(tm_url: &Url) -> anyhow::Result<Vec<TendermintAddress>>
))?;
let peer_tm_address = parse_tm_address(Some(&node_id), &listen_url)?;
peers.push(peer_tm_address);
if peers.len() >= threshold {
tracing::debug!(?threshold, "Found desired number of initial peers");
break;
}
}
if peers.len() < threshold {
tracing::warn!(
"bootstrap node reported only {} peers; we may have trouble peering",
peers.len(),
);
}
Ok(peers)
}
Expand Down
4 changes: 2 additions & 2 deletions testnets/tm_config_template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ addr_book_file = "config/addrbook.json"
addr_book_strict = true

# Maximum number of inbound peers
max_num_inbound_peers = 40
max_num_inbound_peers = 100

# Maximum number of outbound peers to connect to, excluding persistent peers
max_num_outbound_peers = 10
max_num_outbound_peers = 50

# List of node IDs, to which a connection will be (re)established ignoring any existing limits
unconditional_peer_ids = ""
Expand Down

0 comments on commit 081fe52

Please sign in to comment.