git.delta.rocks / unique-network / refs/commits / 18ed55433818

difftreelog

Merge branch 'develop' into tests/eth-helpers

Max Andreev2022-12-21parents: #994aeb1 #ccd7200.patch.diff
in: master

2 files changed

modifiedREADME.mddiffbeforeafterboth
--- a/README.md
+++ b/README.md
@@ -82,7 +82,7 @@
 
 ```
 git clone https://github.com/UniqueNetwork/polkadot-launch.git
-git checkout feature/runtime-upgrade-testing
+git checkout unique-network
 ```
 
 ### Build relay
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
598 PreviousCalculatedRecord::<T>::set(None);598 PreviousCalculatedRecord::<T>::set(None);
599599
600 {600 {
601 // Address handled in the last payout loop iteration (below)
601 let last_id = RefCell::new(None);602 let last_id = RefCell::new(None);
603 // Reward balance for the address in the iteration
602 let income_acc = RefCell::new(BalanceOf::<T>::default());604 let income_acc = RefCell::new(BalanceOf::<T>::default());
605 // Staked balance for the address in the iteration (before stake is recalculated)
603 let amount_acc = RefCell::new(BalanceOf::<T>::default());606 let amount_acc = RefCell::new(BalanceOf::<T>::default());
604607
605 // this closure is used to perform some of the actions if we break the loop because we reached the number of stakers for recalculation,608 // This closure is used to finalize handling single staker address in each of the two conditions: (1) when we break out of the payout
606 // but there were unrecalculated records in the storage.609 // loop because we reached the number of stakes for rewarding, (2) When all stakes by the single address are handled and the payout
610 // loop switches to handling the next staker address:
611 // 1. Transfer full reward amount to the payee
612 // 2. Lock the reward in staking lock
613 // 3. Update TotalStaked amount
614 // 4. Issue StakingRecalculation event
607 let flush_stake = || -> DispatchResult {615 let flush_stake = || -> DispatchResult {
608 if let Some(last_id) = &*last_id.borrow() {616 if let Some(last_id) = &*last_id.borrow() {
609 if !income_acc.borrow().is_zero() {617 if !income_acc.borrow().is_zero() {
635 Ok(())643 Ok(())
636 };644 };
637645
646 // Reward payment loop. Should loop for no more than config.max_stakers_per_calculation
647 // iterations in one extrinsic call
648 //
649 // stakers_number - keeps the remaining number of iterations (staker addresses to handle)
650 // next_recalc_block_for_stake - is taken from the state and stores the starting relay block from which reward should be paid out
651 // income_acc - stores the reward amount to pay to the staker address (accumulates over all address stake records)
638 while let Some((652 while let Some((
639 (current_id, staked_block),653 (current_id, staked_block),
640 (amount, next_recalc_block_for_stake),654 (amount, next_recalc_block_for_stake),
641 )) = storage_iterator.next()655 )) = storage_iterator.next()
642 {656 {
657 // last_id is not equal current_id when we switch to handling a new staker address
658 // or just start handling the very first address. In the latter case last_id will be None and
659 // flush_stake will do nothing
643 if last_id.borrow().as_ref() != Some(&current_id) {660 if last_id.borrow().as_ref() != Some(&current_id) {
644 flush_stake()?;661 flush_stake()?;
645 *last_id.borrow_mut() = Some(current_id.clone());662 *last_id.borrow_mut() = Some(current_id.clone());
646 stakers_number -= 1;663 stakers_number -= 1;
647 };664 };
665
666 // Increase accumulated reward for current address and update current staking record, i.e. (address, staked_block) -> amount
648 if current_recalc_block >= next_recalc_block_for_stake {667 if current_recalc_block >= next_recalc_block_for_stake {
649 *amount_acc.borrow_mut() += amount;668 *amount_acc.borrow_mut() += amount;
650 Self::recalculate_and_insert_stake(669 Self::recalculate_and_insert_stake(
659 );678 );
660 }679 }
661680
681 // Break out if we reached the address limit
662 if stakers_number == 0 {682 if stakers_number == 0 {
663 if storage_iterator.next().is_some() {683 if storage_iterator.next().is_some() {
684 // Save the last calculated record to pick up in the next extrinsic call
664 PreviousCalculatedRecord::<T>::set(Some((current_id, staked_block)));685 PreviousCalculatedRecord::<T>::set(Some((current_id, staked_block)));
665 }686 }
666 break;687 break;
834 income - base855 income - base
835 }856 }
836857
858 /// Get relay block number rounded down to multiples of config.recalculation_interval.
859 /// We need it to reward stakers in integer parts of recalculation_interval
837 fn get_current_recalc_block(860 fn get_current_recalc_block(
838 current_relay_block: T::BlockNumber,861 current_relay_block: T::BlockNumber,
839 config: &PalletConfiguration<T>,862 config: &PalletConfiguration<T>,