difftreelog
Merge pull request #800 from UniqueNetwork/fix/payout-stakers
in: master
Fix/payout stakers
4 files changed
Cargo.lockdiffbeforeafterboth554955495550[[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",pallets/app-promotion/CHANGELOG.mddiffbeforeafterboth--- a/pallets/app-promotion/CHANGELOG.md
+++ b/pallets/app-promotion/CHANGELOG.md
@@ -4,6 +4,13 @@
<!-- bureaucrate goes here -->
+## [0.1.2] - 2022-12-20
+
+### Fixed
+
+- The behaviour of the `payoutStakers` extrinsic
+ in which only one stake is calculated for the last processed staker.
+
## [0.1.1] - 2022-12-13
### Added
pallets/app-promotion/Cargo.tomldiffbeforeafterboth--- a/pallets/app-promotion/Cargo.toml
+++ b/pallets/app-promotion/Cargo.toml
@@ -9,7 +9,7 @@
license = 'GPLv3'
name = 'pallet-app-promotion'
repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = '0.1.1'
+version = '0.1.2'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
pallets/app-promotion/src/lib.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -608,6 +608,8 @@
{
// Address handled in the last payout loop iteration (below)
let last_id = RefCell::new(None);
+ // Block number (as a part of the key) for which calculation was performed in the last payout loop iteration
+ let mut last_staked_calculated_block = Default::default();
// Reward balance for the address in the iteration
let income_acc = RefCell::new(BalanceOf::<T>::default());
// Staked balance for the address in the iteration (before stake is recalculated)
@@ -666,9 +668,22 @@
// or just start handling the very first address. In the latter case last_id will be None and
// flush_stake will do nothing
if last_id.borrow().as_ref() != Some(¤t_id) {
- flush_stake()?;
- *last_id.borrow_mut() = Some(current_id.clone());
- stakers_number -= 1;
+ if stakers_number > 0 {
+ flush_stake()?;
+ *last_id.borrow_mut() = Some(current_id.clone());
+ stakers_number -= 1;
+ }
+ // Break out if we reached the address limit
+ else {
+ if let Some(staker) = &*last_id.borrow() {
+ // Save the last calculated record to pick up in the next extrinsic call
+ PreviousCalculatedRecord::<T>::set(Some((
+ staker.clone(),
+ last_staked_calculated_block,
+ )));
+ }
+ break;
+ };
};
// Increase accumulated reward for current address and update current staking record, i.e. (address, staked_block) -> amount
@@ -685,15 +700,7 @@
&mut *income_acc.borrow_mut(),
);
}
-
- // Break out if we reached the address limit
- if stakers_number == 0 {
- if storage_iterator.next().is_some() {
- // Save the last calculated record to pick up in the next extrinsic call
- PreviousCalculatedRecord::<T>::set(Some((current_id, staked_block)));
- }
- break;
- }
+ last_staked_calculated_block = staked_block;
}
flush_stake()?;
}