difftreelog
Merge pull request #800 from UniqueNetwork/fix/payout-stakers
in: master
Fix/payout stakers
4 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5549,7 +5549,7 @@
[[package]]
name = "pallet-app-promotion"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
"frame-benchmarking",
"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.tomldiffbeforeafterboth1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Unique App Promotion Pallet'7edition = '2021'8homepage = 'https://unique.network'9license = 'GPLv3'10name = 'pallet-app-promotion'11repository = 'https://github.com/UniqueNetwork/unique-chain'12version = '0.1.1'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = [20 'frame-benchmarking',21 'frame-support/runtime-benchmarks',22 'frame-system/runtime-benchmarks',23 # 'pallet-unique/runtime-benchmarks',24]25std = [26 'codec/std',27 'frame-benchmarking/std',28 'frame-support/std',29 'frame-system/std',30 'pallet-balances/std',31 'pallet-timestamp/std',32 'pallet-randomness-collective-flip/std',33 'pallet-evm/std',34 'sp-io/std',35 'sp-std/std',36 'sp-runtime/std',37 'sp-core/std',38 'serde/std',3940]41try-runtime = ["frame-support/try-runtime"]4243[dependencies]44scale-info = { version = "2.0.1", default-features = false, features = [45 "derive",46] }47################################################################################48# Substrate Dependencies4950codec = { default-features = false, features = [51 'derive',52], package = 'parity-scale-codec', version = '3.1.2' }53frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }54frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }55frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }56pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }57pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }58pallet-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }59pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }60sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }61sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }62sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }63sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }64serde = { default-features = false, features = ['derive'], version = '1.0.130' }6566################################################################################67# local dependencies6869up-data-structs = { default-features = false, path = "../../primitives/data-structs" }70pallet-common = { default-features = false, path = "../common" }71pallet-configuration = { default-features = false, path = "../configuration" }72pallet-unique = { default-features = false, path = "../unique" }73pallet-evm-contract-helpers = { default-features = false, path = "../evm-contract-helpers" }74pallet-evm-migration = { default-features = false, path = "../evm-migration" }7576# [dev-dependencies]7778################################################################################1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Unique App Promotion Pallet'7edition = '2021'8homepage = 'https://unique.network'9license = 'GPLv3'10name = 'pallet-app-promotion'11repository = 'https://github.com/UniqueNetwork/unique-chain'12version = '0.1.2'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = [20 'frame-benchmarking',21 'frame-support/runtime-benchmarks',22 'frame-system/runtime-benchmarks',23 # 'pallet-unique/runtime-benchmarks',24]25std = [26 'codec/std',27 'frame-benchmarking/std',28 'frame-support/std',29 'frame-system/std',30 'pallet-balances/std',31 'pallet-timestamp/std',32 'pallet-randomness-collective-flip/std',33 'pallet-evm/std',34 'sp-io/std',35 'sp-std/std',36 'sp-runtime/std',37 'sp-core/std',38 'serde/std',3940]41try-runtime = ["frame-support/try-runtime"]4243[dependencies]44scale-info = { version = "2.0.1", default-features = false, features = [45 "derive",46] }47################################################################################48# Substrate Dependencies4950codec = { default-features = false, features = [51 'derive',52], package = 'parity-scale-codec', version = '3.1.2' }53frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }54frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }55frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }56pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }57pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }58pallet-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }59pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }60sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }61sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }62sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }63sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }64serde = { default-features = false, features = ['derive'], version = '1.0.130' }6566################################################################################67# local dependencies6869up-data-structs = { default-features = false, path = "../../primitives/data-structs" }70pallet-common = { default-features = false, path = "../common" }71pallet-configuration = { default-features = false, path = "../configuration" }72pallet-unique = { default-features = false, path = "../unique" }73pallet-evm-contract-helpers = { default-features = false, path = "../evm-contract-helpers" }74pallet-evm-migration = { default-features = false, path = "../evm-migration" }7576# [dev-dependencies]7778################################################################################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()?;
}