Skip to content
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(wallet): correct version for vaults in substates table #1308

Merged

Conversation

sdbondi
Copy link
Member

@sdbondi sdbondi commented Feb 24, 2025

Description

fix(wallet): correct version for vaults in substates table

Motivation and Context

Bug in the transaction result handling caused the account version to be used instead of the vault substate version.

How Has This Been Tested?

Manually (partially)

What process can a PR reviewer use to test or verify this change?

Breaking Changes

  • None
  • Requires data directory to be deleted
  • Other - Please specify

Summary by CodeRabbit

  • Refactor
    • Updated the transaction processing logic for improved consistency and stability in wallet operations.

Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

The changes update the handling of substate version references within the commit_result function in the Transaction API. The code has been modified to use child.version() instead of s.version() when constructing VersionedSubstateId objects. These modifications ensure that the correct substate version is referenced in method calls such as substates_upsert_child and substates_upsert_root.

Changes

File Path Change Summary
dan_layer/wallet/sdk/src/apis/transaction.rs Replaced instances of s.version() with child.version() in the construction of VersionedSubstateId for calls like substates_upsert_child and substates_upsert_root.

Sequence Diagram(s)

sequenceDiagram
    participant TR as TransactionApi::commit_result
    participant ID as VersionedSubstateId::new
    participant USC as substates_upsert_child
    participant USR as substates_upsert_root

    TR->>ID: Create VersionedSubstateId(child.version())
    ID-->>TR: Return new versioned substate id
    TR->>USC: Call substates_upsert_child with new id
    TR->>USR: Call substates_upsert_root with new id
Loading

Poem

Hop along with code so neat,
Substates now keep the right beat.
child.version() leads the way,
In every call it makes our day.
A bunny cheers for code so bright, 🐰✨
Jumping through bytes with pure delight!


📜 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 aad784a and f36ede4.

📒 Files selected for processing (1)
  • dan_layer/wallet/sdk/src/apis/transaction.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: machete
  • GitHub Check: file licenses
  • GitHub Check: fmt
  • GitHub Check: check stable
  • GitHub Check: clippy
  • GitHub Check: check nightly
🔇 Additional comments (4)
dan_layer/wallet/sdk/src/apis/transaction.rs (4)

342-342: LGTM! Improved variable naming.

The destructuring assignment clearly indicates that we're working with a child substate.


385-389: LGTM! Fixed version handling for child substates.

The change correctly uses the child's version instead of the parent's version, which aligns with the PR objective to fix the version handling for child objects in the substates table.


370-373:

❓ Verification inconclusive

Verify the resource address access.

The change correctly uses the child's version and adds explicit resource address access. However, ensure that the vault's resource address is always available.


🏁 Script executed:

#!/bin/bash
# Description: Check for null/None handling of vault resource addresses.

# Search for patterns where vault resource address is accessed
ast-grep --pattern $'vault().resource_address()'

# Search for any error handling around resource address access
rg -A 5 'resource_address.*unwrap|unwrap.*resource_address'

Length of output: 10666


Resource Address Safety Check
The update correctly leverages the child’s version and directly accesses the vault’s resource address. However, since the code uses .unwrap() to extract the resource address (as confirmed by similar patterns elsewhere in the codebase), please ensure that every vault instance is guaranteed to have a valid resource address. If there's any risk that a vault might not have an assigned resource address, consider adding explicit error handling to prevent potential runtime panics.

  • Confirm that all vault initializations enforce a non-null resource address.
  • If feasible, replace the direct .unwrap() with robust error handling or fallback behavior in contexts where the resource address might not be set.

356-357:

✅ Verification successful

Verify the version change for vault substates.

The change from using the account's version to the child's version is correct. However, ensure that this change doesn't affect any vault-specific version tracking or validation.


🏁 Script executed:

#!/bin/bash
# Description: Check for any vault-specific version validation or tracking in the codebase.

# Search for vault version validation patterns
ast-grep --pattern $'fn $_($$) {
  $$$
  vault.$version()
  $$$
}'

# Search for any vault version-related code
rg -A 5 'vault.*version|version.*vault' 

Length of output: 12769


Vault Substate Version Change Confirmed

The change to use the child's version in the construction of the VersionedSubstateId is correct and appears to be isolated, without impacting vault-specific version tracking. Our repository search (particularly in applications/tari_dan_wallet_daemon/src/services/account_monitor.rs) shows that version validations compare versioned addresses consistently. Please double-check that any interactions with vault-specific version functions remain congruent with this update.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ 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. (Beta)
  • @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.

@sdbondi sdbondi changed the title fix(wallet): correct version for child objects in substates table fix(wallet): correct version for vaults in substates table Feb 24, 2025
@sdbondi sdbondi force-pushed the wallet-substate-version-fix branch from 9725f08 to f36ede4 Compare February 24, 2025 09:22
@sdbondi sdbondi enabled auto-merge February 24, 2025 09:30
@sdbondi sdbondi disabled auto-merge February 24, 2025 09:56
@sdbondi sdbondi merged commit c5a66c0 into tari-project:development Feb 24, 2025
12 of 13 checks passed
sdbondi added a commit to ksrichard/tari-dan that referenced this pull request Feb 25, 2025
* development:
  fix(mempool): provide finalize result for invalid transactions (tari-project#1307)
  fix(wallet): correct version for vaults in substates table (tari-project#1308)
  fix(indexer): list_substates can also list nfts (tari-project#1302)
  chore(bindings): update package.lock (tari-project#1306)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants