Skip to content

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented May 28, 2025

Issue being fixed or feature implemented

Fixes the loading mechanism for data contracts to ensure they are loaded in the version they appear in.

What was done?

Updated the methods responsible for loading data contracts to respect their versioning. This includes modifications to the from_platform_versioned methods and adjustments in the ActiveSystemDataContract struct to handle version-specific logic.
Changed it so data contracts would use the correct config structure when serializing. A data contract in V1 serializing to storage structure V0 was using config structure V1, when it should have been using config structure V0.

How Has This Been Tested?

Changes were verified through existing unit tests that validate the loading and serialization of data contracts. Additional tests were added to cover edge cases related to version handling.

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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced version-aware conversion traits to improve compatibility across platform versions.
    • Added support for bounded version ranges in contract configuration, enabling more flexible version management.
    • Enabled platform version-aware data contract serialization with improved config validation.
    • Added method to adjust data contract configurations for platform version compatibility.
    • Added conversion from newer to older data contract config versions for backward compatibility.
  • Refactor

    • Simplified and unified test setup functions by reducing redundant parameters.
    • Enhanced system contract management with atomic updates and version tracking.
    • Removed explicit platform version arguments in core drive open calls for streamlined initialization.
    • Updated internal contract loading to use new atomic contract wrapper abstraction.
    • Simplified system contract loading by removing platform version parameter.
  • Bug Fixes

    • Improved serialization logic to ensure consistent contract output across platform versions.
  • Tests

    • Expanded test coverage for contract serialization and version differences.
    • Added tests comparing serialized withdrawal contracts across platform versions.

Copy link
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

The changes introduce version-bound abstractions for contract configuration, enabling platform-version-aware conversions and serialization for data contracts. This includes new traits for infallible conversions, updates to contract version structures, and adjustments to test and helper functions to remove explicit platform version passing. System contract management is refactored for atomic updates and version tracking.

Changes

File(s) Change Summary
.../src/data_contract/config/mod.rs
.../src/data_contract/config/v0/mod.rs
Refined contract config version selection to use default_current_version; added method for platform version validity; implemented From<DataContractConfigV1> for DataContractConfigV0.
.../src/data_contract/serialized_version/mod.rs
.../src/data_contract/serialized_version/v0/mod.rs
.../src/data_contract/serialized_version/v1/mod.rs
Updated serialization to use platform-version-aware conversions; added FromPlatformVersioned<DataContract> implementations for both V0 and V1 formats.
.../src/system_data_contracts.rs Added a test to compare serialization of withdrawal contracts across platform versions.
.../src/main.rs
.../src/platform_types/platform/mod.rs
.../src/open/mod.rs
Removed explicit platform version argument from Drive::open and related calls.
.../src/cache/system_contracts.rs Introduced ActiveSystemDataContract for atomic updates and version tracking; refactored SystemDataContracts to use this abstraction; simplified contract loading.
.../src/drive/credit_pools/epochs/operations_factory.rs
.../src/drive/credit_pools/storage_fee_distribution_pool/get_storage_fees_from_distribution_pool/v0/mod.rs
.../src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs
.../src/drive/document/delete/mod.rs
.../src/drive/document/update/mod.rs
.../src/drive/identity/contract_info/identity_contract_nonce/merge_identity_contract_nonce/v0/mod.rs
.../src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs
.../src/drive/identity/insert/add_new_identity/mod.rs
.../src/drive/identity/key/fetch/mod.rs
.../src/drive/identity/update/operations/merge_identity_nonce_operations/v0/mod.rs
.../src/drive/system/genesis_time/mod.rs
.../src/query/mod.rs
.../src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs
.../src/util/grove_operations/batch_move/v0/mod.rs
.../src/util/grove_operations/batch_move_items_in_path_query/v0/mod.rs
.../src/util/test_helpers/setup.rs
.../tests/deterministic_root_hash.rs
.../tests/query_tests.rs
.../tests/query_tests_history.rs
Updated tests and helpers to remove or simplify platform version arguments, reflecting updated function signatures.
.../src/util/test_helpers/setup.rs setup_drive simplified to remove platform version parameter; updated related helper.
.../src/lib.rs (platform version) Added FromPlatformVersioned and IntoPlatformVersioned traits for infallible, version-aware conversions.
.../src/version/dpp_versions/dpp_contract_versions/mod.rs
.../src/version/dpp_versions/dpp_contract_versions/v1.rs
.../src/version/dpp_versions/dpp_contract_versions/v2.rs
Changed config field to FeatureVersionBounds in contract version structures, enabling version ranges and default selection.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Drive
    participant SystemDataContracts
    participant ActiveSystemDataContract

    Client->>Drive: open(path, config)
    Drive->>SystemDataContracts: load_genesis_system_contracts()
    SystemDataContracts->>ActiveSystemDataContract: new(contract, protocol_version)
    ActiveSystemDataContract-->>SystemDataContracts: ActiveSystemDataContract instance
    SystemDataContracts-->>Drive: SystemDataContracts instance
    Drive-->>Client: (Drive, Option<PlatformVersion>)
Loading
sequenceDiagram
    participant DataContract
    participant SerializationFormatV0
    participant SerializationFormatV1
    participant PlatformVersion

    DataContract->>SerializationFormatV0: from_platform_versioned(self, platform_version)
    DataContract->>SerializationFormatV1: from_platform_versioned(self, platform_version)
    Note over SerializationFormatV0,SerializationFormatV1: Config adjusted via config_valid_for_platform_version
Loading

Suggested reviewers

  • shumkov

Poem

In the warren of code, a new path is laid,
With version bounds and contracts arrayed.
Platform-aware, our conversions now hop,
Atomic contracts never stop!
Tests are lighter, helpers neat—
This rabbit’s work is quite a feat!
🐇✨


📜 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 df7896b and 3af73f4.

📒 Files selected for processing (4)
  • packages/rs-drive-abci/src/platform_types/platform/mod.rs (2 hunks)
  • packages/rs-drive/src/drive/identity/withdrawals/document/find_withdrawal_documents_by_status_and_transaction_indices/v0/mod.rs (1 hunks)
  • packages/wasm-dpp/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js (1 hunks)
  • packages/wasm-dpp/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/wasm-dpp/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js
  • packages/wasm-dpp/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/rs-drive-abci/src/platform_types/platform/mod.rs
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
  • GitHub Check: Rust packages (wasm-dpp) / Formatting
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (wasm-dpp) / Detect immutable structure changes
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Formatting
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (2)
packages/rs-drive/src/drive/identity/withdrawals/document/find_withdrawal_documents_by_status_and_transaction_indices/v0/mod.rs (2)

125-125: LGTM! Test updated to use the new contract loading approach.

The test change mirrors the implementation update and maintains consistency with the new contract management system.


64-64:

✅ Verification successful

LGTM! Simplified contract loading using the new cache system.

The change to use drive.cache.system_data_contracts.load_withdrawals() aligns with the new ActiveSystemDataContract abstraction mentioned in the PR objectives.

Please verify that the new cache system properly handles version-specific loading internally, since the explicit platform_version parameter is no longer passed to the contract loading method:


🏁 Script executed:

#!/bin/bash
# Verify that the cache system handles version-specific contract loading
ast-grep --pattern 'impl $_ {
  $$$
  fn load_withdrawals($$$) {
    $$$
  }
  $$$
}'

Length of output: 87


🏁 Script executed:

#!/bin/bash
# Locate the implementation of load_withdrawals and inspect its signature
rg -n "fn load_withdrawals" -A3 -n .

Length of output: 358


🏁 Script executed:

#!/bin/bash
# Show the beginning of system_contracts.rs for struct definitions
sed -n '1,80p' packages/rs-drive/src/cache/system_contracts.rs

# List all struct declarations
rg -n "pub struct" -n packages/rs-drive/src/cache/system_contracts.rs

# List impl blocks and look for constructors
rg -n "impl " -n packages/rs-drive/src/cache/system_contracts.rs

Length of output: 3398


🏁 Script executed:

#!/bin/bash
# Display reload_system_contracts implementation to verify version handling
sed -n '70,140p' packages/rs-drive/src/cache/system_contracts.rs

Length of output: 3197


Approved – cache abstraction handles version-specific loading internally

The SystemDataContracts::reload_system_contracts method invokes load_system_data_contract(Withdrawals, platform_version) and swaps the result into the withdrawals cache, and load_genesis_system_contracts initializes it with PlatformVersion::first(). The load_withdrawals() call then simply returns the most recently loaded contract. This maintains the same version-aware behavior without passing platform_version at each call site.

No changes required.

✨ 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 added this to the v2.0.0 milestone May 28, 2025
@QuantumExplorer QuantumExplorer changed the title fix!: load data contracts in their respective versions fix(platform)!: load data contracts in their respective versions May 28, 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: 1

♻️ Duplicate comments (7)
packages/rs-drive/tests/query_tests.rs (7)

275-279: Duplicate of the previous remark – same change pattern.


347-351: Duplicate of the previous remark – same change pattern.


823-827: Duplicate of the previous remark – same change pattern.


871-875: Duplicate of the previous remark – same change pattern.


919-923: Duplicate of the previous remark – same change pattern.


957-961: Duplicate of the previous remark – same change pattern.


996-1000: Duplicate of the previous remark – same change pattern.

🧹 Nitpick comments (4)
packages/rs-drive/tests/query_tests.rs (1)

204-208: Signature-update looks correct, but double-check unused import

setup_drive is now invoked with the single Option<DriveConfig> argument as required by the new signature – good catch.
Minor follow-ups:

  1. Make sure every other call site across the codebase was updated the same way (grep for setup_drive().
  2. The explicit import use std::option::Option::None; (line 47) was previously needed to pass None but is probably unused now – if it’s no longer required, consider dropping it to avoid a dead import.

No functional issues observed here.

packages/rs-dpp/src/data_contract/serialized_version/v0/mod.rs (1)

91-146: Consider refactoring to reduce code duplication.

The FromPlatformVersioned<DataContract> implementation is functionally correct and adds the essential platform version-aware config validation via config.config_valid_for_platform_version(platform_version). However, there's significant code duplication between this implementation and the existing From<DataContract> implementation (lines 38-89).

Consider extracting the common conversion logic into a helper function that takes an optional platform version parameter to reduce maintenance burden.

Example refactor approach:

impl DataContractInSerializationFormatV0 {
    fn from_data_contract_with_optional_platform_version(
        value: DataContract, 
        platform_version: Option<&PlatformVersion>
    ) -> Self {
        // Common implementation with conditional config processing
    }
}

Then both trait implementations could delegate to this helper.

packages/rs-dpp/src/data_contract/serialized_version/v1/mod.rs (1)

105-189: Functional implementation with code duplication concern.

The FromPlatformVersioned<DataContract> implementation correctly handles both DataContract::V0 and DataContract::V1 variants with appropriate field mapping. Key improvements over the existing From implementation:

  1. Platform version-aware config validation via config.config_valid_for_platform_version(platform_version) (lines 119, 163)
  2. Proper handling of V1-specific fields when converting from V0 (defaulting to None or Default)

However, similar to the v0 file, there's significant code duplication between this implementation and the existing From<DataContract> implementation (lines 191-271).

Consider applying the same refactoring approach suggested for the v0 file to extract common conversion logic and reduce maintenance overhead.

packages/rs-drive/src/cache/system_contracts.rs (1)

104-143: Consider documenting or using constants for the protocol versions.

The hardcoded protocol versions (1 for most contracts, 9 for token_history and keyword_search) would benefit from either:

  1. Documentation explaining why these specific versions are used
  2. Named constants that make the versions more maintainable

Consider defining constants at the module level:

+/// Protocol version when most system contracts became active
+const GENESIS_PROTOCOL_VERSION: ProtocolVersion = 1;
+
+/// Protocol version when token history and keyword search contracts became active
+const TOKEN_HISTORY_PROTOCOL_VERSION: ProtocolVersion = 9;
+
 /// System contracts
 pub struct SystemDataContracts {

Then use these constants in the initialization:

-                1,
+                GENESIS_PROTOCOL_VERSION,
-                9,
+                TOKEN_HISTORY_PROTOCOL_VERSION,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 80f8be4 and 7917331.

📒 Files selected for processing (33)
  • packages/rs-dpp/src/data_contract/config/mod.rs (3 hunks)
  • packages/rs-dpp/src/data_contract/config/v0/mod.rs (2 hunks)
  • packages/rs-dpp/src/data_contract/serialized_version/mod.rs (7 hunks)
  • packages/rs-dpp/src/data_contract/serialized_version/v0/mod.rs (2 hunks)
  • packages/rs-dpp/src/data_contract/serialized_version/v1/mod.rs (2 hunks)
  • packages/rs-dpp/src/system_data_contracts.rs (2 hunks)
  • packages/rs-drive-abci/src/main.rs (1 hunks)
  • packages/rs-drive-abci/src/platform_types/platform/mod.rs (0 hunks)
  • packages/rs-drive/src/cache/system_contracts.rs (2 hunks)
  • packages/rs-drive/src/drive/credit_pools/epochs/operations_factory.rs (1 hunks)
  • packages/rs-drive/src/drive/credit_pools/storage_fee_distribution_pool/get_storage_fees_from_distribution_pool/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/document/delete/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/document/update/mod.rs (4 hunks)
  • packages/rs-drive/src/drive/identity/contract_info/identity_contract_nonce/merge_identity_contract_nonce/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/insert/add_new_identity/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/key/fetch/mod.rs (4 hunks)
  • packages/rs-drive/src/drive/identity/update/operations/merge_identity_nonce_operations/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/system/genesis_time/mod.rs (3 hunks)
  • packages/rs-drive/src/open/mod.rs (1 hunks)
  • packages/rs-drive/src/query/mod.rs (2 hunks)
  • packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs (5 hunks)
  • packages/rs-drive/src/util/grove_operations/batch_move/v0/mod.rs (3 hunks)
  • packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/v0/mod.rs (3 hunks)
  • packages/rs-drive/src/util/test_helpers/setup.rs (2 hunks)
  • packages/rs-drive/tests/deterministic_root_hash.rs (2 hunks)
  • packages/rs-drive/tests/query_tests.rs (8 hunks)
  • packages/rs-drive/tests/query_tests_history.rs (1 hunks)
  • packages/rs-platform-version/src/lib.rs (1 hunks)
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/mod.rs (1 hunks)
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v1.rs (1 hunks)
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v2.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/rs-drive-abci/src/platform_types/platform/mod.rs
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
packages/rs-dpp/src/data_contract/config/mod.rs (1)
Learnt from: QuantumExplorer
PR: dashpay/platform#2227
File: packages/rs-drive-abci/src/platform_types/platform_state/mod.rs:141-141
Timestamp: 2024-10-08T13:28:03.529Z
Learning: When converting `PlatformStateV0` to `PlatformStateForSavingV1` in `packages/rs-drive-abci/src/platform_types/platform_state/mod.rs`, only version `0` needs to be handled in the match on `platform_state_for_saving_structure_default` because the changes are retroactive.
packages/rs-dpp/src/data_contract/serialized_version/mod.rs (1)
Learnt from: QuantumExplorer
PR: dashpay/platform#2227
File: packages/rs-drive-abci/src/platform_types/platform_state/mod.rs:141-141
Timestamp: 2024-10-08T13:28:03.529Z
Learning: When converting `PlatformStateV0` to `PlatformStateForSavingV1` in `packages/rs-drive-abci/src/platform_types/platform_state/mod.rs`, only version `0` needs to be handled in the match on `platform_state_for_saving_structure_default` because the changes are retroactive.
🧬 Code Graph Analysis (14)
packages/rs-drive/src/drive/credit_pools/epochs/operations_factory.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/drive/identity/update/operations/merge_identity_nonce_operations/v0/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/drive/system/genesis_time/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/v0/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/util/grove_operations/batch_move/v0/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/drive/identity/contract_info/identity_contract_nonce/merge_identity_contract_nonce/v0/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/drive/document/update/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/tests/deterministic_root_hash.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/drive/identity/key/fetch/mod.rs (1)
packages/rs-drive/src/util/test_helpers/setup.rs (1)
  • setup_drive (39-46)
packages/rs-drive/src/open/mod.rs (1)
packages/rs-drive/src/cache/system_contracts.rs (1)
  • load_genesis_system_contracts (104-144)
packages/rs-dpp/src/system_data_contracts.rs (1)
packages/rs-dpp/src/data_contract/config/mod.rs (1)
  • data_contract (114-136)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: Rust packages (dapi-grpc) / Linting
  • GitHub Check: Rust packages (dapi-grpc) / Tests
  • GitHub Check: Rust packages (dapi-grpc) / Formatting
  • GitHub Check: Rust packages (rs-dapi-client) / Check each feature
  • GitHub Check: Rust packages (rs-dapi-client) / Tests
  • GitHub Check: Rust packages (rs-dapi-client) / Linting
  • GitHub Check: Rust packages (rs-dapi-client) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (38)
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs (1)

25-25: LGTM! Function call correctly updated to match new signature.

The change correctly updates the setup_drive call to use the simplified signature that only takes an optional DriveConfig parameter, removing the previously required platform version argument.

packages/rs-drive/src/drive/credit_pools/epochs/operations_factory.rs (1)

429-429: LGTM! Function call correctly updated to match new signature.

The change correctly updates the setup_drive call to align with the simplified function signature that only requires an optional DriveConfig parameter.

packages/rs-drive/src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs (1)

60-60: LGTM! Function call correctly updated to match new signature.

The change correctly updates the setup_drive call to use the simplified signature, maintaining consistency with the broader refactoring effort.

packages/rs-drive/src/drive/identity/update/operations/merge_identity_nonce_operations/v0/mod.rs (1)

180-180: LGTM! Test helper function correctly updated to match new signature.

The change correctly updates the setup_drive call in the setup_base_test helper function to align with the simplified signature. This change will benefit all tests that use this helper function.

packages/rs-drive/src/drive/credit_pools/storage_fee_distribution_pool/get_storage_fees_from_distribution_pool/v0/mod.rs (1)

55-55: LGTM! Consistent API simplification.

The update to setup_drive(None) correctly aligns with the simplified function signature that removes the explicit platform version parameter. This change maintains the test's functionality while contributing to a cleaner API design.

packages/rs-drive/src/drive/identity/contract_info/identity_contract_nonce/merge_identity_contract_nonce/v0/mod.rs (1)

307-307: Excellent! Helper function updated consistently.

The change to setup_drive(None) in the setup_base_test helper function correctly implements the API simplification and benefits all the test functions that use this helper (including merge_identity_contract_nonce_with_bump, merge_identity_contract_nonce_0_is_invalid, and merge_identity_contract_nonce_many_updates).

packages/rs-drive/src/drive/identity/insert/add_new_identity/mod.rs (1)

193-193: Perfect update to simplified API.

The change to setup_drive(None) correctly implements the function signature update while preserving all test functionality for identity insertion and fetching validation across different platform versions.

packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/v0/mod.rs (1)

161-161: Excellent consistency across all test functions!

All three test functions (test_batch_move_items_in_path_query_success, test_batch_move_items_in_path_query_no_elements, and test_batch_move_items_in_path_query_range_query) have been correctly updated to use setup_drive(None), maintaining comprehensive test coverage for batch move operations while aligning with the simplified API design.

Also applies to: 318-318, 365-365

packages/rs-drive/src/util/grove_operations/batch_move/v0/mod.rs (1)

134-134: LGTM! Function signature update is consistent with refactoring.

The changes correctly update the setup_drive calls to match the new function signature that removes the platform version parameter. This aligns with the broader refactoring effort described in the PR objectives.

Also applies to: 240-240, 288-288

packages/rs-drive/src/drive/system/genesis_time/mod.rs (1)

60-60: LGTM! Consistent function signature updates.

The changes properly update setup_drive calls to use the new single-parameter signature, removing the platform version argument as part of the coordinated refactoring effort.

Also applies to: 71-71, 137-137

packages/rs-drive/src/drive/document/update/mod.rs (1)

855-855: LGTM! Function signature updates maintain test functionality.

The changes correctly update setup_drive calls from setup_drive(Some(config), None) to setup_drive(Some(config)), properly removing the platform version parameter while preserving the drive configuration. This is consistent with the broader refactoring effort.

Also applies to: 1162-1162, 1369-1369, 1712-1712

packages/rs-drive-abci/src/main.rs (1)

473-473: LGTM! Drive::open signature update is consistent with refactoring.

The change correctly updates the Drive::open call to remove the platform version parameter, aligning with the broader codebase refactoring to simplify drive initialization by removing explicit platform version passing.

packages/rs-drive/src/drive/document/delete/mod.rs (1)

92-93: LGTM! API simplification aligns with the broader refactor.

The removal of the PlatformVersion parameter from the Drive::open method call is consistent with the PR's objective to update data contract loading methods to handle version-specific logic internally. This simplifies the API while maintaining functionality.

packages/rs-drive/src/query/mod.rs (2)

2324-2324: Use default platform version in Drive::open test helper
The call to Drive::open in setup_family_contract has been updated to pass None instead of an explicit PlatformVersion, in line with the refactored signature that uses an internal default. Please verify that the default platform version used internally matches the intended version for all downstream operations (e.g., create_initial_state_structure).


2357-2357: Omit explicit platform version in withdrawal contract setup
In setup_withdrawal_contract, Drive::open now receives None for the platform version argument. This aligns with the updated method signature. Confirm that this change does not introduce any versioning mismatches in the withdrawal contract tests.

packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/mod.rs (1)

16-16: Excellent architectural improvement for version-bound contract configuration.

The change from FeatureVersion to FeatureVersionBounds enables more precise version control by allowing specification of min/max version ranges instead of a single version. This aligns perfectly with the PR objective of loading data contracts in their respective versions and provides better flexibility for version-specific handling.

packages/rs-drive/tests/query_tests_history.rs (1)

171-171: LGTM! Function signature simplification improves maintainability.

The removal of the second parameter (None for specific_platform_version) simplifies the test setup by relying on internal defaults for platform version handling. This change is consistent with the broader refactor across the codebase to remove explicit platform version passing, improving code maintainability.

packages/rs-drive/tests/deterministic_root_hash.rs (1)

319-319: LGTM! Correct function signature update.

The changes properly align with the setup_drive function signature simplification, removing the second parameter as shown in the helper function definition.

Also applies to: 338-338

packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs (1)

146-146: LGTM! Consistent test setup updates.

All test functions correctly updated to use the new setup_drive signature. The changes are mechanical and preserve all existing test functionality.

Also applies to: 237-237, 382-382, 458-458, 494-494

packages/rs-drive/src/drive/identity/key/fetch/mod.rs (1)

1049-1049: LGTM! Proper test setup function updates.

All identity key fetch test functions correctly updated to match the simplified setup_drive function signature. No functional changes to the tests themselves.

Also applies to: 1085-1085, 1125-1125, 1165-1165

packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v1.rs (1)

17-21: LGTM! Proper version bounds migration.

The change from a simple integer to FeatureVersionBounds structure enhances version handling capabilities while maintaining backward compatibility by setting all bounds to the previous value (0).

packages/rs-dpp/src/data_contract/config/v0/mod.rs (2)

2-2: LGTM: Import addition supports version conversion.

The import of DataContractConfigV1 is necessary for the new conversion implementation.


197-213: LGTM: Well-implemented backward compatibility conversion.

The From<DataContractConfigV1> for DataContractConfigV0 implementation correctly enables version downgrade by performing direct field mapping. This is essential for the version-aware contract loading mechanism described in the PR objectives, allowing V1 configs to be used on platforms that only support V0.

The implementation preserves all data without loss, which is appropriate for a backward compatibility conversion.

packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v2.rs (1)

17-21: LGTM: Enhanced version handling with bounds.

The migration from a simple config version to FeatureVersionBounds provides better control over version compatibility. The bounds (min: 0, max: 1, default: 1) correctly support both V0 and V1 configurations with V1 as the current default, which aligns perfectly with the backward compatibility conversion implemented in the config module.

This change supports the PR objective of loading data contracts in their respective versions by providing precise version range control.

packages/rs-dpp/src/data_contract/serialized_version/mod.rs (2)

20-20: LGTM! Import addition supports platform-versioned conversions.

The addition of IntoPlatformVersioned to the imports is necessary for the explicit platform-version-aware conversions introduced below.


163-164: Excellent refactoring to explicit platform-versioned conversions.

The systematic replacement of .into() calls with .into_platform_versioned(platform_version) makes the versioning semantics explicit and ensures proper version-aware serialization. This change is consistent across all TryFromPlatformVersioned implementations and aligns with the new infallible conversion traits.

Also applies to: 168-169, 195-196, 200-201, 227-228, 232-233, 259-260, 264-265, 291-292, 296-297, 323-324, 328-329

packages/rs-drive/src/open/mod.rs (1)

61-61: LGTM! Simplified system contracts loading aligns with refactoring.

The removal of the platform version parameter from SystemDataContracts::load_genesis_system_contracts() simplifies the API and delegates version management to internal abstractions, as shown in the implementation that now uses PlatformVersion::first() internally and wraps contracts in ActiveSystemDataContract.

packages/rs-dpp/src/data_contract/config/mod.rs (2)

33-38: LGTM! Version selection logic updated for new FeatureVersionBounds structure.

The changes to use platform_version.dpp.contract_versions.config.default_current_version instead of directly matching on the config field align correctly with the updated FeatureVersionBounds type that now provides structured bounds with min_version, max_version, and default_current_version.

Also applies to: 73-78, 118-123


49-67: Well-designed method for platform version compatibility.

The config_valid_for_platform_version method provides a clean approach to handle version compatibility by:

  • Preserving V0 configs unchanged
  • Downgrading V1 to V0 only when the platform's max supported version is 0
  • Otherwise preserving the original config

This logic ensures backward compatibility while respecting platform version constraints.

packages/rs-drive/src/util/test_helpers/setup.rs (2)

39-39: LGTM! Test helper simplified to align with Drive API changes.

The removal of the specific_platform_version parameter and the corresponding update to the Drive::open call simplifies the test setup API and aligns with the broader refactoring that delegates platform version management to internal Drive mechanisms.

Also applies to: 42-42


53-56: Good adaptation of dependent function.

The setup_drive_with_initial_state_structure function correctly adapts to the simplified setup_drive API while maintaining its own platform version handling logic for the initial state structure creation.

packages/rs-dpp/src/data_contract/serialized_version/v0/mod.rs (1)

10-11: Good addition of platform version support imports.

The imports for PlatformVersion and FromPlatformVersioned are correctly added to support the new trait implementation.

packages/rs-dpp/src/system_data_contracts.rs (2)

70-72: Good addition of serialization test imports.

The imports for DataContractInSerializationFormat, PlatformSerializableWithPlatformVersion, and TryIntoPlatformVersioned are correctly added to support the new serialization tests.


88-137:

❓ Verification inconclusive

Comprehensive serialization test with helpful comments.

The test serialize_withdrawal_contract_v1_vs_v9 provides excellent coverage of the platform version-aware serialization behavior. The test correctly:

  1. Loads contracts for different platform versions and verifies they differ
  2. Serializes both contracts targeting the same platform version and verifies consistency
  3. Tests serialization byte length differences across versions
  4. Includes helpful comments explaining the expected behavior (lines 123, 136)

The hardcoded byte lengths (1747, 1757, 1758) might be somewhat brittle if serialization details change, but they provide valuable regression testing for the specific versioning behavior being implemented.

Consider verifying that the expected byte lengths remain stable across different environments:


🏁 Script executed:

#!/bin/bash
# Description: Run the serialization test to verify byte length stability
# Expected: Test should pass consistently

cargo test serialize_withdrawal_contract_v1_vs_v9 -- --nocapture

Length of output: 17762


Confirm byte length stability locally

The serialize_withdrawal_contract_v1_vs_v9 test in packages/rs-dpp/src/system_data_contracts.rs (lines 88–137) provides thorough coverage of version-aware serialization, including:

  • Loading v1 vs v9 contracts and asserting they differ
  • Serializing both against the same platform version to ensure consistent structure
  • Verifying hardcoded byte-length differences (1747, 1757, 1758) for regression safety

Since the sandbox environment lacks a C linker (cc), we couldn’t execute the test here. Please run the following locally to confirm the expected byte lengths remain stable across your environment:

cargo test serialize_withdrawal_contract_v1_vs_v9 -- --nocapture
packages/rs-dpp/src/data_contract/serialized_version/v1/mod.rs (1)

17-18: Correct platform version imports added.

The imports for PlatformVersion and FromPlatformVersioned are properly added to support the new trait implementation.

packages/rs-platform-version/src/lib.rs (1)

54-79: Well-designed infallible conversion traits.

The introduction of FromPlatformVersioned<T> and IntoPlatformVersioned<T> traits provides a clean, infallible alternative to the existing fallible conversion traits. Key strengths:

  1. Clear documentation: The traits are well-documented with their purpose and guarantees
  2. Ergonomic design: The automatic implementation of IntoPlatformVersioned<U> for types where U: FromPlatformVersioned<T> (lines 71-79) follows Rust's standard library patterns
  3. Type safety: Infallible conversions ensure guaranteed valid results for supported versions
  4. Consistent API: Mirrors the existing fallible traits while providing deterministic behavior

This foundation enables the platform version-aware data contract serialization implemented in the other reviewed files.

packages/rs-drive/src/cache/system_contracts.rs (2)

56-68: LGTM! Clean refactoring to use the new abstraction.

The consistent replacement of ArcSwap<DataContract> with ActiveSystemDataContract across all system contract fields provides a uniform interface for version-aware contract management.


92-98: LGTM! Correct usage of the new store method.

The removal of explicit Arc::new() wrapping is correct since ActiveSystemDataContract::store already handles the Arc wrapping internally. This simplifies the code and avoids double-wrapping.

Copy link
Member Author

@QuantumExplorer QuantumExplorer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self Reviewed

@QuantumExplorer QuantumExplorer merged commit d8951d4 into v2.0-dev May 28, 2025
147 of 149 checks passed
@QuantumExplorer QuantumExplorer deleted the fixload-data-contracts-version branch May 28, 2025 17:57
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