-
Notifications
You must be signed in to change notification settings - Fork 283
feat: add debug_db* methods #1177
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
Conversation
WalkthroughThis 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
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
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 goodThe 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 parametersThese 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
📒 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 parsingThis 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 featureIncrementing 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 solidThe 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 goodThis 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 correctSimple and direct wrapper around the database's
Ancients
method to get the count of ancient items.
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:
3. Deployment tag versioning
Has the version in
params/version.go
been updated?4. Breaking change label
Does this PR have the
breaking-change
label?Summary by CodeRabbit