mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-18 03:18:05 +00:00
perf: add object pooling and enhanced metrics for streaming optimization
- Implement gRPC/shred connection pools for memory efficiency - Add atomic processing time stats with auto-calibration clock - Optimize event parsers and protocol handlers - Refactor metrics system for advanced performance monitoring
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::event_parser::common::{types::EventType, EventMetadata};
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::signature::Signature;
|
||||
|
||||
/// Block元数据事件
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
@@ -22,7 +21,7 @@ impl BlockMetaEvent {
|
||||
program_received_time_us: i64,
|
||||
) -> Self {
|
||||
let metadata = EventMetadata::new(
|
||||
Cow::Borrowed(""),
|
||||
Signature::default(),
|
||||
slot,
|
||||
block_time_ms / 1000,
|
||||
block_time_ms,
|
||||
|
||||
@@ -237,6 +237,7 @@ impl_unified_event!(
|
||||
// Migrate to CP Swap event
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct BonkMigrateToCpswapEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub payer: Pubkey,
|
||||
pub base_mint: Pubkey,
|
||||
@@ -276,10 +277,10 @@ impl_unified_event!(BonkMigrateToCpswapEvent,);
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BonkPoolStateAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub pool_state: PoolState,
|
||||
}
|
||||
@@ -289,10 +290,10 @@ impl_unified_event!(BonkPoolStateAccountEvent,);
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BonkGlobalConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub global_config: GlobalConfig,
|
||||
}
|
||||
@@ -302,10 +303,10 @@ impl_unified_event!(BonkGlobalConfigAccountEvent,);
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BonkPlatformConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub platform_config: PlatformConfig,
|
||||
}
|
||||
|
||||
@@ -142,10 +142,10 @@ pub fn pool_state_parser(
|
||||
if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) {
|
||||
Some(Box::new(BonkPoolStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool_state,
|
||||
}))
|
||||
@@ -193,10 +193,10 @@ pub fn global_config_parser(
|
||||
if let Some(global_config) = global_config_decode(&account.data[8..GLOBAL_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(BonkGlobalConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
global_config,
|
||||
}))
|
||||
@@ -241,10 +241,10 @@ pub fn platform_config_parser(
|
||||
{
|
||||
Some(Box::new(BonkPlatformConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
platform_config,
|
||||
}))
|
||||
|
||||
@@ -228,10 +228,10 @@ impl_unified_event!(
|
||||
pub struct PumpFunBondingCurveAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub bonding_curve: BondingCurve,
|
||||
}
|
||||
@@ -243,10 +243,10 @@ impl_unified_event!(PumpFunBondingCurveAccountEvent,);
|
||||
pub struct PumpFunGlobalAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub global: Global,
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ pub fn bonding_curve_parser(
|
||||
if let Some(bonding_curve) = bonding_curve_decode(&account.data[8..BONDING_CURVE_SIZE + 8]) {
|
||||
Some(Box::new(PumpFunBondingCurveAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
bonding_curve,
|
||||
}))
|
||||
@@ -91,10 +91,10 @@ pub fn global_parser(
|
||||
if let Some(global) = global_decode(&account.data[8..GLOBAL_SIZE + 8]) {
|
||||
Some(Box::new(PumpFunGlobalAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
global,
|
||||
}))
|
||||
|
||||
@@ -366,11 +366,12 @@ impl_unified_event!(
|
||||
/// 全局配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpSwapGlobalConfigAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub global_config: GlobalConfig,
|
||||
}
|
||||
@@ -379,11 +380,12 @@ impl_unified_event!(PumpSwapGlobalConfigAccountEvent,);
|
||||
/// 池
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpSwapPoolAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub pool: Pool,
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ pub fn global_config_parser(
|
||||
if let Some(config) = global_config_decode(&account.data[8..GLOBAL_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(PumpSwapGlobalConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
global_config: config,
|
||||
}))
|
||||
@@ -88,10 +88,10 @@ pub fn pool_parser(
|
||||
if let Some(pool) = pool_decode(&account.data[8..POOL_SIZE + 8]) {
|
||||
Some(Box::new(PumpSwapPoolAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool: pool,
|
||||
}))
|
||||
|
||||
@@ -9,6 +9,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||
/// 交易
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4SwapEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
// base in
|
||||
pub amount_in: u64,
|
||||
@@ -42,6 +43,7 @@ impl_unified_event!(RaydiumAmmV4SwapEvent,);
|
||||
/// 添加流动性
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4DepositEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub max_coin_amount: u64,
|
||||
pub max_pc_amount: u64,
|
||||
@@ -67,6 +69,7 @@ impl_unified_event!(RaydiumAmmV4DepositEvent,);
|
||||
/// 初始化
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4Initialize2Event {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub nonce: u8,
|
||||
pub open_time: u64,
|
||||
@@ -100,6 +103,7 @@ impl_unified_event!(RaydiumAmmV4Initialize2Event,);
|
||||
/// 移除流动性
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4WithdrawEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub amount: u64,
|
||||
|
||||
@@ -131,6 +135,7 @@ impl_unified_event!(RaydiumAmmV4WithdrawEvent,);
|
||||
/// 提现
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4WithdrawPnlEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
|
||||
pub token_program: Pubkey,
|
||||
@@ -156,11 +161,12 @@ impl_unified_event!(RaydiumAmmV4WithdrawPnlEvent,);
|
||||
/// 池信息
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4AmmInfoAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub amm_info: AmmInfo,
|
||||
}
|
||||
|
||||
@@ -96,10 +96,10 @@ pub fn amm_info_parser(
|
||||
if let Some(amm_info) = amm_info_decode(&account.data[..AMM_INFO_SIZE]) {
|
||||
Some(Box::new(RaydiumAmmV4AmmInfoAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
amm_info: amm_info,
|
||||
}))
|
||||
|
||||
@@ -223,10 +223,10 @@ impl_unified_event!(RaydiumClmmOpenPositionV2Event,);
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RaydiumClmmAmmConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub amm_config: AmmConfig,
|
||||
}
|
||||
@@ -236,10 +236,10 @@ impl_unified_event!(RaydiumClmmAmmConfigAccountEvent,);
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RaydiumClmmPoolStateAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub pool_state: PoolState,
|
||||
}
|
||||
@@ -249,10 +249,10 @@ impl_unified_event!(RaydiumClmmPoolStateAccountEvent,);
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RaydiumClmmTickArrayStateAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub tick_array_state: TickArrayState,
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ pub fn amm_config_parser(
|
||||
if let Some(amm_config) = amm_config_decode(&account.data[8..AMM_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumClmmAmmConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
amm_config: amm_config,
|
||||
}))
|
||||
@@ -135,10 +135,10 @@ pub fn pool_state_parser(
|
||||
if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumClmmPoolStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool_state: pool_state,
|
||||
}))
|
||||
@@ -218,10 +218,10 @@ pub fn tick_array_state_parser(
|
||||
{
|
||||
Some(Box::new(RaydiumClmmTickArrayStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
tick_array_state: tick_array_state,
|
||||
}))
|
||||
|
||||
@@ -10,6 +10,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||
/// 交易
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmSwapEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub amount_in: u64,
|
||||
pub minimum_amount_out: u64,
|
||||
@@ -35,6 +36,7 @@ impl_unified_event!(RaydiumCpmmSwapEvent,);
|
||||
/// 存款
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmDepositEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub lp_token_amount: u64,
|
||||
pub maximum_token0_amount: u64,
|
||||
@@ -59,6 +61,7 @@ impl_unified_event!(RaydiumCpmmDepositEvent,);
|
||||
/// 初始化
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmInitializeEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub init_amount0: u64,
|
||||
pub init_amount1: u64,
|
||||
@@ -90,6 +93,7 @@ impl_unified_event!(RaydiumCpmmInitializeEvent,);
|
||||
/// 提款
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmWithdrawEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub lp_token_amount: u64,
|
||||
pub minimum_token0_amount: u64,
|
||||
@@ -115,11 +119,12 @@ impl_unified_event!(RaydiumCpmmWithdrawEvent,);
|
||||
/// 池配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmAmmConfigAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub amm_config: AmmConfig,
|
||||
}
|
||||
@@ -128,11 +133,12 @@ impl_unified_event!(RaydiumCpmmAmmConfigAccountEvent,);
|
||||
/// 池状态
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmPoolStateAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub pool_state: PoolState,
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ pub fn amm_config_parser(
|
||||
if let Some(amm_config) = amm_config_decode(&account.data[8..AMM_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumCpmmAmmConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
amm_config: amm_config,
|
||||
}))
|
||||
@@ -104,10 +104,10 @@ pub fn pool_state_parser(
|
||||
if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumCpmmPoolStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool_state: pool_state,
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user