-
Notifications
You must be signed in to change notification settings - Fork 23
feat: account fetch metrics fine-grained by RPC origin #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThis change introduces an AccountFetchOrigin enum and threads it through account-fetching APIs across multiple crates (magicblock-aperture, magicblock-chainlink, remote_account_provider, magicblock-metrics, tests, and integrations). Many public and internal function signatures now accept an additional fetch_origin: AccountFetchOrigin parameter and propagate it into fetch, clone, and metrics calls. Metrics counters for account fetches were converted to per-origin counter vectors and are now incremented using the provided origin. Possibly related PRs
Suggested reviewers
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)magicblock-metrics/src/metrics/types.rs (3)
🔇 Additional comments (4)
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 |
Manual Deploy AvailableYou can trigger a manual deploy of this PR branch to testnet: Alternative: Comment
Comment updated automatically when the PR is synchronized. |
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
magicblock-chainlink/src/chainlink/fetch_cloner.rs (1)
1863-1960: Tests exercise the new origin parameter forGetAccount; consider adding coverage for other originsAll updated tests in this module use
AccountFetchOrigin::GetAccount, which validates the main ensure/fetch flows. If you want direct unit coverage forGetMultipleAccountsandSendTransactionorigins (beyond higher‑level integration tests), adding targeted cases here or in a nearby module would improve confidence that no origin is accidentally mis‑wired.Also applies to: 2191-2260, 2356-2362, 2426-2456, 2503-2530, 2579-2590, 2621-2660, 2729-2735, 2821-2827, 2903-2913
magicblock-chainlink/src/chainlink/mod.rs (1)
313-329: Origin‑awareensure_accounts/fetch_accountsAPI looks consistentAdding a
fetch_origin: AccountFetchOriginparameter toensure_accounts,fetch_accounts, andfetch_accounts_common, and threading it through tofetch_and_clone_accounts_with_dedup, makes origin an explicit part of the public contract. This is a breaking but coherent change; as long as all internal and Aperture call sites are updated, the design is sound.Also applies to: 335-357, 366-372, 397-402
magicblock-chainlink/src/remote_account_provider/mod.rs (1)
521-577: Refetch path may perform a redundant RPC fetch and double‑count metricsIn
try_get_multi_until_slots_match, therefetchblock calls:self.fetch(pubkeys.to_vec(), None, self.chain_slot(), fetch_origin);before entering the retry loop, but at that point there are no pending entries in
fetching_accountsfor these pubkeys, so thisfetchcall’s results are never delivered—only RPC traffic and metrics are generated. The firsttry_get_multicall inside the loop will then set up channels and spawn its ownfetch, which actually resolves callers.Consider removing this standalone
self.fetch(...)and relying on the loop’stry_get_multicalls, or restructuring so the forced refetch reuses the same pending‑request mechanism instead of firing a “blind” fetch.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (12)
magicblock-aperture/src/requests/http/mod.rs(3 hunks)magicblock-chainlink/src/chainlink/fetch_cloner.rs(32 hunks)magicblock-chainlink/src/chainlink/mod.rs(8 hunks)magicblock-chainlink/src/lib.rs(1 hunks)magicblock-chainlink/src/remote_account_provider/mod.rs(19 hunks)magicblock-chainlink/tests/01_ensure-accounts.rs(9 hunks)magicblock-chainlink/tests/03_deleg_after_sub.rs(3 hunks)magicblock-chainlink/tests/08_subupdate-ordering.rs(2 hunks)magicblock-chainlink/tests/basics.rs(3 hunks)magicblock-chainlink/tests/utils/test_context.rs(2 hunks)magicblock-metrics/src/metrics/mod.rs(4 hunks)magicblock-metrics/src/metrics/types.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📚 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/lib.rsmagicblock-chainlink/tests/01_ensure-accounts.rsmagicblock-chainlink/tests/08_subupdate-ordering.rsmagicblock-chainlink/tests/03_deleg_after_sub.rsmagicblock-chainlink/src/chainlink/fetch_cloner.rsmagicblock-chainlink/src/remote_account_provider/mod.rs
📚 Learning: 2025-10-26T16:53:29.820Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 587
File: magicblock-chainlink/src/remote_account_provider/mod.rs:134-0
Timestamp: 2025-10-26T16:53:29.820Z
Learning: In magicblock-chainlink/src/remote_account_provider/mod.rs, the `Endpoint::separate_pubsub_url_and_api_key()` method uses `split_once("?api-key=")` because the api-key parameter is always the only query parameter right after `?`. No additional query parameter parsing is needed for this use case.
Applied to files:
magicblock-chainlink/src/lib.rsmagicblock-chainlink/tests/basics.rsmagicblock-chainlink/tests/03_deleg_after_sub.rsmagicblock-aperture/src/requests/http/mod.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/lib.rsmagicblock-chainlink/tests/03_deleg_after_sub.rsmagicblock-aperture/src/requests/http/mod.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/lib.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/tests/basics.rsmagicblock-chainlink/tests/01_ensure-accounts.rsmagicblock-chainlink/tests/08_subupdate-ordering.rsmagicblock-chainlink/src/chainlink/mod.rsmagicblock-chainlink/tests/03_deleg_after_sub.rsmagicblock-aperture/src/requests/http/mod.rsmagicblock-chainlink/tests/utils/test_context.rsmagicblock-chainlink/src/chainlink/fetch_cloner.rsmagicblock-chainlink/src/remote_account_provider/mod.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/tests/basics.rsmagicblock-chainlink/tests/01_ensure-accounts.rsmagicblock-chainlink/tests/03_deleg_after_sub.rsmagicblock-chainlink/tests/utils/test_context.rsmagicblock-chainlink/src/chainlink/fetch_cloner.rsmagicblock-chainlink/src/remote_account_provider/mod.rs
📚 Learning: 2025-11-19T11:31:24.218Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-chainlink/tests/ix_01_ensure-accounts.rs:85-114
Timestamp: 2025-11-19T11:31:24.218Z
Learning: In the magicblock-validator codebase, compressed delegation records are never subscribed to by design. Tests for compressed delegation flows should focus on verifying that the delegated account (e.g., counter PDA) is cloned as delegated and not subscribed, but do not need to check for subscription to delegation-record-like PDAs in the compressed path because subscriptions to compressed delegation records never occur.
Applied to files:
magicblock-chainlink/tests/01_ensure-accounts.rsmagicblock-chainlink/tests/03_deleg_after_sub.rsmagicblock-chainlink/src/chainlink/fetch_cloner.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/remote_account_provider/mod.rs
🧬 Code graph analysis (3)
magicblock-metrics/src/metrics/mod.rs (1)
magicblock-chainlink/src/remote_account_provider/mod.rs (1)
new(278-335)
magicblock-chainlink/src/chainlink/fetch_cloner.rs (2)
magicblock-chainlink/src/remote_account_provider/remote_account.rs (2)
delegated(95-101)slot(203-215)magicblock-chainlink/src/remote_account_provider/program_account.rs (1)
get_loaderv3_get_program_data_address(37-41)
magicblock-chainlink/src/remote_account_provider/mod.rs (1)
magicblock-metrics/src/metrics/mod.rs (3)
set_monitored_accounts_count(469-471)inc_account_fetches_found(515-528)inc_account_fetches_not_found(530-546)
🔇 Additional comments (23)
magicblock-chainlink/src/lib.rs (1)
9-9: Re-exporting AccountFetchOrigin from crate root is appropriatePublicly re-exporting
AccountFetchOriginfrommagicblock-chainlinkaligns with how tests and callers use the type and avoids leaking the metrics module path into higher layers. Looks good.magicblock-chainlink/tests/basics.rs (1)
4-4: Consistent origin tagging for ensure_accounts in basics testsUsing
AccountFetchOrigin::GetMultipleAccountsfor allensure_accountscalls keeps the test behavior unchanged while aligning with the updated API and origin-aware metrics. The fetch-count expectations and clone assertions remain valid.Also applies to: 48-55, 60-67, 103-110, 118-125
magicblock-aperture/src/requests/http/mod.rs (1)
13-13: Correct mapping of HTTP helpers to AccountFetchOrigin variantsImporting
AccountFetchOriginand using:
GetAccountinread_account_with_ensure, andGetMultipleAccountsinread_accounts_with_ensurecorrectly tags fetches by the initiating RPC method while preserving existing timing and error-handling behavior. This is exactly what the per-origin metrics need.
Also applies to: 105-111, 131-137
magicblock-metrics/src/metrics/types.rs (1)
76-95: AccountFetchOrigin enum and Display implementation look solidThe
AccountFetchOriginenum is minimal and well-scoped, and theDisplaymapping to"get_multiple_accounts","get_account", and"send_transaction"provides clear, stable strings for metric labels and logs. Trait bounds and visibility are appropriate.magicblock-chainlink/tests/03_deleg_after_sub.rs (1)
7-7: Origin tagging in deleg-after-sub test matches updated APIBringing
AccountFetchOrigininto scope and passingAccountFetchOrigin::GetMultipleAccountstoensure_accountskeeps the delegation flow test behavior the same while satisfying the new signature. Metric attribution remains consistent with other multi-account-style tests.Also applies to: 57-64, 86-93
magicblock-chainlink/tests/08_subupdate-ordering.rs (1)
2-2: Subupdate-ordering test updated correctly for AccountFetchOriginThe added
AccountFetchOriginimport and use ofAccountFetchOrigin::GetMultipleAccountsin the initialensure_accountscall integrate cleanly with the new API without altering the test’s ordering assertions.Also applies to: 59-66
magicblock-chainlink/tests/01_ensure-accounts.rs (1)
9-9: Ensure-accounts tests correctly adapted to AccountFetchOriginUpdating all
ensure_accountsinvocations in this file to includeAccountFetchOrigin::GetMultipleAccountsmatches the new API and maintains existing test coverage across all scenarios (non-existing, delegated, other-authority, undelegating, and invalid delegation record). The failure-case test that inspects the rawResultstill behaves as intended.Also applies to: 39-46, 70-77, 106-113, 147-154, 192-199, 247-254, 295-302, 338-344
magicblock-metrics/src/metrics/mod.rs (3)
8-10: Publicly re‑exportingAccountFetchOriginis appropriateMaking
AccountFetchOriginavailable from the metrics crate aligns with how other metric types are exposed and keeps downstream imports consistent.
197-237: Per‑origin account‑fetch counters are well‑named and correctly registeredThe six new counters cleanly separate found/not‑found by origin and are all registered in
register(), so they can fully replace the old aggregate counters while still allowing dashboards to sum back to totals.Also applies to: 365-370
515-545: Origin‑aware dispatch for found/not‑found metrics looks correctMatching on
AccountFetchOriginand incrementing the corresponding per‑origin counter is straightforward and exhaustive; this keeps compiler pressure on future enum extensions and aligns with howfetch_originis threaded from callers.magicblock-chainlink/src/chainlink/fetch_cloner.rs (6)
15-16: ImportingAccountFetchOriginat this level is the right abstraction pointFetchCloner is where high‑level fetch flows are orchestrated, so depending on the shared
AccountFetchOrigintype here (rather than re‑defining an origin enum) keeps origin semantics centralized.
287-297: Confirm intent for subscription‑driven fetches being classified asGetAccountBoth the LoaderV3 program‑data path and delegation‑record companion fetch on subscription updates use
AccountFetchOrigin::GetAccount. If metrics are meant to reflect only HTTP RPC origins, this is reasonable as a “closest fit”; if you eventually want to distinguish subscription‑triggered fetches, this would be the main place to introduce a dedicated origin.Also applies to: 360-366
493-515: Delegation‑record fetch now correctly carries the caller’s originAdding
fetch_origintofetch_and_parse_delegation_recordand passing it through totry_get_multi_until_slots_matchensures delegation‑record lookups are counted under the same origin as the parent ensure/fetch call, without changing functional behavior.Also applies to: 1112-1126
571-612: Core fetch‑and‑clone flow propagatesfetch_originconsistently
fetch_and_clone_accountsnow forwardsfetch_originboth totry_get_multiand to the delegated/program‑data companion fetch tasks, so all underlying RPC activity (including secondary lookups) is tagged with the initiating RPC origin.Also applies to: 737-752, 866-908
1161-1197: Deduplicated fetch path keeps origin context intact
fetch_and_clone_accounts_with_deduppassesfetch_originthrough toshould_refresh_undelegating_in_bank_accountand the finalfetch_and_clone_accountscall, so both refresh checks and actual remote fetches share the correct origin label without impacting dedup semantics.Also applies to: 1239-1245
1296-1352: Companion‑fetch helper tasks correctly forwardfetch_originThe
task_to_fetch_with_delegation_record,task_to_fetch_with_program_data, andtask_to_fetch_with_companionhelpers now passfetch_originintotry_get_multi_until_slots_match, ensuring all two‑account companion fetches are attributed to the right origin in metrics.magicblock-chainlink/src/chainlink/mod.rs (2)
11-11: BringingAccountFetchOrigininto the Chainlink API is appropriateChainlink is the main public surface for fetch/ensure operations, so importing the shared origin type here is the right place to define origin semantics for upstream callers.
274-278:ensure_transaction_accountscorrectly tags fetches asSendTransactionPassing
AccountFetchOrigin::SendTransactionintoensure_accountsensures all account fetches performed during transaction processing (including delegation and program‑data lookups) are attributed to the sendTransaction origin in metrics.magicblock-chainlink/src/remote_account_provider/mod.rs (5)
49-55: Metric/origin imports are structured cleanlyImporting the metric increment helpers alongside
AccountFetchOriginkeeps all fetch‑related metrics concerns localized here without widening the public surface of RemoteAccountProvider.
507-519:try_getwrapper correctly forwards origin intotry_get_multiExtending
try_getwithfetch_originand delegating totry_get_multi(&[pubkey], None, fetch_origin)preserves the single‑result invariant while ensuring even single‑account fetches are origin‑aware for metrics.
622-667:try_get_multiorigin threading and fetch invocation are consistentAdding
fetch_origintotry_get_multiand passing it through toself.fetch(pubkeys.to_vec(), mark_empty_if_not_found, min_context_slot, fetch_origin)means every RPC call behind this method is counted under the correct origin; subscription override logic and pending‑request handling remain unchanged.
852-858: Fetch metrics correctly separate RPC success from found/not‑found by originExtending
fetchto acceptfetch_originand then calling:
inc_account_fetches_success(pubkeys.len() as u64)for any successful RPC response, andinc_account_fetches_found(fetch_origin, found_count)/inc_account_fetches_not_found(fetch_origin, not_found_count)cleanly distinguishes RPC‑level success from on‑chain presence, with per‑origin breakdown matching how
mark_empty_if_not_foundis treated.Also applies to: 1000-1037
1190-1195: Tests updated to supplyAccountFetchOrigin::GetAccountAll RemoteAccountProvider tests now pass
AccountFetchOrigin::GetAccountintotry_getandtry_get_multi_until_slots_match, which keeps existing behavior while validating the new parameter plumb‑through. This should be enough for this module; broader origin combinations are better exercised at the Chainlink/Aperture levels.Also applies to: 1246-1249, 1342-1351, 1382-1387, 1420-1425, 1559-1665
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
test-integration/test-chainlink/tests/ix_programs.rs (1)
4-12: AccountFetchOrigin wiring in program-cloning tests is sound, with a minor semantic considerationAll
ensure_accountsinvocations now correctly pass the new origin parameter, and usingAccountFetchOrigin::GetAccountworks fine for these program-cloning scenarios, including the single-program tests.For the multi-program cases (e.g.,
ixtest_clone_multiple_programs_v1_v2_v3), if your intent is to model a batched account/program fetch akin to agetMultipleAccounts-style RPC for metrics, you might consider using the corresponding origin there. Otherwise, the current choice is perfectly acceptable for the behaviours asserted in these tests.Also applies to: 439-442, 467-470, 496-499, 523-526, 575-578, 603-606
test-integration/test-chainlink/tests/ix_full_scenarios.rs (1)
2-10: UseGetMultipleAccountsorigin for batched fetch_accounts calls to align metrics with actual RPC semanticsBoth
fetch_accounts(&all_pubkeys, …)calls operate on batches of pubkeys but useAccountFetchOrigin::GetAccount. Since thefetch_originparameter affects only metrics recording (not RPC call behavior), this causes the batched account fetches to be tagged under single-account counters, misrepresenting observability. Change toAccountFetchOrigin::GetMultipleAccountsat lines 165-169 and 213-217 for accurate metrics classification.test-integration/test-chainlink/tests/ix_exceed_capacity.rs (1)
2-7: UpdateAccountFetchOrigintoGetMultipleAccountsfor multi-account operationsThe tests exercise reading multiple accounts but attribute them to
AccountFetchOrigin::GetAccount, which affects metrics attribution. TheGetMultipleAccountsvariant exists for this purpose and should be used when fetching multiple pubkeys.Update lines 45-48, 77-84, and the similar call earlier in the test (around line 44) to use
AccountFetchOrigin::GetMultipleAccountsfor semantic accuracy and correct metric categorization.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
test-integration/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (9)
test-integration/test-chainlink/src/test_context.rs(1 hunks)test-integration/test-chainlink/tests/ix_01_ensure-accounts.rs(4 hunks)test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rs(4 hunks)test-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.rs(2 hunks)test-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rs(2 hunks)test-integration/test-chainlink/tests/ix_exceed_capacity.rs(3 hunks)test-integration/test-chainlink/tests/ix_full_scenarios.rs(3 hunks)test-integration/test-chainlink/tests/ix_programs.rs(7 hunks)test-integration/test-chainlink/tests/ix_remote_account_provider.rs(7 hunks)
🧰 Additional context used
🧠 Learnings (7)
📚 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:
test-integration/test-chainlink/src/test_context.rstest-integration/test-chainlink/tests/ix_full_scenarios.rstest-integration/test-chainlink/tests/ix_01_ensure-accounts.rstest-integration/test-chainlink/tests/ix_exceed_capacity.rstest-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rstest-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.rstest-integration/test-chainlink/tests/ix_programs.rstest-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_remote_account_provider.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:
test-integration/test-chainlink/src/test_context.rstest-integration/test-chainlink/tests/ix_full_scenarios.rstest-integration/test-chainlink/tests/ix_01_ensure-accounts.rstest-integration/test-chainlink/tests/ix_exceed_capacity.rstest-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rstest-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_remote_account_provider.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:
test-integration/test-chainlink/tests/ix_01_ensure-accounts.rstest-integration/test-chainlink/tests/ix_exceed_capacity.rstest-integration/test-chainlink/tests/ix_03_deleg_after_sub.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:
test-integration/test-chainlink/tests/ix_exceed_capacity.rstest-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rstest-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.rstest-integration/test-chainlink/tests/ix_programs.rstest-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_remote_account_provider.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:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_remote_account_provider.rs
📚 Learning: 2025-11-19T11:31:24.218Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-chainlink/tests/ix_01_ensure-accounts.rs:85-114
Timestamp: 2025-11-19T11:31:24.218Z
Learning: In the magicblock-validator codebase, compressed delegation records are never subscribed to by design. Tests for compressed delegation flows should focus on verifying that the delegated account (e.g., counter PDA) is cloned as delegated and not subscribed, but do not need to check for subscription to delegation-record-like PDAs in the compressed path because subscriptions to compressed delegation records never occur.
Applied to files:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rs
📚 Learning: 2025-10-26T16:53:29.820Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 587
File: magicblock-chainlink/src/remote_account_provider/mod.rs:134-0
Timestamp: 2025-10-26T16:53:29.820Z
Learning: In magicblock-chainlink/src/remote_account_provider/mod.rs, the `Endpoint::separate_pubsub_url_and_api_key()` method uses `split_once("?api-key=")` because the api-key parameter is always the only query parameter right after `?`. No additional query parameter parsing is needed for this use case.
Applied to files:
test-integration/test-chainlink/tests/ix_remote_account_provider.rs
🔇 Additional comments (7)
test-integration/test-chainlink/src/test_context.rs (1)
201-212: Wire AccountFetchOrigin throughTestContext::ensure_accountcorrectlyUsing the new
ensure_accountssignature withmagicblock_chainlink::AccountFetchOrigin::GetAccountfor this single-account helper is consistent and keeps behaviour unchanged aside from origin tagging.test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rs (1)
2-7: Origin parameter usage in delegation-after-subscribe test is consistentImporting
AccountFetchOriginand passingAccountFetchOrigin::GetAccountfor allensure_accountscalls (each operating on a single pubkey) matches the test’s intent and the updated API; nothing else needs changing here.Also applies to: 24-27, 39-42, 63-66
test-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.rs (1)
7-12: Correct AccountFetchOrigin wiring for redelegation (separate slots)The added
AccountFetchOriginimport and usingAccountFetchOrigin::GetAccountin the loneensure_accountscall align with the single-account flow under test and the new signature.Also applies to: 37-40
test-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rs (1)
7-11: Consistent origin tagging in same-slot redelegation testUsing
AccountFetchOrigin::GetAccountfor the single-accountensure_accountscall is consistent with the rest of the delegation tests and the updated API; no further changes needed here.Also applies to: 36-39
test-integration/test-chainlink/tests/ix_01_ensure-accounts.rs (1)
2-8: AccountFetchOrigin usage in basic ensure-accounts tests is appropriateEach
ensure_accountscall here operates on a single pubkey, and tagging them withAccountFetchOrigin::GetAccountfits the scenarios under test while satisfying the new signature; nothing else stands out.Also applies to: 20-24, 45-49, 75-79
test-integration/test-chainlink/tests/ix_remote_account_provider.rs (2)
18-18: LGTM!The import of
AccountFetchOriginis correctly added to support the updated API signatures.
67-70: LGTM!The
try_get()calls correctly useAccountFetchOrigin::GetAccount, which properly categorizes these single-account fetches in the metrics system.Also applies to: 123-126, 143-146
There was a problem hiding this 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
♻️ Duplicate comments (1)
test-integration/test-chainlink/tests/ix_remote_account_provider.rs (1)
170-170: UseAccountFetchOrigin::GetMultipleAccountsfor multi-account fetches.All three
try_get_multicalls useAccountFetchOrigin::GetAccount, which misclassifies these multi-account fetches in the metrics system. They should useGetMultipleAccountsto properly increment theACCOUNT_FETCHES_GET_MULTIPLE_ACCOUNTS_*_COUNTmetrics.Apply this diff to all three calls:
- .try_get_multi(&all_pubkeys, None, AccountFetchOrigin::GetAccount) + .try_get_multi(&all_pubkeys, None, AccountFetchOrigin::GetMultipleAccounts)Also applies to: 197-197, 226-226
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rs(4 hunks)test-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.rs(2 hunks)test-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rs(2 hunks)test-integration/test-chainlink/tests/ix_full_scenarios.rs(3 hunks)test-integration/test-chainlink/tests/ix_remote_account_provider.rs(7 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 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:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_full_scenarios.rstest-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rstest-integration/test-chainlink/tests/ix_remote_account_provider.rstest-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.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:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_remote_account_provider.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:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rstest-integration/test-chainlink/tests/ix_remote_account_provider.rstest-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.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:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_full_scenarios.rstest-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rstest-integration/test-chainlink/tests/ix_remote_account_provider.rstest-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.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:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rstest-integration/test-chainlink/tests/ix_full_scenarios.rs
📚 Learning: 2025-11-19T11:31:24.218Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-chainlink/tests/ix_01_ensure-accounts.rs:85-114
Timestamp: 2025-11-19T11:31:24.218Z
Learning: In the magicblock-validator codebase, compressed delegation records are never subscribed to by design. Tests for compressed delegation flows should focus on verifying that the delegated account (e.g., counter PDA) is cloned as delegated and not subscribed, but do not need to check for subscription to delegation-record-like PDAs in the compressed path because subscriptions to compressed delegation records never occur.
Applied to files:
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rs
🔇 Additional comments (4)
test-integration/test-chainlink/tests/ix_03_deleg_after_sub.rs (1)
6-6: LGTM! Correct origin for single-account fetches.The test correctly uses
AccountFetchOrigin::GetAccountfor allensure_accountscalls, which is appropriate since the test fetches a single account (pubkeys = [counter_pda]).Also applies to: 24-28, 40-43, 64-67
test-integration/test-chainlink/tests/ix_07_redeleg_us_same_slot.rs (1)
10-10: LGTM! Correct origin for single-account fetch.The test correctly uses
AccountFetchOrigin::GetAccountfor theensure_accountscall with a single account (pubkeys = [counter_pda]).Also applies to: 36-39
test-integration/test-chainlink/tests/ix_remote_account_provider.rs (1)
67-70: LGTM! Correct origin for single-account fetches.All
try_getcalls correctly useAccountFetchOrigin::GetAccountfor fetching individual accounts.Also applies to: 122-125, 141-144
test-integration/test-chainlink/tests/ix_06_redeleg_us_separate_slots.rs (1)
10-10: LGTM! Correct origin for single-account fetch.The test correctly uses
AccountFetchOrigin::GetAccountfor theensure_accountscall with a single account (pubkeys = [counter_pda]).Also applies to: 36-39
bmuddha
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
magicblock-metrics/src/metrics/mod.rs(3 hunks)magicblock-metrics/src/metrics/types.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
magicblock-metrics/src/metrics/types.rs (3)
magicblock-committor-service/src/intent_executor/error.rs (1)
value(111-118)magicblock-committor-service/src/intent_executor/mod.rs (1)
value(74-82)magicblock-committor-service/src/types.rs (1)
value(23-29)
magicblock-metrics/src/metrics/mod.rs (2)
magicblock-chainlink/src/remote_account_provider/mod.rs (1)
new(278-335)magicblock-aperture/src/state/subscriptions.rs (4)
new(342-355)new(410-413)count(335-337)count(370-372)
🔇 Additional comments (3)
magicblock-metrics/src/metrics/mod.rs (3)
8-10: Public re-export ofAccountFetchOriginis appropriateRe-exporting
AccountFetchOrigin(alongside the existing metric types) frommetricskeeps the public surface coherent and matches how other metric-related types are exposed, which is useful for downstream crates that need to tag origin without depending ontypesdirectly.
197-213: Per-origin account-fetch counters are wired correctlyConverting
ACCOUNT_FETCHES_FOUND_COUNT/ACCOUNT_FETCHES_NOT_FOUND_COUNTtoIntCounterVecwith a single"origin"label cleanly supports the per-RPC-origin breakdown described in the PR. The metric names and help strings stay stable, and the low, enum-backed cardinality fororiginis safe for Prometheus.
487-500: Origin-aware helper functions correctly dispatch to labeled countersThe updated helpers now take
fetch_origin: AccountFetchOriginand usewith_label_values(&[fetch_origin.value()])beforeinc_by(count). This centralizes label handling and ensures callers can’t accidentally drift from the agreed string representation while still preserving the previous call pattern (just with the added origin).
Summary
Make account fetch metrics fine-grained by RPC origin
Details
Split account fetch metrics into origin-specific counters to track which
RPC method initiated each fetch:
Replace ACCOUNT_FETCHES_FOUND_COUNT with:
Replace ACCOUNT_FETCHES_NOT_FOUND_COUNT with:
Propagate AccountFetchOrigin through all fetch layers (Aperture →
Chainlink → FetchCloner → RemoteAccountProvider) and update auxiliary
fetch paths (delegation records, program data) to use parent request's
origin for accurate metrics categorization.
This enables dashboards to sum these metrics to recover previous totals
while gaining visibility into fetch patterns by RPC method.
Summary by CodeRabbit
New Features
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.