difftreelog
fix the behaviour of the `payoutStakers` extrinsic in which only one stake is calculated for the last processed staker.
in: master
1 file changed
pallets/app-promotion/src/lib.rsdiffbeforeafterboth600 {600 {601 // Address handled in the last payout loop iteration (below)601 // Address handled in the last payout loop iteration (below)602 let last_id = RefCell::new(None);602 let last_id = RefCell::new(None);603 // Block number (as a part of the key) for which calculation was performed in the last payout loop iteration604 let mut last_staked_calculated_block = Default::default();603 // Reward balance for the address in the iteration605 // Reward balance for the address in the iteration604 let income_acc = RefCell::new(BalanceOf::<T>::default());606 let income_acc = RefCell::new(BalanceOf::<T>::default());605 // Staked balance for the address in the iteration (before stake is recalculated)607 // Staked balance for the address in the iteration (before stake is recalculated)658 // or just start handling the very first address. In the latter case last_id will be None and660 // or just start handling the very first address. In the latter case last_id will be None and659 // flush_stake will do nothing661 // flush_stake will do nothing660 if last_id.borrow().as_ref() != Some(¤t_id) {662 if last_id.borrow().as_ref() != Some(¤t_id) {663 if stakers_number > 0 {661 flush_stake()?;664 flush_stake()?;662 *last_id.borrow_mut() = Some(current_id.clone());665 *last_id.borrow_mut() = Some(current_id.clone());663 stakers_number -= 1;666 stakers_number -= 1;664 };667 }668 // Break out if we reached the address limit669 else {670 if let Some(staker) = &*last_id.borrow() {671 // Save the last calculated record to pick up in the next extrinsic call672 PreviousCalculatedRecord::<T>::set(Some((673 staker.clone(),674 last_staked_calculated_block,675 )));676 }677 break;678 };679 };665680666 // Increase accumulated reward for current address and update current staking record, i.e. (address, staked_block) -> amount681 // Increase accumulated reward for current address and update current staking record, i.e. (address, staked_block) -> amount678 );693 );679 }694 }680681 // Break out if we reached the address limit682 if stakers_number == 0 {683 if storage_iterator.next().is_some() {684 // Save the last calculated record to pick up in the next extrinsic call685 PreviousCalculatedRecord::<T>::set(Some((current_id, staked_block)));695 last_staked_calculated_block = staked_block;686 }687 break;688 }689 }696 }690 flush_stake()?;697 flush_stake()?;691 }698 }