Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(drive-abci): document purchase on mutable document from different epoch had issue #2420

Merged
merged 4 commits into from
Jan 14, 2025

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Jan 14, 2025

Issue being fixed or feature implemented

If a document was changed at a different epoch, the bought at a different later epoch, this would cause a grovedb error. This has now been fixed.

What was done?

We also took the time to upgrade some dependencies in GroveDB, and reduce some dependencies as well leading to slightly faster compilation time.

How Has This Been Tested?

All tests are passing.

Breaking Changes

None expected.

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
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Dependency Updates

    • Updated rocksdb library version from 0.22.0 to 0.23.0 in multiple packages
    • Updated grovedb and related dependencies to version 2.2.1
    • Updated intmap library to version 3.0.1
    • Updated grovedb-version to version 2.2.1 in the platform-version package
  • New Test Files

    • Added JSON schema for a crypto card game document
    • Introduced new test cases for document pricing and purchasing mechanisms
  • Internal Improvements

    • Enhanced validation logic for document handling
    • Modified data type handling in some internal functions
    • Updated enum field types in grove operations
  • Action and Dockerfile Updates

    • Updated default RocksDB version in GitHub action and Dockerfile to 9.9.3

@QuantumExplorer QuantumExplorer added the bug Something isn't working label Jan 14, 2025
@QuantumExplorer QuantumExplorer added this to the v1.8.0 milestone Jan 14, 2025
@QuantumExplorer QuantumExplorer self-assigned this Jan 14, 2025
Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

This pull request involves multiple package updates across the Dash Drive repository, primarily focusing on dependency version upgrades. The changes include updating rocksdb to version 0.23.0 in multiple packages, upgrading grovedb-related dependencies to version 2.2.1, and modifying the intmap dependency to version 3.0.1. Additionally, there are some type-related changes in the codebase, specifically converting some u64 types to u16 in key-related operations. A new JSON schema for a crypto card game has also been introduced.

Changes

File Change Summary
packages/rs-drive-abci/Cargo.toml Updated rocksdb dependency from 0.22.0 to 0.23.0
packages/rs-drive/Cargo.toml - Updated intmap to 3.0.1
- Updated multiple grovedb dependencies to 2.2.1
- Modified server feature to use grovedb/minimal
packages/rs-platform-version/Cargo.toml Updated grovedb-version to 2.2.1
packages/strategy-tests/Cargo.toml Updated rocksdb dependency from 0.22.0 to 0.23.0
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs Added new tests for document price and purchase scenarios
packages/rs-drive-abci/tests/supporting_files/contract/crypto-card-game/crypto-card-game-direct-purchase-documents-mutable.json Added new JSON schema for crypto card game documents
packages/rs-drive/src/drive/document/estimation_costs/stateless_delete_of_non_tree_for_costs/v0/mod.rs Modified data types from u64 to u16
packages/rs-drive/src/util/grove_operations/mod.rs Updated BatchDeleteUpTreeApplyType enum to use IntMap<u16, EstimatedLayerInformation>
.github/actions/librocksdb/action.yaml Updated version input parameter description and default value from "8.10.2" to "9.9.3"
Dockerfile Updated RocksDB clone version from v8.10.2 to v9.9.3

Possibly related PRs

Suggested reviewers

  • shumkov
  • lklimek

Poem

🐰 Hop, hop, through Cargo's domain,
Versions dance, dependencies reign!
From RocksDB to GroveDB's might,
Upgrading code with rabbit's delight!
A version leap, a codebase bright! 🚀


📜 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 5cdae04 and 1ce86d3.

📒 Files selected for processing (2)
  • .github/actions/librocksdb/action.yaml (1 hunks)
  • Dockerfile (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dapi-grpc) / Check each feature
  • GitHub Check: Rust packages (dapi-grpc) / Tests
  • GitHub Check: Rust packages (dapi-grpc) / Unused dependencies
  • GitHub Check: Rust packages (dapi-grpc) / Linting
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (2)
.github/actions/librocksdb/action.yaml (1)

9-9: Verify RocksDB version compatibility with rust-rocksdb crate.

The RocksDB version has been updated from 8.10.2 to 9.9.3. Let's verify that this version is compatible with the rust-rocksdb crate being used.

Also applies to: 11-11

Dockerfile (1)

263-263: LGTM! Version update is consistent.

The RocksDB version update to 9.9.3 matches the version specified in the GitHub Action, maintaining consistency across the build process.


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.

@QuantumExplorer QuantumExplorer changed the title fix: document purchase on mutable document from different epoch had issue fix(drive-abci): document purchase on mutable document from different epoch had issue Jan 14, 2025
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: 3

🧹 Nitpick comments (4)
packages/rs-drive-abci/tests/supporting_files/contract/crypto-card-game/crypto-card-game-direct-purchase-documents-mutable.json (1)

13-61: Consider adding maximum bounds for numeric properties.

While minimum bounds are set for attack and defense, consider adding maximum bounds to prevent potential integer overflow issues.

         "attack": {
           "type": "integer",
           "description": "Attack power of the card",
           "minimum": 0,
+          "maximum": 65535,
           "position": 5
         },
         "defense": {
           "type": "integer",
           "description": "Defense level of the card",
           "minimum": 0,
+          "maximum": 65535,
           "position": 6
         }
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs (3)

Line range hint 6451-6466: Refactor Random Number Generator Initialization for Test Isolation

The tests in the nft_tests module use the same seed for the StdRng random number generator. To ensure test isolation and reproducibility, consider initializing the RNG with different seeds in each test or resetting the RNG state within each test.


Line range hint 6451-7186: Reduce Code Duplication Across Tests

The tests test_document_set_price_and_purchase and test_document_set_price_and_purchase_different_epoch_documents_mutable share significant portions of setup and logic. Refactor shared code into helper functions or fixtures to enhance maintainability and readability.


7730-7731: Clarify Test Name for Better Understanding

The test test_document_set_price_and_purchase_different_epoch could be renamed for clarity. A name like test_document_set_price_and_purchase_across_epochs more accurately describes the test's purpose.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be5cd6d and 5cdae04.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • packages/rs-drive-abci/Cargo.toml (1 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs (2 hunks)
  • packages/rs-drive-abci/tests/supporting_files/contract/crypto-card-game/crypto-card-game-direct-purchase-documents-mutable.json (1 hunks)
  • packages/rs-drive/Cargo.toml (2 hunks)
  • packages/rs-drive/src/drive/document/estimation_costs/stateless_delete_of_non_tree_for_costs/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/util/grove_operations/mod.rs (1 hunks)
  • packages/rs-platform-version/Cargo.toml (1 hunks)
  • packages/strategy-tests/Cargo.toml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dapi-grpc) / Unused dependencies
  • GitHub Check: Rust packages (dapi-grpc) / Tests
  • GitHub Check: Rust packages (dapi-grpc) / Linting
  • GitHub Check: Rust packages (dapi-grpc) / Check each feature
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit
🔇 Additional comments (13)
packages/rs-platform-version/Cargo.toml (1)

14-14: Verify grovedb-version 2.2.1 changelog for breaking changes.

The upgrade from 2.1.0 to 2.2.1 should be reviewed for any breaking changes that might affect the platform versioning functionality.

Run this script to check the changelog and release notes:

✅ Verification successful

✓ grovedb-version 2.2.1 upgrade is safe

The upgrade from 2.1.0 to 2.2.1 contains only bug fixes and optimizations with no breaking changes. The changes include a sub tree prefix fix and state sync optimization.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check grovedb-version 2.2.1 release notes and changes

# Search for any BREAKING CHANGE markers in commit messages
gh api graphql -f query='
{
  repository(owner: "dashpay", name: "grovedb") {
    releases(first: 5, orderBy: {field: CREATED_AT, direction: DESC}) {
      nodes {
        tagName
        description
      }
    }
  }
}'

# Look for any migration guides or upgrade notes
rg -i "upgrade|migration|breaking.?change" -g "*.md"

Length of output: 17350

packages/rs-drive/Cargo.toml (3)

55-60: Verify consistency of grovedb ecosystem updates.

All grovedb-related dependencies have been updated to version 2.2.1, which is good for consistency. However, we should verify the compatibility and changes across the ecosystem.

Run this script to check for any compatibility issues:

✅ Verification successful

GroveDB ecosystem update verification successful

All GroveDB-related dependencies are consistently set to version 2.2.1 in both Cargo.toml and Cargo.lock, with proper integration through feature flags and error handling. No compatibility issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify grovedb ecosystem compatibility

# Check if all grovedb dependencies are at the same version
rg '"grovedb.*"' -A 1

# Look for any compatibility matrices in documentation
rg -i "compatibility|version.?matrix" -g "*.md"

Length of output: 8555


52-52: Review intmap's breaking changes from 2.0.0 to 3.0.1.

The major version bump (2.0.0 -> 3.0.1) of intmap requires careful review of breaking changes.

Run this script to check the changelog:


107-107: Assess impact of switching from grovedb/full to grovedb/minimal.

The server feature now uses grovedb/minimal instead of grovedb/full. This change could affect functionality and needs to be verified.

Run this script to understand the feature differences:

✅ Verification successful

Switching to grovedb/minimal is safe for production code

The change only affects test configuration and does not impact production code. All grovedb imports in the codebase use core functionality that is available in both minimal and full features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare grovedb full vs minimal features

# Search for feature documentation
rg -i "feature.*full|feature.*minimal" -g "*.md"

# Look for any usage of full-specific features that might break
ast-grep --pattern 'use grovedb::$_'

Length of output: 48870


Script:

#!/bin/bash
# Search for grovedb's Cargo.toml and feature definitions
fd Cargo.toml | xargs rg -l "grovedb.*dependencies|grovedb.*features|features.*minimal|features.*full"

# Search for feature documentation in grovedb source
rg -i "feature.*minimal|feature.*full" -g "*.rs"

Length of output: 612

packages/strategy-tests/Cargo.toml (1)

49-49: Verify RocksDB version compatibility.

The upgrade to RocksDB 0.23.0 should be verified for compatibility with other dependencies and potential performance impacts.

Run this script to check for any compatibility issues or breaking changes:

✅ Verification successful

RocksDB version upgrade verified as safe

Both packages use RocksDB 0.23.0 consistently, and the codebase uses standard, stable RocksDB APIs. No compatibility issues or breaking changes detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check RocksDB version compatibility and changelog
# Test: Look for breaking changes in RocksDB 0.23.0

# Check if other packages are using different RocksDB versions
rg -g "Cargo.toml" "rocksdb.*version.*0\.[0-9]+\.[0-9]+"

# Check for any RocksDB related test failures in CI logs
rg -i "rocksdb.*(?:error|fail|break)" .github/

Length of output: 240


Script:

#!/bin/bash
# Check for RocksDB usage patterns and imports
ast-grep --pattern 'use rocksdb::$_'

# Look for RocksDB configuration or setup code
rg -g "*.rs" "rocksdb::(?:DB|Options|WriteOptions|ReadOptions)" -A 2

Length of output: 363

packages/rs-drive-abci/Cargo.toml (1)

102-102: LGTM! Consistent RocksDB version across packages.

The RocksDB version update to 0.23.0 aligns with the version used in strategy-tests, maintaining consistency across packages.

packages/rs-drive-abci/tests/supporting_files/contract/crypto-card-game/crypto-card-game-direct-purchase-documents-mutable.json (3)

8-12: LGTM! Document configuration aligns with purchase requirements.

The configuration enables document mutability, deletion, and transfers, which is essential for the document purchase functionality across epochs.


62-121: LGTM! Comprehensive indexing strategy.

The indices are well-designed for efficient querying of:

  • Ownership tracking
  • Card attributes (attack, defense)
  • Transfer history with block heights
  • Combined queries (owner + transfer time)

123-130: Verify required fields for document purchases.

The schema correctly requires transfer-related fields ($transferredAt, $transferredAtBlockHeight, $transferredAtCoreBlockHeight) which are essential for tracking document purchases across epochs.

✅ Verification successful

Transfer-related fields are correctly specified and consistent with the codebase.

The schema follows the established pattern for crypto card game documents, requiring all three transfer-related fields ($transferredAt, $transferredAtBlockHeight, $transferredAtCoreBlockHeight) which are properly supported by the implementation in document_info.rs.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that transfer-related fields are consistently used across the codebase
# Test: Look for usage of transfer-related fields in document operations

# Check for transfer field usage in document operations
rg -A 5 '\$transferredAt|\$transferredAtBlockHeight|\$transferredAtCoreBlockHeight' \
   --type rust \
   packages/rs-drive*/src/

Length of output: 3807


Script:

#!/bin/bash
# Search for other document purchase schemas
fd -e json . packages/rs-drive-abci/tests/supporting_files/contract/ \
   --exec grep -l "transferredAt\|transferredAtBlockHeight\|transferredAtCoreBlockHeight" {} \;

# Show content of found files
fd -e json . packages/rs-drive-abci/tests/supporting_files/contract/ \
   --exec grep -A 10 "required" {} \;

Length of output: 13164

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs (3)

8011-8012: ⚠️ Potential issue

Increment Document Revision Before Purchase

In test_document_set_price_and_purchase_different_epoch, the document's revision should be incremented before making the purchase to reflect the state change. Missing this step may lead to version conflicts or rejection of the state transition.

Apply this change to increment the document revision:

 document.bump_revision();
+document.bump_revision();
 let documents_batch_purchase_transition =

Likely invalid or redundant comment.


7197-7199: Verify Correctness of Balance Calculation

In test_document_set_price_and_purchase, the assertion on line 7198:

assert_eq!(buyers_balance, dash_to_credits!(0.9) - 68691480);

Ensure that the buyers_balance accurately reflects all fees and credits involved in the transaction, including storage fees, processing fees, and the purchase amount.

✅ Verification successful

Balance Calculation is Accurate and Complete

The assertion buyers_balance = dash_to_credits!(0.9) - 68691480 is correct and accounts for:

  • Purchase price (0.1 DASH)
  • Storage fee (64,611,000 credits)
  • Processing fee (4,080,480 credits)
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Find the complete test implementation
ast-grep --pattern 'fn test_document_set_price_and_purchase($$$) {
  $$$
}'

# Search for similar test cases and fee calculations
rg "test_document.*purchase" -A 5
rg "68691480|storage.*fee|processing.*fee" -A 2

Length of output: 67310


8088-8090: Assert Ownership Transfer After Purchase

After the purchase in test_document_set_price_and_purchase_different_epoch, verify that the document's ownership has been correctly transferred to the purchaser. This ensures the purchase operation completed successfully.

Add the following assertion:

assert_eq!(document.owner_id(), purchaser.id());
packages/rs-drive/src/drive/document/estimation_costs/stateless_delete_of_non_tree_for_costs/v0/mod.rs (1)

85-90: Ensure Key Length Fits Within u16 Bounds

When casting (key_info_path.len() - 1) to u16, verify that the length does not exceed u16::MAX. If there's a possibility of overflow, implement checks or use a larger integer type to prevent data loss.

@QuantumExplorer QuantumExplorer merged commit e94b7bb into v1.8-dev Jan 14, 2025
77 checks passed
@QuantumExplorer QuantumExplorer deleted the fix/DocumentPurchase branch January 14, 2025 12:23
@coderabbitai coderabbitai bot mentioned this pull request Jan 15, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants