From 0e8438ee38ca97b2397fe4491b864c476b08dfe4 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Tue, 29 Aug 2023 11:47:05 +0700 Subject: [PATCH 1/2] add tolerance to nom pool try-state --- substrate/frame/nomination-pools/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/substrate/frame/nomination-pools/src/lib.rs b/substrate/frame/nomination-pools/src/lib.rs index c4bebc5a1d03..e6974683e903 100644 --- a/substrate/frame/nomination-pools/src/lib.rs +++ b/substrate/frame/nomination-pools/src/lib.rs @@ -3133,7 +3133,13 @@ impl Pallet { // the sum of the pending rewards must be less than the leftover balance. Since the // reward math rounds down, we might accumulate some dust here. let pending_rewards_lt_leftover_bal = RewardPool::::current_balance(id) >= - pools_members_pending_rewards.get(&id).copied().unwrap_or_default(); + pools_members_pending_rewards + .get(&id) + .copied() + .unwrap_or_default() + // allow for some tiny tolerance here to account for existential deposit + // increases which may only be handled lazily. + .saturating_sub(T::Currency::minimum_balance()); if !pending_rewards_lt_leftover_bal { log::warn!( "pool {:?}, sum pending rewards = {:?}, remaining balance = {:?}", From 8df7af977012ff7253e95e6e986bd5f74b1a242a Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Tue, 12 Sep 2023 13:09:44 +1000 Subject: [PATCH 2/2] address PR comments --- substrate/frame/nomination-pools/src/lib.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/substrate/frame/nomination-pools/src/lib.rs b/substrate/frame/nomination-pools/src/lib.rs index e6974683e903..485cdada7173 100644 --- a/substrate/frame/nomination-pools/src/lib.rs +++ b/substrate/frame/nomination-pools/src/lib.rs @@ -3133,13 +3133,11 @@ impl Pallet { // the sum of the pending rewards must be less than the leftover balance. Since the // reward math rounds down, we might accumulate some dust here. let pending_rewards_lt_leftover_bal = RewardPool::::current_balance(id) >= - pools_members_pending_rewards - .get(&id) - .copied() - .unwrap_or_default() - // allow for some tiny tolerance here to account for existential deposit - // increases which may only be handled lazily. - .saturating_sub(T::Currency::minimum_balance()); + pools_members_pending_rewards.get(&id).copied().unwrap_or_default(); + + // this is currently broken in Kusama, a fix is being worked on in + // . until it is fixed, log a + // warning instead of panicing with an `ensure` statement. if !pending_rewards_lt_leftover_bal { log::warn!( "pool {:?}, sum pending rewards = {:?}, remaining balance = {:?}", @@ -3148,10 +3146,6 @@ impl Pallet { RewardPool::::current_balance(id) ); } - ensure!( - pending_rewards_lt_leftover_bal, - "The sum of the pending rewards must be less than the leftover balance." - ); Ok(()) })?;