diff --git a/pallets/universal-dividend/src/compute_claim_uds.rs b/pallets/universal-dividend/src/compute_claim_uds.rs index 231aac8830b0a5c3ac83b409aed499715a310058..1c2cbe8b7065cf01a5efc22555dd7900ec71f7d6 100644 --- a/pallets/universal-dividend/src/compute_claim_uds.rs +++ b/pallets/universal-dividend/src/compute_claim_uds.rs @@ -24,18 +24,22 @@ pub(super) fn compute_claim_uds<Balance: AtLeast32BitUnsigned>( ) -> (UdIndex, Balance) { let mut total_amount = Zero::zero(); let mut total_count = 0; - for (ud_index, ud_amount) in past_reevals.rev() { - if ud_index <= first_ud_index { + // We start in reverse order, i.e. the most recent reeval first + for (reeval_index, ud_amount) in past_reevals.rev() { + // Therefore, if our first UD is above the current reeval index, we have reached our final useful reeval and must break + if reeval_index <= first_ud_index { let count = current_ud_index - first_ud_index; total_amount += Balance::from(count) * ud_amount; total_count += count; // First unclaimed UD is reached; stop counting now. break; - } else { - let count = current_ud_index - ud_index; + } + // Otherwise, we consume the full reeval contained UDs + else { + let count = current_ud_index - reeval_index; total_amount += Balance::from(count) * ud_amount; total_count += count; - current_ud_index = ud_index; + current_ud_index = reeval_index; } }