Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
FRAME: Minor fix for failsafe. (#13741)
Browse files Browse the repository at this point in the history
* max instead of min

* Remove debug stuff

* remove debug code

* warn log on no provider ref

* format string for log

---------

Co-authored-by: muharem <ismailov.m.h@gmail.com>
  • Loading branch information
gavofyork and muharem committed Apr 1, 2023
1 parent 9b94d38 commit d6f278b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 6 additions & 1 deletion frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,12 @@ pub mod pallet {
// Gah!! We have a non-zero reserve balance but no provider refs :(
// This shouldn't practically happen, but we need a failsafe anyway: let's give
// them enough for an ED.
a.free = a.free.min(Self::ed());
log::warn!(
target: LOG_TARGET,
"account with a non-zero reserve balance has no provider refs, account_id: '{:?}'.",
who
);
a.free = a.free.max(Self::ed());
system::Pallet::<T>::inc_providers(who);
}
let _ = system::Pallet::<T>::inc_consumers(who).defensive();
Expand Down
9 changes: 2 additions & 7 deletions frame/nis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ pub mod pallet {
AlreadyCommunal,
/// The receipt is already private.
AlreadyPrivate,
Release1,
Release2,
Tah,
}

pub(crate) struct WeightCounter {
Expand Down Expand Up @@ -724,8 +721,7 @@ pub mod pallet {
let dropped = receipt.proportion.is_zero();

if amount > on_hold {
T::Currency::release(&T::HoldReason::get(), &who, on_hold, Exact)
.map_err(|_| Error::<T>::Release1)?;
T::Currency::release(&T::HoldReason::get(), &who, on_hold, Exact)?;
let deficit = amount - on_hold;
// Try to transfer deficit from pot to receipt owner.
summary.receipts_on_hold.saturating_reduce(on_hold);
Expand Down Expand Up @@ -756,8 +752,7 @@ pub mod pallet {
)?;
summary.receipts_on_hold.saturating_reduce(on_hold);
}
T::Currency::release(&T::HoldReason::get(), &who, amount, Exact)
.map_err(|_| Error::<T>::Release2)?;
T::Currency::release(&T::HoldReason::get(), &who, amount, Exact)?;
}

if dropped {
Expand Down

0 comments on commit d6f278b

Please sign in to comment.