git.delta.rocks / unique-network / refs/commits / 41d4d76e5d72

difftreelog

fix the behaviour of the `payoutStakers` extrinsic in which only one stake is calculated for the last processed staker.

PraetorP2022-12-20parent: #e1b9a6a.patch.diff
in: master

1 file changed

modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
600 {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 iteration
604 let mut last_staked_calculated_block = Default::default();
603 // Reward balance for the address in the iteration605 // Reward balance for the address in the iteration
604 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 and
659 // flush_stake will do nothing661 // flush_stake will do nothing
660 if last_id.borrow().as_ref() != Some(&current_id) {662 if last_id.borrow().as_ref() != Some(&current_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 limit
669 else {
670 if let Some(staker) = &*last_id.borrow() {
671 // Save the last calculated record to pick up in the next extrinsic call
672 PreviousCalculatedRecord::<T>::set(Some((
673 staker.clone(),
674 last_staked_calculated_block,
675 )));
676 }
677 break;
678 };
679 };
665680
666 // 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) -> amount
678 );693 );
679 }694 }
680
681 // Break out if we reached the address limit
682 if stakers_number == 0 {
683 if storage_iterator.next().is_some() {
684 // Save the last calculated record to pick up in the next extrinsic call
685 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 }