This commit is contained in:
GroovieGermanikus 2023-08-02 14:26:13 +02:00
parent b41d05e613
commit 92a977fb98
5 changed files with 13 additions and 23 deletions

View File

@ -147,9 +147,7 @@ async fn new_endpoint_with_validator_identity(validator_identity: ValidatorIdent
)
.expect("Failed to initialize QUIC connection certificates");
let endpoint_outbound = create_tpu_client_endpoint(certificate.clone(), key.clone());
endpoint_outbound
create_tpu_client_endpoint(certificate, key)
}
fn create_tpu_client_endpoint(
@ -196,13 +194,12 @@ fn create_tpu_client_endpoint(
// send potentially large amount of transactions to a single TPU
#[tracing::instrument(skip_all, level = "debug")]
async fn send_tx_batch_to_tpu(auto_connection: &AutoReconnect, txs: &Vec<VersionedTransaction>) {
async fn send_tx_batch_to_tpu(auto_connection: &AutoReconnect, txs: &[VersionedTransaction]) {
for chunk in txs.chunks(MAX_PARALLEL_STREAMS) {
let all_send_fns = chunk
.iter()
.map(|tx| {
let tx_raw = bincode::serialize(tx).unwrap();
tx_raw
bincode::serialize(tx).unwrap()
})
.map(|tx_raw| {
auto_connection.send_uni(tx_raw) // ignores error

View File

@ -53,7 +53,7 @@ impl TpuForwardingRequest {
// TODO reame
pub fn deserialize_from_raw_request(raw_proxy_request: &Vec<u8>) -> TpuForwardingRequest {
let request = bincode::deserialize::<TpuForwardingRequest>(&raw_proxy_request)
let request = bincode::deserialize::<TpuForwardingRequest>(raw_proxy_request)
.context("deserialize proxy request")
.unwrap();

View File

@ -51,7 +51,7 @@ impl AutoReconnect {
}
let mut lock = self.current.write().await;
let maybe_conn = lock.as_ref();
return match maybe_conn {
match maybe_conn {
Some(current) => {
if current.close_reason().is_some() {
let old_stable_id = current.stable_id();
@ -73,7 +73,7 @@ impl AutoReconnect {
self.reconnect_count.load(Ordering::SeqCst)
);
new_connection.clone()
new_connection
} else {
debug!("Reuse connection {} with write-lock", current.stable_id());
current.clone()
@ -87,9 +87,9 @@ impl AutoReconnect {
// let old_conn = foo.replace(Some(new_connection.clone()));
debug!("Create initial connection {}", new_connection.stable_id());
new_connection.clone()
new_connection
}
};
}
}
async fn create_connection(&self) -> Connection {

View File

@ -25,16 +25,9 @@ pub struct SelfSignedTlsConfigProvider {
server_crypto: ServerConfig,
}
const INSTANCES: AtomicU32 = AtomicU32::new(0);
impl SelfSignedTlsConfigProvider {
pub fn new_singleton_self_signed_localhost() -> Self {
// note: this check could be relaxed when you know what you are doing!
assert_eq!(
INSTANCES.fetch_add(1, Ordering::Relaxed),
0,
"should be a singleton"
);
let hostnames = vec!["localhost".to_string()];
let (certificate, private_key) = Self::gen_tls_certificate_and_key(hostnames.clone());
let server_crypto = Self::build_server_crypto(certificate.clone(), private_key.clone());
@ -43,7 +36,7 @@ impl SelfSignedTlsConfigProvider {
certificate,
private_key,
client_crypto: Self::build_client_crypto_insecure(),
server_crypto: server_crypto,
server_crypto,
}
}
@ -61,7 +54,7 @@ impl SelfSignedTlsConfigProvider {
.with_no_client_auth();
client_crypto.enable_early_data = true;
client_crypto.alpn_protocols = vec![ALPN_TPU_FORWARDPROXY_PROTOCOL_ID.to_vec()];
return client_crypto;
client_crypto
}
fn build_server_crypto(server_cert: Certificate, server_key: PrivateKey) -> ServerConfig {
@ -74,7 +67,7 @@ impl SelfSignedTlsConfigProvider {
.with_single_cert(vec![server_cert], server_key)
.unwrap();
server_crypto.alpn_protocols = vec![ALPN_TPU_FORWARDPROXY_PROTOCOL_ID.to_vec()];
return server_crypto;
server_crypto
}
pub fn get_client_tls_crypto_config(&self) -> &ClientConfig {

View File

@ -14,7 +14,7 @@ impl ValidatorIdentity {
pub fn new(keypair: Option<Keypair>) -> Self {
let dummy_keypair = Keypair::new();
ValidatorIdentity {
keypair: keypair.map(|kp| Arc::new(kp)),
keypair: keypair.map(Arc::new),
dummy_keypair: Arc::new(dummy_keypair),
}
}
@ -38,7 +38,7 @@ impl ValidatorIdentity {
impl Display for ValidatorIdentity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.keypair {
Some(keypair) => write!(f, "{}", keypair.pubkey().to_string()),
Some(keypair) => write!(f, "{}", keypair.pubkey()),
None => write!(f, "no keypair"),
}
}