Balances: repatriate_reserved should respect freezes (#13885)

* repatriate_reserved should respect freezes

* Docs

* Fix and clean

* Formatting

* Update frame/balances/src/types.rs

Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>

* Fix

* Simplify

* Fixes

* Fixes

---------

Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
This commit is contained in:
Gavin Wood
2023-04-17 19:13:55 +01:00
committed by GitHub
parent b66bc22252
commit d23a251ee9
3 changed files with 46 additions and 39 deletions
@@ -22,7 +22,7 @@ use frame_support::{
ensure,
pallet_prelude::DispatchResult,
traits::{
tokens::{fungible, BalanceStatus as Status},
tokens::{fungible, BalanceStatus as Status, Fortitude::Polite, Precision::BestEffort},
Currency, DefensiveSaturating, ExistenceRequirement,
ExistenceRequirement::AllowDeath,
Get, Imbalance, LockIdentifier, LockableCurrency, NamedReservableCurrency,
@@ -590,13 +590,18 @@ where
/// Is a no-op if:
/// - the value to be moved is zero; or
/// - the `slashed` id equal to `beneficiary` and the `status` is `Reserved`.
///
/// This is `Polite` and thus will not repatriate any funds which would lead the total balance
/// to be less than the frozen amount. Returns `Ok` with the actual amount of funds moved,
/// which may be less than `value` since the operation is done an a `BestEffort` basis.
fn repatriate_reserved(
slashed: &T::AccountId,
beneficiary: &T::AccountId,
value: Self::Balance,
status: Status,
) -> Result<Self::Balance, DispatchError> {
let actual = Self::do_transfer_reserved(slashed, beneficiary, value, true, status)?;
let actual =
Self::do_transfer_reserved(slashed, beneficiary, value, BestEffort, Polite, status)?;
Ok(value.saturating_sub(actual))
}
}