Add support for debug comparing mismatching blocks when verification fails#8535
Add support for debug comparing mismatching blocks when verification fails#8535turbolent wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughChangesThe verifier now reports mismatched block IDs. Mismatch comparison workflow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant VerifyExecutionResult
participant Verifier
participant compare_debug_tx.Run
participant debug-tx
VerifyExecutionResult->>Verifier: verify blocks
Verifier-->>VerifyExecutionResult: return mismatched block IDs
VerifyExecutionResult->>compare_debug_tx.Run: pass comparison config and block IDs
compare_debug_tx.Run->>debug-tx: execute per-block comparisons
debug-tx-->>compare_debug_tx.Run: return results and traces
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
@zhangchiqing PTAL 🙏 |
…ebug-tx-on-verification-mismatch
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/util/cmd/compare-debug-tx/cmd.go`:
- Around line 203-213: Update the result and trace diff condition in Run to also
execute when cfg.BlockIDs is empty, covering the tx-only invocation handled by
runAllBlocks. Preserve the existing single-block behavior and continue using
result1, result2, trace1, and trace2 for the diff output.
- Around line 145-153: Update the conditional around resolveBlockChain in the
command argument handling to check whether --block-id was explicitly provided,
rather than whether flagBlockCount is greater than zero. Preserve validation
requiring --block-count with --block-id and allow the default positional
transaction-ID flow to leave cfg.BlockIDs empty for runAllBlocks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8711d7b3-c19f-49ba-ae91-a7a795f90248
📒 Files selected for processing (4)
cmd/util/cmd/compare-debug-tx/cmd.gocmd/util/cmd/verify_execution_result/cmd.goengine/verification/verifier/verifiers.goengine/verification/verifier/verifiers_test.go
| } else if flagBlockCount > 0 { | ||
| if flagBlockID == "" { | ||
| log.Fatal().Msg("--block-count requires --block-id to be set") | ||
| } | ||
| if len(args) > 0 { | ||
| log.Fatal().Msg("--block-count cannot be used with positional transaction IDs") | ||
| } | ||
| blockIDs = resolveBlockChain(flagBlockID, flagBlockCount) | ||
| cfg.BlockIDs = resolveBlockChain(flagAccessAddress, flagBlockID, flagBlockCount) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Default invocation (no --block-id/--block-ids) always fatals.
flagBlockCount defaults to 1, so flagBlockCount > 0 is always true when --block-ids isn't set — even if the user never touched --block-id/--block-count at all. This means the plain/basic usage (compare-debug-tx txID1 txID2 --branch1 ... --branch2 ...) always hits log.Fatal().Msg("--block-count requires --block-id to be set"), even though runAllBlocks explicitly supports and expects this tx-only mode when cfg.BlockIDs is empty.
The gate should be on whether --block-id was actually set, not on the always-nonzero default count.
🐛 Proposed fix
- } else if flagBlockCount > 0 {
- if flagBlockID == "" {
- log.Fatal().Msg("--block-count requires --block-id to be set")
- }
+ } else if flagBlockID != "" {
if len(args) > 0 {
- log.Fatal().Msg("--block-count cannot be used with positional transaction IDs")
+ log.Fatal().Msg("--block-id cannot be used with positional transaction IDs")
}
cfg.BlockIDs = resolveBlockChain(flagAccessAddress, flagBlockID, flagBlockCount)
+ } else if flagBlockCount > 1 {
+ log.Fatal().Msg("--block-count > 1 requires --block-id to be set")
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| } else if flagBlockCount > 0 { | |
| if flagBlockID == "" { | |
| log.Fatal().Msg("--block-count requires --block-id to be set") | |
| } | |
| if len(args) > 0 { | |
| log.Fatal().Msg("--block-count cannot be used with positional transaction IDs") | |
| } | |
| blockIDs = resolveBlockChain(flagBlockID, flagBlockCount) | |
| cfg.BlockIDs = resolveBlockChain(flagAccessAddress, flagBlockID, flagBlockCount) | |
| } | |
| } else if flagBlockID != "" { | |
| if len(args) > 0 { | |
| log.Fatal().Msg("--block-id cannot be used with positional transaction IDs") | |
| } | |
| cfg.BlockIDs = resolveBlockChain(flagAccessAddress, flagBlockID, flagBlockCount) | |
| } else if flagBlockCount > 1 { | |
| log.Fatal().Msg("--block-count > 1 requires --block-id to be set") | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/util/cmd/compare-debug-tx/cmd.go` around lines 145 - 153, Update the
conditional around resolveBlockChain in the command argument handling to check
whether --block-id was explicitly provided, rather than whether flagBlockCount
is greater than zero. Preserve validation requiring --block-count with
--block-id and allow the default positional transaction-ID flow to leave
cfg.BlockIDs empty for runAllBlocks.
| if len(cfg.BlockIDs) == 1 { | ||
| fmt.Printf("=== Result diff (%s vs %s) ===\n", cfg.Branch1, cfg.Branch2) | ||
| diffFiles(result1.Name(), result2.Name(), cfg.Branch1, cfg.Branch2) | ||
|
|
||
| if flagShowTraceDiff { | ||
| fmt.Printf("=== Trace diff (%s vs %s) ===\n", flagBranch1, flagBranch2) | ||
| diffFiles(trace1.Name(), trace2.Name(), flagBranch1, flagBranch2) | ||
| if cfg.ShowTraceDiff { | ||
| fmt.Printf("=== Trace diff (%s vs %s) ===\n", cfg.Branch1, cfg.Branch2) | ||
| diffFiles(trace1.Name(), trace2.Name(), cfg.Branch1, cfg.Branch2) | ||
| } | ||
| } | ||
|
|
||
| printMismatchStats(blockIDs, perBlock1, perBlock2) | ||
| printMismatchStats(cfg.BlockIDs, perBlock1, perBlock2) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Result/trace diff never prints for the default (no-block) invocation.
runAllBlocks treats len(cfg.BlockIDs) == 0 as a valid single-invocation mode driven by cfg.TxIDs (lines 240-245), but Run only prints the result/trace diff when len(cfg.BlockIDs) == 1. For the plain tx-only mode, cfg.BlockIDs is empty, so this core diff output — the tool's primary purpose — is silently skipped, even though result1/result2 were populated. Only printMismatchStats (which produces "0/0" summaries in this case) runs.
🐛 Proposed fix
- if len(cfg.BlockIDs) == 1 {
+ if len(cfg.BlockIDs) <= 1 {
fmt.Printf("=== Result diff (%s vs %s) ===\n", cfg.Branch1, cfg.Branch2)
diffFiles(result1.Name(), result2.Name(), cfg.Branch1, cfg.Branch2)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if len(cfg.BlockIDs) == 1 { | |
| fmt.Printf("=== Result diff (%s vs %s) ===\n", cfg.Branch1, cfg.Branch2) | |
| diffFiles(result1.Name(), result2.Name(), cfg.Branch1, cfg.Branch2) | |
| if flagShowTraceDiff { | |
| fmt.Printf("=== Trace diff (%s vs %s) ===\n", flagBranch1, flagBranch2) | |
| diffFiles(trace1.Name(), trace2.Name(), flagBranch1, flagBranch2) | |
| if cfg.ShowTraceDiff { | |
| fmt.Printf("=== Trace diff (%s vs %s) ===\n", cfg.Branch1, cfg.Branch2) | |
| diffFiles(trace1.Name(), trace2.Name(), cfg.Branch1, cfg.Branch2) | |
| } | |
| } | |
| printMismatchStats(blockIDs, perBlock1, perBlock2) | |
| printMismatchStats(cfg.BlockIDs, perBlock1, perBlock2) | |
| if len(cfg.BlockIDs) <= 1 { | |
| fmt.Printf("=== Result diff (%s vs %s) ===\n", cfg.Branch1, cfg.Branch2) | |
| diffFiles(result1.Name(), result2.Name(), cfg.Branch1, cfg.Branch2) | |
| if cfg.ShowTraceDiff { | |
| fmt.Printf("=== Trace diff (%s vs %s) ===\n", cfg.Branch1, cfg.Branch2) | |
| diffFiles(trace1.Name(), trace2.Name(), cfg.Branch1, cfg.Branch2) | |
| } | |
| } | |
| printMismatchStats(cfg.BlockIDs, perBlock1, perBlock2) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/util/cmd/compare-debug-tx/cmd.go` around lines 203 - 213, Update the
result and trace diff condition in Run to also execute when cfg.BlockIDs is
empty, covering the tx-only invocation handled by runAllBlocks. Preserve the
existing single-block behavior and continue using result1, result2, trace1, and
trace2 for the diff output.
Depends on #8534
When chunk verification fails, optionally allow running the remote-debugger based comparison for the blocks to automatically get further information (e.g. read/written registers, events, traces, etc.) which helps with figuring out why the chunk did not match – the current error only states there is a mismatch in the final state commitment hash or events hash
Summary by CodeRabbit
New Features
Bug Fixes
Tests