feat: translate comments to English and add PumpSwap buy_exact_quote_in

- Translate all Chinese comments to English
- Add PumpSwap buy_exact_quote_in instruction and event support
- Update event parser to handle new buy_exact_quote_in event type
- Improve code readability across codebase
This commit is contained in:
Estereg
2025-12-17 20:06:14 -03:00
parent bec65dea21
commit e1c537554e
29 changed files with 533 additions and 351 deletions
+10 -10
View File
@@ -8,7 +8,7 @@ use crate::streaming::common::{
MetricsManager, PerformanceMetrics, StreamClientConfig, SubscriptionHandle,
};
/// ShredStream gRPC 客户端
/// ShredStream gRPC client
#[derive(Clone)]
pub struct ShredStreamGrpc {
pub shredstream_client: Arc<ShredstreamProxyClient<Channel>>,
@@ -17,12 +17,12 @@ pub struct ShredStreamGrpc {
}
impl ShredStreamGrpc {
/// 创建客户端,使用默认配置
/// Create client with default configuration
pub async fn new(endpoint: String) -> AnyResult<Self> {
Self::new_with_config(endpoint, StreamClientConfig::default()).await
}
/// 创建客户端,使用自定义配置
/// Create client with custom configuration
pub async fn new_with_config(endpoint: String, config: StreamClientConfig) -> AnyResult<Self> {
let shredstream_client = ShredstreamProxyClient::connect(endpoint.clone()).await?;
MetricsManager::init(config.enable_metrics);
@@ -33,37 +33,37 @@ impl ShredStreamGrpc {
})
}
/// 获取当前配置
/// Get current configuration
pub fn get_config(&self) -> &StreamClientConfig {
&self.config
}
/// 更新配置
/// Update configuration
pub fn update_config(&mut self, config: StreamClientConfig) {
self.config = config;
}
/// 获取性能指标
/// Get performance metrics
pub fn get_metrics(&self) -> PerformanceMetrics {
MetricsManager::global().get_metrics()
}
/// 启用或禁用性能监控
/// Enable or disable performance monitoring
pub fn set_enable_metrics(&mut self, enabled: bool) {
self.config.enable_metrics = enabled;
}
/// 打印性能指标
/// Print performance metrics
pub fn print_metrics(&self) {
MetricsManager::global().print_metrics();
}
/// 启动自动性能监控任务
/// Start automatic performance monitoring task
pub async fn start_auto_metrics_monitoring(&self) {
MetricsManager::global().start_auto_monitoring().await;
}
/// 停止当前订阅
/// Stop current subscription
pub async fn stop(&self) {
let mut handle_guard = self.subscription_handle.lock().await;
if let Some(handle) = handle_guard.take() {
+3 -3
View File
@@ -1,14 +1,14 @@
// ShredStream 相关模块
// ShredStream related modules
pub mod connection;
pub mod pool;
pub mod types;
// 重新导出主要类型
// Re-export main types
pub use connection::*;
pub use pool::*;
pub use types::*;
// 从公用模块重新导出
// Re-export from common modules
pub use crate::streaming::common::{
ConnectionConfig, MetricsEventType, MetricsManager, PerformanceMetrics, StreamClientConfig,
};
+15 -15
View File
@@ -6,7 +6,7 @@ use solana_sdk::transaction::VersionedTransaction;
use super::TransactionWithSlot;
/// TransactionWithSlot 对象池
/// TransactionWithSlot object pool
pub struct TransactionWithSlotPool {
pool: Arc<Mutex<VecDeque<Box<TransactionWithSlot>>>>,
max_size: usize,
@@ -16,7 +16,7 @@ impl TransactionWithSlotPool {
pub fn new(initial_size: usize, max_size: usize) -> Self {
let mut pool = VecDeque::with_capacity(initial_size);
// 预分配对象
// Pre-allocate objects
for _ in 0..initial_size {
pool.push_back(Box::new(TransactionWithSlot::default()));
}
@@ -39,7 +39,7 @@ impl TransactionWithSlotPool {
}
}
/// 带自动归还的 TransactionWithSlot
/// TransactionWithSlot with automatic return
pub struct PooledTransactionWithSlot {
transaction: Box<TransactionWithSlot>,
pool: Arc<Mutex<VecDeque<Box<TransactionWithSlot>>>>,
@@ -47,7 +47,7 @@ pub struct PooledTransactionWithSlot {
}
impl PooledTransactionWithSlot {
/// 从原始数据重置
/// Reset from raw data
pub fn reset_from_data(
&mut self,
transaction: VersionedTransaction,
@@ -59,9 +59,9 @@ impl PooledTransactionWithSlot {
self.transaction.recv_us = recv_us;
}
/// 使用优化的工厂方法创建 TransactionWithSlot(移动数据而不是克隆)
/// Create TransactionWithSlot using optimized factory method (move data instead of cloning)
pub fn into_transaction_with_slot(mut self) -> TransactionWithSlot {
// 移动数据而不是克隆,避免多余的内存分配
// Move data instead of cloning to avoid unnecessary memory allocation
std::mem::replace(self.deref_mut(), TransactionWithSlot::default())
}
}
@@ -70,10 +70,10 @@ impl Drop for PooledTransactionWithSlot {
fn drop(&mut self) {
let mut pool = self.pool.lock().unwrap();
if pool.len() < self.max_size {
// 清理敏感数据
// Clear sensitive data
self.transaction.slot = 0;
self.transaction.recv_us = 0;
// 重置交易为默认值以清理敏感数据
// Reset transaction to default to clear sensitive data
self.transaction.transaction = VersionedTransaction::default();
pool.push_back(std::mem::take(&mut self.transaction));
}
@@ -94,7 +94,7 @@ impl std::ops::DerefMut for PooledTransactionWithSlot {
}
}
/// Shred 对象池管理器
/// Shred object pool manager
pub struct ShredPoolManager {
transaction_pool: TransactionWithSlotPool,
}
@@ -103,8 +103,8 @@ impl ShredPoolManager {
pub fn new() -> Self {
Self {
transaction_pool: TransactionWithSlotPool::new(
5000, // 初始大小 - Shred 事件通常较多
15000, // 最大大小
5000, // Initial size - Shred events are usually numerous
15000, // Max size
),
}
}
@@ -113,7 +113,7 @@ impl ShredPoolManager {
&self.transaction_pool
}
/// 创建优化的 TransactionWithSlot
/// Create optimized TransactionWithSlot
pub fn create_transaction_with_slot_optimized(
&self,
transaction: VersionedTransaction,
@@ -132,16 +132,16 @@ impl Default for ShredPoolManager {
}
}
// 全局 Shred 池管理器实例
// Global Shred pool manager instance
lazy_static::lazy_static! {
pub static ref GLOBAL_SHRED_POOL_MANAGER: ShredPoolManager = ShredPoolManager::new();
}
/// 便捷的全局工厂函数
/// Convenient global factory functions
pub mod factory {
use super::*;
/// 使用对象池创建 TransactionWithSlot(推荐用于高性能场景)
/// Create TransactionWithSlot using object pool (recommended for high-performance scenarios)
pub fn create_transaction_with_slot_pooled(
transaction: VersionedTransaction,
slot: u64,
+2 -2
View File
@@ -1,6 +1,6 @@
use solana_sdk::transaction::VersionedTransaction;
/// 携带槽位信息的交易
/// Transaction with slot information
#[derive(Debug, Clone, Default)]
pub struct TransactionWithSlot {
pub transaction: VersionedTransaction,
@@ -9,7 +9,7 @@ pub struct TransactionWithSlot {
}
impl TransactionWithSlot {
/// 创建新的带槽位的交易
/// Create new transaction with slot
pub fn new(
transaction: VersionedTransaction,
slot: u64,