Skip to content

Conversation

Thegaram
Copy link

@Thegaram Thegaram commented Apr 30, 2025

1. Purpose or design rationale of this PR

Import debug_dbAncient, debug_dbAncients, debug_dbGet from upstream, enabled in RPC and console.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • feat: A new feature

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change

Summary by CodeRabbit

  • New Features
    • Introduced new debug methods for database access via the API and web3 interface, allowing retrieval of raw database values and ancient data.
  • Chores
    • Updated the patch version to 41.

Copy link

coderabbitai bot commented Apr 30, 2025

Walkthrough

This update introduces new database access functionality to the Ethereum client’s debug API. A utility function for parsing hex or string input is added. Three new methods are implemented in the internal debug API for retrieving raw database values, ancient data, and ancient data counts. Corresponding RPC endpoints are exposed in the web3.js extension to allow remote access to these methods. The software patch version is incremented to reflect the new changes.

Changes

File(s) Change Summary
common/bytes.go Added ParseHexOrString function to parse input as hex or raw string bytes.
internal/ethapi/dbapi.go Introduced new methods to PublicDebugAPI: DbGet, DbAncient, and DbAncients for database access.
internal/web3ext/web3ext.go Added new web3.js extension methods: dbGet, dbAncient, and dbAncients in the debug namespace.
params/version.go Incremented VersionPatch constant from 40 to 41.

Sequence Diagram(s)

sequenceDiagram
    participant Web3.js
    participant RPC Server
    participant PublicDebugAPI
    participant ChainDatabase

    Web3.js->>RPC Server: debug_dbGet(key)
    RPC Server->>PublicDebugAPI: DbGet(key)
    PublicDebugAPI->>ChainDatabase: Get(key as bytes)
    ChainDatabase-->>PublicDebugAPI: value
    PublicDebugAPI-->>RPC Server: hex-encoded value
    RPC Server-->>Web3.js: hex-encoded value

    Web3.js->>RPC Server: debug_dbAncient(kind, number)
    RPC Server->>PublicDebugAPI: DbAncient(kind, number)
    PublicDebugAPI->>ChainDatabase: Ancient(kind, number)
    ChainDatabase-->>PublicDebugAPI: ancient value
    PublicDebugAPI-->>RPC Server: hex-encoded ancient value
    RPC Server-->>Web3.js: hex-encoded ancient value

    Web3.js->>RPC Server: debug_dbAncients()
    RPC Server->>PublicDebugAPI: DbAncients()
    PublicDebugAPI->>ChainDatabase: Ancients()
    ChainDatabase-->>PublicDebugAPI: count
    PublicDebugAPI-->>RPC Server: count
    RPC Server-->>Web3.js: count
Loading

Suggested labels

bump-version

Suggested reviewers

  • colinlyguo
  • omerfirmak

Poem

A nibble of bytes, a hop through the chain,
Debugging made easy, no need to explain.
New methods appear, in web3 they dwell,
Ancient secrets unlocked, with a version to tell.
Patch forty-one, let the rabbits rejoice—
For every new feature, we all have a choice!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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: 1

🧹 Nitpick comments (1)
internal/web3ext/web3ext.go (1)

485-499: New database debug API methods look good

The three new methods are properly added to the debug namespace with the correct parameter counts:

  • dbGet: 1 parameter (key)
  • dbAncient: 2 parameters (kind, number)
  • dbAncients: 0 parameters

These methods provide a consistent interface for accessing raw database data via RPC or console.

One consideration: you might want to add input formatters for better type handling, especially for the dbAncient method which expects a string and a number.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eaf06e3 and ccdaebd.

📒 Files selected for processing (4)
  • common/bytes.go (2 hunks)
  • internal/ethapi/dbapi.go (1 hunks)
  • internal/web3ext/web3ext.go (1 hunks)
  • params/version.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
common/bytes.go (1)
common/hexutil/hexutil.go (1)
  • ErrMissingPrefix (46-46)
internal/ethapi/dbapi.go (1)
common/bytes.go (1)
  • ParseHexOrString (99-105)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
common/bytes.go (1)

98-105: Looks good: New utility function for flexible input parsing

This function adds a convenient way to handle inputs that could be either hex-encoded or raw strings. It properly uses errors.Is() to check for the specific error type and has a clear comment explaining its behavior.

The fallback to returning raw bytes when the hex prefix is missing will be useful for the debug database API methods, making them more user-friendly by accepting either format.

params/version.go (1)

27-27: Version increment for the new feature

Incrementing the patch version is appropriate for this non-breaking addition of new debug API methods.

internal/ethapi/dbapi.go (3)

24-31: DbGet implementation is solid

The method correctly uses the new ParseHexOrString utility to handle both hex-encoded and raw string keys, then forwards the request to the chain database.

The error handling is appropriate - if parsing fails, it returns the error, otherwise it returns the database's response.


33-37: DbAncient implementation looks good

This method provides a straightforward wrapper around the chain database's Ancient method, allowing access to immutable data stored in append-only files.


39-43: DbAncients implementation is correct

Simple and direct wrapper around the database's Ancients method to get the count of ancient items.

@Thegaram Thegaram merged commit a4109fd into develop Apr 30, 2025
14 checks passed
@Thegaram Thegaram deleted the feat-add-debug-db-methods branch April 30, 2025 11:55
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