mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-17 02:48:05 +00:00
perf: Refactor event processing system for better performance
This commit is contained in:
@@ -13,7 +13,12 @@ pub struct BlockMetaEvent {
|
||||
}
|
||||
|
||||
impl BlockMetaEvent {
|
||||
pub fn new(slot: u64, block_hash: String, block_time_ms: i64) -> Self {
|
||||
pub fn new(
|
||||
slot: u64,
|
||||
block_hash: String,
|
||||
block_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
) -> Self {
|
||||
let metadata = EventMetadata::new(
|
||||
format!("block_{}_{}", slot, block_hash),
|
||||
"".to_string(),
|
||||
@@ -24,7 +29,7 @@ impl BlockMetaEvent {
|
||||
EventType::BlockMeta,
|
||||
solana_sdk::pubkey::Pubkey::default(),
|
||||
"".to_string(),
|
||||
chrono::Utc::now().timestamp_millis(),
|
||||
program_received_time_us,
|
||||
);
|
||||
Self { metadata, slot, block_hash }
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_transaction_status::UiCompiledInstruction;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature};
|
||||
|
||||
use crate::streaming::event_parser::{
|
||||
common::{utils::*, EventMetadata, EventType, ProtocolType},
|
||||
core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent},
|
||||
protocols::bonk::{
|
||||
bonk_pool_create_event_log_decode, bonk_trade_event_log_decode, discriminators, AmmFeeOn, BonkMigrateToAmmEvent, BonkMigrateToCpswapEvent, BonkPoolCreateEvent, BonkTradeEvent, ConstantCurve, CurveParams, FixedCurve, LinearCurve, MintParams, TradeDirection, VestingParams
|
||||
bonk_pool_create_event_log_decode, bonk_trade_event_log_decode, discriminators, AmmFeeOn,
|
||||
BonkMigrateToAmmEvent, BonkMigrateToCpswapEvent, BonkPoolCreateEvent, BonkTradeEvent,
|
||||
ConstantCurve, CurveParams, FixedCurve, LinearCurve, MintParams, TradeDirection,
|
||||
VestingParams,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -611,11 +613,11 @@ impl EventParser for BonkEventParser {
|
||||
}
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
signature: &str,
|
||||
inner_instruction: &CompiledInstruction,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
@@ -623,7 +625,7 @@ impl EventParser for BonkEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
@@ -632,10 +634,10 @@ impl EventParser for BonkEventParser {
|
||||
&self,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Pubkey],
|
||||
signature: &str,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
@@ -644,7 +646,7 @@ impl EventParser for BonkEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::signature::Signature;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_transaction_status::UiCompiledInstruction;
|
||||
|
||||
use crate::streaming::event_parser::common::filter::EventTypeFilter;
|
||||
use crate::streaming::event_parser::{
|
||||
@@ -23,18 +23,38 @@ impl MutilEventParser {
|
||||
|
||||
// Merge inner_instruction_configs, append configurations to existing Vec
|
||||
for (key, configs) in parse.inner_instruction_configs() {
|
||||
let filtered_configs: Vec<GenericEventParseConfig> = configs.into_iter().filter(|config| {
|
||||
event_type_filter.as_ref().map(|filter| filter.include.contains(&config.event_type)).unwrap_or(true)
|
||||
}).collect();
|
||||
inner.inner_instruction_configs.entry(key).or_insert_with(Vec::new).extend(filtered_configs);
|
||||
let filtered_configs: Vec<GenericEventParseConfig> = configs
|
||||
.into_iter()
|
||||
.filter(|config| {
|
||||
event_type_filter
|
||||
.as_ref()
|
||||
.map(|filter| filter.include.contains(&config.event_type))
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.collect();
|
||||
inner
|
||||
.inner_instruction_configs
|
||||
.entry(key)
|
||||
.or_insert_with(Vec::new)
|
||||
.extend(filtered_configs);
|
||||
}
|
||||
|
||||
// Merge instruction_configs, append configurations to existing Vec
|
||||
for (key, configs) in parse.instruction_configs() {
|
||||
let filtered_configs: Vec<GenericEventParseConfig> = configs.into_iter().filter(|config| {
|
||||
event_type_filter.as_ref().map(|filter| filter.include.contains(&config.event_type)).unwrap_or(true)
|
||||
}).collect();
|
||||
inner.instruction_configs.entry(key).or_insert_with(Vec::new).extend(filtered_configs);
|
||||
let filtered_configs: Vec<GenericEventParseConfig> = configs
|
||||
.into_iter()
|
||||
.filter(|config| {
|
||||
event_type_filter
|
||||
.as_ref()
|
||||
.map(|filter| filter.include.contains(&config.event_type))
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.collect();
|
||||
inner
|
||||
.instruction_configs
|
||||
.entry(key)
|
||||
.or_insert_with(Vec::new)
|
||||
.extend(filtered_configs);
|
||||
}
|
||||
|
||||
// Append program_ids (this is already appending)
|
||||
@@ -54,11 +74,11 @@ impl EventParser for MutilEventParser {
|
||||
}
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
signature: &str,
|
||||
inner_instruction: &CompiledInstruction,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
@@ -66,7 +86,7 @@ impl EventParser for MutilEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
@@ -75,10 +95,10 @@ impl EventParser for MutilEventParser {
|
||||
&self,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Pubkey],
|
||||
signature: &str,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
@@ -87,7 +107,7 @@ impl EventParser for MutilEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_transaction_status::UiCompiledInstruction;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature};
|
||||
|
||||
use crate::streaming::event_parser::{
|
||||
common::{EventMetadata, EventType, ProtocolType},
|
||||
@@ -295,11 +294,11 @@ impl EventParser for PumpFunEventParser {
|
||||
}
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
signature: &str,
|
||||
inner_instruction: &CompiledInstruction,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
@@ -307,7 +306,7 @@ impl EventParser for PumpFunEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
@@ -316,10 +315,10 @@ impl EventParser for PumpFunEventParser {
|
||||
&self,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Pubkey],
|
||||
signature: &str,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
@@ -328,7 +327,7 @@ impl EventParser for PumpFunEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_transaction_status::UiCompiledInstruction;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature};
|
||||
|
||||
use crate::streaming::event_parser::{
|
||||
common::{read_u64_le, EventMetadata, EventType, ProtocolType},
|
||||
@@ -385,11 +384,11 @@ impl EventParser for PumpSwapEventParser {
|
||||
}
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
signature: &str,
|
||||
inner_instruction: &CompiledInstruction,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
@@ -397,7 +396,7 @@ impl EventParser for PumpSwapEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
@@ -406,10 +405,10 @@ impl EventParser for PumpSwapEventParser {
|
||||
&self,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Pubkey],
|
||||
signature: &str,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
@@ -418,7 +417,7 @@ impl EventParser for PumpSwapEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_transaction_status::UiCompiledInstruction;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature};
|
||||
|
||||
use crate::streaming::event_parser::{
|
||||
common::{read_u64_le, EventMetadata, EventType, ProtocolType},
|
||||
@@ -387,11 +386,11 @@ impl EventParser for RaydiumAmmV4EventParser {
|
||||
}
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
signature: &str,
|
||||
inner_instruction: &CompiledInstruction,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
@@ -399,7 +398,7 @@ impl EventParser for RaydiumAmmV4EventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
@@ -408,10 +407,10 @@ impl EventParser for RaydiumAmmV4EventParser {
|
||||
&self,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Pubkey],
|
||||
signature: &str,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
@@ -420,7 +419,7 @@ impl EventParser for RaydiumAmmV4EventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_transaction_status::UiCompiledInstruction;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature};
|
||||
|
||||
use crate::streaming::event_parser::{
|
||||
common::{
|
||||
@@ -428,11 +427,11 @@ impl EventParser for RaydiumClmmEventParser {
|
||||
}
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
signature: &str,
|
||||
inner_instruction: &CompiledInstruction,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
@@ -440,7 +439,7 @@ impl EventParser for RaydiumClmmEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
@@ -449,10 +448,10 @@ impl EventParser for RaydiumClmmEventParser {
|
||||
&self,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Pubkey],
|
||||
signature: &str,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
@@ -461,7 +460,7 @@ impl EventParser for RaydiumClmmEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_transaction_status::UiCompiledInstruction;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature};
|
||||
|
||||
use crate::streaming::event_parser::{
|
||||
common::{read_u64_le, EventMetadata, EventType, ProtocolType},
|
||||
@@ -278,11 +277,11 @@ impl EventParser for RaydiumCpmmEventParser {
|
||||
}
|
||||
fn parse_events_from_inner_instruction(
|
||||
&self,
|
||||
inner_instruction: &UiCompiledInstruction,
|
||||
signature: &str,
|
||||
inner_instruction: &CompiledInstruction,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_inner_instruction(
|
||||
@@ -290,7 +289,7 @@ impl EventParser for RaydiumCpmmEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
@@ -299,10 +298,10 @@ impl EventParser for RaydiumCpmmEventParser {
|
||||
&self,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Pubkey],
|
||||
signature: &str,
|
||||
signature: Signature,
|
||||
slot: u64,
|
||||
block_time: Option<Timestamp>,
|
||||
program_received_time_ms: i64,
|
||||
program_received_time_us: i64,
|
||||
index: String,
|
||||
) -> Vec<Box<dyn UnifiedEvent>> {
|
||||
self.inner.parse_events_from_instruction(
|
||||
@@ -311,7 +310,7 @@ impl EventParser for RaydiumCpmmEventParser {
|
||||
signature,
|
||||
slot,
|
||||
block_time,
|
||||
program_received_time_ms,
|
||||
program_received_time_us,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user