Skip to content

feat: add batch account subscriptions with chunking#1060

Open
thlorenz wants to merge 4 commits intomasterfrom
thlorenz/grpc-improvs-01
Open

feat: add batch account subscriptions with chunking#1060
thlorenz wants to merge 4 commits intomasterfrom
thlorenz/grpc-improvs-01

Conversation

@thlorenz
Copy link
Collaborator

@thlorenz thlorenz commented Mar 17, 2026

Summary

Add batch subscription support to the laser actor to improve efficiency when resubscribing to
multiple accounts. Implements automatic chunking of large subscription batches to prevent
oversized streams and introduces a new AccountSubscribeMultiple message type.

Details

Batch Subscription Support

Added a new AccountSubscribeMultiple message type that allows subscribing to multiple pubkeys
in a single operation. The laser actor now filters out already-subscribed keys before
forwarding to the stream manager, preventing redundant subscriptions.

The client's resubscribe_all_accounts method now uses this batch API instead of iterating
through individual subscriptions, reducing overhead when reestablishing connections after
disconnects.

Large Batch Chunking

The stream manager now automatically chunks subscription batches that exceed
max_subs_in_old_optimized into smaller chunks. Each chunk goes through the normal subscribe →
promote → optimize cycle independently. This prevents any single stream from holding more
accounts than it should while maintaining the integrity of the subscription optimization
process.

Includes comprehensive tests validating:

  • Batches at the optimization limit don't get unnecessarily chunked
  • Large batches are properly split and all accounts are subscribed
  • Optimization is correctly triggered when chunk promotions exceed thresholds

Summary by CodeRabbit

  • New Features

    • Added multi-account subscriptions: subscribe to many accounts in a single operation.
  • Improvements

    • Large requests are automatically chunked and processed in batches for scalable, reliable subscribing.
    • Resubscription flow now uses batched operations for better performance.
    • Graceful handling/reporting when batch subscriptions are not supported over websocket paths.
  • Tests

    • Added tests covering large-batch chunking, promotions, and optimization triggers.

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

Manual Deploy Available

You can trigger a manual deploy of this PR branch to testnet:

Deploy to Testnet 🚀

Alternative: Comment /deploy on this PR to trigger deployment directly.

⚠️ Note: Manual deploy requires authorization. Only authorized users can trigger deployments.

Comment updated automatically when the PR is synchronized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0d627f65-3685-4498-b722-c4707ddf2599

📥 Commits

Reviewing files that changed from the base of the PR and between 4b91549 and 6427fe4.

📒 Files selected for processing (3)
  • magicblock-chainlink/src/remote_account_provider/chain_laser_actor/actor.rs
  • magicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs
  • magicblock-chainlink/src/remote_account_provider/chain_laser_client.rs

📝 Walkthrough

Walkthrough

Adds multi-pubkey subscription support across the remote account provider: introduces AccountSubscribeMultiple messages, a new add_subs handler in the chain laser actor, and client-side subscribe_multiple. StreamManager gains chunked batch processing via account_subscribe_batch to handle large batches, with promotion and optimization logic per chunk. Chain pubsub (websocket) actor now rejects AccountSubscribeMultiple with a new UnsupportedActorMessage error variant. Tests for large-batch behaviors were added.

Suggested reviewers

  • GabrielePicco
  • bmuddha
  • lucacillario
✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch thlorenz/grpc-improvs-01
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Rust Clippy can be used to improve the quality of Rust code reviews.

Clippy is the official Rust linter. It provides lints to catch common mistakes and improve your Rust code.

To configure Clippy, add a clippy.toml file to your project root.

See Clippy Documentation for more details.

@thlorenz thlorenz requested a review from GabrielePicco March 17, 2026 05:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@magicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs`:
- Around line 210-226: The chunking logic only considers new_pks.len() and
ignores existing current_new_subs, so a partial current_new_subs can still cause
a CurrentNew request to exceed max_subs_in_old_optimized; change the batching in
stream_manager.rs (the account_subscribe_batch call path in the chunking around
account_subscribe_batch) to compute the first chunk size as remaining_capacity =
self.config.max_subs_in_old_optimized.saturating_sub(current_new_subs.len()) and
send that first partial chunk (if >0), then send subsequent chunks sized at
max_subs_in_old_optimized; apply the same fix in the other affected block (the
later loop referenced lines ~232-313), and add a regression test that seeds
current_new_subs with some entries (e.g., 5) then attempts to subscribe a larger
batch (e.g., 80) and asserts that no single CurrentNew request exceeds
max_subs_in_old_optimized.

In `@magicblock-chainlink/src/remote_account_provider/chain_laser_client.rs`:
- Around line 96-112: The batched subscription path in subscribe_multiple
(triggered by resub_multiple) forwards pubkeys unchanged, so special-case
clock::ID is lost and creates a real clock account subscription; update
subscribe_multiple (and the resub_multiple call sites that route to it) to map
any clock::ID entries to the SLOT_SUBSCRIPTION_DUMMY sentinel before sending
ChainPubsubActorMessage::AccountSubscribeMultiple, preserving the original
subscribe() behavior that replaces clock::ID with SLOT_SUBSCRIPTION_DUMMY;
ensure the mapping is applied to the HashSet<Pubkey> passed into
subscribe_multiple and any other code paths that build the
AccountSubscribeMultiple message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d3fcab63-8168-4d9b-9401-f5fa3518d103

📥 Commits

Reviewing files that changed from the base of the PR and between adb60d5 and 4b91549.

📒 Files selected for processing (6)
  • magicblock-chainlink/src/remote_account_provider/chain_laser_actor/actor.rs
  • magicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs
  • magicblock-chainlink/src/remote_account_provider/chain_laser_client.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs
  • magicblock-chainlink/src/remote_account_provider/errors.rs
  • magicblock-chainlink/src/remote_account_provider/pubsub_common.rs

@thlorenz thlorenz marked this pull request as ready for review March 17, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant