git.delta.rocks / unique-network / refs/commits / 5509757640ce

difftreelog

Merge pull request #800 from UniqueNetwork/fix/payout-stakers

Yaroslav Bolyukin2022-12-22parents: #2abdf7d #726da5c.patch.diff
in: master
Fix/payout stakers

4 files changed

modifiedCargo.lockdiffbeforeafterboth
55495549
5550[[package]]5550[[package]]
5551name = "pallet-app-promotion"5551name = "pallet-app-promotion"
5552version = "0.1.1"5552version = "0.1.2"
5553dependencies = [5553dependencies = [
5554 "frame-benchmarking",5554 "frame-benchmarking",
5555 "frame-support",5555 "frame-support",
modifiedpallets/app-promotion/CHANGELOG.mddiffbeforeafterboth
44
5<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->
66
7## [0.1.2] - 2022-12-20
8
9### Fixed
10
11- The behaviour of the `payoutStakers` extrinsic
12 in which only one stake is calculated for the last processed staker.
13
7## [0.1.1] - 2022-12-1314## [0.1.1] - 2022-12-13
815
9### Added16### Added
modifiedpallets/app-promotion/Cargo.tomldiffbeforeafterboth
9license = 'GPLv3'9license = 'GPLv3'
10name = 'pallet-app-promotion'10name = 'pallet-app-promotion'
11repository = 'https://github.com/UniqueNetwork/unique-chain'11repository = 'https://github.com/UniqueNetwork/unique-chain'
12version = '0.1.1'12version = '0.1.2'
1313
14[package.metadata.docs.rs]14[package.metadata.docs.rs]
15targets = ['x86_64-unknown-linux-gnu']15targets = ['x86_64-unknown-linux-gnu']
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
608 {608 {
609 // Address handled in the last payout loop iteration (below)609 // Address handled in the last payout loop iteration (below)
610 let last_id = RefCell::new(None);610 let last_id = RefCell::new(None);
611 // Block number (as a part of the key) for which calculation was performed in the last payout loop iteration
612 let mut last_staked_calculated_block = Default::default();
611 // Reward balance for the address in the iteration613 // Reward balance for the address in the iteration
612 let income_acc = RefCell::new(BalanceOf::<T>::default());614 let income_acc = RefCell::new(BalanceOf::<T>::default());
613 // Staked balance for the address in the iteration (before stake is recalculated)615 // Staked balance for the address in the iteration (before stake is recalculated)
666 // or just start handling the very first address. In the latter case last_id will be None and668 // or just start handling the very first address. In the latter case last_id will be None and
667 // flush_stake will do nothing669 // flush_stake will do nothing
668 if last_id.borrow().as_ref() != Some(&current_id) {670 if last_id.borrow().as_ref() != Some(&current_id) {
671 if stakers_number > 0 {
669 flush_stake()?;672 flush_stake()?;
670 *last_id.borrow_mut() = Some(current_id.clone());673 *last_id.borrow_mut() = Some(current_id.clone());
671 stakers_number -= 1;674 stakers_number -= 1;
672 };675 }
676 // Break out if we reached the address limit
677 else {
678 if let Some(staker) = &*last_id.borrow() {
679 // Save the last calculated record to pick up in the next extrinsic call
680 PreviousCalculatedRecord::<T>::set(Some((
681 staker.clone(),
682 last_staked_calculated_block,
683 )));
684 }
685 break;
686 };
687 };
673688
674 // Increase accumulated reward for current address and update current staking record, i.e. (address, staked_block) -> amount689 // Increase accumulated reward for current address and update current staking record, i.e. (address, staked_block) -> amount
686 );701 );
687 }702 }
688
689 // Break out if we reached the address limit
690 if stakers_number == 0 {
691 if storage_iterator.next().is_some() {
692 // Save the last calculated record to pick up in the next extrinsic call
693 PreviousCalculatedRecord::<T>::set(Some((current_id, staked_block)));703 last_staked_calculated_block = staked_block;
694 }
695 break;
696 }
697 }704 }
698 flush_stake()?;705 flush_stake()?;
699 }706 }