feat(cli): add contract diagnostic tool for direct on-chain inspection#765
feat(cli): add contract diagnostic tool for direct on-chain inspection#765
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an experimental, read-only contract diagnostics subtree to cartesi-rollups-cli that inspects Cartesi Rollups contracts directly via RPC (eth_call / eth_getLogs), plus supporting utilities and bindings.
Changes:
- Introduces
cartesi-rollups-cli contract ...with subcommands for application/consensus/inputbox/tournament/epoch/summary/output/commitment/match inspection. - Adds JSON-RPC error extraction + revert-selector matching utilities and reuses them in PRT tournament handling.
- Extends generated contract bindings to include
IAuthorityandIQuorum.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/ethutil/rpcerror.go | Adds JSON-RPC error info extraction and selector-matching helpers. |
| pkg/contracts/iquorum/iquorum.go | New generated Go binding for IQuorum. |
| pkg/contracts/iauthority/iauthority.go | New generated Go binding for IAuthority. |
| pkg/contracts/generate/main.go | Updates binding generator to include IAuthority and IQuorum. |
| internal/prt/util.go | Re-exports JSON-RPC error helpers from pkg/ethutil for backward compatibility. |
| internal/prt/itournament_adapter.go | Uses shared JSON-RPC error helpers and selector matching for “no winner” revert detection. |
| cmd/cartesi-rollups-cli/root/root.go | Registers new contract command under the CLI root. |
| cmd/cartesi-rollups-cli/root/contract/contract.go | Implements contract parent command, shared RPC client setup, consensus detection, and common helpers. |
| cmd/cartesi-rollups-cli/root/contract/types.go | Defines JSON output types for all contract subcommands. |
| cmd/cartesi-rollups-cli/root/contract/app.go | Implements contract app (IApplication inspection + JSON/text output). |
| cmd/cartesi-rollups-cli/root/contract/consensus.go | Implements contract consensus (auto-detect Authority/Quorum/DaveConsensus). |
| cmd/cartesi-rollups-cli/root/contract/inputbox.go | Implements contract inputbox (discover + query InputBox). |
| cmd/cartesi-rollups-cli/root/contract/tournament.go | Implements contract tournament (tournament state, events, and optional tree traversal). |
| cmd/cartesi-rollups-cli/root/contract/epoch.go | Implements contract epoch (event-based epoch/claim history across consensus types). |
| cmd/cartesi-rollups-cli/root/contract/summary.go | Implements contract summary (parallel snapshot across app/consensus/inputbox/tournament). |
| cmd/cartesi-rollups-cli/root/contract/output.go | Implements contract output (output execution checks). |
| cmd/cartesi-rollups-cli/root/contract/commitment.go | Implements contract commitment (commitment state lookup in current tournament). |
| cmd/cartesi-rollups-cli/root/contract/match.go | Implements contract match (match state + commitment discovery via events). |
| cmd/cartesi-rollups-cli/root/contract/selectors.go | Defines selector constants and sentinel errors used by the tool. |
| cmd/cartesi-rollups-cli/root/contract/format.go | Adds formatting + text-output helper primitives. |
| cmd/cartesi-rollups-cli/root/contract/contract_test.go | Unit tests for shared helpers (safeUint64/parseBlockFlag/validateHash/consensusType). |
| cmd/cartesi-rollups-cli/root/contract/format_test.go | Unit tests for formatting and printer output. |
| cmd/cartesi-rollups-cli/root/contract/epoch_test.go | Unit tests for epoch history helpers (block range + merge). |
| cmd/cartesi-rollups-cli/root/contract/tournament_test.go | Unit tests for tournament event formatting and commitment registry resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
66f4738 to
8e20357
Compare
dc91e3e to
c0094d6
Compare
8e20357 to
ab963f0
Compare
|
Examples: Authority: |
|
|
Read-only CLI tool that queries Ethereum contracts directly via eth_call and eth_getLogs — no database required. Nine subcommands: summary, app, consensus, inputbox, tournament, epoch, output, commitment, match. Auto-discovers contract tree from application address, detects consensus type via ERC-165, uses FindTransitions for efficient event discovery, and supports --tree for recursive tournament traversal.
ab963f0 to
28c9c3c
Compare
| // parseBlockFlag parses the --block flag value into a *big.Int. | ||
| // Returns nil for "latest" (the caller resolves it via eth_blockNumber). | ||
| func parseBlockFlag(s string) (*big.Int, error) { | ||
| if s == "" || s == "latest" { |
There was a problem hiding this comment.
what about "finalized" and "safe", should it handle those as well?
| // Note: ClaimSubmitted has indexed topics (submitter, appContract). | ||
| // We cannot use appTopic here because it would filter on submitter (topic1), | ||
| // not appContract (topic2). Instead, fetch all and filter in Go. | ||
| subQ, qErr := buildEventFilterQuery( |
There was a problem hiding this comment.
I'm not sure I understood the restriction from the comment.
Won't nil, appContract for topics solve it?
FilterLogs & ChunkedFilterLogs support matching only the second index if I understood this comment correctly.
Read-only CLI tool that queries Ethereum contracts directly via eth_call
and eth_getLogs — no database required.
Nine subcommands: summary, app, consensus, inputbox, tournament, epoch,
output, commitment, match. Auto-discovers contract tree from application
address, detects consensus type via ERC-165, uses FindTransitions for
efficient event discovery, and supports --tree for recursive tournament
traversal.