Skip to content

Conversation

@jaipaljadeja
Copy link
Member

adds logic to handle pending blocks in all three plugins - drizzle, mongo and sqlite.
adds a condition to not call factory function for pending blocks.
adds necessary tests for all plugins.

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2025

📝 Walkthrough

Walkthrough

This PR introduces new prerelease JSON configuration files for multiple packages (@apibara/indexer, @apibara/plugin-drizzle, @apibara/plugin-mongo, and @apibara/plugin-sqlite), each containing metadata and indicating patch-level changes. In addition, core logic across the indexer and storage plugins has been updated to handle pending blocks appropriately. A new variable (prevFinality) and revised conditional checks ensure that operations like state persistence and invalidation occur only for accepted blocks. The changes are complemented by new test cases that validate the correct behavior for both pending and accepted block scenarios across different plugins.

Changes

File(s) Change Summary
change/@apibara-indexer…json, change/@apibara-plugin-drizzle…json, change/@apibara-plugin-mongo…json, change/@apibara-plugin-sqlite…json Added new prerelease JSON configuration files with metadata, comments on handling pending blocks, and patch-level dependent change types for each package.
packages/indexer/src/indexer.ts Modified factory mode condition to additionally check that finality is not "pending".
packages/plugin-drizzle/src/index.ts,
packages/plugin-mongo/src/index.ts,
packages/plugin-sqlite/src/index.ts
Introduced a prevFinality variable and updated middleware logic to invalidate state and adjust persistence based on whether the block’s finality is "pending".
packages/plugin-drizzle/tests/helper.ts,
packages/plugin-drizzle/tests/storage.test.ts
Updated SQL table definitions to enforce key uniqueness and added tests verifying pending data handling, multiple pending updates, and non-persistence for pending blocks.
packages/plugin-mongo/tests/storage.test.ts Added tests to simulate and verify proper behavior for pending and accepted block handling in MongoDB storage.
packages/plugin-sqlite/src/kv.ts,
packages/plugin-sqlite/src/persistence.ts,
packages/plugin-sqlite/tests/kv.test.ts,
packages/plugin-sqlite/tests/persistence.test.ts
Exported key type definitions and introduced new SQLite types, plus added tests to validate key-value storage and persistence behavior for pending versus accepted blocks.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant M as Middleware
    participant S as Storage
    participant I as Invalidation

    C->>M: Send block (with finality)
    alt Finality is "pending"
      M->>I: Invalidate state (invalidate/invalidateState/invalidateKV)
      M->>M: Update prevFinality to "pending"
    else Finality is accepted
      M->>S: Persist state (persistState)
      M->>M: Update prevFinality
    end
Loading

Possibly related PRs

  • Remove sink in favour of middleware #128: The changes in the main PR, which introduce a new JSON file for the @apibara/indexer package, are related to the retrieved PR that also modifies the @apibara/indexer package by replacing the sink with middleware, as both involve updates to the package's configuration and functionality.
  • cli: add file formatting with prettier and add noIndexer flag #147: The changes in the main PR, which involve adding a new JSON file for the @apibara/indexer package, are related to the changes in the retrieved PR that also introduces a new JSON file for the same package, indicating a connection at the code level.
  • indexer: reconnect indexer on internal stream errors #121: The changes in the main PR, which involve the introduction of a new JSON file for the @apibara/indexer package specifying a prerelease version, are related to the changes in the retrieved PR, which also introduces a new JSON file for the same package but focuses on reconnecting the indexer on internal stream errors, indicating both PRs modify the same package's metadata.

Suggested reviewers

  • fracek

Poem

Hop along, I'm the coding rabbit, swift and spry,
Hopping through JSON configs under a starry sky.
With prevFinality tracks and pending blocks in sight,
Our code now dances perfectly, by day and night.
Tests pass with a wink, as the logic takes flight—
A joyful little hop, and everything’s just right! 🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 d342e71 and 0b6ccd0.

📒 Files selected for processing (3)
  • packages/plugin-drizzle/src/index.ts (4 hunks)
  • packages/plugin-mongo/src/index.ts (4 hunks)
  • packages/plugin-sqlite/src/index.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/plugin-drizzle/src/index.ts
  • packages/plugin-mongo/src/index.ts
  • packages/plugin-sqlite/src/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

@jaipaljadeja jaipaljadeja requested a review from fracek March 13, 2025 22:13
Copy link
Contributor

@fracek fracek left a comment

Choose a reason for hiding this comment

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

Looks good. It looks like we can simplify some of the logic based on the fact that state is not persisted for pending blocks.

@jaipaljadeja
Copy link
Member Author

Looks good. It looks like we can simplify some of the logic based on the fact that state is not persisted for pending blocks.

good catch! just pushed the changes.

@jaipaljadeja jaipaljadeja requested a review from fracek March 17, 2025 05:40
@fracek fracek merged commit ba825d3 into apibara:main Mar 17, 2025
2 checks passed
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