Skip to content

Conversation

paritytech-release-backport-bot[bot]

Backport #8108 into unstable2507 from RomarQ.

See the documentation on how to use this bot.

…s for a new reserve (#8108)

# Description

Solves: #8099

Based on the documentation and existing code, the usable balance is
computed with the following formula:

```rs
// If Fortitude == Polite
let usable_balance = free - max(frozen - reserved, existential balance)
```

### The problem:

If an account's `free balance` is lower than `frozen balance`, no
reserves will be allowed even though the `usable balance` is enough to
cover the reserve, resulting in a `LiquidityRestrictions` error, which
should not happen.

### Visual example of how `usable/spendable` balance works:
```bash
|__total__________________________________|
|__on_hold__|_____________free____________|
|__________frozen___________|
|__on_hold__|__ed__|
            |__untouchable__|__spendable__|
```

## 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` is incorrect,
and instead of checking that the new `free` balance is higher or equal
to the `frozen` balance, it should make sure the `new free` balance is
higher or equal to the `usable` balance.

---------

Co-authored-by: Kian Paimani <[email protected]>
(cherry picked from commit 7c2642d)
@sigurpol sigurpol enabled auto-merge (squash) September 19, 2025 13:31
@sigurpol sigurpol merged commit 1bd023c into unstable2507 Sep 19, 2025
240 of 243 checks passed
@sigurpol sigurpol deleted the backport-8108-to-unstable2507 branch September 19, 2025 13:50
sigurpol added a commit to sigurpol/runtimes that referenced this pull request Sep 22, 2025
Bump pallet-balances to include SDK PR [#9789](paritytech/polkadot-sdk#9789).
kianenigma pushed a commit to polkadot-fellows/runtimes that referenced this pull request Sep 23, 2025
Bump pallet-balances to include SDK PR
[#9789](paritytech/polkadot-sdk#9789).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A3-backport Pull request is already reviewed well in another branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants