#让SDK中打印 submit_timing 的数据( SwqosType和 提交耗时)返回给buy 和 sell 方法。

主要解决问题:
当 wait_tx_confirmed 参数为 false 时,SUBMIT_TIMEOUT_SECS 等待改为2秒,要么全部提交完成返回,要么不等待提交未返回的交易,方便快速创建交易订单。

#Let the SDK print submit_timing data (SwqosType and submission time) and return it to the buy and sell methods.

Main problems solved:

When the wait_tx_confirmed parameter is false, the SUBMIT_TIMEOUT_SECS wait is changed to 2 seconds. Either all submissions are completed and returned, or the unreturned transactions are not waited for submission, which facilitates the rapid creation of transaction orders.
This commit is contained in:
Admin
2026-04-01 15:46:01 +08:00
parent ae890ad976
commit eaa3214e4d
4 changed files with 23 additions and 19 deletions
+13 -6
View File
@@ -25,6 +25,7 @@ use crate::{
trading::MiddlewareManager,
};
use once_cell::sync::Lazy;
use crate::swqos::{ SwqosType};
/// Global syscall bypass manager (reserved for future time/IO optimizations).
/// 全局系统调用绕过管理器(预留,后续可接入时间/IO 等优化)。
@@ -55,7 +56,7 @@ impl TradeExecutor for GenericTradeExecutor {
async fn swap(
&self,
params: SwapParams,
) -> Result<(bool, Vec<Signature>, Option<anyhow::Error>)> {
) -> Result<(bool, Vec<Signature>, Option<anyhow::Error>, Vec<(SwqosType, i64)>)> {
// Sample total start only when logging or simulate. 仅在有日志或 simulate 时取起点。
let total_start = (params.log_enabled || params.simulate).then(Instant::now);
let timing_start_us: Option<i64> = if params.log_enabled {
@@ -215,7 +216,9 @@ impl TradeExecutor for GenericTradeExecutor {
} else {
(ok, signatures, err)
};
Ok(confirm_result)
//就是把confirm_result 拆开 再加上 submit_timings
Ok((confirm_result.0, confirm_result.1, confirm_result.2, submit_timings))
} else {
// Not waiting for confirmation: confirmed is not measured (-); total is per-channel submit time only.
if log_enabled {
@@ -229,7 +232,11 @@ impl TradeExecutor for GenericTradeExecutor {
None,
);
}
Ok((ok, signatures, err))
Ok((ok, signatures, err, submit_timings))
};
result
@@ -254,7 +261,7 @@ async fn simulate_transaction(
is_buy: bool,
with_tip: bool,
gas_fee_strategy: GasFeeStrategy,
) -> Result<(bool, Vec<Signature>, Option<anyhow::Error>)> {
) -> Result<(bool, Vec<Signature>, Option<anyhow::Error>, Vec<(SwqosType, i64)>)> {
use crate::trading::common::build_transaction;
use solana_client::rpc_config::RpcSimulateTransactionConfig;
use solana_commitment_config::CommitmentLevel;
@@ -330,7 +337,7 @@ async fn simulate_transaction(
trace!(target: "sol_trade_sdk", "Compute Units Consumed: {}", units_consumed);
}
}
return Ok((false, vec![signature], Some(anyhow::anyhow!("{:?}", err))));
return Ok((false, vec![signature], Some(anyhow::anyhow!("{:?}", err)), Vec::new()));
}
// Simulation succeeded
@@ -345,7 +352,7 @@ async fn simulate_transaction(
}
}
Ok((true, vec![signature], None))
Ok((true, vec![signature], None, Vec::new()))
}
#[cfg(test)]