Skip to content

feat: add query to retrieve parent tree information#368

Merged
QuantumExplorer merged 2 commits intodevelopfrom
branch
May 11, 2025
Merged

feat: add query to retrieve parent tree information#368
QuantumExplorer merged 2 commits intodevelopfrom
branch

Conversation

@QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented May 11, 2025

Issue being fixed or feature implemented

Add functionality to retrieve parent tree information when querying in a subtree.

What was done?

  • Introduced verify_query_get_parent_tree_info_with_options and verify_query_get_parent_tree_info methods to retrieve parent tree information based on the provided proof and query.
  • Updated the GroveDBProof structure to return the parent tree type along with the root hash and results.
  • Added relevant tests to ensure the new functionality works as expected.

How Has This Been Tested?

Unit tests were added to verify the correctness of the new query methods, including checks for expected outputs and handling of edge cases.

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.

Summary by CodeRabbit

  • New Features

    • Added methods to support proof verification that also return parent tree feature information, including the tree's aggregate type and values.
    • Introduced the ability to retrieve and inspect parent tree characteristics during proof verification.
    • Extended version tracking with a new feature version for verifying queries that retrieve parent tree info with options.
    • Added a method to identify the feature type of tree elements.
  • Bug Fixes

    • Standardized error messages for invalid proof structures during verification.
  • Tests

    • Enhanced and added tests to validate the new parent tree info retrieval functionality in proof verification.

@QuantumExplorer QuantumExplorer requested a review from fominok as a code owner May 11, 2025 12:51
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 11, 2025

Walkthrough

The changes introduce the ability for GroveDB proof verification to return information about the parent tree's feature type during query verification. This includes new methods, internal refactoring to propagate the parent tree info, updates to version tracking, and expanded test coverage to validate the new functionality.

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 a new verify_query_get_parent_tree_info_with_options field to version tracking structs and constants for proof operations, initializing it to 0 in both v1 and v2.
grovedb/src/element/helpers.rs Added a tree_feature_type method to the Element implementation, returning an enum describing the tree's aggregate feature type and values, under specific feature flags.
grovedb/src/operations/proof/mod.rs Modified public verification methods of GroveDBProof to map internal results, discarding the middle element of the returned tuple for consistency. No signature changes.
grovedb/src/operations/proof/verify.rs Added new public methods to verify proofs and return parent tree feature info, updated internal verification function signatures to propagate this info, and refactored recursive logic to track and return the parent tree feature type.
grovedb/src/tests/sum_tree_tests.rs Enhanced tests to assert parent tree feature info in proof verification results and added a new test for the new verification method, using pattern matching for validation.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test
    participant GroveDb as GroveDb
    participant ProofVerifier as ProofVerifier (internal)
    participant Element as Element

    Test->>GroveDb: verify_query_get_parent_tree_info(proof, query, version)
    GroveDb->>ProofVerifier: verify_proof_internal(proof, query, options, version)
    ProofVerifier->>Element: tree_feature_type()
    Element-->>ProofVerifier: TreeFeatureType
    ProofVerifier-->>GroveDb: (root_hash, TreeFeatureType, results)
    GroveDb-->>Test: (root_hash, TreeFeatureType, results)
Loading

Suggested reviewers

  • fominok

Poem

In the grove where proofs are grown,
Now parent trees are clearly shown.
With feature types, their secrets spill,
Each sum and count, a rabbit’s thrill!
Tests now hop with extra glee—
For every node, its pedigree.
🐇🌳✨


📜 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 ea1f8c7 and 58ea608.

📒 Files selected for processing (1)
  • grovedb/src/element/helpers.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • grovedb/src/element/helpers.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Code Coverage
  • GitHub Check: Compilation errors
  • GitHub Check: Tests
✨ 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.
    • 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.

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.

Copy link
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

🧹 Nitpick comments (4)
grovedb/src/operations/proof/mod.rs (1)

73-82: Verify verification method documentation for new return value structure.

The method comments for verification methods should be updated to reflect that internally these methods now return a triple containing parent tree information, even though the public API continues to return just root hash and results.

 /// Verifies a query with options using the proof and returns the root hash
 /// and the query result.
+/// Note: Internally, this also computes parent tree information which is exposed
+/// through the dedicated `verify_query_get_parent_tree_info_with_options` method.
 pub fn verify_with_options(
grovedb/src/tests/sum_tree_tests.rs (2)

109-122: Consider extracting a helper for the repeated proof-verification assertions

The 11-line block that:

  1. calls verify_query_get_parent_tree_info,
  2. asserts root_hash equality,
  3. checks result_set.len(),
  4. asserts on parent,

is duplicated several times in this file (and will likely appear in future tests). A small helper such as assert_parent_tree_info(...) would keep individual tests focused on intent and reduce maintenance overhead.

This is purely a readability / DRY improvement – feel free to ignore if you prefer the current explicit style.


1741-1809: Huge raw proof literal hampers readability and slows down compile times

test_verify_query_get_parent_tree_info embeds a ~3 KB hex string directly in the source. Consider moving it to:

  • a compressed test fixture file loaded at runtime, or
  • a const &[u8] in a separate module reused by multiple tests.

This makes the test file easier to scan and prevents accidental whitespace edits from breaking the hex payload.

grovedb/src/operations/proof/verify.rs (1)

70-122: Duplicate pre-condition logic – extract or reuse existing validator

verify_query_get_parent_tree_info_with_options re-implements all the limit/offset/subquery checks that already exist in verify_query_with_options. Duplicating this logic invites divergence (e.g. the double word in the error message “for for root tree”). Consider factoring the common validation into a small private helper and call it from both entry points.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d8ce92 and ea1f8c7.

📒 Files selected for processing (7)
  • 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/element/helpers.rs (1 hunks)
  • grovedb/src/operations/proof/mod.rs (6 hunks)
  • grovedb/src/operations/proof/verify.rs (11 hunks)
  • grovedb/src/tests/sum_tree_tests.rs (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
grovedb/src/operations/proof/mod.rs (2)
grovedb/src/lib.rs (1)
  • root_hash (463-478)
merk/src/merk/mod.rs (1)
  • root_hash (313-319)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Code Coverage
  • GitHub Check: Compilation errors
  • GitHub Check: Linting
  • GitHub Check: Tests
🔇 Additional comments (5)
grovedb-version/src/version/v2.rs (1)

147-147: Versioning for new parent tree info retrieval feature correctly added.

The addition of verify_query_get_parent_tree_info_with_options with an initial version value of 0 properly tracks the new verification method in the versioning system. This versioning change is consistent with the PR's objective to add query functionality that retrieves parent tree information.

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

81-81: Added proper struct field for version tracking of new feature.

This field declaration for verify_query_get_parent_tree_info_with_options in the GroveDBOperationsProofVersions struct correctly enables version tracking for the new verification method that returns parent tree information. The change is consistent with the PR's goals and the versioning pattern used throughout the project.

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

147-147: Consistently added versioning for feature across all GroveDB versions.

The addition of verify_query_get_parent_tree_info_with_options with a version value of 0 in the GROVE_V1 constant ensures the new verification capability is properly tracked across all supported GroveDB versions. This consistency is important for maintaining backward compatibility.

grovedb/src/operations/proof/mod.rs (1)

81-81: Maintained API compatibility while extending internal verification results.

All public verification methods have been updated to handle the new triple return format from internal verification methods, which now include parent tree information. The .map(|(root_hash, _, results)| (root_hash, results)) transformation elegantly maintains backward compatibility by discarding the middle element (parent tree info) for existing API methods, while allowing new specialized methods to access this information.

This approach ensures existing code continues to work while new functionality is made available through dedicated methods.

Also applies to: 101-101, 121-121, 141-141, 161-161, 181-181

grovedb/src/operations/proof/verify.rs (1)

392-401: Last parent tree feature type may be non-deterministic for multi-key queries

last_parent_tree_type is overwritten every time the recursion descends into a child tree.
If the query contains several keys at the same level (e.g. {k1,k2}) the last visited key will win, leaving the returned parent type dependent on iteration order, not on the caller’s intent.

Please confirm that:

  • the API is only meant for single-key path queries (then add an explicit guard), or
  • the “first” tree should be retained (then update logic to assign only once).

@QuantumExplorer
Copy link
Member Author

Self reviewed.

@QuantumExplorer QuantumExplorer merged commit 6c55ea1 into develop May 11, 2025
8 checks passed
@QuantumExplorer QuantumExplorer deleted the branch branch May 11, 2025 13:19
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.

1 participant