Skip to content

Conversation

@shumkov
Copy link
Collaborator

@shumkov shumkov commented Mar 18, 2025

Issue being fixed or feature implemented

Token transfer is allowed to non-existing identity

What was done?

  • Return a consensus error if recipient identity doesn't exist

How Has This Been Tested?

None

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • 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 enhanced validation during token transfers to ensure that recipient identities are confirmed before completion.
    • Provided improved error notifications for cases where the recipient’s identity is missing, offering clearer feedback during token operations.

@shumkov shumkov added this to the v2.0.0 milestone Mar 18, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request introduces a new error type, TokenTransferRecipientIdentityNotExistError (error code 40718), which is used to handle cases where a token transfer recipient identity is missing. The changes span multiple modules by updating the error handling definitions in consensus-related files, adding a new token error module, incorporating a validation check during token transfers, and extending error conversion logic in WASM. The modifications preserve existing functionality while expanding error handling for token transfer operations.

Changes

File(s) Change Summary
packages/rs-dpp/src/errors/consensus/(codes.rs, state/state_error.rs) Added new error variant TokenTransferRecipientIdentityNotExistError with code 40718 to the StateError and updated corresponding imports.
packages/rs-dpp/src/errors/consensus/state/token/(mod.rs, token_transfer_recipient_identity_not_exist_error.rs) Introduced a new module and defined the TokenTransferRecipientIdentityNotExistError struct with its constructor, getter, and a From trait implementation for conversion to ConsensusError.
packages/rs-drive-abci/src/execution/validation/.../state_v0/mod.rs Integrated recipient identity validation in token transfer actions using platform.drive.fetch_identity_balance to return the new error if the identity does not exist.
packages/wasm-dpp/src/errors/consensus/consensus_error.rs Updated from_state_error to include a new match arm that handles the TokenTransferRecipientIdentityNotExistError using the generic_consensus_error! macro.

Sequence Diagram(s)

sequenceDiagram
    participant TTA as TokenTransferAction
    participant D as platform.drive
    participant V as Validator
    participant EH as ErrorHandler

    TTA->>D: fetch_identity_balance(recipient_id)
    D-->>TTA: returns balance (or None)
    TTA->>V: validate recipient identity
    alt Recipient Not Found
      V->>EH: return TokenTransferRecipientIdentityNotExistError (40718)
    else Recipient Found
      V->>TTA: proceed with token transfer
    end
Loading

Possibly related PRs

Suggested reviewers

  • QuantumExplorer
  • pauldelucia

Poem

Oh, hop along the code trail bright,
A rabbit sings of errors taking flight.
When recipient identities go astray,
New checks ensure we’re on the right way.
Bugs beware—code rabbits lead the day!
🐰✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 2490558 and aed05bc.

📒 Files selected for processing (6)
  • packages/rs-dpp/src/errors/consensus/codes.rs (1 hunks)
  • packages/rs-dpp/src/errors/consensus/state/state_error.rs (2 hunks)
  • packages/rs-dpp/src/errors/consensus/state/token/mod.rs (2 hunks)
  • packages/rs-dpp/src/errors/consensus/state/token/token_transfer_recipient_identity_not_exist_error.rs (1 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_transfer_transition_action/state_v0/mod.rs (6 hunks)
  • packages/wasm-dpp/src/errors/consensus/consensus_error.rs (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/rs-dpp/src/errors/consensus/state/token/token_transfer_recipient_identity_not_exist_error.rs (1)
packages/rs-dpp/src/errors/consensus/state/state_error.rs (1) (1)
  • from (285:287)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dpp) / Tests
  • 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 (13)
packages/rs-dpp/src/errors/consensus/codes.rs (1)

307-307: Good addition of error code for token transfer validation.

Adding the TokenTransferRecipientIdentityNotExistError with code 40718 properly extends the token error section (40700-40799). This error will be used to handle cases where token transfers are attempted to non-existent identities.

packages/wasm-dpp/src/errors/consensus/consensus_error.rs (2)

87-87: Proper extension of token error imports.

The import statement correctly includes the new TokenTransferRecipientIdentityNotExistError with the other token-related errors.


387-389: Correctly wired the new error type to WASM bindings.

This match arm properly handles the new TokenTransferRecipientIdentityNotExistError by converting it to a JavaScript value using the generic_consensus_error! macro, ensuring proper error propagation to JavaScript.

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_transfer_transition_action/state_v0/mod.rs (2)

4-4: Import properly extended with new error type.

The import statement correctly includes the new TokenTransferRecipientIdentityNotExistError along with other token-related errors.


127-139: Excellent implementation of recipient identity validation.

This validation logic properly checks if the recipient identity exists before allowing a token transfer, which addresses the core issue. The implementation follows the pattern of other validation checks in this file:

  1. Fetches required data (recipient identity balance)
  2. Checks for the error condition (identity doesn't exist if balance is None)
  3. Returns the appropriate error

This will prevent tokens from being sent to non-existent identities, improving the robustness of the system.

packages/rs-dpp/src/errors/consensus/state/state_error.rs (2)

45-45: Token error imports properly extended.

The import statement correctly includes the new TokenTransferRecipientIdentityNotExistError with other token-related errors.


280-281: Correctly added new error variant to StateError enum.

The new TokenTransferRecipientIdentityNotExistError variant is properly added to the StateError enum with the #[error(transparent)] attribute, which forwards the display implementation to the inner error type. This maintains consistency with the rest of the enum variants.

packages/rs-dpp/src/errors/consensus/state/token/mod.rs (2)

18-18: Properly added new module for token transfer recipient identity validation.

The addition of this module declaration follows the established pattern in the file for handling specific token-related error cases.


38-38: Correctly exported the new error module for public use.

The public export is consistently placed in alphabetical order with the other token error exports, maintaining the file's organization.

packages/rs-dpp/src/errors/consensus/state/token/token_transfer_recipient_identity_not_exist_error.rs (4)

1-8: Imports are appropriate and complete.

All necessary dependencies are imported for error handling, serialization, and identifier management.


9-16: Error struct properly defined with necessary traits.

The error struct correctly implements standard traits (Error, Debug, Clone, etc.) and platform-specific serialization traits. The error message is descriptive and includes the relevant recipient ID.


18-26: Appropriate constructor and accessor methods.

The implementation provides a clean constructor and a getter method for the recipient ID, following good encapsulation practices.


28-32: Properly implemented From trait for error conversion.

The implementation correctly converts this specific error into a ConsensusError by wrapping it in the appropriate StateError variant, aligning with the PR objective to return a consensus error when token transfers are attempted to non-existing identities.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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.

@shumkov shumkov self-assigned this Mar 18, 2025
@shumkov shumkov moved this to In review / testing in Platform team Mar 18, 2025
Copy link
Member

@pauldelucia pauldelucia left a comment

Choose a reason for hiding this comment

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

Works as intended in DET

@shumkov shumkov merged commit 03cdc36 into v2.0-dev Mar 19, 2025
123 of 124 checks passed
@shumkov shumkov deleted the fix/transfer-to-non-existing-identity branch March 19, 2025 08:33
@github-project-automation github-project-automation bot moved this from In review / testing to Done in Platform team Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants