Skip to content

Add reorg block check#892

Merged
Kukoomomo merged 1 commit intomainfrom
submitter_reorg_check
Mar 2, 2026
Merged

Add reorg block check#892
Kukoomomo merged 1 commit intomainfrom
submitter_reorg_check

Conversation

@Kukoomomo
Copy link
Copy Markdown
Contributor

@Kukoomomo Kukoomomo commented Mar 2, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and validation for block data retrieval operations, ensuring the system gracefully handles missing data.
    • Enhanced reliability with early error detection and clear error messaging.

@Kukoomomo Kukoomomo requested a review from a team as a code owner March 2, 2026 02:26
@Kukoomomo Kukoomomo requested review from Web3Jumb0 and removed request for a team March 2, 2026 02:27
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

The change adds defensive nil-check guards to the reorg detection service functions, validating that latestBlock and per-block fetch results are not nil before processing, with explicit error returns when nil values are encountered.

Changes

Cohort / File(s) Summary
Nil-Check Guards
tx-submitter/services/reorg.go
Introduces nil validation for latestBlock and fetched block results in DetectReorg and updateHistory functions, returning descriptive errors when nil values are encountered.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A rabbit hops through guard clauses new,
Nil checks prevent what bugs might do,
With early returns, errors shine bright,
Our reorg service runs just right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add reorg block check' directly aligns with the main change: introducing nil-check guards for blocks in reorg detection logic to catch and return errors for nil blocks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch submitter_reorg_check

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tx-submitter/services/reorg.go (1)

56-58: Consider centralizing block fetch + nil validation.

The same fetch-and-nil-check logic appears in multiple places; a small helper would reduce duplication and keep error messages uniform.

♻️ Optional refactor sketch
+func (r *ReorgDetector) blockByNumberOrError(ctx context.Context, num *big.Int, label string) (*types.Block, error) {
+	block, err := r.l1Client.BlockByNumber(ctx, num)
+	if err != nil {
+		return nil, fmt.Errorf("failed to get %s: %w", label, err)
+	}
+	if block == nil {
+		return nil, fmt.Errorf("%s is nil", label)
+	}
+	return block, nil
+}

Also applies to: 67-69, 101-103, 117-119

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

In `@tx-submitter/services/reorg.go` around lines 56 - 58, Duplicate
fetch-and-nil-check logic around latestBlock (e.g., the checks using latestBlock
== nil at the shown location and also at the occurrences around lines 67-69,
101-103, 117-119) should be centralized: add a helper function (e.g.,
fetchLatestBlockOrErr or ensureLatestBlock) that performs the block fetch and
returns (block, error) with a uniform error message when nil, then replace all
inline fetch + nil checks with calls to that helper (update callers in reorg.go
to use the helper and handle its error). Ensure the helper name appears in
imports/signatures where used so callers are easy to find and the error text is
consistent across all replaced sites.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tx-submitter/services/reorg.go`:
- Around line 56-58: Duplicate fetch-and-nil-check logic around latestBlock
(e.g., the checks using latestBlock == nil at the shown location and also at the
occurrences around lines 67-69, 101-103, 117-119) should be centralized: add a
helper function (e.g., fetchLatestBlockOrErr or ensureLatestBlock) that performs
the block fetch and returns (block, error) with a uniform error message when
nil, then replace all inline fetch + nil checks with calls to that helper
(update callers in reorg.go to use the helper and handle its error). Ensure the
helper name appears in imports/signatures where used so callers are easy to find
and the error text is consistent across all replaced sites.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c00f42 and acb9d3a.

📒 Files selected for processing (1)
  • tx-submitter/services/reorg.go

@Kukoomomo Kukoomomo merged commit 895120c into main Mar 2, 2026
9 checks passed
@Kukoomomo Kukoomomo deleted the submitter_reorg_check branch March 2, 2026 03:26
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