Move get_clients into gossip_service (#4109)
This commit is contained in:
parent
598f765960
commit
1ab5098576
|
@ -5,12 +5,8 @@ use itertools::izip;
|
||||||
use log::*;
|
use log::*;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use solana::cluster_info::FULLNODE_PORT_RANGE;
|
|
||||||
use solana::contact_info::ContactInfo;
|
|
||||||
use solana::gen_keys::GenKeys;
|
use solana::gen_keys::GenKeys;
|
||||||
use solana_client::perf_utils::{sample_txs, SampleStats};
|
use solana_client::perf_utils::{sample_txs, SampleStats};
|
||||||
use solana_client::thin_client::create_client;
|
|
||||||
use solana_client::thin_client::ThinClient;
|
|
||||||
use solana_drone::drone::request_airdrop_transaction;
|
use solana_drone::drone::request_airdrop_transaction;
|
||||||
use solana_exchange_api::exchange_instruction;
|
use solana_exchange_api::exchange_instruction;
|
||||||
use solana_exchange_api::exchange_state::*;
|
use solana_exchange_api::exchange_state::*;
|
||||||
|
@ -907,29 +903,11 @@ pub fn airdrop_lamports(client: &Client, drone_addr: &SocketAddr, id: &Keypair,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_clients(nodes: &[ContactInfo]) -> Vec<ThinClient> {
|
|
||||||
nodes
|
|
||||||
.iter()
|
|
||||||
.filter_map(|node| {
|
|
||||||
let cluster_entrypoint = node;
|
|
||||||
let cluster_addrs = cluster_entrypoint.client_facing_addr();
|
|
||||||
if ContactInfo::is_valid_address(&cluster_addrs.0)
|
|
||||||
&& ContactInfo::is_valid_address(&cluster_addrs.1)
|
|
||||||
{
|
|
||||||
let client = create_client(cluster_addrs, FULLNODE_PORT_RANGE);
|
|
||||||
Some(client)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana::fullnode::FullnodeConfig;
|
use solana::fullnode::FullnodeConfig;
|
||||||
use solana::gossip_service::discover_nodes;
|
use solana::gossip_service::{discover_nodes, get_clients};
|
||||||
use solana::local_cluster::{ClusterConfig, LocalCluster};
|
use solana::local_cluster::{ClusterConfig, LocalCluster};
|
||||||
use solana_drone::drone::run_local_drone;
|
use solana_drone::drone::run_local_drone;
|
||||||
use solana_exchange_api::exchange_processor::process_instruction;
|
use solana_exchange_api::exchange_processor::process_instruction;
|
||||||
|
|
|
@ -2,9 +2,9 @@ pub mod bench;
|
||||||
mod cli;
|
mod cli;
|
||||||
pub mod order_book;
|
pub mod order_book;
|
||||||
|
|
||||||
use crate::bench::{airdrop_lamports, do_bench_exchange, get_clients, Config};
|
use crate::bench::{airdrop_lamports, do_bench_exchange, Config};
|
||||||
use log::*;
|
use log::*;
|
||||||
use solana::gossip_service::discover_nodes;
|
use solana::gossip_service::{discover_nodes, get_clients};
|
||||||
use solana_sdk::signature::KeypairUtil;
|
use solana_sdk::signature::KeypairUtil;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -2,10 +2,7 @@ mod bench;
|
||||||
mod cli;
|
mod cli;
|
||||||
|
|
||||||
use crate::bench::{do_bench_tps, generate_and_fund_keypairs, Config, NUM_LAMPORTS_PER_ACCOUNT};
|
use crate::bench::{do_bench_tps, generate_and_fund_keypairs, Config, NUM_LAMPORTS_PER_ACCOUNT};
|
||||||
use solana::cluster_info::FULLNODE_PORT_RANGE;
|
use solana::gossip_service::{discover_nodes, get_clients};
|
||||||
use solana::contact_info::ContactInfo;
|
|
||||||
use solana::gossip_service::discover_nodes;
|
|
||||||
use solana_client::thin_client::create_client;
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -39,21 +36,8 @@ fn main() {
|
||||||
);
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
let clients: Vec<_> = nodes
|
|
||||||
.iter()
|
let clients = get_clients(&nodes);
|
||||||
.filter_map(|node| {
|
|
||||||
let cluster_entrypoint = node.clone();
|
|
||||||
let cluster_addrs = cluster_entrypoint.client_facing_addr();
|
|
||||||
if ContactInfo::is_valid_address(&cluster_addrs.0)
|
|
||||||
&& ContactInfo::is_valid_address(&cluster_addrs.1)
|
|
||||||
{
|
|
||||||
let client = create_client(cluster_addrs, FULLNODE_PORT_RANGE);
|
|
||||||
Some(client)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let (keypairs, keypair_balance) = generate_and_fund_keypairs(
|
let (keypairs, keypair_balance) = generate_and_fund_keypairs(
|
||||||
&clients[0],
|
&clients[0],
|
||||||
|
|
|
@ -210,6 +210,14 @@ impl ContactInfo {
|
||||||
pub fn client_facing_addr(&self) -> (SocketAddr, SocketAddr) {
|
pub fn client_facing_addr(&self) -> (SocketAddr, SocketAddr) {
|
||||||
(self.rpc, self.tpu)
|
(self.rpc, self.tpu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn valid_client_facing_addr(&self) -> Option<(SocketAddr, SocketAddr)> {
|
||||||
|
if ContactInfo::is_valid_address(&self.rpc) && ContactInfo::is_valid_address(&self.tpu) {
|
||||||
|
Some((self.rpc, self.tpu))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Signable for ContactInfo {
|
impl Signable for ContactInfo {
|
||||||
|
@ -272,6 +280,7 @@ mod tests {
|
||||||
assert!(ContactInfo::is_valid_address(&loopback));
|
assert!(ContactInfo::is_valid_address(&loopback));
|
||||||
// assert!(!ContactInfo::is_valid_ip_internal(loopback.ip(), false));
|
// assert!(!ContactInfo::is_valid_ip_internal(loopback.ip(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_default() {
|
fn test_default() {
|
||||||
let ci = ContactInfo::default();
|
let ci = ContactInfo::default();
|
||||||
|
@ -333,4 +342,14 @@ mod tests {
|
||||||
assert_eq!(d1.rpc, socketaddr!("127.0.0.1:8899"));
|
assert_eq!(d1.rpc, socketaddr!("127.0.0.1:8899"));
|
||||||
assert_eq!(d1.rpc_pubsub, socketaddr!("127.0.0.1:8900"));
|
assert_eq!(d1.rpc_pubsub, socketaddr!("127.0.0.1:8900"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_valid_client_facing() {
|
||||||
|
let mut ci = ContactInfo::default();
|
||||||
|
assert_eq!(ci.valid_client_facing_addr(), None);
|
||||||
|
ci.tpu = socketaddr!("127.0.0.1:123");
|
||||||
|
assert_eq!(ci.valid_client_facing_addr(), None);
|
||||||
|
ci.rpc = socketaddr!("127.0.0.1:234");
|
||||||
|
assert!(ci.valid_client_facing_addr().is_some());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
use crate::bank_forks::BankForks;
|
use crate::bank_forks::BankForks;
|
||||||
use crate::blocktree::Blocktree;
|
use crate::blocktree::Blocktree;
|
||||||
use crate::cluster_info::ClusterInfo;
|
use crate::cluster_info::ClusterInfo;
|
||||||
|
use crate::cluster_info::FULLNODE_PORT_RANGE;
|
||||||
use crate::contact_info::ContactInfo;
|
use crate::contact_info::ContactInfo;
|
||||||
use crate::service::Service;
|
use crate::service::Service;
|
||||||
use crate::streamer;
|
use crate::streamer;
|
||||||
|
use solana_client::thin_client::{create_client, ThinClient};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
@ -105,6 +107,14 @@ pub fn discover(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_clients(nodes: &[ContactInfo]) -> Vec<ThinClient> {
|
||||||
|
nodes
|
||||||
|
.iter()
|
||||||
|
.filter_map(ContactInfo::valid_client_facing_addr)
|
||||||
|
.map(|addrs| create_client(addrs, FULLNODE_PORT_RANGE))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn spy(
|
fn spy(
|
||||||
spy_ref: Arc<RwLock<ClusterInfo>>,
|
spy_ref: Arc<RwLock<ClusterInfo>>,
|
||||||
num_nodes: Option<usize>,
|
num_nodes: Option<usize>,
|
||||||
|
|
Loading…
Reference in New Issue