feat: add batch account subscriptions with chunking#1060
feat: add batch account subscriptions with chunking#1060
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019cfa24-700f-7098-9e8a-36d52400c89a Co-authored-by: Amp <amp@ampcode.com>
Manual Deploy AvailableYou can trigger a manual deploy of this PR branch to testnet: Alternative: Comment
Comment updated automatically when the PR is synchronized. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds multi-pubkey subscription support across the remote account provider: introduces Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment 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 See Clippy Documentation for more details. |
There was a problem hiding this comment.
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
📒 Files selected for processing (6)
magicblock-chainlink/src/remote_account_provider/chain_laser_actor/actor.rsmagicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rsmagicblock-chainlink/src/remote_account_provider/chain_laser_client.rsmagicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rsmagicblock-chainlink/src/remote_account_provider/errors.rsmagicblock-chainlink/src/remote_account_provider/pubsub_common.rs
magicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs
Show resolved
Hide resolved
Amp-Thread-ID: https://ampcode.com/threads/T-019cfa6d-750e-766a-acf2-e75a3fb8bdef Co-authored-by: Amp <amp@ampcode.com>
…iption Amp-Thread-ID: https://ampcode.com/threads/T-019cfa71-a15d-742e-8e25-145d6e247250 Co-authored-by: Amp <amp@ampcode.com>
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
AccountSubscribeMultiplemessage type.Details
Batch Subscription Support
Added a new
AccountSubscribeMultiplemessage type that allows subscribing to multiple pubkeysin 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_accountsmethod now uses this batch API instead of iteratingthrough 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_optimizedinto 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:
Summary by CodeRabbit
New Features
Improvements
Tests