Skip to content

Commit 7e04786

Browse files
authored
Merge pull request #63 from helius-labs/filter-check-bug
Fix filters overhead bug
2 parents 113413c + 3a1806f commit 7e04786

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

javascript/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "laserstream-napi"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
edition = "2021"
55

66
[lib]

javascript/napi-src/stream.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const FORK_DEPTH_SAFETY_MARGIN: u64 = 31; // Max fork depth for processed commit
2222

2323
// SDK metadata constants
2424
const SDK_NAME: &str = "laserstream-javascript";
25-
const SDK_VERSION: &str = "0.2.3";
25+
const SDK_VERSION: &str = "0.2.4";
2626

2727
/// Custom interceptor that adds SDK metadata headers to all gRPC requests
2828
#[derive(Clone)]
@@ -383,34 +383,59 @@ impl StreamInner {
383383
if let Some(geyser::subscribe_update::UpdateOneof::Pong(_pong)) = &message.update_oneof {
384384
continue;
385385
}
386-
386+
387387
// Track slot updates for reconnection (only decode when necessary)
388388
if let Some(geyser::subscribe_update::UpdateOneof::Slot(slot)) = &message.update_oneof {
389389
tracked_slot.store(slot.slot, Ordering::SeqCst);
390-
390+
391391
// Check if this slot update is EXCLUSIVELY from our internal subscription
392392
// Only skip if the message contains ONLY the internal filter ID (not mixed with user subscriptions)
393393
if message.filters.len() == 1 && message.filters.contains(&internal_slot_sub_id) {
394394
continue; // Skip forwarding this message
395395
}
396+
397+
// If we reach here, user ALSO has a slot subscription
398+
// Remove internal filter ID so it doesn't leak to user
399+
// OPTIMIZATION: Only clean filters for slot messages (not all messages)
400+
let mut clean_message = message;
401+
if let Some(pos) = clean_message.filters.iter().position(|id| id == &internal_slot_sub_id) {
402+
clean_message.filters.swap_remove(pos);
403+
}
404+
405+
// Serialize the protobuf message to bytes
406+
let mut buf = Vec::new();
407+
if let Err(_e) = clean_message.encode(&mut buf) {
408+
// Failed to encode protobuf message, skip this message
409+
continue;
410+
}
411+
412+
let bytes_wrapper = crate::SubscribeUpdateBytes(buf);
413+
414+
// mark that at least one message was forwarded in this session
415+
progress_flag.store(true, Ordering::SeqCst);
416+
417+
// Use Blocking mode to prevent message drops and handle errors
418+
let status = ts_callback.call(Ok(bytes_wrapper), ThreadsafeFunctionCallMode::Blocking);
419+
if status != napi::Status::Ok {
420+
// Failed to deliver bytes to JavaScript, continue processing
421+
// Continue processing other messages instead of breaking the stream
422+
}
423+
continue; // Skip to next message
396424
}
397-
398-
// Clean up internal filter ID from ALL message types
399-
let mut clean_message = message;
400-
clean_message.filters.retain(|filter_id| filter_id != &internal_slot_sub_id);
401-
402-
// Serialize the protobuf message to bytes
425+
426+
// For all non-slot messages, forward as-is (no filter cleanup needed)
427+
// Internal slot ID will never appear in account/transaction/block messages
403428
let mut buf = Vec::new();
404-
if let Err(_e) = clean_message.encode(&mut buf) {
429+
if let Err(_e) = message.encode(&mut buf) {
405430
// Failed to encode protobuf message, skip this message
406431
continue;
407432
}
408-
433+
409434
let bytes_wrapper = crate::SubscribeUpdateBytes(buf);
410-
435+
411436
// mark that at least one message was forwarded in this session
412437
progress_flag.store(true, Ordering::SeqCst);
413-
438+
414439
// Use Blocking mode to prevent message drops and handle errors
415440
let status = ts_callback.call(Ok(bytes_wrapper), ThreadsafeFunctionCallMode::Blocking);
416441
if status != napi::Status::Ok {

javascript/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helius-laserstream",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "High-performance Laserstream gRPC client with automatic reconnection",
55
"main": "client.js",
66
"types": "client.d.ts",
@@ -83,12 +83,12 @@
8383
}
8484
},
8585
"optionalDependencies": {
86-
"helius-laserstream-darwin-arm64": "0.2.3",
87-
"helius-laserstream-darwin-x64": "0.2.3",
88-
"helius-laserstream-linux-arm64-gnu": "0.2.3",
89-
"helius-laserstream-linux-arm64-musl": "0.2.3",
90-
"helius-laserstream-linux-x64-gnu": "0.2.3",
91-
"helius-laserstream-linux-x64-musl": "0.2.3"
86+
"helius-laserstream-darwin-arm64": "0.2.4",
87+
"helius-laserstream-darwin-x64": "0.2.4",
88+
"helius-laserstream-linux-arm64-gnu": "0.2.4",
89+
"helius-laserstream-linux-arm64-musl": "0.2.4",
90+
"helius-laserstream-linux-x64-gnu": "0.2.4",
91+
"helius-laserstream-linux-x64-musl": "0.2.4"
9292
},
9393
"dependencies": {
9494
"@types/protobufjs": "^6.0.0",

0 commit comments

Comments
 (0)