diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index 670da58024be528bf8e823741d3465143008936b..3b1f570660e36c35540eda9c7b7fad97a7fa3568 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 + }) } }