mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-16 10:28:05 +00:00
refactor: overhaul event parser architecture for better performance
- Centralize event parsing logic and remove factory pattern - Add high-performance clock module to reduce latency - Consolidate protocol parsers with unified interface - Introduce account pubkey caching and streamline traits - Remove deprecated macro-based and multi-protocol implementations
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::common::SimdUtils;
|
||||
use crate::streaming::event_parser::common::filter::EventTypeFilter;
|
||||
use crate::streaming::event_parser::common::high_performance_clock::elapsed_micros_since;
|
||||
use crate::streaming::event_parser::common::{EventMetadata, EventType, ProtocolType};
|
||||
use crate::streaming::event_parser::core::traits::{elapsed_micros_since, UnifiedEvent};
|
||||
use crate::streaming::event_parser::core::traits::UnifiedEvent;
|
||||
use crate::streaming::event_parser::protocols::bonk::parser::BONK_PROGRAM_ID;
|
||||
use crate::streaming::event_parser::protocols::pumpfun::parser::PUMPFUN_PROGRAM_ID;
|
||||
use crate::streaming::event_parser::protocols::pumpswap::parser::PUMPSWAP_PROGRAM_ID;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::streaming::event_parser::core::traits::{elapsed_micros_since, UnifiedEvent};
|
||||
use crate::streaming::event_parser::common::high_performance_clock::elapsed_micros_since;
|
||||
use crate::streaming::event_parser::core::traits::UnifiedEvent;
|
||||
use crate::streaming::event_parser::protocols::block::block_meta_event::BlockMetaEvent;
|
||||
|
||||
pub struct CommonEventParser {}
|
||||
@@ -10,10 +11,8 @@ impl CommonEventParser {
|
||||
block_time_ms: i64,
|
||||
recv_us: i64,
|
||||
) -> Box<dyn UnifiedEvent> {
|
||||
let mut block_meta_event =
|
||||
BlockMetaEvent::new(slot, block_hash, block_time_ms, recv_us);
|
||||
block_meta_event
|
||||
.set_handle_us(elapsed_micros_since(recv_us));
|
||||
let mut block_meta_event = BlockMetaEvent::new(slot, block_hash, block_time_ms, recv_us);
|
||||
block_meta_event.set_handle_us(elapsed_micros_since(recv_us));
|
||||
Box::new(block_meta_event)
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,133 +0,0 @@
|
||||
/// Macro to generate boilerplate EventParser implementation for protocol parsers
|
||||
///
|
||||
/// This macro eliminates the repetitive code where each parser simply delegates
|
||||
/// all EventParser trait methods to its inner GenericEventParser.
|
||||
///
|
||||
/// Usage:
|
||||
/// ```rust
|
||||
/// impl_event_parser_delegate!(MyEventParser);
|
||||
/// ```
|
||||
///
|
||||
/// This will generate the complete EventParser implementation that delegates
|
||||
/// all methods to `self.inner`.
|
||||
#[macro_export]
|
||||
macro_rules! impl_event_parser_delegate {
|
||||
($parser_type:ty) => {
|
||||
#[async_trait::async_trait]
|
||||
impl $crate::streaming::event_parser::core::traits::EventParser for $parser_type {
|
||||
fn instruction_configs(
|
||||
&self,
|
||||
) -> std::collections::HashMap<
|
||||
Vec<u8>,
|
||||
Vec<$crate::streaming::event_parser::core::traits::GenericEventParseConfig>,
|
||||
> {
|
||||
self.inner.instruction_configs()
|
||||
}
|
||||
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &solana_sdk::instruction::CompiledInstruction,
|
||||
signature: solana_sdk::signature::Signature,
|
||||
slot: u64,
|
||||
block_time: Option<prost_types::Timestamp>,
|
||||
recv_us: i64,
|
||||
outer_index: i64,
|
||||
inner_index: Option<i64>,
|
||||
transaction_index: Option<u64>,
|
||||
config: &GenericEventParseConfig,
|
||||
) -> Vec<Box<dyn $crate::streaming::event_parser::core::traits::UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
inner_instruction,
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
recv_us,
|
||||
outer_index,
|
||||
inner_index,
|
||||
transaction_index,
|
||||
config,
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_events_from_grpc_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &yellowstone_grpc_proto::prelude::InnerInstruction,
|
||||
signature: solana_sdk::signature::Signature,
|
||||
slot: u64,
|
||||
block_time: Option<prost_types::Timestamp>,
|
||||
recv_us: i64,
|
||||
outer_index: i64,
|
||||
inner_index: Option<i64>,
|
||||
transaction_index: Option<u64>,
|
||||
config: &GenericEventParseConfig,
|
||||
) -> Vec<Box<dyn $crate::streaming::event_parser::core::traits::UnifiedEvent>> {
|
||||
self.inner.parse_events_from_grpc_inner_instruction(inner_instruction, signature, slot, block_time, recv_us, outer_index, inner_index, transaction_index, config)
|
||||
}
|
||||
|
||||
fn parse_events_from_instruction(
|
||||
&self,
|
||||
instruction: &solana_sdk::instruction::CompiledInstruction,
|
||||
accounts: &[solana_sdk::pubkey::Pubkey],
|
||||
signature: solana_sdk::signature::Signature,
|
||||
slot: u64,
|
||||
block_time: Option<prost_types::Timestamp>,
|
||||
recv_us: i64,
|
||||
outer_index: i64,
|
||||
inner_index: Option<i64>,
|
||||
bot_wallet: Option<solana_sdk::pubkey::Pubkey>,
|
||||
transaction_index: Option<u64>,
|
||||
inner_instructions: Option<&solana_transaction_status::InnerInstructions>,
|
||||
callback: std::sync::Arc<
|
||||
dyn for<'a> Fn(&'a Box<dyn $crate::streaming::event_parser::core::traits::UnifiedEvent>)
|
||||
+ Send
|
||||
+ Sync,
|
||||
>,
|
||||
) -> anyhow::Result<()> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
instruction,
|
||||
accounts,
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
recv_us,
|
||||
outer_index,
|
||||
inner_index,
|
||||
bot_wallet,
|
||||
transaction_index,
|
||||
inner_instructions,
|
||||
callback,
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_events_from_grpc_instruction(
|
||||
&self,
|
||||
instruction: &yellowstone_grpc_proto::prelude::CompiledInstruction,
|
||||
accounts: &[solana_sdk::pubkey::Pubkey],
|
||||
signature: solana_sdk::signature::Signature,
|
||||
slot: u64,
|
||||
block_time: Option<prost_types::Timestamp>,
|
||||
recv_us: i64,
|
||||
outer_index: i64,
|
||||
inner_index: Option<i64>,
|
||||
bot_wallet: Option<solana_sdk::pubkey::Pubkey>,
|
||||
transaction_index: Option<u64>,
|
||||
inner_instructions: Option<&yellowstone_grpc_proto::prelude::InnerInstructions>,
|
||||
callback: std::sync::Arc<
|
||||
dyn for<'a> Fn(&'a Box<dyn $crate::streaming::event_parser::core::traits::UnifiedEvent>)
|
||||
+ Send
|
||||
+ Sync,
|
||||
>,
|
||||
) -> anyhow::Result<()> {
|
||||
self.inner.parse_events_from_grpc_instruction(instruction, accounts, signature, slot, block_time, recv_us, outer_index, inner_index, bot_wallet, transaction_index, inner_instructions, callback)
|
||||
}
|
||||
|
||||
fn should_handle(&self, program_id: &solana_sdk::pubkey::Pubkey) -> bool {
|
||||
self.inner.should_handle(program_id)
|
||||
}
|
||||
|
||||
fn supported_program_ids(&self) -> Vec<solana_sdk::pubkey::Pubkey> {
|
||||
self.inner.supported_program_ids()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod common_event_parser;
|
||||
pub mod traits;
|
||||
pub mod account_event_parser;
|
||||
pub mod macros;
|
||||
pub mod common_event_parser;
|
||||
pub mod global_state;
|
||||
pub use traits::{EventParser, UnifiedEvent};
|
||||
pub mod traits;
|
||||
pub use traits::UnifiedEvent;
|
||||
|
||||
pub mod event_parser;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user