From 6ea902a749870f244df96e0daa815b0123f45a8c Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Tue, 17 Oct 2023 15:28:42 +0200 Subject: [PATCH] fix :) - use treasury account - compare weight in the good way - actually mutate refuynd queue --- pallets/duniter-account/src/lib.rs | 35 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index 670da5802..3b1f57066 100644 --- a/pallets/duniter-account/src/lib.rs +++ b/pallets/duniter-account/src/lib.rs @@ -260,12 +260,12 @@ pub mod pallet { if !amount.is_zero() { // take money from treasury let res = <T as pallet::Config>::Currency::withdraw( - &queud_refund.account, + // TODO optimize: avoid calling treasury account_id which requires computation + &pallet_treasury::Pallet::<T>::account_id(), amount, frame_support::traits::WithdrawReasons::FEE, // a fee but in reverse ExistenceRequirement::KeepAlive, ); - // if success if let Ok(imbalance) = res { // perform refund @@ -282,21 +282,22 @@ pub mod pallet { /// perform as many refunds as possible within the supplied weight limit pub fn process_refund_queue(weight_limit: Weight) -> Weight { - let mut queue = RefundQueue::<T>::get(); - if queue.is_empty() { - return Weight::zero(); - } - let mut total_weight = Weight::zero(); - while total_weight.any_gt(weight_limit) { - // TODO take into account maximum weight - // - <T as pallet::Config>::WeightInfo::try_refund() - let Some(queued_refund) = queue.pop() else { - break; - }; - let consumed_weight = Self::try_refund(queued_refund); - total_weight = total_weight.saturating_add(consumed_weight); - } - total_weight + RefundQueue::<T>::mutate(|mut queue| { + if queue.is_empty() { + return Weight::zero(); + } + let mut total_weight = Weight::zero(); + while total_weight.any_lt(weight_limit) { + // TODO take into account maximum weight + // - <T as pallet::Config>::WeightInfo::try_refund() + let Some(queued_refund) = queue.pop() else { + break; + }; + let consumed_weight = Self::try_refund(queued_refund); + total_weight = total_weight.saturating_add(consumed_weight); + } + total_weight + }) } } -- GitLab