From 92a977fb984e1bc9447367820019302810f6a9b9 Mon Sep 17 00:00:00 2001 From: GroovieGermanikus Date: Wed, 2 Aug 2023 14:26:13 +0200 Subject: [PATCH] clippy --- quic-forward-proxy/src/outbound/tx_forward.rs | 9 +++------ quic-forward-proxy/src/proxy_request_format.rs | 2 +- quic-forward-proxy/src/quinn_auto_reconnect.rs | 8 ++++---- .../src/tls_self_signed_pair_generator.rs | 13 +++---------- quic-forward-proxy/src/validator_identity.rs | 4 ++-- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/quic-forward-proxy/src/outbound/tx_forward.rs b/quic-forward-proxy/src/outbound/tx_forward.rs index f436d1f4..b6977c65 100644 --- a/quic-forward-proxy/src/outbound/tx_forward.rs +++ b/quic-forward-proxy/src/outbound/tx_forward.rs @@ -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) { +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 diff --git a/quic-forward-proxy/src/proxy_request_format.rs b/quic-forward-proxy/src/proxy_request_format.rs index 8345175e..b0b7918a 100644 --- a/quic-forward-proxy/src/proxy_request_format.rs +++ b/quic-forward-proxy/src/proxy_request_format.rs @@ -53,7 +53,7 @@ impl TpuForwardingRequest { // TODO reame pub fn deserialize_from_raw_request(raw_proxy_request: &Vec) -> TpuForwardingRequest { - let request = bincode::deserialize::(&raw_proxy_request) + let request = bincode::deserialize::(raw_proxy_request) .context("deserialize proxy request") .unwrap(); diff --git a/quic-forward-proxy/src/quinn_auto_reconnect.rs b/quic-forward-proxy/src/quinn_auto_reconnect.rs index 5b04642c..e3f62759 100644 --- a/quic-forward-proxy/src/quinn_auto_reconnect.rs +++ b/quic-forward-proxy/src/quinn_auto_reconnect.rs @@ -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 { diff --git a/quic-forward-proxy/src/tls_self_signed_pair_generator.rs b/quic-forward-proxy/src/tls_self_signed_pair_generator.rs index 3abae350..2a6ccbd8 100644 --- a/quic-forward-proxy/src/tls_self_signed_pair_generator.rs +++ b/quic-forward-proxy/src/tls_self_signed_pair_generator.rs @@ -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 { diff --git a/quic-forward-proxy/src/validator_identity.rs b/quic-forward-proxy/src/validator_identity.rs index 3397b432..df4f659f 100644 --- a/quic-forward-proxy/src/validator_identity.rs +++ b/quic-forward-proxy/src/validator_identity.rs @@ -14,7 +14,7 @@ impl ValidatorIdentity { pub fn new(keypair: Option) -> 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"), } }