Add support for debug trace APIs#291
Conversation
WalkthroughThe recent changes introduce a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Bootstrap
participant DebugAPI
participant Storage
participant Logger
User->>Bootstrap: Start(trace=true)
Bootstrap->>Bootstrap: Initialize components
alt trace enabled
Bootstrap->>DebugAPI: Create DebugAPI instance
DebugAPI->>Storage: Initialize with TraceIndexer and BlockIndexer
DebugAPI->>Logger: Initialize with Logger
end
Bootstrap->>DebugAPI: Add DebugAPI to supported APIs
User->>DebugAPI: TraceTransaction(hash)
DebugAPI->>Storage: Fetch transaction details
Storage->>DebugAPI: Return transaction details
DebugAPI->>User: Return TraceTransaction result
Assessment against linked issues
Poem
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? 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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- api/api.go (2 hunks)
- api/debug.go (1 hunks)
- bootstrap/bootstrap.go (3 hunks)
Additional comments not posted (5)
api/debug.go (2)
15-19: TheDebugAPIstruct is well-defined with clear responsibilities for each field.
21-27: The constructor forDebugAPIis correctly implemented and initializes all fields properly.bootstrap/bootstrap.go (2)
106-106: The integration of thetraceparameter in thestartServerandstartIngestionfunctions is correctly implemented. Ensure that thetraceparameter is properly passed and used in all relevant contexts.Also applies to: 251-251
336-340: The conditional creation ofdebugAPIbased on thecfg.TracesEnabledconfiguration is a good practice. It ensures that resources are allocated only when necessary.api/api.go (1)
Line range hint
29-63: The update to theSupportedAPIsfunction to include theDebugAPIis correctly implemented. Ensure that theDebugAPIis only appended when it is notnil, which is handled well here.
| // TraceTransaction will return a debug execution trace of a transaction if it exists, | ||
| // currently we only support CALL traces, so the config is ignored. | ||
| func (d *DebugAPI) TraceTransaction( | ||
| ctx context.Context, | ||
| hash gethCommon.Hash, | ||
| _ *tracers.TraceConfig, | ||
| ) (json.RawMessage, error) { | ||
| res, err := d.tracer.GetTransaction(hash) | ||
| if err != nil { | ||
| return handleError[json.RawMessage](d.logger, err) | ||
| } | ||
| return res, nil | ||
| } |
There was a problem hiding this comment.
Ensure proper error handling and logging in TraceTransaction. Consider adding more detailed logs for debugging purposes.
| func (d *DebugAPI) TraceBlockByNumber( | ||
| ctx context.Context, | ||
| number rpc.BlockNumber, | ||
| _ *tracers.TraceConfig, | ||
| ) ([]json.RawMessage, error) { | ||
| block, err := d.blocks.GetByHeight(uint64(number.Int64())) | ||
| if err != nil { | ||
| return handleError[[]json.RawMessage](d.logger, err) | ||
| } | ||
|
|
||
| results := make([]json.RawMessage, len(block.TransactionHashes)) | ||
| for i, h := range block.TransactionHashes { | ||
| results[i], err = d.TraceTransaction(ctx, h, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| return results, nil | ||
| } | ||
|
|
||
| func (d *DebugAPI) TraceBlockByHash( | ||
| ctx context.Context, | ||
| hash gethCommon.Hash, | ||
| _ *tracers.TraceConfig, | ||
| ) ([]json.RawMessage, error) { | ||
| block, err := d.blocks.GetByID(hash) | ||
| if err != nil { | ||
| return handleError[[]json.RawMessage](d.logger, err) | ||
| } | ||
|
|
||
| results := make([]json.RawMessage, len(block.TransactionHashes)) | ||
| for i, h := range block.TransactionHashes { | ||
| results[i], err = d.TraceTransaction(ctx, h, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| return results, nil | ||
| } |
There was a problem hiding this comment.
Both TraceBlockByNumber and TraceBlockByHash methods are implemented consistently. Ensure that the error handling is robust and consider optimizing the loop for performance.
Closes: #251
Description
This PR exposes APIs for debug tracing functionality. It adds 3 API methods:
debug_traceTransactionwhich returns transaction call trace by IDdebug_traceBlockByNumberwhich accumulates transaction call traces by block numberdebug_traceBlockByHashwhich accumulates transaction call traces by block hashFor contributor use:
masterbranchFiles changedin the Github PR explorerSummary by CodeRabbit
New Features
Enhancements