From 9d850c2d3901ec1044ef66b751c9c52adbbb86c8 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Wed, 2 Aug 2023 12:11:57 +0100 Subject: [PATCH 1/3] Provide helpful message when get ED wrong. --- frame/balances/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index e77b0f5e5d956..967fc35466e03 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -730,6 +730,12 @@ pub mod pallet { let existential_deposit = Self::ed(); let wipeout = new_free < existential_deposit; + debug_assert!( + !wipeout || ::is_zero(&new_free), + "Attempt to force balance to be {:?} but this is less than ED {:?}", + new_free, + existential_deposit + ); let new_free = if wipeout { Zero::zero() } else { new_free }; // First we try to modify the account's balance to the forced balance. From cffa676e0dae352c574e784272d45792bbfaf167 Mon Sep 17 00:00:00 2001 From: Squirrel Date: Tue, 15 Aug 2023 17:24:08 +0100 Subject: [PATCH 2/3] Update frame/balances/src/lib.rs Co-authored-by: Liam Aharon --- frame/balances/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 967fc35466e03..1c4cd5ad48aee 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -731,7 +731,7 @@ pub mod pallet { let wipeout = new_free < existential_deposit; debug_assert!( - !wipeout || ::is_zero(&new_free), + !wipeout || new_free.is_zero(), "Attempt to force balance to be {:?} but this is less than ED {:?}", new_free, existential_deposit From 2047053e6591b60e368f9217a93118abd97ee954 Mon Sep 17 00:00:00 2001 From: Squirrel Date: Tue, 15 Aug 2023 17:25:44 +0100 Subject: [PATCH 3/3] Update frame/balances/src/lib.rs --- frame/balances/src/lib.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 1c4cd5ad48aee..fcde46bde89b9 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -730,12 +730,15 @@ pub mod pallet { let existential_deposit = Self::ed(); let wipeout = new_free < existential_deposit; - debug_assert!( - !wipeout || new_free.is_zero(), - "Attempt to force balance to be {:?} but this is less than ED {:?}", - new_free, - existential_deposit - ); + #[cfg(debug_assertions)] + if wipeout && !new_free.is_zero() { + log::error!( + target: LOG_TARGET, + "Attempt to force balance to be {:?} but this is less than ED {:?}", + new_free, + existential_deposit + ); + } let new_free = if wipeout { Zero::zero() } else { new_free }; // First we try to modify the account's balance to the forced balance.