Skip to content

fix(merk): distinct keys are not available for 0..0 range#357

Merged
shumkov merged 1 commit into
developfrom
fix/district-keys-no-available
Feb 3, 2025
Merged

fix(merk): distinct keys are not available for 0..0 range#357
shumkov merged 1 commit into
developfrom
fix/district-keys-no-available

Conversation

@shumkov
Copy link
Copy Markdown
Contributor

@shumkov shumkov commented Feb 3, 2025

Issue being fixed or feature implemented

merk error: invalid operation error distinct keys are not available for ranges using more or less than 1 byte

when inserting two identical keys to query

What was done?

  • Skip duplicate key on query insert
  • Return the same key on merge

How Has This Been Tested?

Changes covered with unit tests

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Chores
    • Improved configuration consistency and organization, including the addition of a new development dependency.
  • Bug Fixes
    • Enhanced query key handling to prevent duplicate entries during insertion.
    • Refined merging logic to consistently return a single instance when identical keys are combined.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 3, 2025

Walkthrough

The changes focus on enhancing formatting consistency and refining control flow in key management within the repository. Updates are made to the package configuration file to align dependency and feature definitions, with a new development dependency introduced. Additionally, the logic for inserting and merging query items is modified to prevent duplicate entries by implementing early returns, accompanied by new tests to validate these behaviors.

Changes

File(s) Summary of Changes
merk/Cargo.toml Reformatted dependency declaration for grovedb-costs, aligned entries in the features section, and added a new dev dependency: assert_matches = "1.5.0"
merk/src/proofs/query/insert.rs Updated insert_item logic to avoid duplicate key insertions; added a new test module with a test function verifying a single key instance for duplicates
merk/src/proofs/query/query_item/merge.rs Modified the merge method to return early when merging identical keys; added a new test module to validate the early return behavior

Sequence Diagram(s)

sequenceDiagram
    participant T as Test
    participant Q as Query.insert_item
    T->>Q: Call insert_item(key)
    alt Duplicate key exists?
        Q-->>T: Skip insertion, return unique list
    else 
        Q-->>T: Insert key and return updated list
    end
Loading
sequenceDiagram
    participant C as Caller
    participant M as QueryItem.merge
    C->>M: Call merge(key, key)
    alt Keys are equal
        M-->>C: Return a clone of the key (early exit)
    else 
        M-->>C: Process merge normally with range logic
    end
Loading

Possibly related PRs

Suggested reviewers

  • fominok
  • lklimek

Poem

I'm a rabbit who loves clean code,
Spaces and keys now tightly bestowed.
No duplicate hops in our query mix,
Merge returns with swift, clever tricks.
Hooray for changes—happy as can be! 🐇🎉


📜 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 44c2244 and 23ddc44.

📒 Files selected for processing (3)
  • merk/Cargo.toml (2 hunks)
  • merk/src/proofs/query/insert.rs (2 hunks)
  • merk/src/proofs/query/query_item/merge.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • merk/Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Tests
  • GitHub Check: Compilation errors
  • GitHub Check: Code Coverage
  • GitHub Check: Linting
🔇 Additional comments (4)
merk/src/proofs/query/query_item/merge.rs (2)

11-13: LGTM! Early return optimization for identical keys.

The early return for identical keys prevents unnecessary range operations and aligns with the PR objective of handling duplicate keys correctly.


79-99: LGTM! Comprehensive test coverage for key merging.

The test effectively validates the behavior of merging identical keys using a realistic key example.

merk/src/proofs/query/insert.rs (2)

150-152: LGTM! Proper handling of duplicate keys.

The special case for identical keys ensures duplicates are skipped during insertion, which directly addresses the PR objective.


178-202: LGTM! Thorough test coverage for key insertion.

The test effectively validates that duplicate keys are handled correctly by ensuring only one instance remains in the query items.


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.

@shumkov shumkov changed the title fix(merk): distinct keys are not available for ranges 0..0 fix(merk): distinct keys are not available for 0..0 range Feb 3, 2025
@shumkov shumkov merged commit b857ddc into develop Feb 3, 2025
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