Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Util] Improve compare-debug-tx#8512

Merged
turbolent merged 2 commits into
masteronflow/flow-go:masterfrom
bastian/improve-compare-debug-txonflow/flow-go:bastian/improve-compare-debug-txCopy head branch name to clipboard
Apr 8, 2026
Merged

[Util] Improve compare-debug-tx#8512
turbolent merged 2 commits into
masteronflow/flow-go:masterfrom
bastian/improve-compare-debug-txonflow/flow-go:bastian/improve-compare-debug-txCopy head branch name to clipboard

Conversation

@turbolent

@turbolent turbolent commented Apr 3, 2026

Copy link
Copy Markdown
Member

Show differences per TX

Summary by CodeRabbit

  • New Features

    • New --show-trace-diff CLI option to optionally include trace differences.
    • Result mismatch statistics showing per-block and per-transaction mismatch counts.
  • Changes

    • --block-count behavior updated: block ID resolution now occurs when value is greater than 0.
    • Diff output is now printed only when processing a single block (trace diff shown only if enabled).

@turbolent
turbolent requested review from a team April 3, 2026 16:17
@turbolent
turbolent requested a review from a team as a code owner April 3, 2026 16:17
@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 55f7c1a.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9abe9e1d-30de-4b9e-b3c5-cf2e768fb2f3

📥 Commits

Reviewing files that changed from the base of the PR and between 328e1e8 and 55f7c1a.

📒 Files selected for processing (1)
  • cmd/util/cmd/compare-debug-tx/cmd.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/util/cmd/compare-debug-tx/cmd.go

📝 Walkthrough

Walkthrough

Added a --show-trace-diff CLI flag, changed block ID resolution condition for --block-count, refactored per-block temp file handling to return files to the caller, and added per-block result/transaction mismatch statistics and conditional diff printing based on block count.

Changes

Cohort / File(s) Summary
CLI flags & core logic
cmd/util/cmd/compare-debug-tx/cmd.go
Added --show-trace-diff flag; changed block ID resolution to run when flagBlockCount > 0.
Temp file handling & cleanup
cmd/util/cmd/compare-debug-tx/cmd.go
Refactored runAllBlocks to return []perBlockFiles; introduced perBlockFiles type and cleanupPerBlockFiles for caller-managed cleanup.
Diff output & statistics
cmd/util/cmd/compare-debug-tx/cmd.go
Conditionalized result/trace diff printing (prints diffs when a single block ID); added per-block mismatch stats and helper funcs printMismatchStats, readFileFromStart, splitTxSections that compare transaction sections across branches.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • peterargue
  • zhangchiqing

Poem

🐇 I hopped through lines of debug light,

Temp files tucked in folders tight,
Traces compared beneath the moon,
Mismatches counted, numbers tune,
A tiny hop — the diffs take flight ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title '[Util] Improve compare-debug-tx' is generic and vague. While it references the correct utility component, it doesn't clearly describe the specific improvements made (per-TX diff visualization, trace diff flag, mismatch statistics) and would not help reviewers understand the main changes from history. Refactor the title to be more specific about the key improvements, such as '[Util] Add per-TX diff output and trace comparison to compare-debug-tx' or '[Util] Enhance compare-debug-tx with per-transaction diffs and mismatch statistics'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bastian/improve-compare-debug-tx

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

codecov-commenter commented Apr 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 96 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/util/cmd/compare-debug-tx/cmd.go 0.00% 96 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/util/cmd/compare-debug-tx/cmd.go (1)

82-92: ⚠️ Potential issue | 🔴 Critical

Default --block-count=1 now forces block mode.

Line 84 now enters the block-only flow on the default value, so a normal compare-debug-tx <tx-id...> invocation hits the --block-id / positional-args fatals. That regresses the existing tx-ID workflow and no longer matches the Line 65 help text.

💡 Suggested fix
-	if flagBlockCount > 0 {
+	if flagBlockCount < 1 {
+		log.Fatal().Msg("--block-count must be >= 1")
+	}
+	if flagBlockID != "" || flagBlockCount > 1 {
 		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)
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/util/cmd/compare-debug-tx/cmd.go` around lines 82 - 92, The code treats
flagBlockCount > 0 as entering block-only mode but the flag's default is 1, so
normal positional tx-ID usage is broken; update the flag definition for
flagBlockCount to default to 0 (so block mode only when user explicitly passes
--block-count > 0) or, alternatively, change the conditional to only trigger
when the flag was explicitly set (e.g., detect and check that flagBlockCount !=
1 if you intend 1 to mean "unset"); adjust the flag declaration where
flagBlockCount is defined and ensure the conditional around
resolveBlockChain(flagBlockID, flagBlockCount) continues to use flagBlockCount
for the resolved logic and that error messages referencing
flagBlockID/positional args remain valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/util/cmd/compare-debug-tx/cmd.go`:
- Around line 368-387: The loop currently compares sections1[j] vs sections2[j]
by slice index, which misattributes mismatches when sections are inserted or
removed; instead parse the transaction ID from each section (the "# ID:" line
returned by splitTxSections) and build maps id->section for both branches (use
the same ID parsing logic for both), then iterate the union of IDs to compare
corresponding sections by ID and increment txsWithMismatch and blockTxMismatches
for IDs whose byte content differs; update txCount/totalTxs to be the size of
the union and keep existing variables (sections1, sections2, splitTxSections,
blockTxMismatches, txsWithMismatch, totalTxs) while replacing the index-based
loop with an ID-keyed comparison.
- Around line 134-145: The code only prints diffs when len(blockIDs)==1, which
skips diffs for the positional-TX path where blockIDs is empty and leads to a
meaningless 0/0 stats output; update the logic so diffFiles(result1.Name(),
result2.Name(), flagBranch1, flagBranch2) (and the trace diff guarded by
flagShowTraceDiff using trace1/trace2) are emitted for both the single-block
case and the positional-TX case (i.e., when len(blockIDs)==1 ||
len(blockIDs)==0), and also guard the printMismatchStats(perBlock1, perBlock2)
call so it is only invoked when there are actual per-block entries (e.g.,
len(blockIDs)>0 or non-empty perBlock1/perBlock2) to avoid the 0/0 summary.

---

Outside diff comments:
In `@cmd/util/cmd/compare-debug-tx/cmd.go`:
- Around line 82-92: The code treats flagBlockCount > 0 as entering block-only
mode but the flag's default is 1, so normal positional tx-ID usage is broken;
update the flag definition for flagBlockCount to default to 0 (so block mode
only when user explicitly passes --block-count > 0) or, alternatively, change
the conditional to only trigger when the flag was explicitly set (e.g., detect
and check that flagBlockCount != 1 if you intend 1 to mean "unset"); adjust the
flag declaration where flagBlockCount is defined and ensure the conditional
around resolveBlockChain(flagBlockID, flagBlockCount) continues to use
flagBlockCount for the resolved logic and that error messages referencing
flagBlockID/positional args remain valid.
🪄 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: 3b171796-937e-4e68-bef7-81bf5e4d078b

📥 Commits

Reviewing files that changed from the base of the PR and between 376e669 and 328e1e8.

📒 Files selected for processing (1)
  • cmd/util/cmd/compare-debug-tx/cmd.go

Comment on lines +134 to +145
if len(blockIDs) == 1 {
fmt.Printf("=== Result diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(result1.Name(), result2.Name(), flagBranch1, flagBranch2)

if flagShowTraceDiff {
fmt.Printf("=== Trace diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(trace1.Name(), trace2.Name(), flagBranch1, flagBranch2)
}
}

fmt.Printf("=== Result diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(result1.Name(), result2.Name(), flagBranch1, flagBranch2)
printMismatchStats(blockIDs, perBlock1, perBlock2)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Single-invocation TX comparisons stop showing diffs.

This branch only emits diffs when exactly one block ID was resolved. In the positional-TX path blockIDs is empty, so the normal result diff disappears, --show-trace-diff becomes a no-op, and the unconditional printMismatchStats call falls through to a meaningless 0/0 block summary.

💡 Suggested fix
-	if len(blockIDs) == 1 {
+	if len(blockIDs) <= 1 {
 		fmt.Printf("=== Result diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
 		diffFiles(result1.Name(), result2.Name(), flagBranch1, flagBranch2)
 
 		if flagShowTraceDiff {
 			fmt.Printf("=== Trace diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
 			diffFiles(trace1.Name(), trace2.Name(), flagBranch1, flagBranch2)
 		}
 	}
 
-	printMismatchStats(blockIDs, perBlock1, perBlock2)
+	if len(blockIDs) > 0 {
+		printMismatchStats(blockIDs, perBlock1, perBlock2)
+	}
📝 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.

Suggested change
if len(blockIDs) == 1 {
fmt.Printf("=== Result diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(result1.Name(), result2.Name(), flagBranch1, flagBranch2)
if flagShowTraceDiff {
fmt.Printf("=== Trace diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(trace1.Name(), trace2.Name(), flagBranch1, flagBranch2)
}
}
fmt.Printf("=== Result diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(result1.Name(), result2.Name(), flagBranch1, flagBranch2)
printMismatchStats(blockIDs, perBlock1, perBlock2)
}
if len(blockIDs) <= 1 {
fmt.Printf("=== Result diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(result1.Name(), result2.Name(), flagBranch1, flagBranch2)
if flagShowTraceDiff {
fmt.Printf("=== Trace diff (%s vs %s) ===\n", flagBranch1, flagBranch2)
diffFiles(trace1.Name(), trace2.Name(), flagBranch1, flagBranch2)
}
}
if len(blockIDs) > 0 {
printMismatchStats(blockIDs, perBlock1, perBlock2)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/util/cmd/compare-debug-tx/cmd.go` around lines 134 - 145, The code only
prints diffs when len(blockIDs)==1, which skips diffs for the positional-TX path
where blockIDs is empty and leads to a meaningless 0/0 stats output; update the
logic so diffFiles(result1.Name(), result2.Name(), flagBranch1, flagBranch2)
(and the trace diff guarded by flagShowTraceDiff using trace1/trace2) are
emitted for both the single-block case and the positional-TX case (i.e., when
len(blockIDs)==1 || len(blockIDs)==0), and also guard the
printMismatchStats(perBlock1, perBlock2) call so it is only invoked when there
are actual per-block entries (e.g., len(blockIDs)>0 or non-empty
perBlock1/perBlock2) to avoid the 0/0 summary.

Comment thread cmd/util/cmd/compare-debug-tx/cmd.go
Comment on lines +368 to +387
sections1 := splitTxSections(data1)
sections2 := splitTxSections(data2)

blockTxMismatches := 0
txCount := max(len(sections1), len(sections2))
totalTxs += txCount

for j := range txCount {
var s1, s2 []byte
if j < len(sections1) {
s1 = sections1[j]
}
if j < len(sections2) {
s2 = sections2[j]
}
if !bytes.Equal(s1, s2) {
txsWithMismatch++
blockTxMismatches++
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Compare mismatch sections by transaction ID, not slice index.

splitTxSections only gives this loop ordered sections, so it compares sections1[j] with sections2[j]. If one branch drops or inserts a single # ID: section, every following transaction is counted as mismatched even when the later IDs still match. Since the output already carries transaction IDs, key the comparison by ID so the per-TX summary stays accurate.

Also applies to: 411-443

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/util/cmd/compare-debug-tx/cmd.go` around lines 368 - 387, The loop
currently compares sections1[j] vs sections2[j] by slice index, which
misattributes mismatches when sections are inserted or removed; instead parse
the transaction ID from each section (the "# ID:" line returned by
splitTxSections) and build maps id->section for both branches (use the same ID
parsing logic for both), then iterate the union of IDs to compare corresponding
sections by ID and increment txsWithMismatch and blockTxMismatches for IDs whose
byte content differs; update txCount/totalTxs to be the size of the union and
keep existing variables (sections1, sections2, splitTxSections,
blockTxMismatches, txsWithMismatch, totalTxs) while replacing the index-based
loop with an ID-keyed comparison.

Comment thread cmd/util/cmd/compare-debug-tx/cmd.go Outdated
@turbolent
turbolent added this pull request to the merge queue Apr 8, 2026
Merged via the queue into master with commit 944c461 Apr 8, 2026
61 checks passed
@turbolent
turbolent deleted the bastian/improve-compare-debug-tx branch April 8, 2026 16:08
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.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.