-
Notifications
You must be signed in to change notification settings - Fork 39
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: check if token is paused on token transfers #2458
Conversation
WalkthroughThis pull request enhances error handling for token state management by introducing a new error variant, Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant Validator as TokenTransferValidation
participant Consensus as ConsensusModule
Client->>Validator: Submit Token Transfer Request
Validator->>Validator: Check token state (paused?)
alt Token Paused
Validator->>Consensus: Return TokenIsPausedError
else Token Active
Validator->>Consensus: Proceed with additional validations
end
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (19)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
...e_transitions/batch/action_validation/token/token_transfer_transition_action/state_v0/mod.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_transfer_transition_action/state_v0/mod.rs (1)
98-113
: Consider optimizing check order for better performance.The token pause check is valid but could be moved before the balance and frozen checks. This would prevent unnecessary database queries when the token is paused.
Apply this diff to optimize the check order:
- // We need to verify that we have enough of the token - let balance = platform - .drive - .fetch_identity_token_balance( - self.token_id().to_buffer(), - owner_id.to_buffer(), - transaction, - platform_version, - )? - .unwrap_or_default(); - execution_context.add_operation(ValidationOperation::RetrieveIdentityTokenBalance); - if balance < self.amount() { - return Ok(SimpleConsensusValidationResult::new_with_error( - ConsensusError::StateError(StateError::IdentityDoesNotHaveEnoughTokenBalanceError( - IdentityDoesNotHaveEnoughTokenBalanceError::new( - self.token_id(), - owner_id, - self.amount(), - balance, - "transfer".to_string(), - ), - )), - )); - } - - // We need to verify that our token account is not frozen - let info = platform.drive.fetch_identity_token_info( - self.token_id().to_buffer(), - owner_id.to_buffer(), - transaction, - platform_version, - )?; - if let Some(info) = info { - if info.frozen() == true { - return Ok(SimpleConsensusValidationResult::new_with_error( - ConsensusError::StateError(StateError::IdentityTokenAccountFrozenError( - IdentityTokenAccountFrozenError::new( - self.token_id(), - owner_id, - "transfer".to_string(), - ), - )), - )); - } - }; - // We need to verify that the token is not paused let token_status = platform.drive.fetch_token_status( self.token_id().to_buffer(), transaction, platform_version, )?; if let Some(status) = token_status { if status.paused() { return Ok(SimpleConsensusValidationResult::new_with_error( ConsensusError::StateError(StateError::TokenIsPausedError( TokenIsPausedError::new(self.token_id()), )), )); } } + + // We need to verify that we have enough of the token + let balance = platform + .drive + .fetch_identity_token_balance( + self.token_id().to_buffer(), + owner_id.to_buffer(), + transaction, + platform_version, + )? + .unwrap_or_default(); + execution_context.add_operation(ValidationOperation::RetrieveIdentityTokenBalance); + if balance < self.amount() { + return Ok(SimpleConsensusValidationResult::new_with_error( + ConsensusError::StateError(StateError::IdentityDoesNotHaveEnoughTokenBalanceError( + IdentityDoesNotHaveEnoughTokenBalanceError::new( + self.token_id(), + owner_id, + self.amount(), + balance, + "transfer".to_string(), + ), + )), + )); + } + + // We need to verify that our token account is not frozen + let info = platform.drive.fetch_identity_token_info( + self.token_id().to_buffer(), + owner_id.to_buffer(), + transaction, + platform_version, + )?; + if let Some(info) = info { + if info.frozen() == true { + return Ok(SimpleConsensusValidationResult::new_with_error( + ConsensusError::StateError(StateError::IdentityTokenAccountFrozenError( + IdentityTokenAccountFrozenError::new( + self.token_id(), + owner_id, + "transfer".to_string(), + ), + )), + )); + } + };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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_is_paused_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
(2 hunks)packages/wasm-dpp/src/errors/consensus/consensus_error.rs
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
- GitHub Check: Rust packages (drive-abci) / Formatting
- GitHub Check: Rust packages (drive-abci) / Detect immutable structure changes
- GitHub Check: Rust packages (drive-abci) / Check each feature
- GitHub Check: Rust packages (drive) / Unused dependencies
- GitHub Check: Rust packages (drive) / Tests
- GitHub Check: Rust packages (drive) / Linting
- 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) / Check each feature
- GitHub Check: Rust packages (dash-sdk) / 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 (5)
packages/rs-dpp/src/errors/consensus/state/token/token_is_paused_error.rs (1)
1-32
: Well-structured error type implementation!The
TokenIsPausedError
implementation follows Rust best practices:
- Proper error handling traits
- Clear error message with context
- Clean conversion to ConsensusError
packages/rs-dpp/src/errors/consensus/state/token/mod.rs (1)
9-9
: Clean module integration!The new module is properly registered and exported, maintaining alphabetical order and consistency with other modules.
Also applies to: 22-22
packages/rs-dpp/src/errors/consensus/state/state_error.rs (1)
55-55
: Correctly extends StateError enum!The new variant is properly added:
- Placed at the end to preserve serialization order
- Consistent use of transparent error attribute
Also applies to: 260-261
packages/rs-dpp/src/errors/consensus/codes.rs (1)
257-257
: LGTM!The new error variant
TokenIsPausedError
is correctly implemented with code40161
and follows the established pattern for token-related errors.packages/wasm-dpp/src/errors/consensus/consensus_error.rs (1)
87-87
: LGTM!The new error variant
TokenIsPausedError
is correctly integrated into the error handling system:
- Properly imported from the token module
- Correctly handled in the
from_state_error
function using thegeneric_consensus_error
macroAlso applies to: 329-329
Issue being fixed or feature implemented
We weren't checking if tokens were paused when doing token transfers
What was done?
Add a check and new error type
How Has This Been Tested?
Confirmed to work as intended using DET and local network
Breaking Changes
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit