Skip to content

fix(platform): start as paused was not working #2582

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

Merged
merged 5 commits into from
Apr 30, 2025

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Apr 30, 2025

Issue being fixed or feature implemented

In the token config start as paused was not working, as it was only being used on token update and not insert.

What was done?

Fixed it and wrote tests.

How Has This Been Tested?

Wrote unit tests.

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
    • Added the ability to configure tokens to start in a paused state, preventing transfers until unpaused.
    • Token status is now recorded during contract insertion to track paused state.
  • Tests
    • Introduced comprehensive tests to verify token transfer behavior when tokens are paused and resumed.
  • Style
    • Corrected a comment typo for improved code clarity.

Copy link
Contributor

coderabbitai bot commented Apr 30, 2025

Walkthrough

This update introduces the ability to configure tokens to start in a paused state and ensures that this status is correctly handled during contract insertion and token transfers. New setter methods and trait implementations are added to manage the paused status in token configuration. Tests are introduced to verify that transfers are blocked when tokens are paused and allowed when resumed. The contract insertion logic is updated to persist the initial token status. Minor comment corrections are also included.

Changes

File(s) Change Summary
.../token_configuration/accessors/mod.rs, .../accessors/v0/mod.rs, .../v0/accessors.rs Added set_start_as_paused setter method to token configuration traits and implementations, enabling pause configuration.
.../state_transitions/batch/tests/token/mod.rs Added two comprehensive tests for token transfer behavior when tokens are paused and resumed.
.../drive/contract/insert/insert_contract/v1/mod.rs Updated contract insertion logic to persist the initial token paused/unpaused status in the database.
.../util/batch/drive_op_batch/contract.rs Fixed a comment typo; no code or logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ContractInserter
    participant Database

    User->>ContractInserter: Create data contract with token (start_as_paused)
    ContractInserter->>Database: Insert token configuration
    ContractInserter->>Database: Insert initial TokenStatus (paused/unpaused)
    Note over Database: Token status is now persisted
Loading
sequenceDiagram
    participant User
    participant TokenTransfer
    participant Database

    User->>TokenTransfer: Attempt token transfer
    TokenTransfer->>Database: Check TokenStatus
    alt Token is paused
        TokenTransfer-->>User: Fail with TokenIsPausedError
    else Token is unpaused
        TokenTransfer->>Database: Update balances
        TokenTransfer-->>User: Transfer succeeds
    end
Loading

Possibly related PRs

Suggested reviewers

  • shumkov

Poem

In the meadow where tokens hop,
Some start paused, their transfers stop.
With a twitch and a test, they resume the race,
Hopping along at a brisk, unpaused pace.
Now contracts remember their starting state—
A bunny’s work to automate!
🐇✨


📜 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 86d477f and ecc8e7d.

📒 Files selected for processing (1)
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Linting
  • 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
✨ 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.

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 Apr 30, 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: 2

🧹 Nitpick comments (3)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/mod.rs (3)

3416-3419: Clarify serialized-transition variable naming

resume_transition_transition is a bit of a tongue-twister and doesn’t immediately convey that this is the serialized form of the state-transition. Consider renaming it to something like resume_serialized_transition (or simply serialized_resume_transition) to improve readability.

- let resume_transition_transition = resume_transition
-     .serialize_to_bytes()
-     .expect("expected documents batch serialized state transition");
+ let resume_serialized_transition = resume_transition
+     .serialize_to_bytes()
+     .expect("expected serialized resume transition");

3572-3589: Variable name does not match the action performed

Here the variable is called resume_transition, but the emergency action is TokenEmergencyAction::Pause.
Renaming it to pause_transition (and the subsequent serialized variable) will avoid confusion when skimming the test.

- let resume_transition = BatchTransition::new_token_emergency_action_transition(
+ let pause_transition = BatchTransition::new_token_emergency_action_transition(
     token_id,
     identity.id(),
     contract.id(),
     0,
-    TokenEmergencyAction::Pause,
+    TokenEmergencyAction::Pause,
@@
- let resume_transition_transition = resume_transition
+ let pause_serialized_transition = pause_transition
     .serialize_to_bytes()
-    .expect("expected documents batch serialized state transition");
+    .expect("expected serialized pause transition");

3591-3593: Apply same naming fix for consistency

If you adopt the previous suggestion, adjust the variable used in the subsequent process_raw_state_transitions call accordingly:

- &[resume_transition_transition.clone()],
+ &[pause_serialized_transition.clone()],

Keeping terminology consistent throughout the test makes maintenance less error-prone.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ea78b9 and 928d5f0.

📒 Files selected for processing (6)
  • packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs (1 hunks)
  • packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs (2 hunks)
  • packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs (2 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/mod.rs (2 hunks)
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs (2 hunks)
  • packages/rs-drive/src/util/batch/drive_op_batch/contract.rs (1 hunks)
🧰 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.
🧬 Code Graph Analysis (3)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs (2)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs (2)
  • set_start_as_paused (192-194)
  • start_as_paused (49-51)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs (2)
  • set_start_as_paused (198-202)
  • start_as_paused (60-64)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs (2)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs (2)
  • set_start_as_paused (93-93)
  • start_as_paused (30-30)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs (2)
  • set_start_as_paused (192-194)
  • start_as_paused (49-51)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs (2)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs (2)
  • set_start_as_paused (93-93)
  • start_as_paused (30-30)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs (2)
  • set_start_as_paused (198-202)
  • start_as_paused (60-64)
🪛 GitHub Check: Rust packages (drive-abci) / Linting
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs

[warning] 7-7: unused import: TokenConfiguration
warning: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs:7:51
|
7 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default

packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs

[warning] 13-13: unused import: TokenConfiguration
warning: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs:13:51
|
13 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^

🪛 GitHub Check: Rust packages (drive) / Linting
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs

[warning] 7-7: unused import: TokenConfiguration
warning: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs:7:51
|
7 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default

packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs

[warning] 13-13: unused import: TokenConfiguration
warning: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs:13:51
|
13 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^

🪛 GitHub Check: Rust packages (wasm-dpp) / Linting
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs

[warning] 7-7: unused import: TokenConfiguration
warning: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs:7:51
|
7 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default

packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs

[warning] 13-13: unused import: TokenConfiguration
warning: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs:13:51
|
13 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^

🪛 GitHub Check: Rust packages (dpp) / Linting
packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs

[failure] 7-7: unused import: TokenConfiguration
error: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs:7:51
|
7 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^
|
= note: -D unused-imports implied by -D warnings
= help: to override -D warnings add #[allow(unused_imports)]

packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs

[failure] 13-13: unused import: TokenConfiguration
error: unused import: TokenConfiguration
--> packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs:13:51
|
13 | use crate::data_contract::{GroupContractPosition, TokenConfiguration};
| ^^^^^^^^^^^^^^^^^^

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (dpp) / Check each feature
  • 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 (6)
packages/rs-drive/src/util/batch/drive_op_batch/contract.rs (1)

37-37: Minor comment correction.

The comment has been corrected by adding the word "to", making it grammatically accurate.

packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/v0/mod.rs (1)

92-94: LGTM: New setter for token start-as-paused status.

This new setter method correctly adds the ability to configure tokens to start in a paused state, addressing the PR objective to fix the "start as paused" functionality. The implementation is consistent with the existing API patterns.

packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/accessors.rs (1)

191-194: LGTM: Implementation of start-as-paused setter.

The implementation is straightforward and correct, directly setting the start_as_paused field in the TokenConfigurationV0 struct. This complements the existing getter method (lines 49-51) and completes the API for controlling the token's initial paused state.

packages/rs-dpp/src/data_contract/associated_token/token_configuration/accessors/mod.rs (1)

197-202: LGTM: Enum dispatch implementation for start-as-paused.

This implementation properly routes the set_start_as_paused method to the appropriate version-specific implementation (currently just V0). The pattern follows the established pattern used for other accessors in this file, maintaining consistency in the codebase.

packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs (2)

15-15: Appropriate imports added for token status functionality.

The added imports correctly bring in the necessary components for managing token statuses, including path utilities and serialization capabilities.

Also applies to: 19-19, 23-24


235-248: Good implementation of token pause status persistence.

This change correctly addresses the issue where "start as paused" functionality wasn't working during token creation. The implementation:

  1. Creates a TokenStatus instance using the configured start_as_paused value from token configuration
  2. Serializes the status to bytes
  3. Persists it in the database at the appropriate path alongside other token information

The code follows the existing pattern of token-related batch operations and has proper error handling.

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 7212211 into v2.0-dev Apr 30, 2025
123 of 124 checks passed
@QuantumExplorer QuantumExplorer deleted the fix/FixStartAsPaused branch April 30, 2025 23: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