feat: Astralane QUIC, code review fixes, README & example updates
- Add Astralane QUIC client (astralane_quic.rs) and SwqosTransport::Quic - README: Astralane QUIC usage, remove third-party doc links, add QUIC to examples - Code review: API key not in logs, PumpSwap no clone, PDA Result, SELL_DISCRIMINATOR, ensure_wsol_ata refactor, tracing in astralane, only supports fix - instruction/utils: pumpfun/pumpswap PDA & discriminator unit tests - trading_client example: SwqosTransport, Astralane QUIC in config - cli_trading: fix all unused variable warnings (_prefix) - Add docs/CODE_REVIEW_REPORT.md Made-with: Cursor
This commit is contained in:
+111
-87
@@ -2,6 +2,7 @@ use crate::swqos::common::{default_http_client_builder, poll_transaction_confirm
|
||||
use rand::seq::IndexedRandom;
|
||||
use reqwest::Client;
|
||||
use std::{sync::Arc, time::Instant};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
use std::time::Duration;
|
||||
use anyhow::Result;
|
||||
@@ -19,24 +20,37 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
/// Empty body for getHealth POST; avoid per-request allocation.
|
||||
static PING_BODY: &[u8] = &[];
|
||||
|
||||
use crate::swqos::astralane_quic::AstralaneQuicClient;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum AstralaneBackend {
|
||||
Http {
|
||||
endpoint: String,
|
||||
auth_token: String,
|
||||
http_client: Client,
|
||||
ping_handle: Arc<tokio::sync::Mutex<Option<JoinHandle<()>>>>,
|
||||
stop_ping: Arc<AtomicBool>,
|
||||
},
|
||||
Quic(Arc<AstralaneQuicClient>),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AstralaneClient {
|
||||
pub endpoint: String,
|
||||
pub auth_token: String,
|
||||
pub rpc_client: Arc<SolanaRpcClient>,
|
||||
pub http_client: Client,
|
||||
pub ping_handle: Arc<tokio::sync::Mutex<Option<JoinHandle<()>>>>,
|
||||
pub stop_ping: Arc<AtomicBool>,
|
||||
backend: AstralaneBackend,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl SwqosClientTrait for AstralaneClient {
|
||||
async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction, wait_confirmation: bool) -> Result<()> {
|
||||
self.send_transaction(trade_type, transaction, wait_confirmation).await
|
||||
self.send_transaction_impl(trade_type, transaction, wait_confirmation).await
|
||||
}
|
||||
|
||||
async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>, wait_confirmation: bool) -> Result<()> {
|
||||
self.send_transactions(trade_type, transactions, wait_confirmation).await
|
||||
for transaction in transactions {
|
||||
self.send_transaction_impl(trade_type, transaction, wait_confirmation).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_tip_account(&self) -> Result<String> {
|
||||
@@ -50,59 +64,71 @@ impl SwqosClientTrait for AstralaneClient {
|
||||
}
|
||||
|
||||
impl AstralaneClient {
|
||||
/// 使用 HTTP(irisb)提交。
|
||||
pub fn new(rpc_url: String, endpoint: String, auth_token: String) -> Self {
|
||||
let rpc_client = SolanaRpcClient::new(rpc_url);
|
||||
let http_client = default_http_client_builder().build().unwrap();
|
||||
|
||||
let client = Self {
|
||||
rpc_client: Arc::new(rpc_client),
|
||||
endpoint,
|
||||
auth_token,
|
||||
http_client,
|
||||
ping_handle: Arc::new(tokio::sync::Mutex::new(None)),
|
||||
stop_ping: Arc::new(AtomicBool::new(false)),
|
||||
let ping_handle = Arc::new(tokio::sync::Mutex::new(None));
|
||||
let stop_ping = Arc::new(AtomicBool::new(false));
|
||||
|
||||
let client = Self {
|
||||
rpc_client: Arc::new(rpc_client),
|
||||
backend: AstralaneBackend::Http {
|
||||
endpoint,
|
||||
auth_token,
|
||||
http_client,
|
||||
ping_handle,
|
||||
stop_ping,
|
||||
},
|
||||
};
|
||||
|
||||
// Start ping task
|
||||
let client_clone = client.clone();
|
||||
tokio::spawn(async move {
|
||||
client_clone.start_ping_task().await;
|
||||
});
|
||||
|
||||
client
|
||||
}
|
||||
|
||||
/// Start periodic ping task to keep connections active
|
||||
/// 使用 QUIC 提交。
|
||||
pub async fn new_quic(rpc_url: String, quic_endpoint: &str, api_key: String) -> Result<Self> {
|
||||
let rpc_client = SolanaRpcClient::new(rpc_url);
|
||||
let quic_client = AstralaneQuicClient::connect(quic_endpoint, &api_key).await?;
|
||||
Ok(Self {
|
||||
rpc_client: Arc::new(rpc_client),
|
||||
backend: AstralaneBackend::Quic(Arc::new(quic_client)),
|
||||
})
|
||||
}
|
||||
|
||||
async fn start_ping_task(&self) {
|
||||
let endpoint = self.endpoint.clone();
|
||||
let auth_token = self.auth_token.clone();
|
||||
let http_client = self.http_client.clone();
|
||||
let stop_ping = self.stop_ping.clone();
|
||||
|
||||
let handle = tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(30));
|
||||
loop {
|
||||
interval.tick().await; // first tick completes immediately → one ping at start
|
||||
if stop_ping.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
if let Err(e) = Self::send_ping_request(&http_client, &endpoint, &auth_token).await {
|
||||
eprintln!("Astralane ping request failed: {}", e);
|
||||
match &self.backend {
|
||||
AstralaneBackend::Http { endpoint, auth_token, http_client, ping_handle, stop_ping } => {
|
||||
let endpoint = endpoint.clone();
|
||||
let auth_token = auth_token.clone();
|
||||
let http_client = http_client.clone();
|
||||
let ping_handle = ping_handle.clone();
|
||||
let stop_ping = stop_ping.clone();
|
||||
let handle = tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(30));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if stop_ping.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
if let Err(e) = Self::send_ping_request(&http_client, &endpoint, &auth_token).await {
|
||||
warn!(target: "sol_trade_sdk", "Astralane ping request failed: {}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
let mut guard = ping_handle.lock().await;
|
||||
if let Some(old) = guard.as_ref() {
|
||||
old.abort();
|
||||
}
|
||||
});
|
||||
|
||||
// Update ping_handle - use Mutex to safely update
|
||||
{
|
||||
let mut ping_guard = self.ping_handle.lock().await;
|
||||
if let Some(old_handle) = ping_guard.as_ref() {
|
||||
old_handle.abort();
|
||||
*guard = Some(handle);
|
||||
}
|
||||
*ping_guard = Some(handle);
|
||||
AstralaneBackend::Quic(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Send ping request: POST endpoint?api-key=...&method=getHealth (endpoint is irisb from constants).
|
||||
/// Send ping request: POST endpoint?api-key=...&method=getHealth
|
||||
async fn send_ping_request(http_client: &Client, endpoint: &str, auth_token: &str) -> Result<()> {
|
||||
let response = http_client
|
||||
.post(endpoint)
|
||||
@@ -112,57 +138,54 @@ impl AstralaneClient {
|
||||
.send()
|
||||
.await?;
|
||||
let status = response.status();
|
||||
let _ = response.bytes().await; // consume body so connection returns to pool
|
||||
let _ = response.bytes().await;
|
||||
if !status.is_success() {
|
||||
eprintln!("Astralane ping request returned non-success status: {}", status);
|
||||
warn!(target: "sol_trade_sdk", "Astralane ping request returned non-success status: {}", status);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Send transaction via /irisb binary API (no Base64; lower latency).
|
||||
pub async fn send_transaction(&self, trade_type: TradeType, transaction: &VersionedTransaction, wait_confirmation: bool) -> Result<()> {
|
||||
async fn send_transaction_impl(&self, trade_type: TradeType, transaction: &VersionedTransaction, wait_confirmation: bool) -> Result<()> {
|
||||
let start_time = Instant::now();
|
||||
let signature = transaction.get_signature();
|
||||
|
||||
let body_bytes = bincode_serialize(transaction).map_err(|e| anyhow::anyhow!("Astralane binary serialize failed: {}", e))?;
|
||||
|
||||
let response = self.http_client
|
||||
.post(&self.endpoint)
|
||||
.query(&[("api-key", self.auth_token.as_str()), ("method", "sendTransaction")])
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.body(body_bytes)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let status = response.status();
|
||||
let _ = response.bytes().await;
|
||||
if status.is_success() {
|
||||
println!(" [astralane] {} submitted: {:?}", trade_type, start_time.elapsed());
|
||||
} else {
|
||||
eprintln!(" [astralane] {} submission failed: status {}", trade_type, status);
|
||||
return Err(anyhow::anyhow!("Astralane sendTransaction failed: {}", status));
|
||||
match &self.backend {
|
||||
AstralaneBackend::Http { endpoint, auth_token, http_client, .. } => {
|
||||
let response = http_client
|
||||
.post(endpoint)
|
||||
.query(&[("api-key", auth_token.as_str()), ("method", "sendTransaction")])
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.body(body_bytes)
|
||||
.send()
|
||||
.await?;
|
||||
let status = response.status();
|
||||
let _ = response.bytes().await;
|
||||
if status.is_success() {
|
||||
info!(target: "sol_trade_sdk", "[astralane] {} submitted: {:?}", trade_type, start_time.elapsed());
|
||||
} else {
|
||||
error!(target: "sol_trade_sdk", "[astralane] {} submission failed: status {}", trade_type, status);
|
||||
return Err(anyhow::anyhow!("Astralane sendTransaction failed: {}", status));
|
||||
}
|
||||
}
|
||||
AstralaneBackend::Quic(quic) => {
|
||||
quic.send_transaction(&body_bytes).await?;
|
||||
info!(target: "sol_trade_sdk", "[astralane-quic] {} submitted: {:?}", trade_type, start_time.elapsed());
|
||||
}
|
||||
}
|
||||
|
||||
let start_time = Instant::now();
|
||||
match poll_transaction_confirmation(&self.rpc_client, *signature, wait_confirmation).await {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
println!(" signature: {:?}", signature);
|
||||
println!(" [astralane] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
|
||||
info!(target: "sol_trade_sdk", "signature: {:?}", signature);
|
||||
error!(target: "sol_trade_sdk", "[astralane] {} confirmation failed: {:?}", trade_type, start_time.elapsed());
|
||||
return Err(e);
|
||||
},
|
||||
}
|
||||
}
|
||||
if wait_confirmation {
|
||||
println!(" signature: {:?}", signature);
|
||||
println!(" [astralane] {} confirmed: {:?}", trade_type, start_time.elapsed());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn send_transactions(&self, trade_type: TradeType, transactions: &Vec<VersionedTransaction>, wait_confirmation: bool) -> Result<()> {
|
||||
for transaction in transactions {
|
||||
self.send_transaction(trade_type, transaction, wait_confirmation).await?;
|
||||
info!(target: "sol_trade_sdk", "signature: {:?}", signature);
|
||||
info!(target: "sol_trade_sdk", "[astralane] {} confirmed: {:?}", trade_type, start_time.elapsed());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -170,18 +193,19 @@ impl AstralaneClient {
|
||||
|
||||
impl Drop for AstralaneClient {
|
||||
fn drop(&mut self) {
|
||||
// Ensure ping task stops when client is destroyed
|
||||
self.stop_ping.store(true, Ordering::Relaxed);
|
||||
|
||||
// Try to stop ping task immediately
|
||||
// Use tokio::spawn to avoid blocking Drop
|
||||
let ping_handle = self.ping_handle.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut ping_guard = ping_handle.lock().await;
|
||||
if let Some(handle) = ping_guard.as_ref() {
|
||||
handle.abort();
|
||||
match &self.backend {
|
||||
AstralaneBackend::Http { stop_ping, ping_handle, .. } => {
|
||||
stop_ping.store(true, Ordering::Relaxed);
|
||||
let ping_handle = ping_handle.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut guard = ping_handle.lock().await;
|
||||
if let Some(handle) = guard.as_ref() {
|
||||
handle.abort();
|
||||
}
|
||||
*guard = None;
|
||||
});
|
||||
}
|
||||
*ping_guard = None;
|
||||
});
|
||||
AstralaneBackend::Quic(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
//! 内联自 [Astralane/astralane-quic-client](https://github.com/Astralane/astralane-quic-client),
|
||||
//! 用于向 Astralane QUIC TPU 提交交易,不依赖外部 crate,便于审计与安全可控。
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use quinn::crypto::rustls::QuicClientConfig;
|
||||
use quinn::{ClientConfig, Connection, Endpoint, IdleTimeout, TransportConfig};
|
||||
use rcgen::{CertificateParams, KeyPair};
|
||||
use rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
|
||||
use std::net::SocketAddr;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::{info, warn};
|
||||
|
||||
/// ALPN protocol identifier for Astralane TPU.
|
||||
const ALPN_ASTRALANE_TPU: &[u8] = b"astralane-tpu";
|
||||
|
||||
/// Maximum Solana transaction size.
|
||||
pub const MAX_TRANSACTION_SIZE: usize = 1232;
|
||||
|
||||
/// QUIC application error codes returned by the server.
|
||||
pub mod error_code {
|
||||
pub const OK: u32 = 0;
|
||||
pub const UNKNOWN_API_KEY: u32 = 1;
|
||||
pub const CONNECTION_LIMIT: u32 = 2;
|
||||
|
||||
pub fn describe(code: u32) -> &'static str {
|
||||
match code {
|
||||
OK => "OK",
|
||||
UNKNOWN_API_KEY => "Unknown API key",
|
||||
CONNECTION_LIMIT => "Connection limit exceeded",
|
||||
_ => "Unknown error",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// QUIC client for sending transactions to Astralane's TPU endpoint.
|
||||
pub struct AstralaneQuicClient {
|
||||
endpoint: Endpoint,
|
||||
connection: Mutex<Connection>,
|
||||
server_addr: SocketAddr,
|
||||
#[allow(dead_code)]
|
||||
api_key: String,
|
||||
}
|
||||
|
||||
impl AstralaneQuicClient {
|
||||
/// Connect to an Astralane QUIC server.
|
||||
/// Generates a self-signed TLS certificate with the API key as the Common Name (CN).
|
||||
pub async fn connect(server_addr: &str, api_key: &str) -> Result<Self> {
|
||||
let _ = rustls::crypto::ring::default_provider().install_default();
|
||||
let addr = SocketAddr::from_str(server_addr).or_else(|_| {
|
||||
use std::net::ToSocketAddrs;
|
||||
server_addr
|
||||
.to_socket_addrs()
|
||||
.ok()
|
||||
.and_then(|mut addrs| addrs.next())
|
||||
.ok_or_else(|| anyhow::anyhow!("Cannot resolve address: {}", server_addr))
|
||||
}).context("Invalid server address")?;
|
||||
|
||||
info!("[astralane-quic] Building TLS config (CN = api_key)");
|
||||
let client_config = Self::build_client_config(api_key)?;
|
||||
|
||||
let mut endpoint =
|
||||
Endpoint::client("0.0.0.0:0".parse()?).context("Failed to create QUIC endpoint")?;
|
||||
endpoint.set_default_client_config(client_config);
|
||||
|
||||
info!("[astralane-quic] Connecting to {} ...", addr);
|
||||
let connection = endpoint
|
||||
.connect(addr, "astralane")?
|
||||
.await
|
||||
.context("Failed to connect to Astralane QUIC server")?;
|
||||
|
||||
info!("[astralane-quic] Connected at {}", addr);
|
||||
|
||||
Ok(Self {
|
||||
endpoint,
|
||||
connection: Mutex::new(connection),
|
||||
server_addr: addr,
|
||||
api_key: api_key.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Send a single bincode-serialized `VersionedTransaction`.
|
||||
/// Fire-and-forget; automatically reconnects if the connection is dead.
|
||||
pub async fn send_transaction(&self, transaction_bytes: &[u8]) -> Result<()> {
|
||||
if transaction_bytes.len() > MAX_TRANSACTION_SIZE {
|
||||
anyhow::bail!(
|
||||
"Transaction too large: {} bytes (max {})",
|
||||
transaction_bytes.len(),
|
||||
MAX_TRANSACTION_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
let conn = {
|
||||
let mut guard = self.connection.lock().await;
|
||||
if let Some(reason) = guard.close_reason() {
|
||||
if let quinn::ConnectionError::ApplicationClosed(ref info) = reason {
|
||||
let code = info.error_code.into_inner();
|
||||
if code != error_code::OK as u64 {
|
||||
anyhow::bail!(
|
||||
"Server closed connection: {} (code {})",
|
||||
error_code::describe(code as u32),
|
||||
code
|
||||
);
|
||||
}
|
||||
}
|
||||
warn!("[astralane-quic] Connection dead, reconnecting to {} ...", self.server_addr);
|
||||
*guard = self
|
||||
.endpoint
|
||||
.connect(self.server_addr, "astralane")?
|
||||
.await
|
||||
.context("Failed to reconnect to Astralane QUIC server")?;
|
||||
info!("[astralane-quic] Reconnected to {}", self.server_addr);
|
||||
}
|
||||
guard.clone()
|
||||
};
|
||||
|
||||
let mut send_stream = conn
|
||||
.open_uni()
|
||||
.await
|
||||
.context("Failed to open unidirectional stream")?;
|
||||
|
||||
send_stream
|
||||
.write_all(transaction_bytes)
|
||||
.await
|
||||
.context("Failed to write transaction data")?;
|
||||
|
||||
send_stream.finish().context("Failed to finish stream")?;
|
||||
info!("[astralane-quic] Transaction sent ({} bytes)", transaction_bytes.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reconnect to the server if the connection was closed.
|
||||
pub async fn reconnect(&self) -> Result<()> {
|
||||
let mut guard = self.connection.lock().await;
|
||||
if guard.close_reason().is_some() {
|
||||
info!("[astralane-quic] Reconnecting at {}", self.server_addr);
|
||||
*guard = self
|
||||
.endpoint
|
||||
.connect(self.server_addr, "astralane")?
|
||||
.await
|
||||
.context("Failed to reconnect to Astralane QUIC server")?;
|
||||
info!("[astralane-quic] Reconnected to {}", self.server_addr);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check if the connection is still alive.
|
||||
pub async fn is_connected(&self) -> bool {
|
||||
self.connection.lock().await.close_reason().is_none()
|
||||
}
|
||||
|
||||
/// Close the connection gracefully.
|
||||
pub async fn close(&self) {
|
||||
self.connection
|
||||
.lock()
|
||||
.await
|
||||
.close(error_code::OK.into(), b"client closing");
|
||||
}
|
||||
|
||||
fn build_client_config(api_key: &str) -> Result<ClientConfig> {
|
||||
let key_pair = KeyPair::generate_for(&rcgen::PKCS_ECDSA_P256_SHA256)?;
|
||||
let mut cert_params = CertificateParams::new(vec![])?;
|
||||
cert_params.distinguished_name.push(
|
||||
rcgen::DnType::CommonName,
|
||||
rcgen::DnValue::Utf8String(api_key.to_string()),
|
||||
);
|
||||
let cert = cert_params.self_signed(&key_pair)?;
|
||||
|
||||
let cert_der = CertificateDer::from(cert.der().to_vec());
|
||||
let key_der = PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der()));
|
||||
|
||||
let mut crypto = rustls::ClientConfig::builder()
|
||||
.dangerous()
|
||||
.with_custom_certificate_verifier(Arc::new(SkipServerVerification))
|
||||
.with_client_auth_cert(vec![cert_der], key_der)
|
||||
.context("Failed to set client certificate")?;
|
||||
|
||||
crypto.alpn_protocols = vec![ALPN_ASTRALANE_TPU.to_vec()];
|
||||
|
||||
let mut transport = TransportConfig::default();
|
||||
transport.max_idle_timeout(Some(
|
||||
IdleTimeout::try_from(Duration::from_secs(30)).unwrap(),
|
||||
));
|
||||
transport.keep_alive_interval(Some(Duration::from_secs(25)));
|
||||
|
||||
let mut client_config =
|
||||
ClientConfig::new(Arc::new(QuicClientConfig::try_from(crypto).unwrap()));
|
||||
client_config.transport_config(Arc::new(transport));
|
||||
|
||||
Ok(client_config)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for AstralaneQuicClient {
|
||||
fn drop(&mut self) {
|
||||
self.connection
|
||||
.get_mut()
|
||||
.close(error_code::OK.into(), b"client closing");
|
||||
}
|
||||
}
|
||||
|
||||
/// Skip server certificate verification (Astralane server may use self-signed cert).
|
||||
#[derive(Debug)]
|
||||
struct SkipServerVerification;
|
||||
|
||||
impl rustls::client::danger::ServerCertVerifier for SkipServerVerification {
|
||||
fn verify_server_cert(
|
||||
&self,
|
||||
_end_entity: &CertificateDer<'_>,
|
||||
_intermediates: &[CertificateDer<'_>],
|
||||
_server_name: &rustls::pki_types::ServerName<'_>,
|
||||
_ocsp_response: &[u8],
|
||||
_now: rustls::pki_types::UnixTime,
|
||||
) -> Result<rustls::client::danger::ServerCertVerified, rustls::Error> {
|
||||
Ok(rustls::client::danger::ServerCertVerified::assertion())
|
||||
}
|
||||
|
||||
fn verify_tls12_signature(
|
||||
&self,
|
||||
_message: &[u8],
|
||||
_cert: &CertificateDer<'_>,
|
||||
_dss: &rustls::DigitallySignedStruct,
|
||||
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
|
||||
Ok(rustls::client::danger::HandshakeSignatureValid::assertion())
|
||||
}
|
||||
|
||||
fn verify_tls13_signature(
|
||||
&self,
|
||||
_message: &[u8],
|
||||
_cert: &CertificateDer<'_>,
|
||||
_dss: &rustls::DigitallySignedStruct,
|
||||
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
|
||||
Ok(rustls::client::danger::HandshakeSignatureValid::assertion())
|
||||
}
|
||||
|
||||
fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> {
|
||||
vec![
|
||||
rustls::SignatureScheme::ECDSA_NISTP256_SHA256,
|
||||
rustls::SignatureScheme::ECDSA_NISTP384_SHA384,
|
||||
rustls::SignatureScheme::RSA_PSS_SHA256,
|
||||
rustls::SignatureScheme::RSA_PSS_SHA384,
|
||||
rustls::SignatureScheme::RSA_PSS_SHA512,
|
||||
rustls::SignatureScheme::RSA_PKCS1_SHA256,
|
||||
rustls::SignatureScheme::RSA_PKCS1_SHA384,
|
||||
rustls::SignatureScheme::RSA_PKCS1_SHA512,
|
||||
rustls::SignatureScheme::ED25519,
|
||||
]
|
||||
}
|
||||
}
|
||||
+28
-11
@@ -1,3 +1,4 @@
|
||||
pub mod astralane_quic;
|
||||
pub mod common;
|
||||
pub mod serialization;
|
||||
pub mod solana_rpc;
|
||||
@@ -86,6 +87,14 @@ pub const SWQOS_BLACKLIST: &[SwqosType] = &[
|
||||
SwqosType::NextBlock, // NextBlock is disabled by default
|
||||
];
|
||||
|
||||
/// SWQOS 提交通道:HTTP 或 QUIC(低延迟)。部分提供商(如 Astralane)支持 QUIC。
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
pub enum SwqosTransport {
|
||||
#[default]
|
||||
Http,
|
||||
Quic,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum TradeType {
|
||||
Create,
|
||||
@@ -209,8 +218,8 @@ pub enum SwqosConfig {
|
||||
FlashBlock(String, SwqosRegion, Option<String>),
|
||||
/// BlockRazor(api_token, region, custom_url)
|
||||
BlockRazor(String, SwqosRegion, Option<String>),
|
||||
/// Astralane(api_token, region, custom_url)
|
||||
Astralane(String, SwqosRegion, Option<String>),
|
||||
/// Astralane(api_token, region, custom_url, transport). transport=None 表示 Http。
|
||||
Astralane(String, SwqosRegion, Option<String>, Option<SwqosTransport>),
|
||||
/// Stellium(api_token, region, custom_url)
|
||||
Stellium(String, SwqosRegion, Option<String>),
|
||||
/// Lightspeed(api_key, region, custom_url) - Solana Vibe Station
|
||||
@@ -239,7 +248,7 @@ impl SwqosConfig {
|
||||
SwqosConfig::Node1(_, _, _) => SwqosType::Node1,
|
||||
SwqosConfig::FlashBlock(_, _, _) => SwqosType::FlashBlock,
|
||||
SwqosConfig::BlockRazor(_, _, _) => SwqosType::BlockRazor,
|
||||
SwqosConfig::Astralane(_, _, _) => SwqosType::Astralane,
|
||||
SwqosConfig::Astralane(_, _, _, _) => SwqosType::Astralane,
|
||||
SwqosConfig::Stellium(_, _, _) => SwqosType::Stellium,
|
||||
SwqosConfig::Lightspeed(_, _, _) => SwqosType::Lightspeed,
|
||||
SwqosConfig::Soyas(_, _, _) => SwqosType::Soyas,
|
||||
@@ -351,14 +360,22 @@ impl SwqosConfig {
|
||||
);
|
||||
Ok(Arc::new(blockrazor_client))
|
||||
},
|
||||
SwqosConfig::Astralane(auth_token, region, url) => {
|
||||
let endpoint = SwqosConfig::get_endpoint(SwqosType::Astralane, region, url);
|
||||
let astralane_client = AstralaneClient::new(
|
||||
rpc_url.clone(),
|
||||
endpoint.to_string(),
|
||||
auth_token
|
||||
);
|
||||
Ok(Arc::new(astralane_client))
|
||||
SwqosConfig::Astralane(auth_token, region, url, transport) => {
|
||||
let use_quic = transport.map_or(false, |t| t == SwqosTransport::Quic);
|
||||
if use_quic {
|
||||
let quic_endpoint = crate::constants::swqos::ASTRALANE_QUIC_ENDPOINT;
|
||||
let astralane_client =
|
||||
AstralaneClient::new_quic(rpc_url.clone(), quic_endpoint, auth_token).await?;
|
||||
Ok(Arc::new(astralane_client))
|
||||
} else {
|
||||
let endpoint = SwqosConfig::get_endpoint(SwqosType::Astralane, region, url);
|
||||
let astralane_client = AstralaneClient::new(
|
||||
rpc_url.clone(),
|
||||
endpoint.to_string(),
|
||||
auth_token,
|
||||
);
|
||||
Ok(Arc::new(astralane_client))
|
||||
}
|
||||
},
|
||||
SwqosConfig::Stellium(auth_token, region, url) => {
|
||||
let endpoint = SwqosConfig::get_endpoint(SwqosType::Stellium, region, url);
|
||||
|
||||
Reference in New Issue
Block a user