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(sdk): using incorrect proof result in transfers #2379

Closed
wants to merge 5 commits into from

Conversation

pauldelucia
Copy link
Member

@pauldelucia pauldelucia commented Dec 5, 2024

Issue being fixed or feature implemented

We were using the wrong proof result in transfers, so it would always return a proof error even though the transfer is successful

What was done?

How Has This Been Tested?

Untested

Breaking Changes

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

    • Enhanced the transfer_credits functionality for improved balance transfer handling.
  • Bug Fixes

    • Updated error handling to ensure consistent responses when balance is unavailable.
    • Improved handling of non-identity results to provide clearer error messages.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Warning

Rate limit exceeded

@pauldelucia has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 39 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1124f9a and 6f6eaec.

Walkthrough

The pull request modifies the transfer_credits method in the TransferToIdentity trait and its implementation in the Identity struct. The key change involves altering the result handling from directly accessing the balance of the identity object to using a match statement that checks for StateTransitionProofResult::VerifiedBalanceTransfer(sender, _recipient). Additionally, error handling has been updated to return a specific error for non-identity results. The method signature remains unchanged, ensuring compatibility with existing interfaces.

Changes

File Path Change Summary
packages/rs-sdk/src/platform/transition/transfer.rs Updated transfer_credits method to handle StateTransitionProofResult::VerifiedBalanceTransfer instead of directly accessing identity. Enhanced error handling for non-identity results.

Possibly related PRs

  • feat(sdk): added transfer transition to rs-sdk #2289: The changes in this PR introduce the transfer_credits method in the TransferToIdentity trait, which directly relates to the modifications made in the main PR regarding the implementation of the transfer_credits method and its handling of results and error management.

Suggested labels

rs-sdk, enhancement

Suggested reviewers

  • QuantumExplorer
  • shumkov

Poem

In the meadow where bunnies play,
Changes hop in a bright new way.
Credits now dance from sender's paw,
Simplified paths, we cheer and draw!
With every leap, our code takes flight,
Hooray for updates, all feels just right! 🐇✨


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

@pauldelucia pauldelucia changed the title fix: using incorrect proof result in transfers fix(sdk): using incorrect proof result in transfers Dec 5, 2024
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: 0

🧹 Outside diff range and nitpick comments (1)
packages/rs-sdk/src/platform/transition/transfer.rs (1)

65-66: LGTM! Consider enhancing error messages.

The change from VerifiedPartialIdentity to VerifiedBalanceTransfer correctly aligns with the transfer operation semantics and fixes the proof result handling issue. The implementation properly accesses the balance from the sender identity.

Consider making the error messages more specific:

-            _ => Err(Error::DapiClientError("proved a non identity".to_string())),
+            _ => Err(Error::DapiClientError("expected VerifiedBalanceTransfer result but got a different proof result".to_string())),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf6282d and 075fb7a.

📒 Files selected for processing (1)
  • packages/rs-sdk/src/platform/transition/transfer.rs (1 hunks)
🔇 Additional comments (1)
packages/rs-sdk/src/platform/transition/transfer.rs (1)

65-66: Verify complete migration to VerifiedBalanceTransfer.

Let's ensure no other transfer-related code still expects VerifiedPartialIdentity.

✅ Verification successful

Migration to VerifiedBalanceTransfer is correctly implemented

The verification shows that:

  • VerifiedBalanceTransfer is properly used in transfer.rs for balance transfers
  • VerifiedPartialIdentity is only used in other contexts (withdraw and top-up operations) where it's the appropriate variant
  • The enum definition in rs-dpp confirms VerifiedBalanceTransfer takes two PartialIdentity parameters for sender and recipient
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining uses of VerifiedPartialIdentity in transfer-related code
rg -A 5 "VerifiedPartialIdentity.*transfer" 

# Search for all uses of StateTransitionProofResult to ensure consistent handling
ast-grep --pattern 'match $_ { StateTransitionProofResult::$$$_ }'

Length of output: 114


Script:

#!/bin/bash
# Let's try a broader search for StateTransitionProofResult variants
rg -A 5 "StateTransitionProofResult::"

# Also search for any VerifiedPartialIdentity mentions
rg "VerifiedPartialIdentity"

# Look for transfer-related state transitions
rg -A 5 "BalanceTransfer"

Length of output: 12481

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: 0

🧹 Outside diff range and nitpick comments (2)
packages/rs-sdk/src/platform/transition/transfer.rs (2)

71-71: Clarify the error message for unexpected result type

The error message "proved a non identity" may be unclear or contain a typo. It could be confusing for users encountering this error.

Consider revising the error message to be more descriptive:

-        _ => Err(Error::DapiClientError("proved a non identity".to_string())),
+        _ => Err(Error::DapiClientError("expected a VerifiedBalanceTransfer result".to_string())),

67-69: Enhance error handling when balance is missing

When the sender.balance is None, the error message "expected an identity balance after transfer" might not provide sufficient context.

Consider adding more details to the error message to aid in debugging:

-                sender.balance.ok_or(Error::DapiClientError(
-                    "expected an identity balance after transfer".to_string(),
-                ))
+                sender.balance.ok_or(Error::DapiClientError(format!(
+                    "expected an identity balance after transfer for identity: {}",
+                    sender.id()
+                )))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 075fb7a and 1124f9a.

📒 Files selected for processing (1)
  • packages/rs-sdk/src/platform/transition/transfer.rs (1 hunks)
🔇 Additional comments (1)
packages/rs-sdk/src/platform/transition/transfer.rs (1)

65-72: ⚠️ Potential issue

Undefined variable result used in match statement

The variable result used in the match statement is not defined in this scope. Currently, identity is assigned from state_transition.broadcast_and_wait(sdk, settings).await?, but result is not declared.

To fix this issue, assign the result to result instead of identity:

-        let identity: PartialIdentity = state_transition.broadcast_and_wait(sdk, settings).await?;
+        let result = state_transition.broadcast_and_wait(sdk, settings).await?;

         match result {
             StateTransitionProofResult::VerifiedBalanceTransfer(sender, _recipient) => {
                 sender.balance.ok_or(Error::DapiClientError(
                     "expected an identity balance after transfer".to_string(),
                 ))
             }
             _ => Err(Error::DapiClientError("received unexpected proof result".to_string())),
         }

Alternatively, if broadcast_and_wait returns a PartialIdentity, ensure that you're using the correct variable and types in your match statement.

Run the following script to verify the return type of broadcast_and_wait:

✅ Verification successful

Let me gather more information about the implementation and usage of this method.


Let me try a different search strategy to understand the context better.


The review comment is correct - there's an undefined variable result in the code

Looking at the complete implementation in transfer.rs, we can see that broadcast_and_wait returns a PartialIdentity which is assigned to the identity variable, but then the code tries to match on an undefined result variable. The review's suggested fix to assign to result instead of identity is the correct approach since the match pattern expects a StateTransitionProofResult.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the return type of `broadcast_and_wait` method.

# Expected: Find the definition of `broadcast_and_wait` and check its return type.
rg -A 5 'fn broadcast_and_wait' packages/rs-sdk/src/platform/transition/broadcast.rs

Length of output: 484


Script:

#!/bin/bash
# Check the implementation of StateTransitionProofResult enum
rg -A 10 "enum StateTransitionProofResult" packages/rs-sdk/src/

# Check implementations of TryFrom<StateTransitionProofResult> for PartialIdentity
ast-grep --pattern 'impl TryFrom<StateTransitionProofResult> for PartialIdentity'

# Find where broadcast_and_wait is called with PartialIdentity
rg -B 5 "broadcast_and_wait.*PartialIdentity" packages/rs-sdk/src/

Length of output: 218


Script:

#!/bin/bash
# Find the file containing StateTransitionProofResult definition
fd -e rs | xargs rg "StateTransitionProofResult"

# Look for the implementation of the transfer module
rg -A 10 "impl Transfer" packages/rs-sdk/src/platform/transition/transfer.rs

# Check the complete transfer.rs file to understand the context
cat packages/rs-sdk/src/platform/transition/transfer.rs

Length of output: 6161

@pauldelucia pauldelucia closed this Dec 6, 2024
@pauldelucia pauldelucia deleted the fix/transfer-proof-result branch December 6, 2024 04:51
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