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

[Assets] Check for ContainsFreezes on dead_account #5948

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions substrate/frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,28 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

pub(super) fn dead_account(
id: T::AssetId,
who: &T::AccountId,
d: &mut AssetDetails<T::Balance, T::AccountId, DepositBalanceOf<T, I>>,
reason: &ExistenceReasonOf<T, I>,
force: bool,
) -> DeadConsequence {
) -> Result<DeadConsequence, DispatchError> {
use ExistenceReason::*;

ensure!(T::Freezer::frozen_balance(id, &who).is_none(), Error::<T, I>::ContainsFreezes);

match *reason {
Consumer => frame_system::Pallet::<T>::dec_consumers(who),
Sufficient => {
d.sufficients = d.sufficients.saturating_sub(1);
frame_system::Pallet::<T>::dec_sufficients(who);
},
DepositRefunded => {},
DepositHeld(_) | DepositFrom(..) if !force => return Keep,
DepositHeld(_) | DepositFrom(..) if !force => return Ok(Keep),
DepositHeld(_) | DepositFrom(..) => {},
}
d.accounts = d.accounts.saturating_sub(1);
Remove
Ok(Remove)
}

/// Returns `true` when the balance of `account` can be increased by `amount`.
Expand Down Expand Up @@ -361,7 +365,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
T::Currency::unreserve(&who, deposit);
}

if let Remove = Self::dead_account(&who, &mut details, &account.reason, false) {
if let Remove = Self::dead_account(id.clone(), &who, &mut details, &account.reason, false)? {
Account::<T, I>::remove(&id, &who);
} else {
debug_assert!(false, "refund did not result in dead account?!");
Expand Down Expand Up @@ -397,7 +401,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

T::Currency::unreserve(&depositor, deposit);

if let Remove = Self::dead_account(&who, &mut details, &account.reason, false) {
if let Remove = Self::dead_account(id.clone(), &who, &mut details, &account.reason, false)? {
Account::<T, I>::remove(&id, &who);
} else {
debug_assert!(false, "refund did not result in dead account?!");
Expand Down Expand Up @@ -561,7 +565,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
account.balance = account.balance.saturating_sub(actual);
if account.balance < details.min_balance {
debug_assert!(account.balance.is_zero(), "checked in prep; qed");
target_died = Some(Self::dead_account(target, details, &account.reason, false));
target_died = Some(Self::dead_account(id.clone(), target, details, &account.reason, false)?);
if let Some(Remove) = target_died {
return Ok(())
}
Expand Down Expand Up @@ -681,7 +685,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
if source_account.balance < details.min_balance {
debug_assert!(source_account.balance.is_zero(), "checked in prep; qed");
source_died =
Some(Self::dead_account(source, details, &source_account.reason, false));
Some(Self::dead_account(id.clone(), source, details, &source_account.reason, false)?);
if let Some(Remove) = source_died {
Account::<T, I>::remove(&id, &source);
return Ok(())
Expand Down Expand Up @@ -782,7 +786,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
} else if let Some(deposit) = v.reason.take_deposit() {
T::Currency::unreserve(&who, deposit);
}
if let Remove = Self::dead_account(&who, &mut details, &v.reason, false) {
if let Remove = Self::dead_account(id.clone(), &who, &mut details, &v.reason, false)? {
Account::<T, I>::remove(&id, &who);
dead_accounts.push(who);
} else {
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ pub mod pallet {
CallbackFailed,
/// The asset ID must be equal to the [`NextAssetId`].
BadAssetId,
/// The asset cannot be destroyed because some accounts for this asset contain freezes.
ContainsFreezes,
}

#[pallet::call(weight(<T as Config<I>>::WeightInfo))]
Expand Down
Loading