Skip to content

Conversation

@Shubbu03
Copy link

@Shubbu03 Shubbu03 commented Dec 2, 2025

Summary

This PR adds the Magic Router–specific RPC methods to the ephemeral validator so that the existing Connection/ConnectionMagicRouter client code can be reused against a validator endpoint.

Changes

Extend JsonRpcHttpMethod and HttpDispatcher to support:

  • getRoutes
  • getBlockhashForAccounts
  • getDelegationStatus

Implement validator-side handlers:

  • getRoutes: returns [] (validator is not a router; API compatibility only).
  • getBlockhashForAccounts: aliases getLatestBlockhash, ignoring params (single validator - blockhash source).
  • getDelegationStatus: returns { isDelegated: boolean } based on AccountSharedData::delegated() in AccountsDb, without resolving delegation records.

Fixes #658

Summary by CodeRabbit

  • New Features
    • Added getDelegationStatus RPC method to query account delegation status.
    • Added getRoutes RPC method for route information.
    • Added getBlockhashForAccounts RPC method support.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

📝 Walkthrough

Walkthrough

This pull request implements support for three custom Magic Router RPC methods in the validator: getRoutes, getBlockhashForAccounts, and getDelegationStatus. The changes add new JSON-RPC method variants for both HTTP and WebSocket protocols, create a new handler for retrieving account delegation status from the local AccountsDb, wire the methods through the HTTP dispatcher, and provide a mocked implementation for getRoutes that returns an empty list. This allows the validator to handle Magic Router API calls without returning errors, enabling SDK users to interact with validator endpoints using the same client code as the router.

Suggested reviewers

  • thlorenz
  • lucacillario
  • GabrielePicco

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements all three required RPC methods (getRoutes, getBlockhashForAccounts, getDelegationStatus) with appropriate validator-side behavior matching issue #658 requirements.
Out of Scope Changes check ✅ Passed All changes are scope-compliant: new RPC method definitions, HTTP dispatcher routing, account delegation status retrieval, and validator-compatible response handling directly address issue #658.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

📜 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 2be43c5 and 9adb9c6.

📒 Files selected for processing (6)
  • magicblock-aperture/src/requests/http/get_blockhash_for_accounts.rs (1 hunks)
  • magicblock-aperture/src/requests/http/get_delegation_status.rs (1 hunks)
  • magicblock-aperture/src/requests/http/get_routes.rs (1 hunks)
  • magicblock-aperture/src/requests/http/mod.rs (1 hunks)
  • magicblock-aperture/src/requests/mod.rs (2 hunks)
  • magicblock-aperture/src/server/http/dispatch.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/http/get_program_accounts.rs:17-25
Timestamp: 2025-10-21T13:06:38.900Z
Learning: The magicblock validator does not support ledger forking, so commitment-based state queries (processed/confirmed/finalized) are not applicable. RPC methods can safely ignore commitment and minContextSlot parameters from Solana RPC config objects.
📚 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-aperture/src/requests/http/mod.rs
  • magicblock-aperture/src/requests/mod.rs
🧬 Code graph analysis (1)
magicblock-aperture/src/requests/http/get_delegation_status.rs (1)
magicblock-aperture/src/requests/mod.rs (1)
  • params (27-31)
🔇 Additional comments (8)
magicblock-aperture/src/server/http/dispatch.rs (1)

229-231: LGTM!

The routing for the three new Magic Router compatibility methods follows the established pattern. The sync/async distinction is appropriate: GetRoutes and GetBlockhashForAccounts are synchronous since they don't perform I/O, while GetDelegationStatus is correctly awaited as it calls read_account_with_ensure.

magicblock-aperture/src/requests/http/mod.rs (1)

305-309: LGTM!

The module declarations are well-organized with a clear comment indicating their purpose. Grouping the Magic Router compatibility methods separately improves discoverability.

magicblock-aperture/src/requests/http/get_blockhash_for_accounts.rs (1)

1-17: LGTM!

The implementation correctly aliases getLatestBlockhash for API compatibility. The docstring clearly explains that this is an intentional simplification for the validator context (single blockhash source). Based on learnings, the magicblock validator doesn't support ledger forking, so returning the latest blockhash is the appropriate behavior.

magicblock-aperture/src/requests/http/get_routes.rs (1)

1-15: LGTM!

The implementation correctly returns an empty routes list for API compatibility, as a validator is not a router. The docstring clearly documents this intentional behavior.

magicblock-aperture/src/requests/http/get_delegation_status.rs (1)

28-38: LGTM!

The account retrieval and delegation status derivation logic is correct. Using unwrap_or(false) for non-existent accounts is appropriate—an account that doesn't exist cannot be delegated. The response payload format matches the documented API contract.

magicblock-aperture/src/requests/mod.rs (3)

80-85: LGTM! Well-documented enum additions.

The three new HTTP method variants are clearly documented with accurate descriptions of their validator-side behavior. The comments correctly indicate that:

  • GetRoutes is mocked (returns empty array for compatibility)
  • GetBlockhashForAccounts aliases the existing getLatestBlockhash
  • GetDelegationStatus exposes a simple delegation flag

149-151: LGTM! String mappings are correct.

The string mappings correctly use camelCase convention and match the method names expected by the Magic Router SDK.


91-102: AI summary is inaccurate: WebSocket variants were not added despite claims.

The AI summary states that GetRoutes, GetBlockhashForAccounts, and GetDelegationStatus were added to JsonRpcWsMethod, but the diff shows no changes to this enum. Only HTTP variants were added.

If WebSocket support is required for these methods (for Magic Router or other clients), the corresponding JsonRpcWsMethod variants and handlers must be added.

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

📜 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 cd990cd and c107fbd.

📒 Files selected for processing (4)
  • magicblock-aperture/src/requests/http/get_delegation_status.rs (1 hunks)
  • magicblock-aperture/src/requests/http/mocked.rs (1 hunks)
  • magicblock-aperture/src/requests/http/mod.rs (1 hunks)
  • magicblock-aperture/src/server/http/dispatch.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/http/get_program_accounts.rs:17-25
Timestamp: 2025-10-21T13:06:38.900Z
Learning: The magicblock validator does not support ledger forking, so commitment-based state queries (processed/confirmed/finalized) are not applicable. RPC methods can safely ignore commitment and minContextSlot parameters from Solana RPC config objects.
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
📚 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-aperture/src/requests/http/mod.rs
  • magicblock-aperture/src/requests/http/get_delegation_status.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-aperture/src/requests/http/get_delegation_status.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-aperture/src/requests/http/get_delegation_status.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-aperture/src/requests/http/get_delegation_status.rs
🧬 Code graph analysis (3)
magicblock-aperture/src/requests/http/mod.rs (1)
magicblock-aperture/src/requests/http/get_delegation_status.rs (1)
  • get_delegation_status (12-30)
magicblock-aperture/src/requests/http/mocked.rs (1)
magicblock-aperture/src/requests/payload.rs (2)
  • encode_no_context (85-100)
  • encode_no_context (138-148)
magicblock-aperture/src/requests/http/get_delegation_status.rs (1)
magicblock-aperture/src/requests/mod.rs (1)
  • params (27-31)
🔇 Additional comments (3)
magicblock-aperture/src/requests/http/mod.rs (1)

305-307: Module wiring for get_delegation_status looks consistent

The new module export and Router-compatibility comment align with existing handler organization and keep router-specific logic clearly separated.

magicblock-aperture/src/requests/http/get_delegation_status.rs (1)

1-31: get_delegation_status handler is concise and reuses existing helpers appropriately

The handler cleanly uses parse_params!/some_or_err!, read_account_with_ensure, and AccountSharedData::delegated() to derive a minimal { "isDelegated": bool } response, defaulting safely to false when the account is absent or cannot be ensured. This matches the “validator-only, no router-style resolution” design.

Please just confirm that the Magic Router SDK / client code treats any extra fields as optional and is happy with this minimal object shape.

magicblock-aperture/src/server/http/dispatch.rs (1)

229-233: Verify getBlockhashForAccounts param compatibility with get_latest_blockhash

The routing directly delegates GetBlockhashForAccounts to get_latest_blockhash(request) without visible param transformation. Confirm that get_latest_blockhash accepts the param shape sent by Magic Router SDK's getBlockhashForAccounts calls (which likely differ from standard getLatestBlockhash params). If param shapes are incompatible, add normalization before delegation to achieve the intended drop-in compatibility.

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.

feat: implement handling of RPC methods that magic router uses

2 participants