Skip to content

validate blocks before committing #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025

Conversation

iuwqyir
Copy link
Collaborator

@iuwqyir iuwqyir commented Jul 22, 2025

TL;DR

Added block validation before committing blocks to storage.

What changed?

  • Added a validator field to the Committer struct
  • Initialized the validator in the NewCommitter function
  • Added validation logic in the getSequentialBlockDataToCommit method that:
    • Validates blocks before they are committed
    • Filters out invalid blocks, allowing the process to continue with only valid blocks

How to test?

  1. Run the orchestrator with some blocks that include both valid and invalid data
  2. Verify that only valid blocks are committed to storage
  3. Check logs to ensure invalid blocks are properly identified and filtered out

Why make this change?

This change adds a validation step to ensure data integrity before blocks are committed to storage. By filtering out invalid blocks, the system can continue processing valid blocks without being blocked by corrupted or malformed data, improving resilience and data quality.

Summary by CodeRabbit

  • New Features

    • Improved block validation during the commit process, ensuring only valid blocks are processed and invalid ones are filtered out automatically.
    • Enhanced reliability by integrating a validation step before block data is committed.
  • Bug Fixes

    • Added warnings and error handling for invalid blocks detected during the commit preparation process.

Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

A validator component was integrated into the committer's workflow. The committer struct now accepts a validator via a new option function and uses it to filter valid and invalid blocks before further processing. The orchestrator was updated to create and inject the validator when initializing the committer.

Changes

File(s) Change Summary
internal/orchestrator/committer.go Added validator field to Committer, new WithValidator option, and validation logic in block processing.
internal/orchestrator/orchestrator.go Orchestrator now creates a Validator and injects it into the Committer during initialization.

Sequence Diagram(s)

sequenceDiagram
    participant Orchestrator
    participant Validator
    participant Committer

    Orchestrator->>Validator: Create Validator(rpcClient, storage)
    Orchestrator->>Committer: Create Committer(..., WithValidator(validator))
    Committer->>Committer: getSequentialBlockDataToCommit()
    Committer->>Validator: Validate blocks (if validator is set)
    Validator-->>Committer: Return valid and invalid blocks
    Committer->>Committer: Process only valid blocks
Loading

Estimated code review effort

2 (~15 minutes)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f54705e and df00900.

📒 Files selected for processing (2)
  • internal/orchestrator/committer.go (3 hunks)
  • internal/orchestrator/orchestrator.go (1 hunks)
🧬 Code Graph Analysis (2)
internal/orchestrator/orchestrator.go (2)
internal/orchestrator/validator.go (1)
  • NewValidator (21-27)
internal/orchestrator/committer.go (3)
  • NewCommitter (49-76)
  • WithCommitterWorkModeChan (37-41)
  • WithValidator (43-47)
internal/orchestrator/committer.go (1)
internal/orchestrator/validator.go (1)
  • Validator (15-19)
🧰 Additional context used
🧬 Code Graph Analysis (2)
internal/orchestrator/orchestrator.go (2)
internal/orchestrator/validator.go (1)
  • NewValidator (21-27)
internal/orchestrator/committer.go (3)
  • NewCommitter (49-76)
  • WithCommitterWorkModeChan (37-41)
  • WithValidator (43-47)
internal/orchestrator/committer.go (1)
internal/orchestrator/validator.go (1)
  • Validator (15-19)
🔇 Additional comments (5)
internal/orchestrator/orchestrator.go (2)

88-88: LGTM! Validator instantiation follows established patterns.

The validator creation is consistent with other component instantiations in the orchestrator, using the same RPC client and storage references. The scoping within the committer goroutine ensures proper lifecycle management.


89-89: LGTM! Clean integration of validator with the committer.

The validator is properly injected using the functional options pattern, consistent with the existing code structure. The addition of WithValidator(validator) alongside the existing options maintains clean separation of concerns.

internal/orchestrator/committer.go (3)

32-32: LGTM! Validator field addition is well-designed.

Using a pointer type allows for optional validation functionality and follows Go conventions. The field placement within the struct is logical and consistent with other fields.


43-47: LGTM! Option function follows established patterns perfectly.

The WithValidator function correctly implements the functional options pattern, maintaining consistency with existing option functions like WithCommitterWorkModeChan. The implementation properly encapsulates the validator injection logic.


220-230: Excellent validation integration with proper error handling.

The validation logic is strategically placed in the pipeline:

  • Occurs after data fetching but before sorting/gap checking
  • Nil check prevents issues when validator is not configured
  • Invalid blocks are properly logged and filtered out
  • Validation errors correctly abort the commit process
  • Valid blocks seamlessly continue through existing logic

This implementation maintains data integrity while preserving the existing commit workflow.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator Author

iuwqyir commented Jul 22, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@iuwqyir iuwqyir marked this pull request as ready for review July 22, 2025 18:35
@iuwqyir iuwqyir force-pushed the 07-22-validate_blocks_before_committing branch 2 times, most recently from 22a2d81 to fd74f7c Compare July 22, 2025 18:54
@iuwqyir iuwqyir force-pushed the 05-16-chain_validation_and_fix_command branch from 0b45721 to 7f6a1dc Compare July 22, 2025 19:15
@iuwqyir iuwqyir force-pushed the 07-22-validate_blocks_before_committing branch from fd74f7c to 550fae7 Compare July 22, 2025 19:15
@iuwqyir iuwqyir changed the base branch from 05-16-chain_validation_and_fix_command to graphite-base/241 July 22, 2025 19:30
@iuwqyir iuwqyir force-pushed the 07-22-validate_blocks_before_committing branch from 550fae7 to c7e63de Compare July 22, 2025 19:30
@graphite-app graphite-app bot changed the base branch from graphite-base/241 to main July 22, 2025 19:30
@iuwqyir iuwqyir force-pushed the 07-22-validate_blocks_before_committing branch from c7e63de to df00900 Compare July 22, 2025 19:30
@iuwqyir iuwqyir merged commit b7ead65 into main Jul 22, 2025
6 checks passed
@iuwqyir iuwqyir deleted the 07-22-validate_blocks_before_committing branch July 22, 2025 19:35
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.

1 participant