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): fixed precision loss for balance amount #14406

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

IvanBelyakoff
Copy link
Contributor

What does the PR do

Fixes precision loss for big balances.

Related nimqml PR: status-im/nimqml#57 (will be added here once merged)

Affected areas

Wallet->assets balances

Closes #14402

@status-im-auto
Copy link
Member

status-im-auto commented Apr 11, 2024

Jenkins Builds

Click to see older builds (4)
Commit #️⃣ Finished (UTC) Duration Platform Result
ddd6b45 #1 2024-04-11 17:35:30 ~4 min macos/aarch64 📄log
✔️ ddd6b45 #1 2024-04-11 17:36:46 ~6 min tests/nim 📄log
ddd6b45 #1 2024-04-11 17:40:34 ~9 min macos/x86_64 📄log
ddd6b45 #1 2024-04-11 17:41:00 ~10 min linux/x86_64 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
d4dc062 #2 2024-04-11 17:46:15 ~4 min macos/x86_64 📄log
d4dc062 #2 2024-04-11 17:47:09 ~5 min macos/aarch64 📄log
✔️ d4dc062 #2 2024-04-11 17:47:57 ~6 min tests/nim 📄log
d4dc062 #2 2024-04-11 17:50:24 ~8 min linux/x86_64 📄log
d4dc062 #2 2024-04-11 17:53:02 ~11 min tests/ui 📄log
d4dc062 #2 2024-04-11 18:03:37 ~21 min windows/x86_64 📄log
✔️ 1fd0130 #3 2024-04-12 09:57:07 ~5 min macos/aarch64 🍎dmg
✔️ 1fd0130 #3 2024-04-12 09:58:47 ~6 min tests/nim 📄log
✔️ 1fd0130 #3 2024-04-12 10:00:00 ~8 min macos/x86_64 🍎dmg
✔️ 1fd0130 #3 2024-04-12 10:03:41 ~11 min tests/ui 📄log
✔️ 1fd0130 #3 2024-04-12 10:07:59 ~16 min linux/x86_64 📦tgz
✔️ 1fd0130 #3 2024-04-12 10:22:48 ~30 min windows/x86_64 💿exe

return self.amount
QtProperty[float] amount:
read = getAmountFloat
QtProperty[float64] amount:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what's the difference? 🤔

From the docu:
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, there are CPUs that do not support float64 so I wonder whether we're not breaking something here. This is also the reason why Qt introduces the qreal (or real in QML) type which is an alias for either double or float based on what the CPU supports.

Copy link
Contributor Author

@IvanBelyakoff IvanBelyakoff Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caybro I have updated nimqml PR after discussion with @alexjba - we lost precision when converted float64 to cfloat. So initially I fixed only this case - when using float64 as property type - I mapped it to double, now as NIM uses float64 for float, we map all float to double. If you want to use 32 float as property type, you should use float32 Please have a look there status-im/nimqml#57

Copy link
Member

@micieslak micieslak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should always use big integers for exchanging balances between go/nim/qml. Using floating points, no matter if 32 or 64 bits it always creates a room for distortions. Some time ago I provided some examples here: #11376. The idea is to always pass integers (big integers) and multiplier specific to given token, like 18 for ETH. Then it gives full freedom on UI side to display or use this balance for other operations like comparisons or multiplications (as in airdrop flow), with no risk of introducing distortions.

fixed currency amount property type to be handled by QMetatype properly
@IvanBelyakoff
Copy link
Contributor Author

Ideally, we should always use big integers for exchanging balances between go/nim/qml. Using floating points, no matter if 32 or 64 bits it always creates a room for distortions. Some time ago I provided some examples here: #11376. The idea is to always pass integers (big integers) and multiplier specific to given token, like 18 for ETH. Then it gives full freedom on UI side to display or use this balance for other operations like comparisons or multiplications (as in airdrop flow), with no risk of introducing distortions.

Agree, thank you! Though now it should be twice better since we found what caused big distortions. Since we have a different task for CurrencyAmount as big int, I believe this is out of scope of this fix

Copy link
Member

@caybro caybro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say LGTM

and let's handle the issue as a whole in another PR

@IvanBelyakoff IvanBelyakoff merged commit b9268d8 into master Apr 12, 2024
8 checks passed
@IvanBelyakoff IvanBelyakoff deleted the fix/precision_loss_for_balance branch April 12, 2024 11:20
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.

Wallet: Balances are not updates sometimes
5 participants