Skip to content

Conversation

@GabrielePicco
Copy link
Collaborator

@GabrielePicco GabrielePicco commented Jan 5, 2026

Summary

Compatibility

  • No breaking changes
  • Config change (describe):
  • Migration needed (describe):

Testing

  • tests (or explain)

Checklist

Summary by CodeRabbit

  • Refactor

    • Improved concurrency and request deduplication for remote account fetching, processing subscription updates concurrently to reduce contention and boost throughput.
    • Reworked classification flow to better partition missing accounts and streamline per-account handling.
  • Bug Fixes

    • Reduced noisy subscription/ATA error logging to warnings to improve runtime resilience.
  • Chores

    • Updated workspace dependencies and switched internal locking primitives for caches and mocks.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

📝 Walkthrough

Walkthrough

This PR adds workspace dependencies parking_lot and scc. FetchCloner's pending requests change from Arc<Mutex<HashMap<...>>> to Arc<HashMap<...>> (using scc hash map) and per-subscription updates are processed concurrently via spawned tokio tasks. The classification pipeline is refactored into helper functions (classify_single_account, classify_program) and introduces a new PartitionedNotFound type. Internal uses of std::sync::Mutex in the mock chain pubsub client and LRU cache are replaced with parking_lot::Mutex. ATA subscription failures are downgraded to warnings.

Assessment against linked issues

Objective (grouped with issue refs) Addressed Explanation
Concurrency / lock-free containers / allow concurrent account resolutions (3,8)
Use self: Arc<Self> in fetch cloner method signatures (1) No explicit change to method signatures to self: Arc<Self> is shown; code uses cloning of Arc<Self> for spawned tasks but signature changes are not evident.
Prefer simple containers / use Vec / iterator improvements (2,10) Fold replaced with explicit Vec accumulation and helpers, but broader iterator/collector optimizations are not clearly applied across the codebase.
Break up large functions / refactor readability / split methods (4,6,7,12)
Remove unnecessary logs / change ensure* return types / use AccountsDb::reader (5,9,11) Only ATA subscription logs were downgraded; ensure* return types and AccountsDb::reader usage were not modified and broader log removals are not present.

Out-of-scope changes

Code Change (file_path) Explanation
Added workspace dependency parking_lot = { workspace = true } (magicblock-chainlink/Cargo.toml) Introducing parking_lot as a workspace dependency is not requested by the linked objectives; objective #8 targets lock-free/async containers (e.g., scc), not adding a different synchronous mutex crate.
Replaced std::sync::Mutex with parking_lot::Mutex in mock chain pubsub client (magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs) and LRU cache (magicblock-chainlink/src/remote_account_provider/lru_cache.rs) Objective #8 calls for replacing sync locks with lock-free/async concurrent containers; swapping one synchronous mutex implementation for another does not fulfill that objective and is therefore outside the stated scope.

Suggested reviewers

  • thlorenz
  • bmuddha
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/refactor-cloning-pipeline-v2

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 381c479 and ab1ce91.

📒 Files selected for processing (1)
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
🧰 Additional context used
📓 Path-based instructions (1)
{magicblock-*,programs,storage-proto}/**

⚙️ CodeRabbit configuration file

{magicblock-*,programs,storage-proto}/**: Treat any usage of .unwrap() or .expect() in production Rust code as a MAJOR issue.
These should not be categorized as trivial or nit-level concerns.
Request proper error handling or explicit justification with invariants.

Files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
🧠 Learnings (6)
📚 Learning: 2025-12-17T12:46:36.207Z
Learnt from: GabrielePicco
Repo: magicblock-labs/magicblock-validator PR: 738
File: magicblock-chainlink/src/chainlink/fetch_cloner.rs:1109-1196
Timestamp: 2025-12-17T12:46:36.207Z
Learning: In magicblock-chainlink/src/chainlink/fetch_cloner.rs, eATA account subscriptions are intentionally NOT cancelled even when the eATA doesn't exist or delegation conversion fails. The subscriptions are kept active to watch for future creation or delegation of eATA accounts (per maintainer GabrielePicco).

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
📚 Learning: 2025-12-01T16:02:05.367Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 703
File: magicblock-chainlink/src/submux/mod.rs:652-654
Timestamp: 2025-12-01T16:02:05.367Z
Learning: In magicblock-chainlink/src/submux/mod.rs, the subscribe_program method intentionally adds program_id to program_subs before attempting the subscription. This ensures that even if the initial subscription fails or only partially succeeds across clients, the reconnection logic will retry the subscription. This is a deliberate design pattern for resilience in the multi-client architecture and should not be "fixed" to remove entries on failure.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
📚 Learning: 2025-11-19T09:34:37.917Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: test-integration/test-chainlink/tests/ix_remote_account_provider.rs:62-63
Timestamp: 2025-11-19T09:34:37.917Z
Learning: In test-integration/test-chainlink/tests/ix_remote_account_provider.rs and similar test files, the `_fwd_rx` receiver returned by `init_remote_account_provider()` is intentionally kept alive (but unused) to prevent "receiver dropped" errors on the sender side. The pattern `let (remote_account_provider, _fwd_rx) = init_remote_account_provider().await;` should NOT be changed to `let (remote_account_provider, _) = ...` because dropping the receiver would cause send() operations to fail.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
🧬 Code graph analysis (1)
magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs (1)
magicblock-core/src/token_programs.rs (1)
  • try_derive_eata_address_and_bump (81-89)
🔇 Additional comments (1)
magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs (1)

47-55: LGTM! Appropriate downgrade of subscription failure severity.

The change from error-level to warn-level logging for both ATA and eATA subscription failures is correct. These failures are transient and don't break functionality—the subscriptions are kept active to watch for future account creation or delegation events. This reduces log noise while maintaining observability.

The consistent handling of both ATA and eATA subscription failures at the warn level addresses the observability concern from the previous review. Based on learnings, keeping subscriptions active despite initial failures is an intentional design pattern in this codebase.


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.

Copy link
Collaborator Author

GabrielePicco commented Jan 5, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@GabrielePicco GabrielePicco mentioned this pull request Jan 5, 2026
6 tasks
@GabrielePicco GabrielePicco marked this pull request as ready for review January 5, 2026 19:48
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: 1

Fix all issues with AI Agents 🤖
In @magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs:
- Around line 180-199: The current partition_not_found function uses
mark_empty_if_not_found: Option<&[Pubkey]> and repeatedly calls
mark_empty.contains(p) inside partition, which is O(n) per check; to make
lookups O(1) when the list may grow, convert the incoming slice into a HashSet
before partitioning (e.g., when mark_empty_if_not_found is Some, build a HashSet
from mark_empty and use that set in the partition predicate) so the contains
call inside partition becomes constant-time; update references to mark_empty in
partition_not_found accordingly.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30e4244 and de09c36.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • test-integration/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • magicblock-chainlink/Cargo.toml
  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
🧰 Additional context used
📓 Path-based instructions (1)
{magicblock-*,programs,storage-proto}/**

⚙️ CodeRabbit configuration file

{magicblock-*,programs,storage-proto}/**: Treat any usage of .unwrap() or .expect() in production Rust code as a MAJOR issue.
These should not be categorized as trivial or nit-level concerns.
Request proper error handling or explicit justification with invariants.

Files:

  • magicblock-chainlink/Cargo.toml
  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
🧠 Learnings (14)
📓 Common learnings
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 703
File: magicblock-chainlink/src/submux/mod.rs:652-654
Timestamp: 2025-12-01T16:02:05.367Z
Learning: In magicblock-chainlink/src/submux/mod.rs, the subscribe_program method intentionally adds program_id to program_subs before attempting the subscription. This ensures that even if the initial subscription fails or only partially succeeds across clients, the reconnection logic will retry the subscription. This is a deliberate design pattern for resilience in the multi-client architecture and should not be "fixed" to remove entries on failure.
📚 Learning: 2025-11-24T14:21:00.996Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: Cargo.toml:58-58
Timestamp: 2025-11-24T14:21:00.996Z
Learning: In the magicblock-validator codebase, magicblock-api/Cargo.toml intentionally uses borsh = "1.5.3" (instead of the workspace version 0.10.4) because it needs to deserialize types from the magic-domain-program external dependency, which requires borsh 1.5.x compatibility. This is an intentional exception for interoperability with the magic domain program.

Applied to files:

  • magicblock-chainlink/Cargo.toml
📚 Learning: 2025-12-17T12:46:36.207Z
Learnt from: GabrielePicco
Repo: magicblock-labs/magicblock-validator PR: 738
File: magicblock-chainlink/src/chainlink/fetch_cloner.rs:1109-1196
Timestamp: 2025-12-17T12:46:36.207Z
Learning: In magicblock-chainlink/src/chainlink/fetch_cloner.rs, eATA account subscriptions are intentionally NOT cancelled even when the eATA doesn't exist or delegation conversion fails. The subscriptions are kept active to watch for future creation or delegation of eATA accounts (per maintainer GabrielePicco).

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
📚 Learning: 2025-12-01T16:02:05.367Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 703
File: magicblock-chainlink/src/submux/mod.rs:652-654
Timestamp: 2025-12-01T16:02:05.367Z
Learning: In magicblock-chainlink/src/submux/mod.rs, the subscribe_program method intentionally adds program_id to program_subs before attempting the subscription. This ensures that even if the initial subscription fails or only partially succeeds across clients, the reconnection logic will retry the subscription. This is a deliberate design pattern for resilience in the multi-client architecture and should not be "fixed" to remove entries on failure.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
📚 Learning: 2025-11-19T09:34:37.917Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: test-integration/test-chainlink/tests/ix_remote_account_provider.rs:62-63
Timestamp: 2025-11-19T09:34:37.917Z
Learning: In test-integration/test-chainlink/tests/ix_remote_account_provider.rs and similar test files, the `_fwd_rx` receiver returned by `init_remote_account_provider()` is intentionally kept alive (but unused) to prevent "receiver dropped" errors on the sender side. The pattern `let (remote_account_provider, _fwd_rx) = init_remote_account_provider().await;` should NOT be changed to `let (remote_account_provider, _) = ...` because dropping the receiver would cause send() operations to fail.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
📚 Learning: 2025-11-07T13:20:13.793Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/coordinator.rs:227-238
Timestamp: 2025-11-07T13:20:13.793Z
Learning: In magicblock-processor's ExecutionCoordinator (scheduler/coordinator.rs), the `account_contention` HashMap intentionally does not call `shrink_to_fit()`. Maintaining slack capacity is beneficial for performance by avoiding frequent reallocations during high transaction throughput. As long as empty entries are removed from the map (which `clear_account_contention` does), the capacity overhead is acceptable.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
📚 Learning: 2025-12-03T09:33:48.707Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-committor-service/tests/test_ix_commit_local.rs:867-881
Timestamp: 2025-12-03T09:33:48.707Z
Learning: Repo: magicblock-labs/magicblock-validator PR: 639
Context: test-integration/test-committor-service/tests/test_ix_commit_local.rs (ix_commit_local)
Learning: The PhotonIndexer used for compressed account fetches (get_compressed_account) has built‑in retry logic (defaults to ~10 attempts), so tests should not add separate retry loops around compressed fetches unless there’s a specific need.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-11-07T13:09:52.253Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: test-kit/src/lib.rs:275-0
Timestamp: 2025-11-07T13:09:52.253Z
Learning: In test-kit, the transaction scheduler in ExecutionTestEnv is not expected to shut down during tests. Therefore, using `.unwrap()` in test helper methods like `schedule_transaction` is acceptable and will not cause issues in the test environment.

Applied to files:

  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-10-14T09:56:14.047Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 564
File: test-integration/programs/flexi-counter/src/processor/call_handler.rs:122-125
Timestamp: 2025-10-14T09:56:14.047Z
Learning: The file test-integration/programs/flexi-counter/src/processor/call_handler.rs contains a test smart contract used for integration testing, not production code.

Applied to files:

  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-11-18T08:47:39.702Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/tests/04_redeleg_other_separate_slots.rs:158-165
Timestamp: 2025-11-18T08:47:39.702Z
Learning: In magicblock-chainlink tests involving compressed accounts, `set_remote_slot()` sets the slot of the `AccountSharedData`, while `compressed_account_shared_with_owner_and_slot()` sets the slot of the delegation record. These are two different fields and both calls are necessary.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
📚 Learning: 2025-11-13T09:38:43.804Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/locks.rs:64-102
Timestamp: 2025-11-13T09:38:43.804Z
Learning: In magicblock-processor's TransactionScheduler (scheduler/mod.rs line 59), the executor count is clamped to MAX_SVM_EXECUTORS (63) at initialization time, and executor IDs are assigned sequentially from 0 to count-1. This architectural guarantee ensures that executor IDs used in the bitmask-based AccountLock (scheduler/locks.rs) will always be within valid bounds for bit shifting operations, making runtime bounds checks unnecessary.

Applied to files:

  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
🧬 Code graph analysis (2)
magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs (1)
magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs (5)
  • not_found (639-642)
  • owned_by_deleg (647-650)
  • programs (112-112)
  • programs (651-654)
  • atas (655-658)
magicblock-chainlink/src/remote_account_provider/lru_cache.rs (2)
magicblock-metrics/src/metrics/mod.rs (1)
  • inc_evicted_accounts_count (599-601)
magicblock-chainlink/src/submux/subscribed_accounts_tracker.rs (2)
  • subscribed_accounts (18-18)
  • subscribed_accounts (50-52)
🔇 Additional comments (23)
magicblock-chainlink/src/remote_account_provider/lru_cache.rs (2)

1-6: LGTM: Import changes align with parking_lot adoption.

The switch from std::sync::Mutex to parking_lot::Mutex is appropriate and consistent with the broader codebase migration indicated in the PR objectives.


50-50: Excellent refactor: Removes unwrap() calls while improving performance.

The migration to parking_lot::Mutex eliminates all .unwrap() calls from lock acquisitions (lines 50, 65, 92, 101, 111, 128, 135), directly addressing the coding guideline that treats .unwrap() and .expect() as MAJOR issues in production Rust code. Additionally, parking_lot::Mutex provides better performance characteristics than the standard library mutex.

The changes maintain thread safety and correctness while simplifying error handling by removing the poisoning concept.

Based on coding guidelines, this change removes MAJOR issues (unwrap calls) from production code.

Also applies to: 65-65, 92-92, 101-101, 111-111, 128-128, 135-135

magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs (9)

364-367: LGTM: Correct import changes for parking_lot migration.

The import changes appropriately introduce parking_lot::Mutex for the mock module while maintaining necessary std imports at the module level.


408-413: LGTM: Correct parking_lot migration.

The removal of .unwrap() calls is appropriate since parking_lot::Mutex::lock() returns MutexGuard directly. The lock-and-mutate pattern correctly updates all state under proper synchronization.


416-418: LGTM: Correct lock usage.

The change appropriately uses parking_lot::Mutex::lock() without .unwrap() for direct guard access.


420-428: LGTM: Proper lock-and-clone pattern.

The lock-and-clone pattern correctly avoids holding the mutex guard across the async send() operation, preventing potential deadlocks or blocking.


454-466: LGTM: Correct state management.

The reconnection control methods and state checks properly use parking_lot::Mutex for synchronization. The multiple lock acquisitions in is_connected_and_resubscribed are safe as they only read state and release immediately.


471-479: LGTM: Correct usage with intentional panic.

The change correctly uses parking_lot::Mutex::lock() without .unwrap(). The .expect() on the Option is intentional and documented to surface logic bugs early if take_updates is called more than once.


480-519: LGTM: Correct subscription management.

The subscription methods properly use parking_lot::Mutex for state checks and mutations. Error handling for disconnected state is appropriate, and the lock-and-mutate patterns are correct.


525-554: LGTM: Correct query implementation.

The subscription query methods properly use parking_lot::Mutex to safely read and collect subscription state without holding locks longer than necessary.


556-593: LGTM: Correct reconnection logic with test optimization.

The reconnection methods properly use parking_lot::Mutex for state management. The delay reduction from 50ms to 10ms in resub_multiple is a reasonable test optimization that keeps test execution time minimal without compromising test behavior.

magicblock-chainlink/Cargo.toml (1)

17-17: LGTM! Dependencies support the lock-free refactor.

The additions of parking_lot and scc are appropriate for the lock-free chainlink implementation. scc provides the lock-free HashMap used for pending_requests, and parking_lot offers optimized synchronization primitives.

Also applies to: 37-37

magicblock-chainlink/src/chainlink/fetch_cloner/types.rs (2)

55-58: LGTM! Clean data structure for partitioned results.

The PartitionedNotFound struct provides a clear, typed return value replacing tuple-based returns. This improves code readability and makes the API self-documenting.


60-111: LGTM!

The FetchAndCloneResult struct with its helper methods and Display implementation is well-designed. The is_ok() method provides a clear way to check success, and the Display implementation gives useful debugging output.

magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs (3)

62-91: LGTM!

The refactored classify_remote_accounts cleanly delegates to classify_single_account, improving readability. The zip iteration correctly pairs accounts with their pubkeys.


93-155: LGTM! Well-structured classification logic.

The helper correctly handles all RemoteAccount variants:

  • NotFound → adds to not_found list
  • Found(Fresh) → classifies by owner/executable/ATA
  • Found(Bank) → logs error for unexpected state (appropriate since this shouldn't occur)

The inline attribute is appropriate for this hot-path helper.


157-178: LGTM! Defensive filtering of native loader programs.

The helper correctly filters out native loader programs with a warning, providing a safety net in case new native programs bypass the blacklist. This aligns with the project's preference for logging errors over panicking.

magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs (6)

20-20: LGTM! Lock-free HashMap type change.

The switch from Arc<Mutex<std::collections::HashMap>> to Arc<scc::HashMap> correctly removes mutex contention. The scc::HashMap provides thread-safe operations without explicit locking.

Also applies to: 75-75


165-282: Concurrent subscription processing looks correct.

The refactor to spawn per-update tasks enables parallel processing of subscription updates. The out-of-order slot check (Lines 175-193) correctly guards against stale updates being applied. The idempotent nature of clone_account (newer slot wins) ensures correctness even with concurrent updates for the same account.


664-667: LGTM!

Clean destructuring of the new PartitionedNotFound type.


917-931: LGTM! Correct lock-free deduplication with Entry API.

The scc::HashMap::entry() API provides atomic check-and-modify semantics:

  • Occupied: Another fetch is in progress → add sender to pending list
  • Vacant: First request → insert entry and add to fetch list

This correctly deduplicates concurrent fetch requests without mutex locks.


964-974: LGTM! Correct cleanup and notification sequence.

The cleanup correctly:

  1. Removes the entry atomically via scc::HashMap::remove()
  2. Notifies all pending requesters after fetch_and_clone_accounts completes

The let _ = sender.send(()) pattern appropriately handles dropped receivers. Requesters waking up can safely read from the bank since cloning completes before notification.


119-119: LGTM!

The initialization of scc::HashMap::new() is correct for the lock-free pending requests tracking.

Copy link
Collaborator

@bmuddha bmuddha left a comment

Choose a reason for hiding this comment

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

Looks legit, still some room for improvement in terms of existing locks, but we can address that in later PRs

Base automatically changed from chore/refactor-cloning-pipeline to master January 7, 2026 08:16
@GabrielePicco GabrielePicco force-pushed the chore/refactor-cloning-pipeline-v2 branch from de09c36 to 381c479 Compare January 7, 2026 09:48
@github-actions
Copy link

github-actions bot commented Jan 7, 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.

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: 1

🤖 Fix all issues with AI agents
In @magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs:
- Line 47: The ATA subscription result is currently ignored; change the call to
handle the Result from subscribe_to_account(ata_pubkey).await and log a warning
on Err just like the eATA path does (use the same warn-level message pattern and
include ata_pubkey and the error). Locate the let _ =
this.subscribe_to_account(ata_pubkey).await line and replace it with a match or
if let Err(e) = ... that calls the existing warn logger with context (e.g.,
"failed to subscribe to ATA", ata_pubkey, e).
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de09c36 and 381c479.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • test-integration/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • magicblock-chainlink/Cargo.toml
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
🧰 Additional context used
📓 Path-based instructions (1)
{magicblock-*,programs,storage-proto}/**

⚙️ CodeRabbit configuration file

{magicblock-*,programs,storage-proto}/**: Treat any usage of .unwrap() or .expect() in production Rust code as a MAJOR issue.
These should not be categorized as trivial or nit-level concerns.
Request proper error handling or explicit justification with invariants.

Files:

  • magicblock-chainlink/Cargo.toml
  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
🧠 Learnings (12)
📚 Learning: 2025-11-24T14:21:00.996Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: Cargo.toml:58-58
Timestamp: 2025-11-24T14:21:00.996Z
Learning: In the magicblock-validator codebase, magicblock-api/Cargo.toml intentionally uses borsh = "1.5.3" (instead of the workspace version 0.10.4) because it needs to deserialize types from the magic-domain-program external dependency, which requires borsh 1.5.x compatibility. This is an intentional exception for interoperability with the magic domain program.

Applied to files:

  • magicblock-chainlink/Cargo.toml
📚 Learning: 2025-12-17T12:46:36.207Z
Learnt from: GabrielePicco
Repo: magicblock-labs/magicblock-validator PR: 738
File: magicblock-chainlink/src/chainlink/fetch_cloner.rs:1109-1196
Timestamp: 2025-12-17T12:46:36.207Z
Learning: In magicblock-chainlink/src/chainlink/fetch_cloner.rs, eATA account subscriptions are intentionally NOT cancelled even when the eATA doesn't exist or delegation conversion fails. The subscriptions are kept active to watch for future creation or delegation of eATA accounts (per maintainer GabrielePicco).

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-12-01T16:02:05.367Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 703
File: magicblock-chainlink/src/submux/mod.rs:652-654
Timestamp: 2025-12-01T16:02:05.367Z
Learning: In magicblock-chainlink/src/submux/mod.rs, the subscribe_program method intentionally adds program_id to program_subs before attempting the subscription. This ensures that even if the initial subscription fails or only partially succeeds across clients, the reconnection logic will retry the subscription. This is a deliberate design pattern for resilience in the multi-client architecture and should not be "fixed" to remove entries on failure.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/types.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-11-07T13:20:13.793Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/coordinator.rs:227-238
Timestamp: 2025-11-07T13:20:13.793Z
Learning: In magicblock-processor's ExecutionCoordinator (scheduler/coordinator.rs), the `account_contention` HashMap intentionally does not call `shrink_to_fit()`. Maintaining slack capacity is beneficial for performance by avoiding frequent reallocations during high transaction throughput. As long as empty entries are removed from the map (which `clear_account_contention` does), the capacity overhead is acceptable.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
📚 Learning: 2025-11-19T09:34:37.917Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: test-integration/test-chainlink/tests/ix_remote_account_provider.rs:62-63
Timestamp: 2025-11-19T09:34:37.917Z
Learning: In test-integration/test-chainlink/tests/ix_remote_account_provider.rs and similar test files, the `_fwd_rx` receiver returned by `init_remote_account_provider()` is intentionally kept alive (but unused) to prevent "receiver dropped" errors on the sender side. The pattern `let (remote_account_provider, _fwd_rx) = init_remote_account_provider().await;` should NOT be changed to `let (remote_account_provider, _) = ...` because dropping the receiver would cause send() operations to fail.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs
  • magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
📚 Learning: 2025-11-13T09:38:43.804Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/locks.rs:64-102
Timestamp: 2025-11-13T09:38:43.804Z
Learning: In magicblock-processor's TransactionScheduler (scheduler/mod.rs line 59), the executor count is clamped to MAX_SVM_EXECUTORS (63) at initialization time, and executor IDs are assigned sequentially from 0 to count-1. This architectural guarantee ensures that executor IDs used in the bitmask-based AccountLock (scheduler/locks.rs) will always be within valid bounds for bit shifting operations, making runtime bounds checks unnecessary.

Applied to files:

  • magicblock-chainlink/src/remote_account_provider/lru_cache.rs
📚 Learning: 2025-11-18T08:47:39.702Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/tests/04_redeleg_other_separate_slots.rs:158-165
Timestamp: 2025-11-18T08:47:39.702Z
Learning: In magicblock-chainlink tests involving compressed accounts, `set_remote_slot()` sets the slot of the `AccountSharedData`, while `compressed_account_shared_with_owner_and_slot()` sets the slot of the delegation record. These are two different fields and both calls are necessary.

Applied to files:

  • magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs
📚 Learning: 2025-11-07T13:09:52.253Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: test-kit/src/lib.rs:275-0
Timestamp: 2025-11-07T13:09:52.253Z
Learning: In test-kit, the transaction scheduler in ExecutionTestEnv is not expected to shut down during tests. Therefore, using `.unwrap()` in test helper methods like `schedule_transaction` is acceptable and will not cause issues in the test environment.

Applied to files:

  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
📚 Learning: 2025-10-14T09:56:14.047Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 564
File: test-integration/programs/flexi-counter/src/processor/call_handler.rs:122-125
Timestamp: 2025-10-14T09:56:14.047Z
Learning: The file test-integration/programs/flexi-counter/src/processor/call_handler.rs contains a test smart contract used for integration testing, not production code.

Applied to files:

  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs
🧬 Code graph analysis (2)
magicblock-chainlink/src/remote_account_provider/lru_cache.rs (2)
magicblock-metrics/src/metrics/mod.rs (1)
  • inc_evicted_accounts_count (599-601)
magicblock-chainlink/src/submux/subscribed_accounts_tracker.rs (2)
  • subscribed_accounts (18-18)
  • subscribed_accounts (50-52)
magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs (1)
magicblock-core/src/token_programs.rs (1)
  • try_derive_eata_address_and_bump (81-89)
🔇 Additional comments (17)
magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs (1)

52-52: LGTM! Error handling appropriately relaxed.

Downgrading eATA subscription failures from error to warning aligns with the resilient subscription design, where subscriptions are kept active to watch for future account creation or delegation.

Based on learnings, eATA subscriptions are intentionally maintained even on initial failures.

magicblock-chainlink/src/remote_account_provider/lru_cache.rs (1)

1-1: LGTM! Clean migration to parking_lot::Mutex.

The migration from std::sync::Mutex to parking_lot::Mutex is straightforward and correct. Removed poison error handling is appropriate since parking_lot mutexes don't poison on panic. All functional logic remains unchanged.

Also applies to: 6-6, 50-50, 65-65, 92-92, 101-101, 111-111, 128-128, 135-135

magicblock-chainlink/Cargo.toml (1)

17-17: LGTM! Dependencies added for lock-free refactoring.

The additions of parking_lot (for more efficient mutexes) and scc (for lock-free concurrent collections) align with the PR objectives to implement lock-free Chainlink patterns. Both are properly declared as workspace dependencies.

Also applies to: 37-37

magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs (3)

364-364: LGTM! Mock migrated to parking_lot::Mutex.

The migration from std::sync::Mutex to parking_lot::Mutex in the mock implementation is consistent with changes across the codebase. This improves test performance and simplifies lock handling.

Also applies to: 367-367


409-412: LGTM! Lock handling updated for parking_lot.

All lock acquisitions correctly updated to use parking_lot::Mutex's API directly without .unwrap() calls. The removal of poison error handling is appropriate since parking_lot mutexes don't poison.

Also applies to: 417-417, 421-421, 455-455, 459-459, 463-465, 476-476, 484-484, 491-491, 500-500, 516-516, 530-530, 543-543, 559-559, 566-566, 576-576


589-589: LGTM! Reasonable test delay reduction.

The resubscribe delay reduction from 50ms to 10ms speeds up test execution while still providing a meaningful delay for testing timing-sensitive logic.

magicblock-chainlink/src/chainlink/fetch_cloner/types.rs (1)

55-58: LGTM! New type supports pipeline refactoring.

The PartitionedNotFound struct cleanly separates accounts that should be cloned as empty from those that are genuinely not found. This supports the refactored classification pipeline mentioned in the PR objectives.

magicblock-chainlink/src/chainlink/fetch_cloner/pipeline.rs (3)

62-91: LGTM! Cleaner classification logic.

The refactor from fold to explicit loop with helper functions significantly improves readability while preserving the original logic. This aligns well with the PR objective to "simplify large fold statements into more readable code."


93-155: LGTM! Well-structured classification helper.

The helper function cleanly encapsulates per-account classification logic, improving modularity. All branches (delegation program owner, executable, ATA, plain) are handled correctly.


157-178: LGTM! Appropriate defensive filtering.

The helper correctly filters out native loader programs with appropriate warning logs. This defensive approach prevents issues if a new native program is introduced that bypasses the blacklist.

magicblock-chainlink/src/chainlink/fetch_cloner/mod.rs (7)

1-17: LGTM! Imports aligned with lock-free architecture.

The import changes correctly support the lock-free refactor using the scc crate's concurrent HashMap.


60-87: LGTM! Core lock-free data structure change.

The removal of Mutex in favor of scc::HashMap is the foundation of the lock-free approach. The scc crate's lock-free HashMap supports concurrent access through its Entry API without explicit locking.

Also applies to: 116-116


411-413: LGTM! Helpful documentation.

The comment clarifies the subscription handling for undelegated accounts.


564-567: LGTM! Consistent with pipeline.rs type changes.

The destructuring correctly uses the new PartitionedNotFound struct.


817-832: LGTM! Correct lock-free deduplication with Entry API.

The Entry API usage correctly implements lock-free request deduplication:

  • Occupied: Appends new requester to existing list
  • Vacant: Reserves entry and marks account for fetch

The insert_entry method is part of scc's HashMap VacantEntry API and is used correctly here.


864-874: LGTM! Proper cleanup and notification.

The cleanup correctly:

  1. Removes the entry from pending requests
  2. Signals all waiting requesters that the fetch completed
  3. Appropriately ignores send errors (receivers may be dropped if those requests timed out or were cancelled)

152-282: Concurrent processing with bounded channel is sound.

The refactor to spawn a task per subscription update allows concurrent resolution of delegation records and account updates, directly addressing the PR objective to "allow concurrent account resolutions to handle spikes."

The subscription_updates channel is bounded with capacity 100 (created in magicblock-chainlink/src/chainlink/mod.rs line 117), providing backpressure and preventing unbounded task spawning. The Arc cloning pattern and error handling with proper logging are correct. No .unwrap() or .expect() calls found in the handler.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@GabrielePicco GabrielePicco added this pull request to the merge queue Jan 7, 2026
Merged via the queue into master with commit 3b8dd6c Jan 7, 2026
19 checks passed
@GabrielePicco GabrielePicco deleted the chore/refactor-cloning-pipeline-v2 branch January 7, 2026 10:44
Dodecahedr0x pushed a commit that referenced this pull request Jan 13, 2026
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

Chainlink performance/maintenance optimizations

3 participants