Skip to content
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

feat: introduce accounts_data trait #6

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

lgalabru
Copy link
Member

@lgalabru lgalabru commented Feb 3, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced blockchain functionality with new API endpoints that allow retrieval of individual and multiple account details, block commitment status, token balances, and token supply.
    • Expanded the service configuration to incorporate these account data capabilities seamlessly into the overall system.
    • Introduced a new module for account data management within the RPC structure.

Copy link

coderabbitai bot commented Feb 3, 2025

Warning

Rate limit exceeded

@lgalabru has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1d8b53f and 206c6e1.

📒 Files selected for processing (3)
  • crates/core/src/rpc/accounts_data.rs (1 hunks)
  • crates/core/src/rpc/mod.rs (1 hunks)
  • crates/core/src/simnet/mod.rs (2 hunks)

Walkthrough

The changes introduce a new RPC trait, AccountsData, that defines methods for retrieving account information, multiple account details, block commitment, token account balance, and token supply. A corresponding implementation (SurfpoolAccountsDataRpc) is added with placeholder method bodies. In addition, the new accounts_data module is declared in the RPC module, and the simulation network’s startup function is updated to extend its handler with the new RPC delegate for account data requests.

Changes

File(s) Change Summary
crates/core/.../rpc/accounts_data.rs, crates/core/.../rpc/mod.rs Introduced the AccountsData trait with methods for retrieving account info, multiple accounts, block commitment, token balance, and token supply. Added SurfpoolAccountsDataRpc as its implementation and declared the new module.
crates/core/.../simnet/mod.rs Modified the start function to extend the RPC handler with the new SurfpoolAccountsDataRpc delegate, thereby enabling account data RPC functionality in the simulation network.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant S as RPC Server
    participant A as AccountsData Delegate
    C->>S: Send RPC request (e.g., get_account_info)
    S->>A: Delegate the request 
    A-->>S: Return account data
    S-->>C: Deliver JSON-RPC response
Loading

Poem

In code I hop with cheerful gleam,
New traits and methods, like a dream.
RPC calls now dance and play,
As account data finds its way.
With each new hop, our code is bright –
A bunny’s joy in bytes of light!
🐇💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

🧹 Nitpick comments (2)
crates/core/src/rpc/accounts_data.rs (2)

38-84: Document public RPC trait methods.
Since these methods are user-facing, adding doc comments or examples would clarify how to consume each RPC endpoint and what to expect in terms of inputs, outputs, and potential error scenarios.


86-137: Provide partial implementation or stubs for unimplemented methods.
Relying solely on unimplemented!() might hinder integration testing. Consider returning dummy responses or partial results to facilitate incremental development and testing.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ede5e41 and 04fb542.

📒 Files selected for processing (3)
  • crates/core/src/rpc/accounts_data.rs (1 hunks)
  • crates/core/src/rpc/mod.rs (1 hunks)
  • crates/core/src/simnet/mod.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • crates/core/src/rpc/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
crates/core/src/rpc/accounts_data.rs (1)

1-37: Imports look well-structured.
The comprehensive set of Solana and JSON-RPC imports is appropriate to support the RPC trait.

crates/core/src/simnet/mod.rs (2)

16-16: New import aligns with new RPC trait.
Importing AccountsData is consistent with integrating the new account-related RPC endpoints.


68-68: RPC handler extension looks correct.
Integrating SurfpoolAccountsDataRpc into the server’s IoHandler ensures that account data methods are now exposed to clients.

@lgalabru lgalabru force-pushed the feat/introduce-accounts-data-rpc branch from 04fb542 to 1d8b53f Compare February 3, 2025 17:32
Copy link

@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: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04fb542 and 1d8b53f.

📒 Files selected for processing (3)
  • crates/core/src/rpc/accounts_data.rs (1 hunks)
  • crates/core/src/rpc/mod.rs (1 hunks)
  • crates/core/src/simnet/mod.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/core/src/rpc/mod.rs
  • crates/core/src/simnet/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
crates/core/src/rpc/accounts_data.rs (3)

38-84: Well-structured trait definition following Solana's RPC conventions.

The trait is well-designed with:

  • Clear method signatures matching Solana's RPC API patterns
  • Appropriate use of async BoxFuture for potentially long-running operations
  • Good documentation for SPL Token-specific endpoints

12-16: Consider removing unused imports.

Several imported types from rpc_config appear to be unused in the current implementation:

  • RpcBlockConfig
  • RpcBlocksConfigWrapper
  • RpcEncodingConfigWrapper
  • RpcEpochConfig
  • RpcRequestAirdropConfig
  • RpcSendTransactionConfig
  • RpcSignatureStatusConfig
  • RpcSignaturesForAddressConfig
  • RpcSimulateTransactionConfig
  • RpcTransactionConfig
✅ Verification successful

Unused RPC configuration imports in crates/core/src/rpc/accounts_data.rs

The search confirms that all the listed RPC configuration types (e.g., RpcBlockConfig, RpcBlocksConfigWrapper, etc.) are only mentioned in the import statement (lines 13–15) and aren’t used elsewhere in the file. Consider removing these unused imports to clean up the code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify usage of potentially unused imports
rg -l "Rpc(Block|Blocks|Encoding|Epoch|RequestAirdrop|SendTransaction|SignatureStatus|SignaturesForAddress|SimulateTransaction|Transaction)Config" --type rust

Length of output: 225


Script:

#!/bin/bash
# Check for direct usage of the imported types in crates/core/src/rpc/accounts_data.rs
rg "RpcBlockConfig" --type rust crates/core/src/rpc/accounts_data.rs

Length of output: 158


Script:

#!/bin/bash
# Check for each imported type beyond the import block in crates/core/src/rpc/accounts_data.rs

imports=(
    "RpcBlockConfig"
    "RpcBlocksConfigWrapper"
    "RpcEncodingConfigWrapper"
    "RpcEpochConfig"
    "RpcRequestAirdropConfig"
    "RpcSendTransactionConfig"
    "RpcSignatureStatusConfig"
    "RpcSignaturesForAddressConfig"
    "RpcSimulateTransactionConfig"
    "RpcTransactionConfig"
)

for imp in "${imports[@]}"; do
  echo "Searching for $imp usage (excluding the import block)..."
  rg -n "$imp" --type rust crates/core/src/rpc/accounts_data.rs | grep -v "rpc_config::"
done

Length of output: 4097


1-137: Add tests for the RPC interface.

Consider adding unit tests to:

  1. Verify RPC method signatures match Solana's API
  2. Test error handling once implemented
  3. Ensure proper serialization/deserialization of requests and responses

Comment on lines +86 to +137
pub struct SurfpoolAccountsDataRpc;
impl AccountsData for SurfpoolAccountsDataRpc {
type Metadata = Option<RunloopContext>;

fn get_account_info(
&self,
meta: Self::Metadata,
pubkey_str: String,
config: Option<RpcAccountInfoConfig>,
) -> BoxFuture<Result<RpcResponse<Option<UiAccount>>>> {
unimplemented!()
}

fn get_multiple_accounts(
&self,
meta: Self::Metadata,
pubkey_strs: Vec<String>,
config: Option<RpcAccountInfoConfig>,
) -> BoxFuture<Result<RpcResponse<Vec<Option<UiAccount>>>>> {
unimplemented!()
}

fn get_block_commitment(
&self,
meta: Self::Metadata,
block: Slot,
) -> Result<RpcBlockCommitment<BlockCommitmentArray>> {
unimplemented!()
}

// SPL Token-specific RPC endpoints
// See https://github.com/solana-labs/solana-program-library/releases/tag/token-v2.0.0 for
// program details

fn get_token_account_balance(
&self,
meta: Self::Metadata,
pubkey_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<UiTokenAmount>> {
unimplemented!()
}

fn get_token_supply(
&self,
meta: Self::Metadata,
mint_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<UiTokenAmount>> {
unimplemented!()
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace unimplemented!() with proper error handling.

Currently, all methods use unimplemented!() which will cause runtime panics. Consider:

  1. Adding TODOs with implementation plans
  2. Implementing basic error responses until full implementation is ready

Example implementation pattern:

     fn get_account_info(
         &self,
         meta: Self::Metadata,
         pubkey_str: String,
         config: Option<RpcAccountInfoConfig>,
     ) -> BoxFuture<Result<RpcResponse<Option<UiAccount>>>> {
-        unimplemented!()
+        // TODO: Implement account info retrieval
+        Box::pin(async move {
+            Err(Error::method_not_implemented())
+        })
     }

Apply similar pattern to other methods to provide proper error handling instead of panics.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub struct SurfpoolAccountsDataRpc;
impl AccountsData for SurfpoolAccountsDataRpc {
type Metadata = Option<RunloopContext>;
fn get_account_info(
&self,
meta: Self::Metadata,
pubkey_str: String,
config: Option<RpcAccountInfoConfig>,
) -> BoxFuture<Result<RpcResponse<Option<UiAccount>>>> {
unimplemented!()
}
fn get_multiple_accounts(
&self,
meta: Self::Metadata,
pubkey_strs: Vec<String>,
config: Option<RpcAccountInfoConfig>,
) -> BoxFuture<Result<RpcResponse<Vec<Option<UiAccount>>>>> {
unimplemented!()
}
fn get_block_commitment(
&self,
meta: Self::Metadata,
block: Slot,
) -> Result<RpcBlockCommitment<BlockCommitmentArray>> {
unimplemented!()
}
// SPL Token-specific RPC endpoints
// See https://github.com/solana-labs/solana-program-library/releases/tag/token-v2.0.0 for
// program details
fn get_token_account_balance(
&self,
meta: Self::Metadata,
pubkey_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<UiTokenAmount>> {
unimplemented!()
}
fn get_token_supply(
&self,
meta: Self::Metadata,
mint_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<UiTokenAmount>> {
unimplemented!()
}
}
pub struct SurfpoolAccountsDataRpc;
impl AccountsData for SurfpoolAccountsDataRpc {
type Metadata = Option<RunloopContext>;
fn get_account_info(
&self,
meta: Self::Metadata,
pubkey_str: String,
config: Option<RpcAccountInfoConfig>,
) -> BoxFuture<Result<RpcResponse<Option<UiAccount>>>> {
// TODO: Implement account info retrieval
Box::pin(async move {
Err(Error::method_not_implemented())
})
}
fn get_multiple_accounts(
&self,
meta: Self::Metadata,
pubkey_strs: Vec<String>,
config: Option<RpcAccountInfoConfig>,
) -> BoxFuture<Result<RpcResponse<Vec<Option<UiAccount>>>>> {
unimplemented!()
}
fn get_block_commitment(
&self,
meta: Self::Metadata,
block: Slot,
) -> Result<RpcBlockCommitment<BlockCommitmentArray>> {
unimplemented!()
}
// SPL Token-specific RPC endpoints
// See https://github.com/solana-labs/solana-program-library/releases/tag/token-v2.0.0 for
// program details
fn get_token_account_balance(
&self,
meta: Self::Metadata,
pubkey_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<UiTokenAmount>> {
unimplemented!()
}
fn get_token_supply(
&self,
meta: Self::Metadata,
mint_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<UiTokenAmount>> {
unimplemented!()
}
}

@lgalabru lgalabru force-pushed the feat/introduce-accounts-data-rpc branch from 1d8b53f to 55100e4 Compare February 3, 2025 17:35
@lgalabru lgalabru force-pushed the feat/introduce-accounts-data-rpc branch from 55100e4 to 206c6e1 Compare February 3, 2025 17:37
@lgalabru lgalabru merged commit c179aa5 into main Feb 3, 2025
3 checks passed
@lgalabru lgalabru deleted the feat/introduce-accounts-data-rpc branch February 3, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant