-
Notifications
You must be signed in to change notification settings - Fork 707
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
fungible/s decrease balance preserves account #1683
Conversation
I have a fix and tests for what appear to be the same thing you're working on here: https://github.com/paritytech/polkadot-sdk/pull/1296/files#diff-e04f7799b91b4225b1923b49d8484495f7868868ab32ed78919f310ffe268fd9R190-R193 |
sure, lets work on your PR |
amount = amount.min(free); | ||
match precision { | ||
BestEffort => amount = amount.min(free), | ||
Exact => ensure!(free >= amount, TokenError::FundsUnavailable), | ||
} | ||
let new_balance = old_balance.checked_sub(&amount).ok_or(TokenError::FundsUnavailable)?; |
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.
We shouldn't need this check anymore, as amount
<= free
<= old_balance
(by definition reducible_balance
must be always <= than balance
)
polkadot-sdk/substrate/frame/support/src/traits/tokens/fungible/regular.rs
Lines 80 to 90 in 676bacd
/// Get the maximum amount that `who` can withdraw/transfer successfully based on whether the | |
/// account should be kept alive (`preservation`) or whether we are willing to force the | |
/// reduction and potentially go below user-level restrictions on the minimum amount of the | |
/// account. | |
/// | |
/// Always less than or equal to `balance()`. | |
fn reducible_balance( | |
who: &AccountId, | |
preservation: Preservation, | |
force: Fortitude, | |
) -> Self::Balance; |
Same applies to fungibles
closing this PR, since #1296 is merged |
Ensure
preservation
is respected when decreasing balance throughfangible/s::Unbalanced::decrease_balance
.At present, an account might be removed even if
preservation
is set toPreserve
orProtect
. Given the default implementation ofdecrease_balance
, we can't pinpoint the exact constraint that wasn't satisfied (frozen or ED). As a result, we return theFundsUnavailable
error.There's a more extensive PR that aims to address the same problem: #1296. Due to its broader scope, I'm maintaining this one separately, in the event it can be merged sooner. The new tests introduced here will eventually be superseded by the conformance tests from the referenced PR.
Closes: #1698