mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-23 13:58:06 +00:00
refactor: convert EventParser to static methods and optimize caching
- Replace instance-based EventParser with static method design - Introduce ParserCache module for protocol config caching - Simplify EventProcessor to pure functional handlers - Optimize metrics: remove min/max tracking, keep last + avg only - Reduce atomic operations in hot path for better performance
This commit is contained in:
@@ -5,7 +5,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::common::AnyResult;
|
||||
use crate::protos::shredstream::SubscribeEntriesRequest;
|
||||
use crate::streaming::common::{EventProcessor, SubscriptionHandle};
|
||||
use crate::streaming::common::{process_shred_transaction, SubscriptionHandle};
|
||||
use crate::streaming::event_parser::common::filter::EventTypeFilter;
|
||||
use crate::streaming::event_parser::common::high_performance_clock::get_high_perf_clock;
|
||||
use crate::streaming::event_parser::{Protocol, UnifiedEvent};
|
||||
@@ -37,20 +37,14 @@ impl ShredStreamGrpc {
|
||||
metrics_handle = MetricsManager::global().start_auto_monitoring().await;
|
||||
}
|
||||
|
||||
// 创建事件处理器
|
||||
let mut event_processor = EventProcessor::new(self.config.clone());
|
||||
event_processor.set_protocols_and_event_type_filter(
|
||||
super::common::EventSource::Shred,
|
||||
protocols,
|
||||
event_type_filter,
|
||||
Some(Arc::new(callback)),
|
||||
);
|
||||
|
||||
// 启动流处理
|
||||
let mut client = (*self.shredstream_client).clone();
|
||||
let request = tonic::Request::new(SubscribeEntriesRequest {});
|
||||
let mut stream = client.subscribe_entries(request).await?.into_inner();
|
||||
let event_processor_clone = event_processor.clone();
|
||||
|
||||
// Wrap callback once before the async block
|
||||
let callback = Arc::new(callback);
|
||||
|
||||
let stream_task = tokio::spawn(async move {
|
||||
while let Some(message) = stream.next().await {
|
||||
match message {
|
||||
@@ -64,13 +58,15 @@ impl ShredStreamGrpc {
|
||||
msg.slot,
|
||||
get_high_perf_clock(),
|
||||
);
|
||||
// 直接处理,背压控制在 EventProcessor 内部处理
|
||||
if let Err(e) = event_processor_clone
|
||||
.process_shred_transaction(
|
||||
transaction_with_slot,
|
||||
bot_wallet,
|
||||
)
|
||||
.await
|
||||
// Process transaction - clone Arc and Vec for each call
|
||||
if let Err(e) = process_shred_transaction(
|
||||
transaction_with_slot,
|
||||
&protocols,
|
||||
event_type_filter.as_ref(),
|
||||
callback.clone(),
|
||||
bot_wallet,
|
||||
)
|
||||
.await
|
||||
{
|
||||
error!("Error handling message: {e:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user