Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy QUIC Proxy #187

Merged
merged 7 commits into from
Sep 8, 2023
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
7 changes: 5 additions & 2 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ jobs:
- name: Setup Fly
uses: superfly/flyctl-actions/setup-flyctl@master

- name: Deploy
run: flyctl deploy --remote-only
- name: Deploy lite-rpc
run: flyctl deploy -c cd/lite-rpc.toml --remote-only

- name: Deploy quic-forward-proxy
run: flyctl deploy -c cd/quic-forward-proxy.toml --remote-only
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ futures = "0.3.28"
bytes = "1.4.0"
anyhow = "1.0.70"
log = "0.4.17"
clap = { version = "4.2.4", features = ["derive"] }
clap = { version = "4.2.4", features = ["derive", "env"] }
dashmap = "5.4.0"
const_env = "0.1.2"
jsonrpsee = { version = "0.17.0", features = ["macros", "full"] }
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ FROM base as build
COPY --from=plan /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin lite-rpc
RUN cargo build --release --bin lite-rpc --bin solana-lite-rpc-quic-forward-proxy

FROM debian:bullseye-slim as run
RUN apt-get update && apt-get -y install ca-certificates libc6
COPY --from=build /app/target/release/solana-lite-rpc-quic-forward-proxy /usr/local/bin/
COPY --from=build /app/target/release/lite-rpc /usr/local/bin/

CMD lite-rpc --rpc-addr "$RPC_URL" --ws-addr "$WS_URL"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The app listens by default on ports 8890 and 8891 for HTTP and Websockets respec
fly apps create my-lite-rpc
fly secrets set -a my-lite-rpc RPC_URL=... WS_URL=... # See above table for env options
fly scale vm dedicated-cpu-2x --memory 4096 -a my-lite-rpc
fly deploy -a my-lite-rpc --remote-only
fly deploy -c cd/lite-rpc.toml -a my-lite-rpc --remote-only
```

## License & Copyright
Expand Down
18 changes: 18 additions & 0 deletions cd/lite-rpc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
app = "solana-lite-rpc"
kill_signal = "SIGINT"
kill_timeout = 5

[build]
dockerfile = "../Dockerfile"

[experimental]
cmd = ["sh", "-c", "lite-rpc --rpc-addr $RPC_URL --ws-addr $WS_URL --quic-proxy-addr $QUIC_PROXY_ADDR"]

[env]
PORT_HTTP = "8890"
PORT_WS = "8891"
RUST_LOG = "info"

[metrics]
path = "/metrics"
port = 9091
13 changes: 13 additions & 0 deletions cd/quic-forward-proxy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
app = "solana-quic-forward-proxy"
kill_signal = "SIGINT"
kill_timeout = 5

[build]
dockerfile = "../Dockerfile"

[experimental]
cmd = ["solana-lite-rpc-quic-forward-proxy"]

[env]
PROXY_LISTEN_ADDR = "[::]:11111"
RUST_LOG = "debug"
32 changes: 0 additions & 32 deletions fly.toml

This file was deleted.

5 changes: 2 additions & 3 deletions lite-rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn configure_tpu_connection_path(quic_proxy_addr: Option<String>) -> TpuConnecti
match quic_proxy_addr {
None => TpuConnectionPath::QuicDirectPath,
Some(prox_address) => {
let proxy_socket_addr = parse_host_port_to_ipv4(prox_address.as_str()).unwrap();
let proxy_socket_addr = parse_host_port(prox_address.as_str()).unwrap();
TpuConnectionPath::QuicForwardProxyPath {
// e.g. "127.0.0.1:11111" or "localhost:11111"
forward_proxy_address: proxy_socket_addr,
Expand All @@ -273,11 +273,10 @@ fn configure_tpu_connection_path(quic_proxy_addr: Option<String>) -> TpuConnecti
}
}

fn parse_host_port_to_ipv4(host_port: &str) -> Result<SocketAddr, String> {
fn parse_host_port(host_port: &str) -> Result<SocketAddr, String> {
let addrs: Vec<_> = host_port
.to_socket_addrs()
.map_err(|err| format!("Unable to resolve host {host_port}: {err}"))?
.filter(|addr| addr.is_ipv4())
.collect();
if addrs.is_empty() {
Err(format!("Unable to resolve host: {host_port}"))
Expand Down
2 changes: 1 addition & 1 deletion lite-rpc/src/rpc_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;

lazy_static::lazy_static! {
static ref RPC_RESPONDING: Gauge =
register_gauge!(opts!("literpc_rpc_responding", "If LiteRpc is responding")).unwrap();
register_gauge!(opts!("literpc_rpc_responding", "If RPC is responding")).unwrap();
}

pub struct RpcTester {
Expand Down
2 changes: 1 addition & 1 deletion quic-forward-proxy/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ pub struct Args {
#[arg(short = 'k', long, default_value_t = String::new())]
pub identity_keypair: String,
// e.g. 0.0.0.0:11111 or "localhost:11111"
#[arg(short = 'l', long)]
#[arg(short = 'l', long, env)]
pub proxy_listen_addr: String,
}
18 changes: 1 addition & 17 deletions quic-forward-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use clap::Parser;
use dotenv::dotenv;
use log::info;
use solana_lite_rpc_core::keypair_loader::load_identity_keypair;
use std::net::{SocketAddr, ToSocketAddrs};
use std::sync::Arc;

use crate::validator_identity::ValidatorIdentity;
Expand Down Expand Up @@ -35,7 +34,7 @@ pub async fn main() -> anyhow::Result<()> {
} = Args::parse();
dotenv().ok();

let proxy_listener_addr = parse_host_port_to_ipv4(proxy_listen_addr.as_str()).unwrap();
let proxy_listener_addr = proxy_listen_addr.parse().unwrap();
let validator_identity = ValidatorIdentity::new(load_identity_keypair(&identity_keypair).await);

let tls_config = Arc::new(SelfSignedTlsConfigProvider::new_singleton_self_signed_localhost());
Expand All @@ -59,18 +58,3 @@ pub async fn main() -> anyhow::Result<()> {
}
}
}

fn parse_host_port_to_ipv4(host_port: &str) -> Result<SocketAddr, String> {
let addrs: Vec<_> = host_port
.to_socket_addrs()
.map_err(|err| format!("Unable to resolve host {host_port}: {err}"))?
.filter(|addr| addr.is_ipv4())
.collect();
if addrs.is_empty() {
Err(format!("Unable to resolve host: {host_port}"))
} else if addrs.len() > 1 {
Err(format!("Multiple addresses resolved for host: {host_port}"))
} else {
Ok(addrs[0])
}
}
7 changes: 2 additions & 5 deletions services/src/tpu_utils/quic_proxy_connection_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::net::{SocketAddr, UdpSocket};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::Arc;
Expand Down Expand Up @@ -111,10 +111,7 @@ impl QuicProxyConnectionManager {
const ALPN_TPU_FORWARDPROXY_PROTOCOL_ID: &[u8] = b"solana-tpu-forward-proxy";

let mut endpoint = {
let client_socket =
solana_net_utils::bind_in_range(IpAddr::V4(Ipv4Addr::UNSPECIFIED), (8000, 10000))
.expect("create_endpoint bind_in_range")
.1;
let client_socket = UdpSocket::bind("[::]:0").unwrap();
let config = EndpointConfig::default();
Endpoint::new(config, None, client_socket, TokioRuntime)
.expect("create_endpoint quinn::Endpoint::new")
Expand Down