Skip to content

Conversation

ananas-block
Copy link

@ananas-block ananas-block commented Aug 19, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improves reliability of batched event processing (appends, nullifications, address updates) with stricter sequencing and count checks.
    • Prevents invalid or empty fields from being processed, reducing inconsistent or partial updates.
    • Ensures only the expected number of records are updated or deleted, avoiding queue drift and stuck states.
  • Refactor
    • Standardizes validation and error handling across all batch operations for consistent behavior and clearer failures.

Copy link

coderabbitai bot commented Aug 19, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds strict validation and sequencing checks to three batch persistence paths—append, nullify, and address append—in a single ingester module. Each path now enforces tree/range filters, exact expected counts, per-record field presence, sequential indices, and post-operation DB updates, failing early on any mismatch.

Changes

Cohort / File(s) Summary
Batch Append Path
src/ingester/persist/persisted_batch_event.rs
Replaces LeafIndex-only filter with tree + in-queue checks; validates range, count, sequential indices, and non-empty account hashes; constructs leaf nodes; appends to tree; sets InOutputQueue=false; verifies updated row count.
Batch Nullify Path
src/ingester/persist/persisted_batch_event.rs
Filters by tree, NullifierQueueIndex range, Spent=true, NullifiedInTree=false, InOutputQueue=false; validates count, sequential indices, and non-null nullifiers; appends hashed nullifiers; clears queue index, sets NullifiedInTree=true; verifies updated row count.
Batch Address Append Path
src/ingester/persist/persisted_batch_event.rs
Filters by tree and address QueueIndex range; validates count, sequential indices, and non-empty addresses; appends address leaves; deletes processed queue rows; verifies deleted row count.
Shared Validation/Errors
src/ingester/persist/persisted_batch_event.rs
Introduces consistent expected_count checks, early error paths for missing fields and sequencing gaps across all three batch operations.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant I as Ingester
  participant DB as Database
  participant MT as MerkleTree

  rect rgb(235, 245, 255)
  note over I: Batch Append Flow (accounts)
  I->>DB: Query accounts by tree + leaf range + InOutputQueue=true
  DB-->>I: Records
  I->>I: Validate expected_count, sequential LeafIndex, non-empty hashes
  I->>MT: multi_append(leaf_nodes from accounts)
  MT-->>I: Append result (new_next_index)
  I->>DB: Update InOutputQueue=false for affected LeafIndex range
  DB-->>I: Rows updated (must equal expected_count)
  end

  alt any validation/count mismatch
    I-->>I: Fail early with error
  end
Loading
sequenceDiagram
  autonumber
  participant I as Ingester
  participant DB as Database
  participant MT as MerkleTree

  rect rgb(245, 235, 255)
  note over I: Batch Nullify Flow (nullifiers)
  I->>DB: Query by tree + NullifierQueueIndex range + Spent=true + NullifiedInTree=false + InOutputQueue=false
  DB-->>I: Records
  I->>I: Validate expected_count, sequential queue indices, non-null nullifiers
  I->>MT: multi_append(leaf_nodes from hashed nullifiers)
  MT-->>I: Append result
  I->>DB: Set NullifierQueueIndex=NULL, NullifiedInTree=true
  DB-->>I: Rows updated (must equal expected_count)
  end

  alt any validation/count mismatch
    I-->>I: Fail early with error
  end
Loading
sequenceDiagram
  autonumber
  participant I as Ingester
  participant DB as Database
  participant MT as MerkleTree

  rect rgb(235, 255, 245)
  note over I: Batch Address Append Flow (addresses)
  I->>DB: Query by tree + Address QueueIndex range
  DB-->>I: Records
  I->>I: Validate expected_count, sequential queue indices, non-empty addresses
  I->>MT: multi_append(leaf_nodes from addresses)
  MT-->>I: Append result
  I->>DB: Delete processed address rows by range + tree
  DB-->>I: Rows deleted (must equal expected_count)
  end

  alt any validation/count mismatch
    I-->>I: Fail early with error
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit taps the ledger tree, hop-hop—
Counting leaves that never drop.
Queue by queue, we check in line,
Hashes neat, indices fine.
One wrong nibble? We’ll loudly squeak—
Then bound ahead, append next week! 🐇🌿

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jorrit/chore-add-persisted-batch-event-validation

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@ananas-block ananas-block changed the base branch from sergey/batch-nullify-filter-by-tree to main August 19, 2025 18:09
@ananas-block ananas-block marked this pull request as draft August 19, 2025 18:09
@ananas-block ananas-block marked this pull request as ready for review August 19, 2025 18:09
@ananas-block ananas-block changed the base branch from main to sergey/batch-nullify-filter-by-tree August 19, 2025 18:10
@sergeytimoshin sergeytimoshin force-pushed the sergey/batch-nullify-filter-by-tree branch from 8c9347b to c14fb15 Compare August 22, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants