mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-15 18:08:05 +00:00
refactor: modernize dependency stack and minimize footprint
- Migrate to native 'std::sync' primitives (LazyLock, OnceLock, RwLock). - Replace 'parking_lot' with std library synchronization types. - Switch from 'chrono' to 'std::time::SystemTime' for lightweight timestamps. - Bump core dependencies: tokio (1.50.0) and rustls (0.23.37). - Decouple 'solana-program' by utilizing 'solana-sdk' re-exports. - Prune redundant crates: lazy_static, once_cell, chrono, maplit, and parking_lot. - Remove unused dev-dependencies (criterion) and example-only utils (env_logger). - Improve compile times and reduce supply chain attack surface.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::fmt::Debug;
|
||||
use std::time::Instant;
|
||||
use std::time::{Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
/// 高性能时钟管理器,减少系统调用开销并最小化延迟
|
||||
#[derive(Debug)]
|
||||
@@ -25,12 +25,12 @@ impl HighPerformanceClock {
|
||||
// 通过多次采样来减少初始化误差
|
||||
let mut best_offset = i64::MAX;
|
||||
let mut best_instant = Instant::now();
|
||||
let mut best_timestamp = chrono::Utc::now().timestamp_micros();
|
||||
let mut best_timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_micros() as i64;
|
||||
|
||||
// 进行3次采样,选择延迟最小的
|
||||
for _ in 0..3 {
|
||||
let instant_before = Instant::now();
|
||||
let timestamp = chrono::Utc::now().timestamp_micros();
|
||||
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_micros() as i64;
|
||||
let instant_after = Instant::now();
|
||||
|
||||
let sample_latency = instant_after.duration_since(instant_before).as_nanos() as i64;
|
||||
@@ -69,7 +69,7 @@ impl HighPerformanceClock {
|
||||
/// 重新校准时钟,减少累积漂移
|
||||
fn recalibrate(&mut self) {
|
||||
let current_monotonic = Instant::now();
|
||||
let current_utc = chrono::Utc::now().timestamp_micros();
|
||||
let current_utc = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_micros() as i64;
|
||||
|
||||
// 计算预期的UTC时间戳(基于单调时钟)
|
||||
let expected_utc = self.base_timestamp_us
|
||||
@@ -113,8 +113,8 @@ impl Default for HighPerformanceClock {
|
||||
}
|
||||
|
||||
/// 全局高性能时钟实例
|
||||
static HIGH_PERF_CLOCK: once_cell::sync::OnceCell<HighPerformanceClock> =
|
||||
once_cell::sync::OnceCell::new();
|
||||
static HIGH_PERF_CLOCK: std::sync::OnceLock<HighPerformanceClock> =
|
||||
std::sync::OnceLock::new();
|
||||
|
||||
/// 获取全局高性能时钟实例(最简单的实现)
|
||||
#[inline(always)]
|
||||
|
||||
@@ -36,9 +36,8 @@ impl EventMetadataPool {
|
||||
}
|
||||
|
||||
// Global object pool instances
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref EVENT_METADATA_POOL: EventMetadataPool = EventMetadataPool::new();
|
||||
}
|
||||
pub static EVENT_METADATA_POOL: std::sync::LazyLock<EventMetadataPool> =
|
||||
std::sync::LazyLock::new(EventMetadataPool::new);
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize,
|
||||
@@ -356,14 +355,13 @@ impl EventMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref SOL_MINT: Pubkey = Pubkey::from_str("So11111111111111111111111111111111111111111").unwrap();
|
||||
static ref SYSTEM_PROGRAMS: [Pubkey; 3] = [
|
||||
Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(),
|
||||
Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(),
|
||||
Pubkey::from_str("11111111111111111111111111111111").unwrap(),
|
||||
];
|
||||
}
|
||||
static SOL_MINT: std::sync::LazyLock<Pubkey> =
|
||||
std::sync::LazyLock::new(|| Pubkey::from_str("So11111111111111111111111111111111111111111").unwrap());
|
||||
static SYSTEM_PROGRAMS: std::sync::LazyLock<[Pubkey; 3]> = std::sync::LazyLock::new(|| [
|
||||
Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(),
|
||||
Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(),
|
||||
Pubkey::from_str("11111111111111111111111111111111").unwrap(),
|
||||
]);
|
||||
|
||||
/// Parse token transfer data from next instructions
|
||||
pub fn parse_swap_data_from_next_instructions(
|
||||
|
||||
Reference in New Issue
Block a user