mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-15 01:48:05 +00:00
refactor(event_parser): optimize instruction parsing with better error handling
- Fix borrowing conflicts and boundary conditions - Improve accounts array expansion logic - Refactor inner instruction processing flow
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "solana-streamer-sdk"
|
||||
version = "0.4.11"
|
||||
version = "0.4.12"
|
||||
edition = "2021"
|
||||
authors = ["William <byteblock6@gmail.com>", "sgxiang <sgxiang@gmail.com>", "wei <1415121722@qq.com>"]
|
||||
repository = "https://github.com/0xfnzero/solana-streamer"
|
||||
|
||||
@@ -108,14 +108,14 @@ Add the dependency to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
# Add to your Cargo.toml
|
||||
solana-streamer-sdk = { path = "./solana-streamer", version = "0.4.11" }
|
||||
solana-streamer-sdk = { path = "./solana-streamer", version = "0.4.12" }
|
||||
```
|
||||
|
||||
### Use crates.io
|
||||
|
||||
```toml
|
||||
# Add to your Cargo.toml
|
||||
solana-streamer-sdk = "0.4.11"
|
||||
solana-streamer-sdk = "0.4.12"
|
||||
```
|
||||
|
||||
## ⚙️ Configuration System
|
||||
|
||||
+2
-2
@@ -107,14 +107,14 @@ git clone https://github.com/0xfnzero/solana-streamer
|
||||
|
||||
```toml
|
||||
# 添加到您的 Cargo.toml
|
||||
solana-streamer-sdk = { path = "./solana-streamer", version = "0.4.11" }
|
||||
solana-streamer-sdk = { path = "./solana-streamer", version = "0.4.12" }
|
||||
```
|
||||
|
||||
### 使用 crates.io
|
||||
|
||||
```toml
|
||||
# 添加到您的 Cargo.toml
|
||||
solana-streamer-sdk = "0.4.11"
|
||||
solana-streamer-sdk = "0.4.12"
|
||||
```
|
||||
|
||||
## ⚙️ 配置系统
|
||||
|
||||
@@ -213,17 +213,16 @@ impl EventParser {
|
||||
// 解析每个指令
|
||||
for (index, instruction) in compiled_instructions.iter().enumerate() {
|
||||
if let Some(program_id) = accounts.get(instruction.program_id_index as usize) {
|
||||
if self.should_handle(program_id) {
|
||||
let max_idx = instruction.accounts.iter().max().unwrap_or(&0);
|
||||
// 补齐accounts(使用Pubkey::default())
|
||||
if *max_idx as usize > accounts.len() {
|
||||
for _i in accounts.len()..*max_idx as usize {
|
||||
accounts.push(Pubkey::default());
|
||||
}
|
||||
}
|
||||
let inner_instructions = inner_instructions
|
||||
.iter()
|
||||
.find(|inner_instruction| inner_instruction.index == index as u32);
|
||||
let program_id = *program_id; // 克隆程序ID,避免借用冲突
|
||||
let inner_instructions = inner_instructions
|
||||
.iter()
|
||||
.find(|inner_instruction| inner_instruction.index == index as u32);
|
||||
let max_idx = instruction.accounts.iter().max().unwrap_or(&0);
|
||||
// 补齐accounts(使用Pubkey::default())
|
||||
if *max_idx as usize >= accounts.len() {
|
||||
accounts.resize(*max_idx as usize + 1, Pubkey::default());
|
||||
}
|
||||
if self.should_handle(&program_id) {
|
||||
self.parse_events_from_grpc_instruction(
|
||||
instruction,
|
||||
&accounts,
|
||||
@@ -238,35 +237,34 @@ impl EventParser {
|
||||
inner_instructions,
|
||||
Arc::clone(&callback),
|
||||
)?;
|
||||
|
||||
// Immediately process inner instructions for correct ordering
|
||||
if let Some(inner_instructions) = inner_instructions {
|
||||
for (inner_index, inner_instruction) in
|
||||
inner_instructions.instructions.iter().enumerate()
|
||||
{
|
||||
let inner_accounts = &inner_instruction.accounts;
|
||||
let data = &inner_instruction.data;
|
||||
let instruction =
|
||||
yellowstone_grpc_proto::prelude::CompiledInstruction {
|
||||
program_id_index: inner_instruction.program_id_index,
|
||||
accounts: inner_accounts.to_vec(),
|
||||
data: data.to_vec(),
|
||||
};
|
||||
self.parse_events_from_grpc_instruction(
|
||||
&instruction,
|
||||
&accounts,
|
||||
signature,
|
||||
slot.unwrap_or(0),
|
||||
block_time,
|
||||
recv_us,
|
||||
inner_instructions.index as i64,
|
||||
Some(inner_index as i64),
|
||||
bot_wallet,
|
||||
transaction_index,
|
||||
Some(&inner_instructions),
|
||||
Arc::clone(&callback),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
// Immediately process inner instructions for correct ordering
|
||||
if let Some(inner_instructions) = inner_instructions {
|
||||
for (inner_index, inner_instruction) in
|
||||
inner_instructions.instructions.iter().enumerate()
|
||||
{
|
||||
let inner_accounts = &inner_instruction.accounts;
|
||||
let data = &inner_instruction.data;
|
||||
let instruction =
|
||||
yellowstone_grpc_proto::prelude::CompiledInstruction {
|
||||
program_id_index: inner_instruction.program_id_index,
|
||||
accounts: inner_accounts.to_vec(),
|
||||
data: data.to_vec(),
|
||||
};
|
||||
self.parse_events_from_grpc_instruction(
|
||||
&instruction,
|
||||
&accounts,
|
||||
signature,
|
||||
slot.unwrap_or(0),
|
||||
block_time,
|
||||
recv_us,
|
||||
inner_instructions.index as i64,
|
||||
Some(inner_index as i64),
|
||||
bot_wallet,
|
||||
transaction_index,
|
||||
Some(&inner_instructions),
|
||||
Arc::clone(&callback),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,17 +297,16 @@ impl EventParser {
|
||||
// 解析每个指令
|
||||
for (index, instruction) in compiled_instructions.iter().enumerate() {
|
||||
if let Some(program_id) = accounts.get(instruction.program_id_index as usize) {
|
||||
if self.should_handle(program_id) {
|
||||
let program_id = *program_id; // 克隆程序ID,避免借用冲突
|
||||
let inner_instructions = inner_instructions
|
||||
.iter()
|
||||
.find(|inner_instruction| inner_instruction.index == index as u8);
|
||||
if self.should_handle(&program_id) {
|
||||
let max_idx = instruction.accounts.iter().max().unwrap_or(&0);
|
||||
// 补齐accounts(使用Pubkey::default())
|
||||
if *max_idx as usize > accounts.len() {
|
||||
for _i in accounts.len()..*max_idx as usize {
|
||||
accounts.push(Pubkey::default());
|
||||
}
|
||||
if *max_idx as usize >= accounts.len() {
|
||||
accounts.resize(*max_idx as usize + 1, Pubkey::default());
|
||||
}
|
||||
let inner_instructions = inner_instructions
|
||||
.iter()
|
||||
.find(|inner_instruction| inner_instruction.index == index as u8);
|
||||
self.parse_events_from_instruction(
|
||||
instruction,
|
||||
&accounts,
|
||||
@@ -324,27 +321,26 @@ impl EventParser {
|
||||
inner_instructions,
|
||||
Arc::clone(&callback),
|
||||
)?;
|
||||
|
||||
// Immediately process inner instructions for correct ordering
|
||||
if let Some(inner_instructions) = inner_instructions {
|
||||
for (inner_index, inner_instruction) in
|
||||
inner_instructions.instructions.iter().enumerate()
|
||||
{
|
||||
self.parse_events_from_instruction(
|
||||
&inner_instruction.instruction,
|
||||
&accounts,
|
||||
signature,
|
||||
slot.unwrap_or(0),
|
||||
block_time,
|
||||
recv_us,
|
||||
index as i64,
|
||||
Some(inner_index as i64),
|
||||
bot_wallet,
|
||||
transaction_index,
|
||||
Some(&inner_instructions),
|
||||
Arc::clone(&callback),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
// Immediately process inner instructions for correct ordering
|
||||
if let Some(inner_instructions) = inner_instructions {
|
||||
for (inner_index, inner_instruction) in
|
||||
inner_instructions.instructions.iter().enumerate()
|
||||
{
|
||||
self.parse_events_from_instruction(
|
||||
&inner_instruction.instruction,
|
||||
&accounts,
|
||||
signature,
|
||||
slot.unwrap_or(0),
|
||||
block_time,
|
||||
recv_us,
|
||||
index as i64,
|
||||
Some(inner_index as i64),
|
||||
bot_wallet,
|
||||
transaction_index,
|
||||
Some(&inner_instructions),
|
||||
Arc::clone(&callback),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user