Skip to content

Conversation

@fracek
Copy link
Contributor

@fracek fracek commented Feb 19, 2025

If the stored cursor has an empty uniqueKey, it's serialized as an empty string. This is an issue later when deserializing since that's not a valid value for the uniqueKey.

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2025

Warning

Rate limit exceeded

@fracek has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8e68be2 and b624d01.

📒 Files selected for processing (17)
  • change/@apibara-beaconchain-7b39a030-0724-44c0-8cec-7300e5efa49b.json (1 hunks)
  • change/@apibara-evm-c96dd7a5-d16a-44aa-ac3a-947a9b904517.json (1 hunks)
  • change/@apibara-plugin-drizzle-c4aaf5bc-24c6-4883-9b29-cf614279c5db.json (1 hunks)
  • change/@apibara-plugin-mongo-ddb9c304-419b-4291-bb27-6c198e0501cd.json (1 hunks)
  • change/@apibara-plugin-sqlite-ab552e08-0770-4528-b9a9-f1ffb9e0105f.json (1 hunks)
  • change/@apibara-protocol-c3b43226-48fe-4e9f-abe7-760ca8e09b82.json (1 hunks)
  • package.json (1 hunks)
  • packages/beaconchain/package.json (1 hunks)
  • packages/evm/package.json (1 hunks)
  • packages/plugin-drizzle/package.json (1 hunks)
  • packages/plugin-drizzle/src/persistence.ts (4 hunks)
  • packages/plugin-drizzle/tests/storage.test.ts (4 hunks)
  • packages/plugin-mongo/src/persistence.ts (2 hunks)
  • packages/plugin-mongo/tests/storage.test.ts (0 hunks)
  • packages/plugin-sqlite/package.json (1 hunks)
  • packages/plugin-sqlite/src/persistence.ts (2 hunks)
  • packages/protocol/src/common.ts (1 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces prerelease metadata for the @apibara/plugin-drizzle package by adding a new JSON object with fix details. It updates the root package.json to include new plugin packages in the beachball configuration while bumping version numbers for several packages (beaconchain, evm, plugin-drizzle, and plugin-sqlite). Additionally, the persistence layer of the plugin-drizzle has been modified by adjusting the uniqueKey definition and integrating a new normalizeCursor function for cursor validation.

Changes

File(s) Change Summary
change/@apibara-plugin-drizzle…c5db.json Added prerelease metadata for @apibara/plugin-drizzle including fields: type (prerelease), comment (fix for empty unique key cursor issue), packageName, email, and dependentChangeType (patch).
package.json Updated beachball.groups.include to add plugins: "packages/plugin-drizzle", "packages/plugin-mongo", and "packages/plugin-sqlite".
packages/{beaconchain, evm, plugin-drizzle, plugin-sqlite}/package.json Bumped package versions: beaconchain & evm from 2.0.1-beta.31 to 2.0.1-beta.39; plugin-drizzle & plugin-sqlite from 2.0.0-beta.38 to 2.0.0-beta.39.
packages/plugin-drizzle/src/persistence.ts Modified the uniqueKey field in the checkpoints table (removed not-null and default constraints) and added a new normalizeCursor function for validating and processing cursors in the getState function.
packages/plugin-mongo/src/persistence.ts Updated CheckpointSchema to make uniqueKey a required property that can be null and integrated normalizeCursor in getState.
packages/plugin-sqlite/src/persistence.ts Changed the import statement for Cursor to include normalizeCursor and modified getState to utilize this function for cursor handling.
packages/protocol/src/common.ts Introduced a new function, normalizeCursor, to standardize cursor objects.
packages/plugin-drizzle/tests/storage.test.ts Enhanced the test suite with new cases and updates for various database operations including insertion, updates, deletions, and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant StateManager as getState
    participant CursorNormalizer as normalizeCursor
    participant Database

    Client->>StateManager: Request state data
    StateManager->>CursorNormalizer: Normalize cursor input
    CursorNormalizer-->>StateManager: Return normalized cursor
    StateManager->>Database: Query using normalized cursor
    Database-->>StateManager: Return query result
    StateManager-->>Client: Deliver state data
Loading

Suggested reviewers

  • jaipaljadeja

Poem

I'm a little rabbit, hopping through code so bright,
Prerelease magic in JSON takes flight.
Version bumps and cursor tales,
In each commit, a story prevails.
Bugs are chased, improvements unfurled—
A hoppy celebration in our coding world! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/plugin-drizzle/src/persistence.ts (1)

146-185: Consider improving error handling for cursor validation.

The persistState function should validate the cursor before persisting it to ensure data consistency.

Consider adding cursor validation:

   if (endCursor) {
+    const normalizedCursor = normalizeCursor({
+      orderKey: endCursor.orderKey,
+      uniqueKey: endCursor.uniqueKey,
+    });
     await tx
       .insert(checkpoints)
       .values({
         id: indexerId,
-        orderKey: Number(endCursor.orderKey),
-        uniqueKey: endCursor.uniqueKey,
+        orderKey: Number(normalizedCursor.orderKey),
+        uniqueKey: normalizedCursor.uniqueKey,
       })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81f6df9 and 8e68be2.

📒 Files selected for processing (11)
  • change/@apibara-plugin-drizzle-c4aaf5bc-24c6-4883-9b29-cf614279c5db.json (1 hunks)
  • package.json (1 hunks)
  • packages/beaconchain/package.json (1 hunks)
  • packages/evm/package.json (1 hunks)
  • packages/plugin-drizzle/package.json (1 hunks)
  • packages/plugin-drizzle/src/persistence.ts (4 hunks)
  • packages/plugin-drizzle/tests/storage.test.ts (4 hunks)
  • packages/plugin-mongo/src/persistence.ts (2 hunks)
  • packages/plugin-sqlite/package.json (1 hunks)
  • packages/plugin-sqlite/src/persistence.ts (2 hunks)
  • packages/protocol/src/common.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/plugin-drizzle/package.json
  • packages/plugin-sqlite/package.json
  • packages/evm/package.json
  • change/@apibara-plugin-drizzle-c4aaf5bc-24c6-4883-9b29-cf614279c5db.json
  • package.json
  • packages/beaconchain/package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (11)
packages/protocol/src/common.ts (1)

71-93: LGTM! The cursor normalization logic is well-implemented.

The function correctly handles the following cases:

  • When uniqueKey is present and non-empty, it's cast to the required 0x-prefixed format
  • When uniqueKey is null or empty, it's omitted from the cursor object
packages/plugin-mongo/src/persistence.ts (2)

7-7: LGTM! Type change improves null handling.

The type change from optional to required with null makes the uniqueKey handling more explicit and type-safe.


101-104: LGTM! Cursor normalization is properly integrated.

The implementation correctly uses normalizeCursor to ensure consistent cursor format across the application.

packages/plugin-sqlite/src/persistence.ts (1)

60-63: LGTM! Cursor normalization is well-implemented.

The implementation correctly:

  • Handles the case when unique_key is undefined
  • Uses ternary operator for concise null checking
packages/plugin-drizzle/src/persistence.ts (2)

18-18: LGTM! Field definition is appropriately simplified.

The uniqueKey field definition is correctly simplified to allow null values while maintaining type safety.


212-215: LGTM! Cursor normalization is properly integrated.

The implementation correctly uses normalizeCursor to ensure consistent cursor format.

packages/plugin-drizzle/tests/storage.test.ts (5)

678-686: LGTM! Test correctly handles null uniqueKey in checkpoints.

The test case properly verifies that the checkpoint's uniqueKey can be null, which aligns with the PR's objective of fixing deserialization issues with empty uniqueKey values.


844-852: LGTM! Test verifies filter persistence with null uniqueKey.

The test case properly validates that filters are persisted correctly in factory mode while handling null uniqueKey in checkpoints.


1028-1036: LGTM! Test validates state invalidation with null uniqueKey.

The test case properly verifies that state invalidation works correctly while handling null uniqueKey in checkpoints.


1204-1212: LGTM! Test verifies state finalization with null uniqueKey.

The test case properly validates that state finalization works correctly while handling null uniqueKey in checkpoints.


19-1266: Test suite provides comprehensive coverage for uniqueKey handling.

The test suite thoroughly validates the handling of null uniqueKey values across different scenarios:

  1. State persistence
  2. Filter persistence in factory mode
  3. State invalidation
  4. State finalization

This comprehensive test coverage ensures the PR's objective of fixing deserialization issues with empty uniqueKey values is properly addressed.

Copy link
Member

@jaipaljadeja jaipaljadeja 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! Thanks.

@jaipaljadeja jaipaljadeja merged commit 47db783 into apibara:main Feb 19, 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