Thin client quic (#23973)

Change thin-client to use connection-cache
This commit is contained in:
ryleung-solana
2022-03-31 15:47:00 -04:00
committed by GitHub
parent 31997f8251
commit 8b72200afb
13 changed files with 98 additions and 154 deletions

View File

@ -1,5 +1,5 @@
use {
solana_client::{thin_client::ThinClient, udp_client::UdpTpuConnection},
solana_client::thin_client::ThinClient,
solana_core::validator::{Validator, ValidatorConfig},
solana_gossip::{cluster_info::Node, contact_info::ContactInfo},
solana_sdk::{pubkey::Pubkey, signature::Keypair},
@ -36,7 +36,7 @@ impl ClusterValidatorInfo {
pub trait Cluster {
fn get_node_pubkeys(&self) -> Vec<Pubkey>;
fn get_validator_client(&self, pubkey: &Pubkey) -> Option<ThinClient<UdpTpuConnection>>;
fn get_validator_client(&self, pubkey: &Pubkey) -> Option<ThinClient>;
fn get_contact_info(&self, pubkey: &Pubkey) -> Option<&ContactInfo>;
fn exit_node(&mut self, pubkey: &Pubkey) -> ClusterValidatorInfo;
fn restart_node(

View File

@ -10,7 +10,7 @@ use {
solana_core::consensus::VOTE_THRESHOLD_DEPTH,
solana_entry::entry::{Entry, EntrySlice},
solana_gossip::{
cluster_info::{self, VALIDATOR_PORT_RANGE},
cluster_info,
contact_info::ContactInfo,
crds_value::{self, CrdsData, CrdsValue},
gossip_error::GossipError,
@ -60,7 +60,7 @@ pub fn spend_and_verify_all_nodes<S: ::std::hash::BuildHasher + Sync + Send>(
return;
}
let random_keypair = Keypair::new();
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(ingress_node.client_facing_addr());
let bal = client
.poll_get_balance_with_commitment(
&funding_keypair.pubkey(),
@ -81,7 +81,7 @@ pub fn spend_and_verify_all_nodes<S: ::std::hash::BuildHasher + Sync + Send>(
if ignore_nodes.contains(&validator.id) {
continue;
}
let client = create_client(validator.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(validator.client_facing_addr());
client.poll_for_signature_confirmation(&sig, confs).unwrap();
}
});
@ -91,7 +91,7 @@ pub fn verify_balances<S: ::std::hash::BuildHasher>(
expected_balances: HashMap<Pubkey, u64, S>,
node: &ContactInfo,
) {
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(node.client_facing_addr());
for (pk, b) in expected_balances {
let bal = client
.poll_get_balance_with_commitment(&pk, CommitmentConfig::processed())
@ -106,7 +106,7 @@ pub fn send_many_transactions(
max_tokens_per_transfer: u64,
num_txs: u64,
) -> HashMap<Pubkey, u64> {
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(node.client_facing_addr());
let mut expected_balances = HashMap::new();
for _ in 0..num_txs {
let random_keypair = Keypair::new();
@ -197,7 +197,7 @@ pub fn kill_entry_and_spend_and_verify_rest(
let cluster_nodes =
discover_cluster(&entry_point_info.gossip, nodes, socket_addr_space).unwrap();
assert!(cluster_nodes.len() >= nodes);
let client = create_client(entry_point_info.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(entry_point_info.client_facing_addr());
// sleep long enough to make sure we are in epoch 3
let first_two_epoch_slots = MINIMUM_SLOTS_PER_EPOCH * (3 + 1);
@ -225,7 +225,7 @@ pub fn kill_entry_and_spend_and_verify_rest(
continue;
}
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(ingress_node.client_facing_addr());
let balance = client
.poll_get_balance_with_commitment(
&funding_keypair.pubkey(),
@ -296,7 +296,7 @@ pub fn check_for_new_roots(num_new_roots: usize, contact_infos: &[ContactInfo],
assert!(loop_start.elapsed() < loop_timeout);
for (i, ingress_node) in contact_infos.iter().enumerate() {
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(ingress_node.client_facing_addr());
let root_slot = client
.get_slot_with_commitment(CommitmentConfig::finalized())
.unwrap_or(0);
@ -327,7 +327,7 @@ pub fn check_no_new_roots(
.iter()
.enumerate()
.map(|(i, ingress_node)| {
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(ingress_node.client_facing_addr());
let initial_root = client
.get_slot()
.unwrap_or_else(|_| panic!("get_slot for {} failed", ingress_node.id));
@ -345,7 +345,7 @@ pub fn check_no_new_roots(
let mut reached_end_slot = false;
loop {
for contact_info in contact_infos {
let client = create_client(contact_info.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(contact_info.client_facing_addr());
current_slot = client
.get_slot_with_commitment(CommitmentConfig::processed())
.unwrap_or_else(|_| panic!("get_slot for {} failed", contact_infos[0].id));
@ -367,7 +367,7 @@ pub fn check_no_new_roots(
}
for (i, ingress_node) in contact_infos.iter().enumerate() {
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(ingress_node.client_facing_addr());
assert_eq!(
client
.get_slot()
@ -387,7 +387,7 @@ fn poll_all_nodes_for_signature(
if validator.id == entry_point_info.id {
continue;
}
let client = create_client(validator.client_facing_addr(), VALIDATOR_PORT_RANGE);
let client = create_client(validator.client_facing_addr());
client.poll_for_signature_confirmation(sig, confs)?;
}

View File

@ -6,18 +6,13 @@ use {
},
itertools::izip,
log::*,
solana_client::{
thin_client::{create_client, ThinClient},
udp_client::UdpTpuConnection,
},
solana_client::thin_client::{create_client, ThinClient},
solana_core::{
tower_storage::FileTowerStorage,
validator::{Validator, ValidatorConfig, ValidatorStartProgress},
},
solana_gossip::{
cluster_info::{Node, VALIDATOR_PORT_RANGE},
contact_info::ContactInfo,
gossip_service::discover_cluster,
cluster_info::Node, contact_info::ContactInfo, gossip_service::discover_cluster,
},
solana_ledger::create_new_tmp_ledger,
solana_runtime::genesis_utils::{
@ -393,10 +388,7 @@ impl LocalCluster {
mut voting_keypair: Option<Arc<Keypair>>,
socket_addr_space: SocketAddrSpace,
) -> Pubkey {
let client = create_client(
self.entry_point_info.client_facing_addr(),
VALIDATOR_PORT_RANGE,
);
let client = create_client(self.entry_point_info.client_facing_addr());
// Must have enough tokens to fund vote account and set delegate
let should_create_vote_pubkey = voting_keypair.is_none();
@ -480,10 +472,7 @@ impl LocalCluster {
}
pub fn transfer(&self, source_keypair: &Keypair, dest_pubkey: &Pubkey, lamports: u64) -> u64 {
let client = create_client(
self.entry_point_info.client_facing_addr(),
VALIDATOR_PORT_RANGE,
);
let client = create_client(self.entry_point_info.client_facing_addr());
Self::transfer_with_client(&client, source_keypair, dest_pubkey, lamports)
}
@ -538,7 +527,7 @@ impl LocalCluster {
}
fn transfer_with_client(
client: &ThinClient<UdpTpuConnection>,
client: &ThinClient,
source_keypair: &Keypair,
dest_pubkey: &Pubkey,
lamports: u64,
@ -567,7 +556,7 @@ impl LocalCluster {
}
fn setup_vote_and_stake_accounts(
client: &ThinClient<UdpTpuConnection>,
client: &ThinClient,
vote_account: &Keypair,
from_account: &Arc<Keypair>,
amount: u64,
@ -704,13 +693,10 @@ impl Cluster for LocalCluster {
self.validators.keys().cloned().collect()
}
fn get_validator_client(&self, pubkey: &Pubkey) -> Option<ThinClient<UdpTpuConnection>> {
self.validators.get(pubkey).map(|f| {
create_client(
f.info.contact_info.client_facing_addr(),
VALIDATOR_PORT_RANGE,
)
})
fn get_validator_client(&self, pubkey: &Pubkey) -> Option<ThinClient> {
self.validators
.get(pubkey)
.map(|f| create_client(f.info.contact_info.client_facing_addr()))
}
fn exit_node(&mut self, pubkey: &Pubkey) -> ClusterValidatorInfo {