Skip to content

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Mar 18, 2025

Issue being fixed or feature implemented

Historical documents for token events were using the same document ids based on the token history contract, and identity contract nonce for the token contract, but this meant that if a user would send token A, then send token B the second transaction would use the same document id to try to store info on the transaction.

What was done?

Historical document id now looks like:
fn historical_document_id(&self, owner_id: Identifier) -> Identifier { let token_id = self.token_id(); let name = self.historical_document_type_name(); let owner_nonce = self.identity_contract_nonce(); Document::generate_document_id_v0( &token_id, &owner_id, format!("history_{}", name).as_str(), owner_nonce.to_be_bytes().as_slice(), ) }

How Has This Been Tested?

Not tested, but tests still pass.

Breaking Changes

Breaking, (but previous was failing). It's shouldn't be considered breaking compared to 1.8.

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

Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request simplifies the method signatures used for generating and building historical documents across several modules. The changes remove redundant parameters such as owner_nonce and token_historical_contract from methods like historical_document_id, build_historical_document, and build_historical_document_owned. Instead, values are now derived internally (e.g., via identity_contract_nonce()) and document IDs are generated directly using the token_id with a new "history_" prefix for document type names. These adjustments are reflected in both implementation and test code.

Changes

File(s) Change Summary
packages/rs-dpp/.../token_transition.rs, packages/rs-drive/.../token_transition/mod.rs, packages/wasm-dpp/.../token_transition/mod.rs, packages/rs-drive/.../verify_state_transition_was_executed_with_proof/v0/mod.rs Removed the owner_nonce parameter from historical_document_id; internal logic now derives the nonce via identity_contract_nonce(). Also, removed token_historical_contract from build_historical_document and updated document ID generation to directly use token_id with a "history_" prefix.
packages/rs-dpp/.../token_event.rs, packages/rs-drive-abci/.../verify_state_transitions.rs, packages/rs-drive/.../add_transaction_history_operations/v0/mod.rs Removed the token_history_contract argument from build_historical_document_owned and simplified calls in test code by eliminating redundant parameters. Document ID generation now uses token_id directly and applies a "history_" prefix to the type name.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Client
    participant Transition as TokenTransition
    participant DocGen as DocumentGenerator

    Caller->>Transition: historical_document_id(owner_id)
    Transition->>Transition: derive owner_nonce internally via identity_contract_nonce()
    Transition->>DocGen: generate_document_id using token_id
    DocGen-->>Transition: Return DocumentID
    Transition-->>Caller: Return DocumentID
Loading
sequenceDiagram
    participant Caller as Client
    participant Transition as TokenTransition
    participant Builder as DocumentBuilder

    Caller->>Transition: build_historical_document(token_id, owner_id, block_info, platform_version)
    Transition->>Transition: derive owner_nonce internally
    Transition->>Builder: Build document with formatted name ("history_" prefix)
    Builder-->>Transition: Return Document
    Transition-->>Caller: Return Document
Loading

Possibly related PRs

Suggested labels

js-sdk

Suggested reviewers

  • shumkov

Poem

I'm a rabbit in the codefield, hopping with glee,
Simplifying signatures, as light as can be.
Parameters vanish like carrots in flight,
Internal logic now makes everything right.
With a "history_" twist and a joyful little nose,
I celebrate these changes as our code garden grows!
🥕🐇

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 28fb9a1.

📒 Files selected for processing (7)
  • packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (2 hunks)
  • packages/rs-dpp/src/tokens/token_event.rs (1 hunks)
  • packages/rs-drive-abci/tests/strategy_tests/verify_state_transitions.rs (2 hunks)
  • packages/rs-drive/src/drive/tokens/add_transaction_history_operations/v0/mod.rs (0 hunks)
  • packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mod.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/rs-drive/src/drive/tokens/add_transaction_history_operations/v0/mod.rs
🧰 Additional context used
🧬 Code Definitions (1)
packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs (3)
packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (4) (4)
  • historical_document_id (203:203)
  • historical_document_id (325:335)
  • token_id (182:182)
  • token_id (285:287)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mod.rs (2) (2)
  • historical_document_id (106:108)
  • token_id (86:88)
packages/rs-dpp/src/state_transition/mod.rs (2) (2)
  • owner_id (412:414)
  • name (326:377)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (wasm-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
🔇 Additional comments (8)
packages/rs-drive-abci/tests/strategy_tests/verify_state_transitions.rs (2)

286-287: Signature simplified by removing owner_nonce parameter

The method signature for historical_document_id has been simplified by removing the owner_nonce parameter. The method now only requires batch_transition.owner_id() and seems to be deriving the nonce internally.


528-529: Consistent signature usage for historical_document_id

This is another instance of the simplified historical_document_id method call, maintaining consistency throughout the codebase.

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mod.rs (1)

106-107: Method signature simplified for historical_document_id

The historical_document_id method no longer requires the owner_nonce parameter, simplifying the API while maintaining functionality. This change aligns with the corresponding Rust implementation changes.

packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs (1)

338-339: Simplified historical_document_id call in verification logic

Removed the redundant identity_contract_nonce parameter from the method call, consistent with the method signature changes throughout the codebase. The verification now follows the same simplified pattern.

packages/rs-dpp/src/tokens/token_event.rs (1)

81-94: Simplified document ID generation with consistent naming pattern

The method no longer requires token_history_contract as a parameter and now:

  1. Uses token_id directly instead of extracting it from the contract
  2. Adopts a standardized naming pattern with a "history_" prefix for document type names

These changes make the code more maintainable and create a more intuitive connection between tokens and their history documents.

packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs (1)

131-141: Adoption of base-derived owner nonce looks consistent and simplifies the API
By internally retrieving the owner_nonce from the base transition action, the method signature avoids passing extra parameters. The code properly appends "history_" to the document type name and correctly uses Document::generate_document_id_v0. This change aligns well with the simplified design and maintains clarity.

packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (2)

203-203: Trait signature updated to remove unnecessary parameter
Removing the owner_nonce: IdentityNonce parameter in this trait method declaration is in line with the revised workflow, where the nonce is now fetched directly from the base transition data. This change reduces parameter bloat and simplifies external method calls.


325-335: Implementation mirrors the simpler trait signature
The revised historical_document_id implementation reflects the new signature, deriving its owner_nonce from self.identity_contract_nonce(). The approach here further standardizes how document IDs are generated for historical records.

✨ 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.

@QuantumExplorer QuantumExplorer added this to the v2.0.0 milestone Mar 18, 2025
@QuantumExplorer QuantumExplorer changed the title fix(platform)!: unique token keeps history documents fix(platform): unique token keeps history documents Mar 18, 2025
@QuantumExplorer QuantumExplorer merged commit f5fa96a into v2.0-dev Mar 18, 2025
73 checks passed
@QuantumExplorer QuantumExplorer deleted the fix/UniqueTokenHistoricalDocuments branch March 18, 2025 13:57
@coderabbitai coderabbitai bot mentioned this pull request Mar 30, 2025
6 tasks
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.

2 participants