Skip to content

Conversation

@pauldelucia
Copy link
Member

@pauldelucia pauldelucia commented Apr 14, 2025

Issue being fixed or feature implemented

Allow new tokens on contract update, add advanced structure validation for contract update, basic structure validation for contract update and create.

What was done?

Remove the check for new tokens and replace with validations. Refactor contract validations.

How Has This Been Tested?

Added unit tests

Breaking Changes

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

  • New Features

    • Introduced basic structure validation for data contract creation and update transitions, including checks for group and token configuration integrity.
    • Added advanced structure validation versioning for data contract creation transitions, supporting both initial and updated validation logic.
    • Enhanced token validation to allow new tokens with additional checks on distribution timestamps.
    • Added version-dependent conditional basic structure validation for data contract create and update state transitions.
  • Bug Fixes

    • Improved error reporting for invalid token configurations, such as non-contiguous positions, excessive base supply, and missing localization.
    • Updated error handling to classify certain validation errors as unpaid consensus errors.
  • Tests

    • Expanded test coverage for token and group validation scenarios, including edge cases and error conditions.
    • Added tests for token addition with gaps, large base supply, and invalid localization.
    • Added tests verifying token addition with valid and invalid pre-programmed distribution timestamps.
  • Chores

    • Updated platform and validation versioning to support new validation logic and maintain compatibility with previous versions.
    • Refined method signatures to include block information for enhanced validation context.
    • Simplified method signatures and validation flows by removing redundant parameters and delegating to newer validation versions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

Walkthrough

This update introduces versioned basic structure validation for data contract create and update state transitions, including new validation modules and traits for both transition types. The validation logic for data contract tokens and groups is refactored and restructured, with some checks moved between advanced and basic structure validations. The changes add support for version 6 of Drive ABCI validation, updating the platform version configuration accordingly. Test cases are expanded and adapted to cover new validation scenarios, particularly for tokens. The control flow for state transition validation is adjusted to ensure that contract creation and update transitions now perform their own basic structure validation.

Changes

File(s) / Path(s) Change Summary
.../src/data_contract/methods/validate_update/mod.rs, .../v0/mod.rs Updated validate_update and validate_update_v0 method signatures to accept block_info; enhanced token validation logic to allow new tokens with checks on pre-programmed distribution timestamps; updated related tests.
.../state_transition/state_transitions/data_contract_update/mod.rs Added implementation of versioned basic structure validation for DataContractUpdateTransition; expanded and updated token and group validation tests with new failure cases and improved error assertions.
.../state_transition/state_transitions/data_contract_update/state/v0/mod.rs Removed token distribution timestamp validation logic from state validation; updated validate_update method to accept block_info.
.../state_transition/processor/v0/mod.rs Updated basic structure validation dispatch to include DataContractCreate and DataContractUpdate transitions conditionally based on platform version; removed unconditional early return for these variants.
.../state_transition/state_transitions/data_contract_create/advanced_structure/v0/mod.rs Removed group and token validation logic from advanced structure validation; simplified method signature and updated tests accordingly; delegated validation to version 1 advanced structure validation.
.../state_transition/state_transitions/data_contract_create/basic_structure/mod.rs, .../v0/mod.rs Added new module for versioned basic structure validation and implemented trait for DataContractCreateTransition with group and token validation logic including token positions, base supply, localization, and group existence checks.
.../state_transition/state_transitions/data_contract_create/mod.rs Added and wired up basic structure validation for contract creation; updated advanced structure validation dispatch to support versions 0 and 1; replaced paid consensus errors with unpaid consensus errors in test assertions.
.../state_transition/state_transitions/data_contract_update/basic_structure/mod.rs, .../v0/mod.rs Added new module and trait for versioned basic structure validation for contract update transitions, including group and token checks similar to create transition validation.
.../src/version/drive_abci_versions/drive_abci_validation_versions/mod.rs, .../v6.rs Added version 6 module and constant for Drive ABCI validation versions, configuring new validation versions for multiple state transitions including basic and advanced structure validations for data contract create and update transitions.
.../src/version/v9.rs Updated platform version 9 to use Drive ABCI validation version 6 instead of version 4.
.../state_transition/state_transitions/data_contract_create/advanced_structure/mod.rs, .../v1/mod.rs Added version 1 advanced structure validation for contract creation; implemented trait and method for new validation logic including data contract ID verification and execution context updates.
.../state_transition/check_tx_verification/v0/mod.rs Updated call to has_basic_structure_validation to pass platform_version argument.
.../state_transition/state_transitions/data_contract_create/basic_structure/mod.rs Added new module declaration v0 for basic structure validation.
.../state_transition/state_transitions/data_contract_update/basic_structure/mod.rs Added new module declaration v0 for basic structure validation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant StateTransition
    participant BasicValidator
    participant AdvancedValidator

    Client->>StateTransition: Submit DataContractCreate/UpdateTransition
    StateTransition->>BasicValidator: validate_basic_structure (dispatch by version)
    BasicValidator->>StateTransition: Result (success/errors)
    StateTransition->>AdvancedValidator: validate_advanced_structure (dispatch by version)
    AdvancedValidator->>StateTransition: Result (success/errors)
    StateTransition->>Client: Validation result
Loading

Suggested labels

bug

Suggested reviewers

  • pauldelucia

Poem

In fields of code, the rabbits hop,
Adding checks that never stop.
Tokens and groups, now aligned,
With structure and version intertwined.
Version six, a brand new trick,
Bugs are chased out double-quick!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 46626d8 and cb9351f.

📒 Files selected for processing (1)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/advanced_structure/v0/mod.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/advanced_structure/v0/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Build JS packages / Build JS

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

@pauldelucia pauldelucia marked this pull request as ready for review April 14, 2025 09:31
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: 0

🧹 Nitpick comments (1)
packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs (1)

246-316: Validating newly added tokens

  • Checks for contiguous positions, overflow in base_supply, valid localizations, existence of required groups, and distribution timestamps.
  • The single distribution timestamp check is a potential risk if multiple distributions exist, since only the first is validated. Consider verifying all distribution timestamps or the earliest one to prevent partial rejections.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2c59bd0 and 37d8d38.

📒 Files selected for processing (4)
  • packages/rs-dpp/src/data_contract/methods/validate_update/mod.rs (3 hunks)
  • packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs (20 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs (5 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs (1)
packages/rs-drive/src/state_transition_action/batch/batched_transition/document_transition/document_create_transition_action/v0/mod.rs (1)
  • block_info (53-53)
packages/rs-dpp/src/data_contract/methods/validate_update/mod.rs (1)
packages/rs-drive/src/state_transition_action/batch/batched_transition/document_transition/document_create_transition_action/v0/mod.rs (1)
  • block_info (53-53)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs (6)
packages/rs-drive-abci/src/platform_types/platform_state/mod.rs (1)
  • v0 (116-120)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/mod.rs (3)
  • None (937-937)
  • None (947-947)
  • None (1298-1298)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/mod.rs (2)
  • None (929-929)
  • None (1558-1558)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs (1)
  • default_most_restrictive (166-289)
packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_update_transition/v0/v0_methods.rs (1)
  • new_from_data_contract (18-49)
packages/rs-drive-abci/src/platform_types/state_transitions_processing_result/mod.rs (1)
  • execution_results (109-111)
packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs (3)
packages/rs-drive/src/state_transition_action/batch/batched_transition/document_transition/document_create_transition_action/v0/mod.rs (1)
  • block_info (53-53)
packages/wasm-dpp/src/data_contract/data_contract.rs (1)
  • token_configuration (435-443)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs (1)
  • default_most_restrictive (166-289)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Rust packages (dash-sdk) / Formatting
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • 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 Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (23)
packages/rs-dpp/src/data_contract/methods/validate_update/mod.rs (3)

1-1: New import for BlockInfo
This import cleanly introduces block-related context.


14-14: Including block_info parameter
Adding block_info to the validate_update method signature allows the validator to access block-specific data (e.g., timestamps), which supports richer validation logic, especially for token distribution checks.


23-23: Forwarding block_info to validate_update_v0
Propagating the new parameter ensures consistent usage of block data in all versioned validation methods.

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs (1)

134-136: Passing block_info to validate_update
This change ensures the old contract is validated against the new contract with awareness of the block context (e.g., for time-based checks). The approach looks correct.

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs (12)

1183-1185: Introducing token configuration accessors
These new imports for TokenConfigurationV0Getters and TokenConfigurationV0Setters correctly support reading and modifying token settings.


1194-1195: Test name and structure
This test function name, test_data_contract_update_can_add_new_token, is aligned with the new feature goal. Good clarity on what it validates.


1206-1222: Preparing original contract with no tokens
Lines 1206-1222 handle fetching and applying the base contract before adding the new token. This ensures the test starts with the correct baseline state.


1224-1293: Adding a well-formed token and verifying success
This block builds a valid token configuration (including base supply, valid localizations) and checks that the state transition is successfully applied. The thorough approach is excellent.


1296-1306: Adding test for contiguous token positions
These lines set up a scenario to ensure that skipping token positions triggers an error. The logic is in line with the new contiguous-position requirement.


1308-1328: Applying the original contract with token at position 0
Similar to other tests, this ensures the test environment is precisely known before checking errors around the new token’s position.


1330-1338: Attempt to add token at position 2
This negative test ensures that a gap in token positions triggers a NonContiguousContractTokenPositionsError. The coverage is good.


1352-1369: Serializing the state transition and checking the result
The test properly verifies that the correct consensus error is raised. The code’s clarity and coverage are strong.


1370-1386: Validating large base supply
Ensuring base_supply does not exceed i64::MAX is prudent. This test properly demonstrates a boundary check for numeric overflow.


1394-1418: Reapplying the contract environment
Reusing the pattern of applying the original contract and then updating it ensures consistent test coverage. The steps are well-ordered and easy to follow.


1420-1474: Rejecting tokens with base supply over i64::MAX
Line 1425 specifically sets a base supply that is one over i64::MAX, verifying the intended error path. This is a robust boundary check.


1476-1563: Testing invalid localization
This block checks that a token with empty localizations is rejected, aligning with the new constraints. The code is well-structured, ensuring it’s easy to maintain or expand.

packages/rs-dpp/src/data_contract/methods/validate_update/v0/mod.rs (7)

1-3: Imports for timestamp and block checks
These imports extend validation logic, enabling detection of past distribution timestamps.


7-8: Inclusion of new token errors
InvalidTokenBaseSupplyError and NonContiguousContractTokenPositionsError reflect a more granular validation approach for token additions.


14-16: Expanding token-accessor usage
Fetching token distribution rules and pre-programmed distribution is essential for the revised validation logic.


19-19: Adding TokenContractPosition
Storing the token position type clarifies the contract’s approach to enumerating tokens—improves readability and consistency.


30-30: Introducing block_info in validate_update
This parameter is essential for time-sensitive checks. The approach to pass it through is clean and consistent with Rust’s design.


779-847: Timestamp in the past error
This negative test ensures that if a distribution date precedes the current block’s timestamp, an error is returned. The logic is solid, but again only checks the first distribution.

Would you like a script to search for possible multi-timestamp checks that might be incomplete or untested, to confirm no additional logic is needed?


849-959: Testing token position and base supply boundaries
These sections cover a range of potential errors (non-contiguous positions and supply overflows)—robust coverage.

@pauldelucia pauldelucia marked this pull request as draft April 14, 2025 10:10
@pauldelucia pauldelucia changed the title feat: allow new tokens on contract update feat: allow new tokens on contract update and refactor contract validations Apr 14, 2025
@pauldelucia pauldelucia changed the title feat: allow new tokens on contract update and refactor contract validations feat: allow new tokens on contract update and refactor some contract validations Apr 14, 2025
@pauldelucia pauldelucia marked this pull request as ready for review April 15, 2025 08:32
@pauldelucia pauldelucia marked this pull request as draft April 15, 2025 09:30
@pauldelucia pauldelucia marked this pull request as ready for review April 15, 2025 09:31
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: 0

🧹 Nitpick comments (2)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/advanced_structure/v0/mod.rs (2)

23-37: Comment clarifies version validation placement

The comment explains that this validation was moved to basic structure validation in protocol version 9, which helps understand why this check exists in V0 but might be handled differently in newer versions.

However, ensure this is still needed in V0 advanced validation since it's now also in basic validation. If it's for backward compatibility, consider clarifying that in the comment.

- // Moved this to basic structure validation in protocol version 9
+ // Maintained for backward compatibility, but moved to basic structure validation in protocol version 9

92-92: Test updated to match new method signature

The test has been correctly updated to match the new method signature, using execution context instead of platform version.

Consider adding a specific test for version validation to ensure complete coverage of this validation path.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4561bc7 and 46626d8.

📒 Files selected for processing (1)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/advanced_structure/v0/mod.rs (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/advanced_structure/v0/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.
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Formatting
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • 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 JS packages / Build JS
🔇 Additional comments (3)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/advanced_structure/v0/mod.rs (3)

2-5: These imports support the refactored validation approach

The new imports properly support the shift from direct platform version validation to using execution context and delegating to the V1 validation implementation.


13-13: API change improves validation context handling

Changing the method signature from accepting platform_version to accepting execution_context is a good design decision as it provides more context for validation and aligns with modern Rust patterns for contextual validation.


39-39: Delegation to V1 validation completes the validation chain

The implementation follows a good validation chain pattern, where V0 performs minimal checks before delegating to the V1 implementation. This maintains backward compatibility while allowing the validation logic to evolve.

@QuantumExplorer QuantumExplorer changed the title feat: allow new tokens on contract update and refactor some contract validations feat(platform): allow new tokens on contract update and refactor some contract validations Apr 16, 2025
@QuantumExplorer QuantumExplorer changed the title feat(platform): allow new tokens on contract update and refactor some contract validations feat(platform): allow new tokens on contract update and refactor contract struct validations Apr 16, 2025
@QuantumExplorer QuantumExplorer merged commit 88a57ab into v2.0-dev Apr 16, 2025
78 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/allow-new-tokens-on-contract-update branch April 16, 2025 14:35
@thephez thephez added this to the v2.0.0 milestone Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants