-
Notifications
You must be signed in to change notification settings - Fork 930
Account for reserved balance in ensure_can_withdraw function #8108
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
base: master
Are you sure you want to change the base?
Conversation
code looks good, but it is difficult to say if this is not breaking some other assumptions in the code elsewhere in the currency implementation. Maybe @muharem you could have some opinion |
Thanks for having a look 👍 |
Maybe, we could catch some assumptions with This PR fixes |
The I think we should include this change, since there are multiple pallets (eg. |
// Account for the new reserved amount only if withdrawing for a reserve. | ||
let updated_reserved = if matches!(reasons, WithdrawReasons::RESERVE) { | ||
account.reserved.saturating_add(amount) | ||
} else { | ||
account.reserved | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a correct assumption of the withdraw reason API.
WithdrawReasons::RESERVE says:
In order to reserve some funds for a later return or repatriation.
But it doesn't say the reserved amount will be on the same account.
So I think in this function we shouldn't add the reserved amount.
Then in can_reserve
and reserve
we can be more precise so we can create a new function which does add the amount to the reserved amount.
Then after this I will approve the PR.
Description
Solves: #8099
Based on the documentation and existing code, the usable balance is computed with the following formula:
The problem:
If an account's
free balance
is lower thanfrozen balance
, no reserves will be allowed even though theusable balance
is enough to cover the reserve, resulting in aLiquidityRestrictions
error, which should not happen.Visual example of how
usable/spendable
balance works:Integration
No action is required, the changes only change existing code, it does not add or change any API.
Review Notes
From my understanding, the function
ensure_can_withdraw
was incorrect, and instead of checking that the newfree
balance is higher or equal to thefrozen
balance, it should make sure thenew free
balance is higher or equal to theusable
balance.