Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ default-members = ["crates/rproxy"]
members = [
"crates/rproxy",
]

[workspace.lints.rust]
unreachable_pub = "deny"

[workspace.lints.clippy]
match_same_arms = "warn"
unused_async = "warn"
uninlined_format_args = "warn"
manual_let_else = "warn"
3 changes: 3 additions & 0 deletions crates/rproxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ default-run = "rproxy"
name = "rproxy"
path = "src/bin/main.rs"

[lints]
workspace = true

[dependencies]
actix = "0.13.5"
actix-http = { version = "3.11.1", features = ["ws"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/rproxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Parser;
use thiserror::Error;

use crate::server::{
config::{ConfigLoggingError, ConfigLogging, ConfigMetrics, ConfigMetricsError},
config::{ConfigLogging, ConfigLoggingError, ConfigMetrics, ConfigMetricsError},
proxy::config::{
ConfigAuthrpc,
ConfigAuthrpcError,
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Config {

if let Some(errs) = res.clone().validate() {
for err in errs.iter() {
eprintln!("fatal: {}", err);
eprintln!("fatal: {err}");
}
process::exit(1);
};
Expand Down
3 changes: 2 additions & 1 deletion crates/rproxy/src/jrpc/jrpc_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::Deserialize;
use std::borrow::Cow;

use serde::Deserialize;

// JrpcRequestMeta -----------------------------------------------------

const JRPC_METHOD_FCUV1_WITH_PAYLOAD: Cow<'static, str> =
Expand Down
1 change: 1 addition & 0 deletions crates/rproxy/src/server/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ impl Metrics {
Ok(socket.into())
}

#[expect(clippy::unused_async, reason = "required by the actix framework")]
async fn receive(
req: HttpRequest,
_: web::Payload,
Expand Down
2 changes: 1 addition & 1 deletion crates/rproxy/src/server/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub(crate) trait ProxyInner: 'static {

// ProxyConnectionGuard ------------------------------------------------

pub struct ProxyConnectionGuard {
pub(crate) struct ProxyConnectionGuard {
pub id: Uuid,
pub remote_addr: Option<String>,
pub local_addr: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions crates/rproxy/src/server/proxy/config/authrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl ConfigAuthrpc {
let backend_url = Url::parse(&self.backend_url.clone()).expect(ALREADY_VALIDATED);
let backend_host = backend_url.host_str().expect(ALREADY_VALIDATED);

let backend_ips: Vec<IpAddr> = match format!("{}:0", backend_host).to_socket_addrs() {
let backend_ips: Vec<IpAddr> = match format!("{backend_host}:0").to_socket_addrs() {
Ok(res) => res,
Err(err) => {
warn!(host = backend_host, error = ?err, "Failed to resolve backend host");
Expand All @@ -249,7 +249,7 @@ impl ConfigAuthrpc {
return false;
}

let peer_ips: Vec<IpAddr> = match format!("{}:0", peer_host).to_socket_addrs() {
let peer_ips: Vec<IpAddr> = match format!("{peer_host}:0").to_socket_addrs() {
Ok(res) => res,
Err(err) => {
warn!(host = peer_host, error = ?err, "Failed to resolve peer host");
Expand Down
4 changes: 2 additions & 2 deletions crates/rproxy/src/server/proxy/config/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl ConfigRpc {
let backend_url = Url::parse(&self.backend_url.clone()).expect(ALREADY_VALIDATED);
let backend_host = backend_url.host_str().expect(ALREADY_VALIDATED);

let backend_ips: Vec<IpAddr> = match format!("{}:0", backend_host).to_socket_addrs() {
let backend_ips: Vec<IpAddr> = match format!("{backend_host}:0").to_socket_addrs() {
Ok(res) => res,
Err(err) => {
warn!(host = backend_host, error = ?err, "Failed to resolve backend host");
Expand All @@ -255,7 +255,7 @@ impl ConfigRpc {
return false;
}

let peer_ips: Vec<IpAddr> = match format!("{}:0", peer_host).to_socket_addrs() {
let peer_ips: Vec<IpAddr> = match format!("{peer_host}:0").to_socket_addrs() {
Ok(res) => res,
Err(err) => {
warn!(host = peer_host, error = ?err, "Failed to resolve peer host");
Expand Down
89 changes: 32 additions & 57 deletions crates/rproxy/src/server/proxy/http/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ where
.http_proxy_failure_count
.get_or_create(&LabelsProxy { proxy: P::name() })
.inc();
return Ok(HttpResponse::BadGateway().body(format!("Backend error: {:?}", err)));
return Ok(HttpResponse::BadGateway().body(format!("Backend error: {err:?}")));
}
};

Expand Down Expand Up @@ -374,17 +374,14 @@ where
}

fn postprocess_backend_response(&self, bck_res: ProxiedHttpResponse) {
let cli_req = match self.requests.remove_sync(&bck_res.info.id) {
Some((_, req)) => req,
None => {
error!(
proxy = P::name(),
request_id = %bck_res.info.id,
worker_id = %self.id,
"Proxied http response for unmatching request",
);
return;
}
let Some((_, cli_req)) = self.requests.remove_sync(&bck_res.info.id) else {
error!(
proxy = P::name(),
request_id = %bck_res.info.id,
worker_id = %self.id,
"Proxied http response for unmatching request",
);
return;
};

// hand over to postprocessor asynchronously so that we can return the
Expand Down Expand Up @@ -584,10 +581,7 @@ where
return;
}

let message = match message.as_object_mut() {
Some(message) => message,
None => return,
};
let Some(message) = message.as_object_mut() else { return };

let method = (match message.get_key_value("method") {
Some((_, method)) => method.as_str(),
Expand All @@ -599,14 +593,12 @@ where
if !method.is_empty() {
// single-shot request

let params = match match message.get_mut("params") {
let Some(params) = match message.get_mut("params") {
Some(params) => params,
None => return,
}
.as_array_mut()
{
Some(params) => params,
None => return,
.as_array_mut() else {
return
};

match method.as_str() {
Expand All @@ -615,19 +607,14 @@ where
return;
}

let execution_payload = match params[1].as_object_mut() {
Some(execution_payload) => execution_payload,
None => return,
};
let Some(execution_payload) = params[1].as_object_mut() else { return };

let transactions = match match execution_payload.get_mut("transactions") {
let Some(transactions) = match execution_payload.get_mut("transactions") {
Some(transactions) => transactions,
None => return,
}
.as_array_mut()
{
Some(transactions) => transactions,
None => return,
.as_array_mut() else {
return
};

for transaction in transactions {
Expand All @@ -640,19 +627,14 @@ where
return;
}

let execution_payload = match params[0].as_object_mut() {
Some(execution_payload) => execution_payload,
None => return,
};
let Some(execution_payload) = params[0].as_object_mut() else { return };

let transactions = match match execution_payload.get_mut("transactions") {
let Some(transactions) = match execution_payload.get_mut("transactions") {
Some(transactions) => transactions,
None => return,
}
.as_array_mut()
{
Some(transactions) => transactions,
None => return,
.as_array_mut() else {
return
};

for transaction in transactions {
Expand All @@ -665,19 +647,14 @@ where
return;
}

let execution_payload = match params[0].as_object_mut() {
Some(execution_payload) => execution_payload,
None => return,
};
let Some(execution_payload) = params[0].as_object_mut() else { return };

let transactions = match match execution_payload.get_mut("txs") {
let Some(transactions) = match execution_payload.get_mut("txs") {
Some(transactions) => transactions,
None => return,
}
.as_array_mut()
{
Some(transactions) => transactions,
None => return,
.as_array_mut() else {
return
};

for transaction in transactions {
Expand All @@ -697,12 +674,11 @@ where
}
}

let result = match match message.get_mut("result") {
let Some(result) = (match message.get_mut("result") {
Some(result) => result.as_object_mut(),
None => return,
} {
Some(result) => result,
None => return,
}) else {
return
};

if let Some(execution_payload) = result.get_mut("executionPayload") &&
Expand Down Expand Up @@ -1022,8 +998,7 @@ where
Ok(mrr_res_body) => {
let size = match mrr_res_body.size() {
BodySize::Sized(size) => size, // Body is always sized
BodySize::None => 0,
BodySize::Stream => 0,
BodySize::None | BodySize::Stream => 0,
};
let info = ProxyHttpResponseInfo::new(
cli_req.info.id,
Expand Down Expand Up @@ -1152,7 +1127,7 @@ impl ProxyHttpRequestInfo {

let path_and_query = match req.query_string() {
"" => path.clone(),
val => format!("{}?{}", path, val),
val => format!("{path}?{val}"),
};

Self {
Expand Down Expand Up @@ -1187,12 +1162,12 @@ impl ProxyHttpRequestInfo {
}

#[inline]
pub fn path_and_query(&self) -> &str {
pub(crate) fn path_and_query(&self) -> &str {
&self.path_and_query
}

#[inline]
pub fn remote_addr(&self) -> &Option<String> {
pub(crate) fn remote_addr(&self) -> &Option<String> {
&self.remote_addr
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rproxy/src/server/proxy/ws/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ where
Ok(socket.into())
}

#[expect(clippy::unused_async, reason = "required by the actix framework")]
async fn receive(
cli_req: HttpRequest,
cli_req_body: web::Payload,
Expand Down Expand Up @@ -1303,9 +1304,8 @@ impl ProxyWsPing {

let id = Uuid::from_u128(bytes.get_u128());
let connection_id = Uuid::from_u128(bytes.get_u128());
let timestamp = match UtcDateTime::from_unix_timestamp_nanos(bytes.get_i128()) {
Ok(timestamp) => timestamp,
Err(_) => return None,
let Ok(timestamp) = UtcDateTime::from_unix_timestamp_nanos(bytes.get_i128()) else {
return None
};

Some(Self { id, connection_id, timestamp })
Expand Down
2 changes: 1 addition & 1 deletion crates/rproxy/src/utils/utils_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bytes::Bytes;

// decompress ----------------------------------------------------------

pub fn decompress(body: Bytes, size: usize, content_encoding: String) -> (Bytes, usize) {
pub(crate) fn decompress(body: Bytes, size: usize, content_encoding: String) -> (Bytes, usize) {
match content_encoding.to_ascii_lowercase().as_str() {
"br" => {
let mut decoder = brotli::Decompressor::new(std::io::Cursor::new(body.clone()), 4096);
Expand Down
2 changes: 1 addition & 1 deletion crates/rproxy/src/utils/utils_http.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// is_hop_by_hop_header ------------------------------------------------

pub fn is_hop_by_hop_header(name: &actix_web::http::header::HeaderName) -> bool {
pub(crate) fn is_hop_by_hop_header(name: &actix_web::http::header::HeaderName) -> bool {
matches!(name.as_str().to_ascii_lowercase().as_str(), "connection" | "host" | "keep-alive")
}
7 changes: 3 additions & 4 deletions crates/rproxy/src/utils/utils_loggable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ impl valuable::Valuable for Loggable<'_> {

fn visit(&self, visitor: &mut dyn valuable::Visit) {
match &self.0 {
serde_json::Value::Null => visitor.visit_value(self.as_value()),
serde_json::Value::Bool(_) => visitor.visit_value(self.as_value()),
serde_json::Value::String(_) => visitor.visit_value(self.as_value()),
serde_json::Value::Null |
serde_json::Value::Bool(_) |
serde_json::Value::String(_) |
serde_json::Value::Number(_) => visitor.visit_value(self.as_value()),

serde_json::Value::Array(list) => {
for val in list {
visitor.visit_value(Self(val).as_value());
Expand Down
17 changes: 7 additions & 10 deletions crates/rproxy/src/utils/utils_op_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ use hex::FromHex;

// raw_transaction_to_hash ---------------------------------------------

pub fn raw_transaction_to_hash(transaction: &mut serde_json::Value) {
let hex = match transaction.as_str() {
Some(hex) => hex,
None => return,
pub(crate) fn raw_transaction_to_hash(transaction: &mut serde_json::Value) {
let Some(hex) = transaction.as_str() else {
return;
};
let hex = hex.strip_prefix("0x").unwrap_or(hex);
let bytes = match Vec::from_hex(hex) {
Ok(bytes) => bytes,
Err(_) => return,
let Ok(bytes) = Vec::from_hex(hex) else {
return;
};
let mut buf = bytes.as_slice();
let envelope = match op_alloy_consensus::OpTxEnvelope::decode(&mut buf) {
Ok(envelope) => envelope,
Err(_) => return,
let Ok(envelope) = op_alloy_consensus::OpTxEnvelope::decode(&mut buf) else {
return;
};
let hash = envelope.hash().to_string();
*transaction = serde_json::Value::String(hash);
Expand Down