spy nodes are now gossip entrypoints (#6532)
This commit is contained in:
@ -1491,8 +1491,12 @@ impl ClusterInfo {
|
||||
}
|
||||
|
||||
/// An alternative to Spy Node that has a valid gossip address and fully participate in Gossip.
|
||||
pub fn gossip_node(id: &Pubkey, gossip_addr: &SocketAddr) -> (ContactInfo, UdpSocket) {
|
||||
let (port, (gossip_socket, _)) = Node::get_gossip_port(gossip_addr, VALIDATOR_PORT_RANGE);
|
||||
pub fn gossip_node(
|
||||
id: &Pubkey,
|
||||
gossip_addr: &SocketAddr,
|
||||
) -> (ContactInfo, UdpSocket, Option<TcpListener>) {
|
||||
let (port, (gossip_socket, ip_echo)) =
|
||||
Node::get_gossip_port(gossip_addr, VALIDATOR_PORT_RANGE);
|
||||
let daddr = socketaddr_any!();
|
||||
|
||||
let node = ContactInfo::new(
|
||||
@ -1507,11 +1511,11 @@ impl ClusterInfo {
|
||||
daddr,
|
||||
timestamp(),
|
||||
);
|
||||
(node, gossip_socket)
|
||||
(node, gossip_socket, Some(ip_echo))
|
||||
}
|
||||
|
||||
/// A Node with invalid ports to spy on gossip via pull requests
|
||||
pub fn spy_node(id: &Pubkey) -> (ContactInfo, UdpSocket) {
|
||||
pub fn spy_node(id: &Pubkey) -> (ContactInfo, UdpSocket, Option<TcpListener>) {
|
||||
let (_, gossip_socket) = bind_in_range(VALIDATOR_PORT_RANGE).unwrap();
|
||||
let daddr = socketaddr_any!();
|
||||
|
||||
@ -1527,7 +1531,7 @@ impl ClusterInfo {
|
||||
daddr,
|
||||
timestamp(),
|
||||
);
|
||||
(node, gossip_socket)
|
||||
(node, gossip_socket, None)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1800,9 +1804,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_gossip_node() {
|
||||
//check that a gossip nodes always show up as spies
|
||||
let (node, _) = ClusterInfo::spy_node(&Pubkey::new_rand());
|
||||
let (node, _, _) = ClusterInfo::spy_node(&Pubkey::new_rand());
|
||||
assert!(ClusterInfo::is_spy_node(&node));
|
||||
let (node, _) =
|
||||
let (node, _, _) =
|
||||
ClusterInfo::gossip_node(&Pubkey::new_rand(), &"1.1.1.1:1111".parse().unwrap());
|
||||
assert!(ClusterInfo::is_spy_node(&node));
|
||||
}
|
||||
@ -1811,7 +1815,7 @@ mod tests {
|
||||
fn test_cluster_spy_gossip() {
|
||||
//check that gossip doesn't try to push to invalid addresses
|
||||
let node = Node::new_localhost();
|
||||
let (spy, _) = ClusterInfo::spy_node(&Pubkey::new_rand());
|
||||
let (spy, _, _) = ClusterInfo::spy_node(&Pubkey::new_rand());
|
||||
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new_with_invalid_keypair(
|
||||
node.info,
|
||||
)));
|
||||
|
@ -10,7 +10,7 @@ use solana_ledger::bank_forks::BankForks;
|
||||
use solana_ledger::blocktree::Blocktree;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
||||
use std::net::{IpAddr, SocketAddr, TcpListener, UdpSocket};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::channel;
|
||||
use std::sync::{Arc, RwLock};
|
||||
@ -70,12 +70,14 @@ pub fn discover(
|
||||
gossip_addr: Option<&SocketAddr>,
|
||||
) -> std::io::Result<(Vec<ContactInfo>, Vec<ContactInfo>)> {
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let (gossip_service, spy_ref) = make_gossip_node(entry_point, &exit, gossip_addr);
|
||||
let (gossip_service, ip_echo, spy_ref) = make_gossip_node(entry_point, &exit, gossip_addr);
|
||||
|
||||
let id = spy_ref.read().unwrap().keypair.pubkey();
|
||||
info!("Gossip entry point: {:?}", entry_point);
|
||||
info!("Spy node id: {:?}", id);
|
||||
|
||||
let _ip_echo_server = ip_echo.map(solana_netutil::ip_echo_server);
|
||||
|
||||
let (met_criteria, secs, tvu_peers, archivers) = spy(
|
||||
spy_ref.clone(),
|
||||
num_nodes,
|
||||
@ -247,9 +249,9 @@ fn make_gossip_node(
|
||||
entry_point: &SocketAddr,
|
||||
exit: &Arc<AtomicBool>,
|
||||
gossip_addr: Option<&SocketAddr>,
|
||||
) -> (GossipService, Arc<RwLock<ClusterInfo>>) {
|
||||
) -> (GossipService, Option<TcpListener>, Arc<RwLock<ClusterInfo>>) {
|
||||
let keypair = Arc::new(Keypair::new());
|
||||
let (node, gossip_socket) = if let Some(gossip_addr) = gossip_addr {
|
||||
let (node, gossip_socket, ip_echo) = if let Some(gossip_addr) = gossip_addr {
|
||||
ClusterInfo::gossip_node(&keypair.pubkey(), gossip_addr)
|
||||
} else {
|
||||
ClusterInfo::spy_node(&keypair.pubkey())
|
||||
@ -259,7 +261,7 @@ fn make_gossip_node(
|
||||
let cluster_info = Arc::new(RwLock::new(cluster_info));
|
||||
let gossip_service =
|
||||
GossipService::new(&cluster_info.clone(), None, None, gossip_socket, &exit);
|
||||
(gossip_service, cluster_info)
|
||||
(gossip_service, ip_echo, cluster_info)
|
||||
}
|
||||
|
||||
impl Service for GossipService {
|
||||
|
Reference in New Issue
Block a user