Skip to content

Commit

Permalink
fix: ensure_account_can_die should happen before mutating dest on…
Browse files Browse the repository at this point in the history
… `transfer_and_die`.
  • Loading branch information
pandres95 committed Dec 9, 2024
1 parent d0005af commit d6af473
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions substrate/frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
debug_assert!(source_account.balance >= debit, "checked in prep; qed");
source_account.balance = source_account.balance.saturating_sub(debit);

// Pre-check that an account can die if is below min balance
if source_account.balance < details.min_balance {
source_died =
Some(Self::dead_account(source, details, &source_account.reason, false));
if let Some(Remove) = source_died {
Self::ensure_account_can_die(id.clone(), source)?;
}
}

Account::<T, I>::try_mutate(&id, &dest, |maybe_account| -> DispatchResult {
match maybe_account {
Some(ref mut account) => {
Expand All @@ -714,10 +723,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
// Remove source account if it's now dead.
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));
if let Some(Remove) = source_died {
Self::ensure_account_can_die(id.clone(), source)?;
Account::<T, I>::remove(&id, &source);
return Ok(())
}
Expand Down

0 comments on commit d6af473

Please sign in to comment.