Skip to content

feat!: add should_add_parent_tree_at_path feature to PathQuery#379

Merged
QuantumExplorer merged 3 commits into
developfrom
featadd-parent-tree-at-path
Jul 18, 2025
Merged

feat!: add should_add_parent_tree_at_path feature to PathQuery#379
QuantumExplorer merged 3 commits into
developfrom
featadd-parent-tree-at-path

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer commented Jul 17, 2025

Issue being fixed or feature implemented

Added a new feature to the PathQuery that determines whether to include the parent tree in the results based on the query path.

What was done?

  • Introduced a new field should_add_parent_tree_at_path in GroveDBPathQueryMethodVersions.
  • Updated the GROVE_V1 and GROVE_V2 constants to initialize this new field.
  • Implemented the should_add_parent_tree_at_path method in the PathQuery struct to evaluate whether the parent tree should be included based on the query path and the current grove version.
  • Added tests to validate the functionality of the new feature, ensuring correct behavior for both count tree and aggregation queries.

How Has This Been Tested?

New unit tests were added to cover the functionality of the should_add_parent_tree_at_path method and its integration with existing query functionalities.

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 added ! to the title and described breaking changes in the corresponding section if my code contains any.

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Added support for including parent tree information in query results when specified, enhancing query flexibility.
    • Introduced a method to determine when parent trees should be added to query results.
    • Added a new field to query and version structures to support this feature.
  • Bug Fixes

    • None.
  • Tests

    • Added new tests to verify correct handling of count trees and parent tree aggregation in query results.
    • Updated existing tests to include the new parent tree field.
  • Refactor

    • Updated relevant data structures to support the new parent tree feature.
    • Enabled cloning for certain proof-related structs for improved usability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 17, 2025

Walkthrough

A new feature was introduced to support conditionally adding parent tree information to query results in GroveDB. This involved adding a new boolean field to query-related structs, updating versioning, implementing logic to check this condition during proof verification, and extending tests to cover the new behavior with and without aggregation.

Changes

File(s) Change Summary
grovedb-version/src/version/grovedb_versions.rs, grovedb-version/src/version/v1.rs, grovedb-version/src/version/v2.rs Added should_add_parent_tree_at_path field to version structs and constants for version tracking.
grovedb/src/query/mod.rs Added should_add_parent_tree_at_path method to PathQuery with recursive logic; added add_parent_tree_on_subquery field to tests.
merk/src/proofs/query/mod.rs Added add_parent_tree_on_subquery boolean field to Query struct; updated decoding and initialization.
grovedb/src/operations/proof/verify.rs Updated verify_layer_proof to conditionally add parent tree info to results based on query and version.
grovedb/src/tests/count_tree_tests.rs Added tests for count tree queries with and without parent tree aggregation enabled.
grovedb/src/tests/mod.rs, grovedb/src/tests/query_tests.rs Added add_parent_tree_on_subquery: false to Query and SubqueryBranch struct initializations in tests.
merk/src/proofs/query/verify.rs Added Clone trait derivation to ProvedKeyOptionalValue and ProvedKeyValue structs.
grovedb/src/debugger.rs Set add_parent_tree_on_subquery to false in query_to_grovedb function's returned Query struct.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GroveDB
    participant Query
    participant ProofVerifier

    Client->>GroveDB: Submit query with subqueries (may set add_parent_tree_on_subquery)
    GroveDB->>Query: Build PathQuery with subqueries and flags
    GroveDB->>ProofVerifier: Generate proof for query
    ProofVerifier->>Query: Call should_add_parent_tree_at_path(path, version)
    alt Should add parent tree
        ProofVerifier->>Result: Add parent tree info to result set
    end
    ProofVerifier->>Result: Continue verification
    Result-->>Client: Return query results (with or without parent tree info)
Loading

Possibly related PRs

Suggested reviewers

  • fominok

Poem

In the warren of queries, a new path appears,
With parent trees added, the logic now steers.
Tests hop along, verifying each root,
While versions keep track in their orderly suit.
🐇 The code grows robust, with features anew—
GroveDB’s forest welcomes this view!


📜 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 fc4994c and e301c50.

📒 Files selected for processing (1)
  • merk/src/proofs/query/mod.rs (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • merk/src/proofs/query/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Tests
  • GitHub Check: Code Coverage
✨ Finishing Touches
  • 📝 Generate Docstrings

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

@QuantumExplorer QuantumExplorer changed the title feat:! add should_add_parent_tree_at_path feature to PathQuery feat!: add should_add_parent_tree_at_path feature to PathQuery Jul 17, 2025
Copy link
Copy Markdown
Contributor

@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: 1

🔭 Outside diff range comments (1)
merk/src/proofs/query/mod.rs (1)

162-164: Critical: Missing encoding for the new field.

The Encode implementation encodes left_to_right but doesn't encode the new add_parent_tree_on_subquery field. However, both Decode and BorrowDecode implementations expect to decode this field, which will cause decoding failures.

Add the encoding for the new field:

         // Encode the left_to_right boolean
         self.left_to_right.encode(encoder)?;
 
+        // Encode the add_parent_tree_on_subquery boolean
+        self.add_parent_tree_on_subquery.encode(encoder)?;
+
         Ok(())
🧹 Nitpick comments (4)
grovedb/src/tests/query_tests.rs (1)

3429-3437: Avoid scattering the same default value across hundreds of tests

Every SubqueryBranch literal in this file now repeats

add_parent_tree_on_subquery: false,

to satisfy the new field. When the default is false, a helper/ctor (or Default + struct-update syntax) keeps the tests resilient to future signature changes and removes boilerplate:

-SubqueryBranch {
-    subquery_path: None,
-    subquery: Some(Query::new_range_full().into()),
-    add_parent_tree_on_subquery: false,
-}
+SubqueryBranch::new(None, Some(Query::new_range_full()))

(where new could internally set the flag to false).
This single change would eliminate hundreds of literal updates and make the intent clearer.

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

194-196: Fix the misleading comment.

The comment says "Decode the left_to_right boolean" but this code is actually decoding the add_parent_tree_on_subquery field.

-        // Decode the left_to_right boolean
+        // Decode the add_parent_tree_on_subquery boolean
         let add_parent_tree_on_subquery = bool::decode(decoder)?;

235-237: Fix the misleading comment.

The comment says "Decode the left_to_right boolean" but this code is actually decoding the add_parent_tree_on_subquery field.

-        // Decode the left_to_right boolean
+        // Decode the add_parent_tree_on_subquery boolean
         let add_parent_tree_on_subquery = bool::borrow_decode(decoder)?;
grovedb/src/query/mod.rs (1)

308-428: Consider adding documentation for complex path traversal logic.

The implementation is correct, but the recursive path matching logic is complex. Consider adding inline comments to explain:

  • The path length comparison strategy in the main function
  • The subquery path matching logic in the recursive function
  • Examples of how the method behaves with different path configurations
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5cae12 and 7aa2a04.

📒 Files selected for processing (10)
  • grovedb-version/src/version/grovedb_versions.rs (1 hunks)
  • grovedb-version/src/version/v1.rs (1 hunks)
  • grovedb-version/src/version/v2.rs (1 hunks)
  • grovedb/src/operations/proof/verify.rs (1 hunks)
  • grovedb/src/query/mod.rs (20 hunks)
  • grovedb/src/tests/count_tree_tests.rs (1 hunks)
  • grovedb/src/tests/mod.rs (1 hunks)
  • grovedb/src/tests/query_tests.rs (30 hunks)
  • merk/src/proofs/query/mod.rs (4 hunks)
  • merk/src/proofs/query/verify.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: fominok
PR: dashpay/grovedb#345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function `delete_internal_on_transaction` in `grovedb/src/operations/delete/v1.rs` which is legacy code.
grovedb-version/src/version/grovedb_versions.rs (1)
Learnt from: fominok
PR: dashpay/grovedb#345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function `delete_internal_on_transaction` in `grovedb/src/operations/delete/v1.rs` which is legacy code.
grovedb-version/src/version/v1.rs (1)
Learnt from: fominok
PR: dashpay/grovedb#345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function `delete_internal_on_transaction` in `grovedb/src/operations/delete/v1.rs` which is legacy code.
grovedb-version/src/version/v2.rs (1)
Learnt from: fominok
PR: dashpay/grovedb#345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function `delete_internal_on_transaction` in `grovedb/src/operations/delete/v1.rs` which is legacy code.
grovedb/src/operations/proof/verify.rs (3)
Learnt from: pauldelucia
PR: dashpay/grovedb#366
File: grovedb/src/error.rs:7-7
Timestamp: 2025-04-18T06:12:25.554Z
Learning: The `Error::InvalidProofError` in grovedb/src/operations/proof/util.rs is from the merk error handling system, distinct from grovedb's own `Error::InvalidProof` variant. These are separate error types from different crates.
Learnt from: pauldelucia
PR: dashpay/grovedb#366
File: grovedb/src/error.rs:7-7
Timestamp: 2025-04-18T06:12:25.554Z
Learning: The `Error::InvalidProofError` in grovedb/src/operations/proof/util.rs is from the merk error handling system, distinct from grovedb's own `Error::InvalidProof` variant. These are separate error types from different crates.
Learnt from: fominok
PR: dashpay/grovedb#345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function `delete_internal_on_transaction` in `grovedb/src/operations/delete/v1.rs` which is legacy code.
grovedb/src/tests/mod.rs (1)

undefined

<retrieved_learning>
Learnt from: fominok
PR: #345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function delete_internal_on_transaction in grovedb/src/operations/delete/v1.rs which is legacy code.
</retrieved_learning>

grovedb/src/tests/count_tree_tests.rs (1)
Learnt from: fominok
PR: dashpay/grovedb#345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function `delete_internal_on_transaction` in `grovedb/src/operations/delete/v1.rs` which is legacy code.
grovedb/src/tests/query_tests.rs (1)

undefined

<retrieved_learning>
Learnt from: fominok
PR: #345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function delete_internal_on_transaction in grovedb/src/operations/delete/v1.rs which is legacy code.
</retrieved_learning>

merk/src/proofs/query/verify.rs (2)
Learnt from: pauldelucia
PR: dashpay/grovedb#366
File: grovedb/src/error.rs:7-7
Timestamp: 2025-04-18T06:12:25.554Z
Learning: The `Error::InvalidProofError` in grovedb/src/operations/proof/util.rs is from the merk error handling system, distinct from grovedb's own `Error::InvalidProof` variant. These are separate error types from different crates.
Learnt from: pauldelucia
PR: dashpay/grovedb#366
File: grovedb/src/error.rs:7-7
Timestamp: 2025-04-18T06:12:25.554Z
Learning: The `Error::InvalidProofError` in grovedb/src/operations/proof/util.rs is from the merk error handling system, distinct from grovedb's own `Error::InvalidProof` variant. These are separate error types from different crates.
grovedb/src/query/mod.rs (1)
Learnt from: fominok
PR: dashpay/grovedb#345
File: grovedb/src/operations/delete/v1.rs:19-35
Timestamp: 2025-02-18T08:17:30.690Z
Learning: Refactoring suggestions for legacy code should be avoided as they are considered out of scope for feature PRs. This includes the function `delete_internal_on_transaction` in `grovedb/src/operations/delete/v1.rs` which is legacy code.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Compilation errors
  • GitHub Check: Linting
  • GitHub Check: Tests
  • GitHub Check: Code Coverage
🔇 Additional comments (12)
grovedb-version/src/version/grovedb_versions.rs (1)

17-18: Verify all manual instantiations now set the new field

should_add_parent_tree_at_path is added to GroveDBPathQueryMethodVersions.
Any place where this struct is constructed with a literal (e.g. GroveDBPathQueryMethodVersions { terminal_keys: …, merge: …, ..Default::default() }) will still compile, but full literals without a trailing ..Default::default() will now fail. Please double-check that all such sites (especially in version constants like GROVE_V1, GROVE_V2) have been updated or switched to use the spread syntax to avoid compilation breaks.

grovedb/src/tests/mod.rs (1)

3989-3989: LGTM: Proper test compatibility update

The addition of add_parent_tree_on_subquery: false correctly maintains backward compatibility for this test case. Setting it to false is appropriate here since this test focuses on reference verification without needing parent tree inclusion complexity.

grovedb-version/src/version/v1.rs (1)

178-184: Confirm version‐number semantics for the new method flag

should_add_parent_tree_at_path is introduced with value 0, which is consistent with how brand-new method IDs are usually initialised in this table.
However, if the feature is conditionally compiled or back-ported, the first release that actually supports the logic might need the number 1 to avoid ambiguity with nodes built against older code that implicitly had “feature missing = 0”. Please make sure the chosen value is compatible with any on-disk/versioned data you already produced, otherwise consider bumping it.

grovedb-version/src/version/v2.rs (1)

180-184: Parallel concern: value 0 reused in V2

Same note as for V1: double-check that assigning 0 here does not collide with pre-existing binaries that interpret 0 as “method absent”.
If V2 is the first protocol that can ever call the method, keeping 0 is fine; if not, increment to 1 and document the change.

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

388-392: Clone derive addition looks good

Adding Clone to ProvedKeyOptionalValue is harmless and unblocks users who need to duplicate the result set. No further issues spotted.


448-452: Likewise for ProvedKeyValue

Clone is now derived; implementation stays POD and safe. 👍

merk/src/proofs/query/mod.rs (3)

130-131: LGTM! Well-documented field addition.

The new add_parent_tree_on_subquery field is properly declared with a clear comment explaining its purpose. The boolean type is appropriate for this flag-like behavior.


202-202: LGTM! Consistent field initialization.

The new field is properly included in both Decode and BorrowDecode struct constructors with consistent placement.

Also applies to: 243-243


680-680: LGTM! Appropriate default value.

Setting add_parent_tree_on_subquery to false by default is the correct behavior, maintaining backward compatibility and requiring explicit opt-in for the new feature.

grovedb/src/tests/count_tree_tests.rs (2)

109-209: LGTM! Test correctly validates query behavior without aggregation.

The test properly verifies that when add_parent_tree_on_subquery is not set, the query returns only the child items without including the parent count tree element.


211-318: LGTM! Test correctly validates query behavior with aggregation enabled.

The test properly verifies that when add_parent_tree_on_subquery is set to true, the query returns the parent count tree element along with the child items. The count tree element correctly shows a count of 3 and the last key as "innerkey2".

grovedb/src/query/mod.rs (1)

1413-1413: LGTM! Test updates maintain backward compatibility.

All Query struct initializations have been correctly updated to include add_parent_tree_on_subquery: false, maintaining the existing test behavior while supporting the new field.

Also applies to: 1431-1431, 1596-1596, 1668-1668, 1718-1718, 1736-1736, 1754-1754, 1771-1771, 1900-1900, 1923-1923, 1946-1946, 1978-1978, 2022-2022, 2045-2045, 2070-2070, 2083-2083, 2096-2096, 2123-2123, 2128-2128, 2151-2151

Comment thread grovedb/src/operations/proof/verify.rs
@QuantumExplorer QuantumExplorer merged commit b198e46 into develop Jul 18, 2025
8 checks passed
@QuantumExplorer QuantumExplorer mentioned this pull request Jul 18, 2025
5 tasks
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