Skip to content

Conversation

@tclemos
Copy link
Contributor

@tclemos tclemos commented Dec 29, 2025

closes https://github.com/0xPolygon/devtools/issues/479

Adds a new report command to generate comprehensive blockchain analysis reports for Ethereum-compatible chains. Supports JSON, HTML, and PDF output formats with statistics, visualizations, and performance optimizations.

Features

  • Multiple output formats: JSON, HTML and PDF
  • Comprehensive metrics: Block/transaction counts, gas usage patterns, unique addresses, base fee analysis
  • Top 10 analysis: Highest transaction/gas blocks, most used gas prices/limits
  • Performance optimizations:
    • Concurrent RPC requests (configurable, default: 10)
    • Rate limiting (default: 4 req/s)
    • Batch receipt fetching per block

Usage

JSON

polycli report --rpc-url http://localhost:8545 --start-block 1000 --end-block 2000

HTML

polycli report --rpc-url http://localhost:8545 --start-block 1000 --end-block 2000 --format html

PDF

polycli report --rpc-url http://localhost:8545 --start-block 1000 --end-block 2000 --format pdf -o report.pdf

@tclemos tclemos self-assigned this Dec 29, 2025
@tclemos tclemos changed the title Thiago/cmd report feat: add new report cmd Dec 29, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new report command to generate comprehensive blockchain analysis reports for Ethereum-compatible chains. The command fetches block and transaction data via RPC, calculates statistics, and outputs results in JSON, HTML, or PDF format with support for concurrent requests and rate limiting.

Key changes:

  • New report command with JSON/HTML/PDF output formats
  • Concurrent block fetching (configurable, default 10 workers) with rate limiting (default 4 req/s)
  • Comprehensive metrics including transaction counts, gas usage, unique addresses, and top-10 analyses
  • HTML visualizations with SVG charts and interactive tooltips
  • PDF generation using chromedp for headless browser rendering

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
go.mod / go.sum Added chromedp dependencies for PDF generation and viper v1.19.0 (moved from direct to indirect dependency) with related transitive dependency version adjustments
cmd/root.go Registered the new report command in the CLI
cmd/report/report.go Core implementation: flag validation, concurrent RPC fetching with rate limiting, block/transaction data processing, and output generation
cmd/report/types.go Data structures for report, summary statistics, block info, transaction info, and top-10 analyses
cmd/report/html.go HTML generation functions including stat cards, SVG line charts for transactions and gas usage, and top-10 tables
cmd/report/pdf.go PDF generation using chromedp to render HTML to PDF with page settings
cmd/report/template.html HTML template with embedded CSS for styling and JavaScript for chart tooltips
cmd/report/usage.md Documentation covering features, usage examples, and report contents

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replace time.After() with time.NewTimer() in the PDF generation sleep
logic to prevent goroutine leaks when the context is cancelled before
the timer expires. The timer is now properly stopped via defer.
Restructure the error message to put context before the wrapped error
(%w) instead of after it. The previous format with newlines after %w
would produce malformed output. The new single-line format properly
wraps the error while providing clear context about Chrome/Chromium
requirements.
Move github.com/spf13/viper from a separate require block back to the
main require block where it belongs. This restores consistency with the
go.mod structure in the main branch. The viper dependency is a direct
dependency used for configuration management and should be grouped with
other direct dependencies like cobra and pflag.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +220 to +222
for blockNum := report.StartBlock; blockNum <= report.EndBlock; blockNum++ {
blockChan <- blockNum
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

Potential infinite loop if report.EndBlock is math.MaxUint64. The loop condition checks blockNum less than or equal to report.EndBlock, so if report.EndBlock is math.MaxUint64, the loop will continue indefinitely when blockNum wraps around after incrementing from math.MaxUint64. Consider validating that the block range is reasonable before entering this loop, or add overflow checking to the loop increment.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +30
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

// Allocate a new browser context
ctx, cancelChrome := chromedp.NewContext(ctx)
defer cancelChrome()

var buf []byte
err := chromedp.Run(ctx,
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

Context shadowing issue: the variable 'ctx' is reassigned on line 26, which shadows the parent context created on line 22. This means the timeout context from line 22 is no longer directly accessible. While the new context is derived from the timeout context (so the timeout still applies), this pattern can be confusing and error-prone. Consider using different variable names to make the relationship clearer, such as 'timeoutCtx' and 'chromeCtx'.

Suggested change
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Allocate a new browser context
ctx, cancelChrome := chromedp.NewContext(ctx)
defer cancelChrome()
var buf []byte
err := chromedp.Run(ctx,
timeoutCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Allocate a new browser context derived from the timeout context
chromeCtx, cancelChrome := chromedp.NewContext(timeoutCtx)
defer cancelChrome()
var buf []byte
err := chromedp.Run(chromeCtx,

Copilot uses AI. Check for mistakes.
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