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: balance name issues #1705

Merged
merged 4 commits into from
Feb 23, 2025
Merged

fix: balance name issues #1705

merged 4 commits into from
Feb 23, 2025

Conversation

Nick-1979
Copy link
Member

@Nick-1979 Nick-1979 commented Feb 22, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved the accuracy of voting balance calculations to ensure your displayed balance is updated correctly.
  • Chores

    • Released an updated version of the extension for enhanced functionality.

@Nick-1979 Nick-1979 requested a review from AMIRKHANEF February 22, 2025 09:24
Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

Walkthrough

This pull request updates the balance calculation in the balancify function by replacing the use of balances.free and balances.reserved with balances.freeBalance and balances.reservedBalance, respectively. Additionally, the package version in package.json has been incremented from 0.34.0 to 0.35.0. No changes were made to API exports.

Changes

File(s) Change Summary
packages/extension-polkagate/src/.../balancify.js Updated votingBalance calculation: changed from free/reserved to freeBalance/reservedBalance to reflect new naming and maintain accuracy.
packages/extension/package.json Bumped package version from 0.34.0 to 0.35.0.

Possibly related PRs

  • feat: add support for pool migration #1702: Adjustments in balance handling were made in that PR, particularly related to balance calculations, which aligns with the changes in the votingBalance computation here.

Suggested reviewers

  • AMIRKHANEF

Poem

I'm a rabbit with a skip and a hop,
Dancing through code changes non-stop.
Balances now sing with names so bright,
In the burrow of code, all feels so light.
Hooray for revisions under moonlit night!
🐰✨


📜 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 dca28a0 and dc6ba2a.

📒 Files selected for processing (2)
  • packages/extension-polkagate/src/util/workers/utils/balancify.js (1 hunks)
  • packages/extension/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/extension/package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (2)
packages/extension-polkagate/src/util/workers/utils/balancify.js (2)

33-40:

❓ Verification inconclusive

Verify if balancifyAsset should use consistent property names.

While balancify was updated to use freeBalance/reservedBalance, this function still uses free/reserved. Should these property names also be updated for consistency?


🏁 Script executed:

#!/bin/bash
# Description: Search for usage of balancifyAsset to understand the expected property names

# Search for imports or usage of balancifyAsset
rg -A 5 "balancifyAsset"

# Search for asset balance property access patterns
rg "balances\.(free|reserved)"

Length of output: 4900


Verify property name consistency in balancifyAsset.

The balancifyAsset function currently constructs its JSON payload by mapping balance values using the original object keys:

  • availableBalance and freeBalance are derived from balances.free
  • reservedBalance is derived from balances.reserved

In contrast, other parts of the code (for example, in packages/extension-polkagate/src/util/utils.ts) expect balance values from properties named freeBalance and reservedBalance. Please confirm whether the asset-specific implementation in balancifyAsset should be updated to follow these conventions for consistency, or if the existing keys are intentional for handling asset balances.


19-19:

✅ Verification successful

LGTM! Property names are now consistent.

The change from free/reserved to freeBalance/reservedBalance aligns with the property names used in the base object, improving consistency.

Verify the voting balance calculation workaround.

The comment suggests this is a workaround for incorrect API values after pool migration. Let's verify this is still necessary.


🌐 Web query:

Is there a known issue with voting balance calculation after pool migration in Polkadot.js?

💡 Result:

Yes, there are known issues related to balance calculations in Polkadot.js after nomination pool migrations, particularly involving dual-staking accounts (accounts participating in both nomination pools and direct staking). Here's a breakdown of the key issues:


1. Dual-Staking Migration Conflicts

  • Accounts simultaneously participating in nomination pools and direct staking face migration failures due to overlapping locks/holds on funds:
    • The legacy Currency locks (used by direct staking) conflict with the new fungible holds (used by migrated pools) [8][5].
    • This prevents proper delegation migration via nominationPools.migrateDelegation, leading to incorrect voting balance calculations for OpenGov participation [5][8].

2. Points-to-Balance Conversion Errors

  • A rounding issue in points_to_balance conversions has been reported, where migrated pool members receive slightly less balance than expected due to integer division truncation [3].
  • Example: A member expecting 100 DOT from a pool might receive 99.999 DOT due to rounding errors during migration.

3. Frozen Funds During Pool Destruction

  • Some pools cannot be destroyed due to an extra consumer reference introduced by runtime upgrades:
    • Attempting withdraw_unbonded returns a Token: Frozen error because the pool account retains an unexpected consumer reference [2].
    • This leaves funds temporarily inaccessible and affects voting power calculations until resolved via governance intervention or runtime patches [2].

Recommendations for Users

  1. Dual-Stakers: Unbond direct stakes first via the Staking Dashboard before migrating pools [8].
  2. Check Migration Status: Use nominationPools.memberNeedsDelegateMigration to verify if manual migration is required [5].
  3. Avoid Pool Destruction: Do not destroy pools until runtime fixes are deployed [2].

These issues primarily stem from Polkadot’s transition from Currency locks to fungible holds and ongoing updates to delegation mechanics in OpenGov [6][8]. Developers are actively addressing these through runtime upgrades and migration scripts[5][8].

Citations:


Review Summary: Approved Property Naming Update & Valid Workaround for Voting Balance

  • The update from free/reserved to freeBalance/reservedBalance correctly aligns with the base object, resolving the naming inconsistency.
  • The manual calculation workaround for the voting balance (i.e. summing freeBalance with reservedBalance) remains valid given the known issues with pool migration—especially for dual-staking accounts and rounding inaccuracies—as confirmed by recent reports.

No further changes are necessary at this stage.

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

@Nick-1979 Nick-1979 merged commit b6a5a71 into main Feb 23, 2025
8 checks passed
@Nick-1979 Nick-1979 deleted the balanceNameIssue branch February 23, 2025 07:08
github-actions bot pushed a commit that referenced this pull request Feb 23, 2025
## [0.35.2](v0.35.1...v0.35.2) (2025-02-23)

### Bug Fixes

* balance name issues ([#1705](#1705)) ([b6a5a71](b6a5a71))
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