Release sol-trade-sdk v4.0.15
This commit is contained in:
+42
-1
@@ -50,6 +50,15 @@ fn validate_protocol_params(dex_type: DexType, params: &DexParamEnum) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn normalize_swqos_configs(rpc_url: &str, configs: &[SwqosConfig]) -> Vec<SwqosConfig> {
|
||||
let mut out = configs.to_vec();
|
||||
if !out.iter().any(|c| matches!(c.swqos_type(), SwqosType::Default)) {
|
||||
out.push(SwqosConfig::Default(rpc_url.to_string()));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// 按 mint 查找池地址(通用入口,根据 DEX 类型分发,仅 PumpSwap 等已实现的类型会走优化路径)。
|
||||
///
|
||||
/// * `dex_type`:PumpSwap 时先走 PDA 再回退 getProgramAccounts,其他类型返回未实现错误。
|
||||
@@ -134,8 +143,9 @@ impl TradingInfrastructure {
|
||||
|
||||
// Create SWQOS clients with blacklist checking(QUIC 握手可能较慢,单节点超时 15s)
|
||||
const SWQOS_CLIENT_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(15);
|
||||
let swqos_configs = normalize_swqos_configs(&config.rpc_url, &config.swqos_configs);
|
||||
let mut swqos_clients: Vec<Arc<SwqosClient>> = vec![];
|
||||
for swqos in &config.swqos_configs {
|
||||
for swqos in &swqos_configs {
|
||||
if swqos.is_blacklisted() {
|
||||
if sdk_log::sdk_log_enabled() {
|
||||
warn!(target: "sol_trade_sdk", "⚠️ SWQOS {:?} is blacklisted, skipping", swqos.swqos_type());
|
||||
@@ -752,6 +762,12 @@ impl TradingClient {
|
||||
Some(Arc::new(if cap < v.len() { v[..cap].to_vec() } else { v }));
|
||||
}
|
||||
}
|
||||
if self.use_dedicated_sender_threads {
|
||||
crate::trading::core::async_executor::warm_dedicated_sender_pool(
|
||||
self.sender_thread_cores.as_ref().map(|v| v.as_slice()),
|
||||
self.max_sender_concurrency,
|
||||
);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
@@ -1263,3 +1279,28 @@ impl TradingClient {
|
||||
Ok(signature.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::swqos::SwqosRegion;
|
||||
|
||||
#[test]
|
||||
fn normalize_swqos_configs_adds_default_rpc_route() {
|
||||
let configs = vec![SwqosConfig::Jito("uuid".to_string(), SwqosRegion::Frankfurt, None)];
|
||||
let normalized = normalize_swqos_configs("https://rpc.example", &configs);
|
||||
|
||||
assert_eq!(normalized.len(), 2);
|
||||
assert!(normalized.iter().any(|c| matches!(c.swqos_type(), SwqosType::Jito)));
|
||||
assert!(normalized.iter().any(|c| matches!(c.swqos_type(), SwqosType::Default)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_swqos_configs_does_not_duplicate_default_rpc_route() {
|
||||
let configs = vec![SwqosConfig::Default("https://rpc.example".to_string())];
|
||||
let normalized = normalize_swqos_configs("https://rpc.example", &configs);
|
||||
|
||||
assert_eq!(normalized.len(), 1);
|
||||
assert!(matches!(normalized[0].swqos_type(), SwqosType::Default));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +156,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_fast_now_overhead() {
|
||||
// 测试调用开销
|
||||
let iterations = 10_000;
|
||||
// This is a coarse regression guard, not a benchmark. On non-Linux targets
|
||||
// the fast timer uses `Instant::elapsed()`, and CI/desktop scheduler jitter can
|
||||
// move a single run above 100ns even when the code path is still sub-microsecond.
|
||||
let iterations = 100_000;
|
||||
for _ in 0..1_000 {
|
||||
let _ = fast_now_nanos();
|
||||
}
|
||||
let start = Instant::now();
|
||||
|
||||
for _ in 0..iterations {
|
||||
@@ -171,8 +176,8 @@ mod tests {
|
||||
println!("Average fast_now_nanos() call: {}ns", avg_per_call);
|
||||
}
|
||||
|
||||
// 快速时间戳应该非常快(< 100ns per call)
|
||||
assert!(avg_per_call < 100);
|
||||
// Keep the hot-path timer safely sub-microsecond without making the test flaky.
|
||||
assert!(avg_per_call < 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -147,10 +147,15 @@ async fn run_one_swqos_job(job: SwqosJob) {
|
||||
|
||||
async fn swqos_worker_loop(queue: Arc<ArrayQueue<SwqosJob>>, notify: Arc<Notify>) {
|
||||
loop {
|
||||
let notified = notify.notified();
|
||||
tokio::pin!(notified);
|
||||
notified.as_mut().enable();
|
||||
|
||||
if let Some(job) = queue.pop() {
|
||||
drop(notified);
|
||||
run_one_swqos_job(job).await;
|
||||
} else {
|
||||
notify.notified().await;
|
||||
notified.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,6 +237,15 @@ fn ensure_dedicated_pool(
|
||||
(queue, notify)
|
||||
}
|
||||
|
||||
/// Pre-spawn dedicated sender threads during SDK initialization, avoiding first-submit thread
|
||||
/// creation cost on the trading hot path.
|
||||
pub fn warm_dedicated_sender_pool(
|
||||
sender_thread_cores: Option<&[usize]>,
|
||||
max_sender_concurrency: usize,
|
||||
) {
|
||||
let _ = ensure_dedicated_pool(sender_thread_cores, max_sender_concurrency);
|
||||
}
|
||||
|
||||
fn ensure_dedicated_worker_count(
|
||||
queue: Arc<ArrayQueue<SwqosJob>>,
|
||||
notify: Arc<Notify>,
|
||||
|
||||
Reference in New Issue
Block a user