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/get account info #10

Closed
wants to merge 2 commits into from
Closed

Feat/get account info #10

wants to merge 2 commits into from

Conversation

MicaiahReid
Copy link
Member

@MicaiahReid MicaiahReid commented Feb 5, 2025

Summary by CodeRabbit

  • New Features
    • Introduced enhanced remote connectivity, improving access to external data sources.
  • Bug Fixes
    • Improved error handling for account retrieval, ensuring missing or incomplete account data is managed gracefully.
  • Refactor
    • Streamlined the transformation process for account data, resulting in more consistent and reliable account displays.

Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The changes update the account retrieval and transformation logic along with the RPC configuration management. The get_account_info and get_multiple_accounts methods now include conditional checks, logging, and improved error handling, with a fallback to fetch account data via a remote RPC client if necessary. Additionally, the RunloopContext has been enhanced to include RPC configuration and a new method in the State trait has been added for remote RPC client access. The account transformation utility now requires a valid account reference, simplifying its control flow.

Changes

File(s) Change Summary
crates/core/src/rpc/accounts_data.rs Updated the implementations of get_account_info and get_multiple_accounts. Now includes conditional account checks, logging, and error propagation with a fallback to a remote RPC client when an account isn’t found.
crates/core/src/rpc/mod.rs Enhanced RunloopContext by adding a new rpc_config field and a corresponding constructor. Extended the State trait with get_remote_rpc_client for accessing remote RPC functionality and updated SurfpoolMiddleware to use the new context.
crates/core/src/rpc/utils.rs Modified transform_account_to_ui_account to accept a non-optional account. This removal of the optional check streamlines the account-to-UI account transformation logic.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant R as AccountsDataRpc
    participant SR as StateReader (svm)
    participant RPC as RemoteRpcClient
    participant U as UI Transformation

    C->>R: get_account_info(pubkey)
    R->>SR: Fetch account by pubkey
    alt Account exists
        SR-->>R: Return account data
        R->>U: Transform account data
        U-->>R: UiAccount
    else Account missing
        R->>RPC: Request account from remote RPC
        RPC-->>R: Return account data or error
        R->>U: Transform fetched account data
        U-->>R: UiAccount
    end
    R-->>C: Return UiAccount or error
Loading

Possibly related PRs

  • feat: introduce accounts_data trait #6: Directly modifies the get_account_info and get_multiple_accounts implementations in the AccountsData trait, establishing a strong connection with the current changes.
  • Get fee for message #5: Involves similar updates to account data handling and transformation logic, aligning closely with the modifications in this PR.
  • Get multiple accounts #4: Introduces changes in account retrieval methods within the Minimal trait, which parallels the updated logic in the current implementation.

Poem

In the burrow of code where the changes hop free,
I’ve added new checks for accounts you see.
Logging and fallbacks guide every byte,
Transforming data in the soft moonlight.
With a twitch of my nose and a skip so spry,
I celebrate these tweaks—oh me, oh my! 🐇✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

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.

@@ -122,7 +149,10 @@ impl AccountsData for SurfpoolAccountsDataRpc {
.iter()
.map(|s| {
let pk = verify_pubkey(s)?;
transform_account_to_ui_account(&state_reader.svm.get_account(&pk), &config)
match state_reader.svm.get_account(&pk) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we be hitting RPC here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we haven't done this method yet, this was just making the compiler happy

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 (3)
crates/core/src/rpc/mod.rs (1)

88-96: Consider caching the RPC client.

Creating a new RPC client for each request might be inefficient. Consider caching the client instance.

-    fn get_remote_rpc_client(&self) -> Result<RpcClient, RpcCustomError> {
-        let Some(ctx) = self else {
-            return Err(RpcCustomError::NodeUnhealthy {
-                num_slots_behind: None,
-            }
-            .into());
-        };
-        Ok(RpcClient::new(&ctx.rpc_config.remote_rpc_url))
+    fn get_remote_rpc_client(&self) -> Result<RpcClient, RpcCustomError> {
+        let Some(ctx) = self else {
+            return Err(RpcCustomError::NodeUnhealthy {
+                num_slots_behind: None,
+            }
+            .into());
+        };
+        static RPC_CLIENT: OnceCell<Mutex<Option<RpcClient>>> = OnceCell::new();
+        let client_mutex = RPC_CLIENT.get_or_init(|| Mutex::new(None));
+        let mut client = client_mutex.lock().unwrap();
+        if client.is_none() {
+            *client = Some(RpcClient::new(&ctx.rpc_config.remote_rpc_url));
+        }
+        Ok(client.as_ref().unwrap().clone())
+    }
crates/core/src/rpc/accounts_data.rs (2)

94-97: Consider using structured logging.

Replace println! with a proper logging framework for better observability in production.

-        println!(
-            "account from state: {:?}",
-            state_reader.svm.get_account(&pubkey)
-        );
+        tracing::debug!(
+            account = ?state_reader.svm.get_account(&pubkey),
+            "Retrieved account from state"
+        );

152-155: Consider implementing parallel account retrieval.

For multiple accounts, consider implementing parallel retrieval using async/await for better performance.

-                match state_reader.svm.get_account(&pk) {
-                    Some(account) => Ok(Some(transform_account_to_ui_account(&account, &config)?)),
-                    None => Ok(None),
-                }
+                tokio::spawn(async move {
+                    match state_reader.svm.get_account(&pk) {
+                        Some(account) => Ok(Some(transform_account_to_ui_account(&account, &config)?)),
+                        None => Ok(None),
+                    }
+                }).await?
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 09ddb23 and 721e2ce.

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

32-33: LGTM! Good addition of RPC configuration.

The addition of rpc_config to RunloopContext enables better RPC configuration management.

crates/core/src/rpc/accounts_data.rs (1)

107-117: Uncomment and implement account caching.

The commented-out caching logic should be implemented to improve performance for frequently accessed accounts.

Would you like me to help implement a proper caching mechanism with TTL and size limits?

crates/core/src/rpc/utils.rs (1)

174-234: LGTM! Good improvement in type safety.

The change to require a non-optional Account parameter improves type safety and simplifies the function's logic.

@MicaiahReid
Copy link
Member Author

Closing in favor of #9

@MicaiahReid MicaiahReid closed this Feb 5, 2025
@lgalabru lgalabru deleted the feat/get-account-info branch February 8, 2025 20:34
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.

2 participants