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

refactor: simplify account retrieval #2141

Merged
merged 4 commits into from
Jan 6, 2025

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Jan 4, 2025

Purpose / Abstract

Simplifies the account retrieval operation in nibid q evm account.

Summary by CodeRabbit

Release Notes

  • Refactor

    • Simplified account retrieval operation for nibid q evm account command
    • Updated error handling for nonexistent Ethereum accounts
    • Improved method visibility and address conversion logic in EVM keeper
  • Bug Fixes

    • Enhanced account not found error messaging
    • Removed redundant account retrieval method
  • Documentation

    • Updated comments for clarity in account-related methods

@k-yang k-yang requested a review from a team as a code owner January 4, 2025 16:12
Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

Walkthrough

The pull request introduces changes to the Nibiru EVM module's account retrieval mechanism. The modifications focus on simplifying the account retrieval operation in the nibid q evm account command. Key changes include renaming the GetAccountWithoutBalance method to getAccountWithoutBalance, making it private, and updating the error handling for nonexistent accounts. The changes aim to improve the clarity and consistency of account-related operations within the EVM module.

Changes

File Change Summary
CHANGELOG.md Added entry for PR #2141 refactoring account retrieval
x/evm/keeper/grpc_query.go - Updated EthAccount method to use getAccountWithoutBalance
- Added explicit error handling for nonexistent accounts
x/evm/keeper/grpc_query_test.go - Modified test cases to expect nil for nonexistent accounts
- Updated error message handling
x/evm/keeper/statedb.go - Renamed GetAccountWithoutBalance to getAccountWithoutBalance
- Removed GetAccountOrEmpty method
- Updated address conversion logic

Sequence Diagram

sequenceDiagram
    participant Client
    participant EVMKeeper
    participant StateDB
    Client->>EVMKeeper: Query EVM Account
    EVMKeeper->>StateDB: getAccountWithoutBalance()
    alt Account Exists
        StateDB-->>EVMKeeper: Return Account
        EVMKeeper-->>Client: Return Account Details
    else Account Not Found
        StateDB-->>EVMKeeper: Return nil
        EVMKeeper-->>Client: Return "account not found" error
    end
Loading

Poem

🐰 A Rabbit's Refactor Rhyme 🔧

In Nibiru's EVM, a change so bright,
Accounts now dance with clearer might.
No more empty returns, no more delay,
Just crisp error messages to light the way!
A refactor's tale, both simple and clean. 🌟


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

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.08%. Comparing base (1ae53e4) to head (df0c3bf).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2141      +/-   ##
==========================================
- Coverage   65.10%   65.08%   -0.03%     
==========================================
  Files         274      274              
  Lines       21732    21725       -7     
==========================================
- Hits        14148    14139       -9     
- Misses       6610     6613       +3     
+ Partials      974      973       -1     
Files with missing lines Coverage Δ
x/evm/keeper/grpc_query.go 79.73% <100.00%> (+0.11%) ⬆️
x/evm/keeper/statedb.go 50.45% <100.00%> (-4.10%) ⬇️

... and 1 file with indirect coverage changes

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

🧹 Nitpick comments (2)
x/evm/keeper/statedb.go (1)

187-190: Refine doc-comment for private function.

The doc-comment is slightly terse: “load nonce and codehash without balance.” Consider clarifying that this function:

  1. Queries the account from the accountKeeper.
  2. Deems the account nonexistent (i.e., returns nil) when not found or of the wrong type.
x/evm/keeper/grpc_query.go (1)

211-211: Check for contractness outside the method.

Retrieving the code via k.getAccountWithoutBalance (which returns nil if not found) is consistent with the new approach of streamlined account checking. Ensure external logic verifies whether the account is nil before referencing its fields.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 86d6b3f and 32b62f1.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • x/evm/keeper/grpc_query.go (2 hunks)
  • x/evm/keeper/grpc_query_test.go (2 hunks)
  • x/evm/keeper/statedb.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: integration-tests
🔇 Additional comments (7)
x/evm/keeper/statedb.go (1)

28-28: Ensure calling code gracefully handles nil return.

Changing from a publicly exposed function to a private helper is consistent with the intent to simplify the account retrieval logic. However, confirm downstream usage (like GetAccount) properly checks for nil returns to avoid potential nil-pointer references.

x/evm/keeper/grpc_query.go (1)

67-70: Great approach for nonexistent accounts.

Raising an explicit error instead of returning a silent, empty account clarifies the gRPC contract. This helps users differentiate between genuinely empty data versus a non-existent account scenario.

x/evm/keeper/grpc_query_test.go (4)

147-147: Test coverage for null response.

It's good that you updated the test to expect nil for a non-existent address. This addresses the new error condition thoroughly.


150-150: Align test message with the code.

The new error string "account not found for" is consistent with the code changes in grpc_query.go. This ensures robust test coverage for the not-found scenario.


159-159: Duplicate scenario for nonexistent account.

Testing another input scenario for an unknown address further improves coverage and ensures consistent error messages across different input formats (hex vs. bech32).


162-162: Consistent with updated logic.

This line ensures our test suite enforces the expectation that nonexistent accounts always trigger an error. No concerns here.

CHANGELOG.md (1)

57-57: Accurate changelog entry.

Tying PR #2141 to the actual code changes in the EVM account retrieval logic is precise. The mention highlights the improvement to the nibid q evm account command, which is consistent with the rest of the changes.

@Unique-Divine Unique-Divine merged commit 8cd4ceb into main Jan 6, 2025
13 of 14 checks passed
@Unique-Divine Unique-Divine deleted the fix/evm/query-evm-account-cli branch January 6, 2025 07:03
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.

3 participants