feat: optimize RPC polling and remove data size limit

Significantly reduce RPC pressure and fix MaxLoadedAccountsDataSizeExceeded errors.

Major improvements:
1. Add wait_confirmation parameter to all swqos clients
   - Skip polling entirely when wait_transaction_confirmed=false (100% RPC reduction)
   - Optimize getTransaction calls to only execute on errors or after 10s (50% reduction)
   - Update all 13 swqos client implementations

2. Remove LoadedAccountsDataSize instruction and data_size_limit parameter
   - Eliminate MaxLoadedAccountsDataSizeExceeded errors reported by users
   - Clean up gas_fee_strategy, params, and transaction builder
   - Simplify compute budget instruction generation

Results:
- Single channel: 30 RPC calls → 0-15 calls (50-100% reduction)
- Multi-channel (3x): 90 RPC calls → 0-45 calls (50-100% reduction)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Wood
2025-12-28 13:15:16 +08:00
co-authored by Claude Sonnet 4.5
parent 710de8a92a
commit 321f4c4a25
22 changed files with 183 additions and 179 deletions
+3 -14
View File
@@ -7,30 +7,24 @@ use solana_compute_budget_interface::ComputeBudgetInstruction;
/// Cache key containing all parameters for compute budget instructions
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct ComputeBudgetCacheKey {
data_size_limit: u32,
unit_price: u64,
unit_limit: u32,
is_buy: bool,
}
/// Global cache storing compute budget instructions
/// Uses DashMap for high-performance lock-free concurrent access
static COMPUTE_BUDGET_CACHE: Lazy<DashMap<ComputeBudgetCacheKey, SmallVec<[Instruction; 3]>>> =
static COMPUTE_BUDGET_CACHE: Lazy<DashMap<ComputeBudgetCacheKey, SmallVec<[Instruction; 2]>>> =
Lazy::new(|| DashMap::new());
#[inline(always)]
pub fn compute_budget_instructions(
unit_price: u64,
unit_limit: u32,
data_size_limit: u32,
is_buy: bool,
) -> SmallVec<[Instruction; 3]> {
) -> SmallVec<[Instruction; 2]> {
// Create cache key
let cache_key = ComputeBudgetCacheKey {
data_size_limit,
unit_price: unit_price,
unit_limit: unit_limit,
is_buy,
};
// Try to get from cache first
@@ -39,12 +33,7 @@ pub fn compute_budget_instructions(
}
// Cache miss, generate new instructions
let mut insts = SmallVec::<[Instruction; 3]>::new();
// Only add data_size_limit instruction if > 0 and is_buy
if is_buy && data_size_limit > 0 {
insts.push(ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(data_size_limit));
}
let mut insts = SmallVec::<[Instruction; 2]>::new();
// Only add compute unit price instruction if > 0
if unit_price > 0 {
@@ -24,7 +24,6 @@ pub async fn build_transaction(
business_instructions: Vec<Instruction>,
address_lookup_table_account: Option<AddressLookupTableAccount>,
recent_blockhash: Option<Hash>,
data_size_limit: u32,
middleware_manager: Option<Arc<MiddlewareManager>>,
protocol_name: &str,
is_buy: bool,
@@ -57,8 +56,6 @@ pub async fn build_transaction(
instructions.extend(compute_budget_instructions(
unit_price,
unit_limit,
data_size_limit,
is_buy,
));
// Add business instructions
+1 -2
View File
@@ -200,7 +200,6 @@ pub async fn execute_parallel(
address_lookup_table_account: Option<AddressLookupTableAccount>,
recent_blockhash: Option<Hash>,
durable_nonce: Option<DurableNonceInfo>,
data_size_limit: u32,
middleware_manager: Option<Arc<MiddlewareManager>>,
protocol_name: &'static str,
is_buy: bool,
@@ -320,7 +319,6 @@ pub async fn execute_parallel(
instructions.as_ref().clone(),
address_lookup_table_account,
recent_blockhash,
data_size_limit,
middleware_manager,
protocol_name,
is_buy,
@@ -354,6 +352,7 @@ pub async fn execute_parallel(
.send_transaction(
if is_buy { TradeType::Buy } else { TradeType::Sell },
&transaction,
wait_transaction_confirmed,
)
.await
{
-4
View File
@@ -89,7 +89,6 @@ impl TradeExecutor for GenericTradeExecutor {
params.address_lookup_table_account,
params.recent_blockhash,
params.durable_nonce,
if is_buy { params.data_size_limit } else { 0 },
params.middleware_manager,
self.protocol_name,
is_buy,
@@ -139,7 +138,6 @@ impl TradeExecutor for GenericTradeExecutor {
params.address_lookup_table_account,
params.recent_blockhash,
params.durable_nonce,
if is_buy { params.data_size_limit } else { 0 },
params.middleware_manager,
self.protocol_name,
is_buy,
@@ -184,7 +182,6 @@ async fn simulate_transaction(
address_lookup_table_account: Option<AddressLookupTableAccount>,
recent_blockhash: Option<Hash>,
durable_nonce: Option<DurableNonceInfo>,
data_size_limit: u32,
middleware_manager: Option<Arc<MiddlewareManager>>,
protocol_name: &'static str,
is_buy: bool,
@@ -221,7 +218,6 @@ async fn simulate_transaction(
instructions,
address_lookup_table_account,
recent_blockhash,
data_size_limit,
middleware_manager,
protocol_name,
is_buy,
-1
View File
@@ -53,7 +53,6 @@ pub struct SwapParams {
pub slippage_basis_points: Option<u64>,
pub address_lookup_table_account: Option<AddressLookupTableAccount>,
pub recent_blockhash: Option<Hash>,
pub data_size_limit: u32,
pub wait_transaction_confirmed: bool,
pub protocol_params: DexParamEnum,
pub open_seed_optimize: bool,