mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-19 11:58:06 +00:00
feat: bridge streamer to sol-parser-sdk
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
use crate::common::AnyResult;
|
||||
use crate::streaming::common::MetricsEventType;
|
||||
use crate::streaming::event_parser::common::filter::EventTypeFilter;
|
||||
use crate::streaming::event_parser::common::filter::{passes_event_type_filter, EventTypeFilter};
|
||||
use crate::streaming::event_parser::common::high_performance_clock::elapsed_micros_since;
|
||||
use crate::streaming::event_parser::core::account_event_parser::AccountEventParser;
|
||||
use crate::streaming::event_parser::core::common_event_parser::CommonEventParser;
|
||||
use crate::streaming::event_parser::core::event_parser::EventParser;
|
||||
use crate::streaming::event_parser::{core::traits::DexEvent, Protocol};
|
||||
use crate::streaming::grpc::{EventPretty, MetricsManager};
|
||||
use crate::streaming::parser_sdk_bridge::{parse_account_event_for_streamer, AccountParseResult};
|
||||
use crate::streaming::shred::TransactionWithSlot;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// 创建带 metrics 统计的 callback 包装器
|
||||
///
|
||||
/// 用于 Transaction 事件处理,在调用原始 callback 的同时更新 metrics
|
||||
/// Wrap the user callback and update transaction metrics after delivery.
|
||||
#[inline]
|
||||
fn create_metrics_callback(
|
||||
callback: Arc<dyn Fn(DexEvent) + Send + Sync>,
|
||||
@@ -47,6 +47,18 @@ pub async fn process_grpc_transaction(
|
||||
EventPretty::Account(account_pretty) => {
|
||||
MetricsManager::global().add_account_process_count();
|
||||
|
||||
match parse_account_event_for_streamer(&account_pretty, protocols, event_type_filter) {
|
||||
AccountParseResult::Event(mut event) => {
|
||||
event.metadata_mut().handle_us = elapsed_micros_since(account_pretty.recv_us);
|
||||
let processing_time_us = event.metadata().handle_us as f64;
|
||||
callback(event);
|
||||
update_metrics(MetricsEventType::Account, 1, processing_time_us);
|
||||
return Ok(());
|
||||
}
|
||||
AccountParseResult::Filtered => return Ok(()),
|
||||
AccountParseResult::Unsupported => {}
|
||||
}
|
||||
|
||||
let account_event = AccountEventParser::parse_account_event(
|
||||
protocols,
|
||||
account_pretty,
|
||||
@@ -105,6 +117,10 @@ pub async fn process_grpc_transaction(
|
||||
block_meta_pretty.recv_us,
|
||||
);
|
||||
|
||||
if !passes_event_type_filter(event_type_filter, &block_meta_event) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let processing_time_us = block_meta_event.metadata().handle_us as f64;
|
||||
callback(block_meta_event);
|
||||
update_metrics(MetricsEventType::BlockMeta, 1, processing_time_us);
|
||||
@@ -136,8 +152,8 @@ pub async fn process_shred_transaction(
|
||||
let recv_us = transaction_with_slot.recv_us;
|
||||
|
||||
let adapter_callback = create_metrics_callback(callback);
|
||||
// Shred 路径仅能拿到 static_account_keys,且无 inner_instructions,解析限制见 docs/SHREDSTREAM_LIMITATIONS.md
|
||||
// 若交易使用 ALT,账户可能为 default/错误;无 CPI 合并,timestamp/reserves 等多为 0。
|
||||
// Shred only exposes static account keys and no inner instructions; see
|
||||
// docs/SHREDSTREAM_LIMITATIONS.md for the expected parser limits.
|
||||
let accounts = tx.message.static_account_keys();
|
||||
|
||||
EventParser::parse_instruction_events_from_versioned_transaction(
|
||||
@@ -146,7 +162,7 @@ pub async fn process_shred_transaction(
|
||||
&tx,
|
||||
signature,
|
||||
Some(slot),
|
||||
None, // shred 无 block_time
|
||||
None, // shred has no block_time
|
||||
recv_us,
|
||||
accounts,
|
||||
&[],
|
||||
@@ -174,5 +190,11 @@ fn update_metrics_with_latency(
|
||||
recv_us: i64,
|
||||
block_time_ms: i64,
|
||||
) {
|
||||
MetricsManager::global().update_metrics_with_latency(ty, count, time_us, recv_us, block_time_ms);
|
||||
MetricsManager::global().update_metrics_with_latency(
|
||||
ty,
|
||||
count,
|
||||
time_us,
|
||||
recv_us,
|
||||
block_time_ms,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user