diff --git a/.gitignore b/.gitignore index d01bd1a..c77fa9e 100755 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,6 @@ Cargo.lock # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ + +.cargo/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 4030670..31f86e8 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "solana-streamer-sdk" -version = "0.1.9" +version = "0.1.10" edition = "2021" authors = ["William ", "sgxiang ", "wei <1415121722@qq.com>"] repository = "https://github.com/0xfnzero/solana-streamer" diff --git a/README.md b/README.md index 2d2cd03..5975762 100755 --- a/README.md +++ b/README.md @@ -41,14 +41,14 @@ Add the dependency to your `Cargo.toml`: ```toml # Add to your Cargo.toml -solana-streamer-sdk = { path = "./solana-streamer", version = "0.1.9" } +solana-streamer-sdk = { path = "./solana-streamer", version = "0.1.10" } ``` ### Use crates.io ```toml # Add to your Cargo.toml -solana-streamer-sdk = "0.1.9" +solana-streamer-sdk = "0.1.10" ``` ## Usage Examples diff --git a/README_CN.md b/README_CN.md index b67c11e..c801a87 100644 --- a/README_CN.md +++ b/README_CN.md @@ -41,14 +41,14 @@ git clone https://github.com/0xfnzero/solana-streamer ```toml # 添加到您的 Cargo.toml -solana-streamer-sdk = { path = "./solana-streamer", version = "0.1.9" } +solana-streamer-sdk = { path = "./solana-streamer", version = "0.1.10" } ``` ### 使用 crates.io ```toml # 添加到您的 Cargo.toml -solana-streamer-sdk = "0.1.9" +solana-streamer-sdk = "0.1.10" ``` ## 使用示例 diff --git a/src/streaming/event_parser/common/types.rs b/src/streaming/event_parser/common/types.rs index 68c8820..942b547 100755 --- a/src/streaming/event_parser/common/types.rs +++ b/src/streaming/event_parser/common/types.rs @@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use solana_sdk::pubkey::Pubkey; use solana_transaction_status::UiInstruction; -use std::sync::Arc; +use std::{hash::{DefaultHasher, Hash, Hasher}, sync::Arc}; use tokio::sync::Mutex; // Object pool size configuration @@ -320,7 +320,11 @@ impl EventMetadata { } pub fn set_id(&mut self, id: String) { - self.id = id; + let _id = format!("{}-{}-{}", self.signature, self.event_type.to_string(), id); + let mut hasher = DefaultHasher::new(); + _id.hash(&mut hasher); + let hash_value = hasher.finish(); + self.id = format!("{:x}", hash_value); } pub fn set_transfer_datas(&mut self, transfer_datas: Vec) { diff --git a/src/streaming/event_parser/core/traits.rs b/src/streaming/event_parser/core/traits.rs index fae2f00..926940e 100755 --- a/src/streaming/event_parser/core/traits.rs +++ b/src/streaming/event_parser/core/traits.rs @@ -271,13 +271,15 @@ pub trait EventParser: Send + Sync { program_received_time_ms: i64, bot_wallet: Option, ) -> Result>> { - // 生成缓存键 - let cache_key = format!("{}_{}_{}", signature, slot.unwrap_or(0), program_received_time_ms); + + // TODO: bug - 待优化 + // // 生成缓存键 + // let cache_key = format!("{}_{}_{}", signature, slot.unwrap_or(0), program_received_time_ms); - // 尝试从缓存获取 - if let Some(cached_events) = PARSE_CACHE.get(&cache_key).await { - return Ok(cached_events); - } + // // 尝试从缓存获取 + // if let Some(cached_events) = PARSE_CACHE.get(&cache_key).await { + // return Ok(cached_events); + // } let transaction = tx.transaction; // 检查交易元数据 @@ -443,7 +445,7 @@ pub trait EventParser: Send + Sync { let result = self.process_events(instruction_events, bot_wallet); // 缓存结果 - PARSE_CACHE.set(cache_key, result.clone()).await; + // PARSE_CACHE.set(cache_key, result.clone()).await; Ok(result) }