git.delta.rocks / unique-network / refs/commits / 97044329ec08

difftreelog

fix logic payout

PraetorP2022-09-02parent: #61a1841.patch.diff
in: master

3 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -424,7 +424,7 @@
 			client: Arc<C>,
 			_marker: std::marker::PhantomData<P>,
 		}
-		
+
 		impl<C, P> $name<C, P> {
 			pub fn new(client: Arc<C>) -> Self {
 				Self {
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
41 vec,41 vec,
42 iter::Sum,42 iter::Sum,
43 borrow::ToOwned,43 borrow::ToOwned,
44 cell::RefCell,
44};45};
45use sp_core::H160;46use sp_core::H160;
46use codec::EncodeLike;47use codec::EncodeLike;
474 let next_recalc_block = current_recalc_block + T::RecalculationInterval::get();475 let next_recalc_block = current_recalc_block + T::RecalculationInterval::get();
475476
476 let mut storage_iterator = Self::get_next_calculated_key()477 let mut storage_iterator = Self::get_next_calculated_key()
477 .map_or(Staked::<T>::iter(), |key| {478 .map_or(Staked::<T>::iter(), |key| Staked::<T>::iter_from(key));
478 Staked::<T>::iter_from(key)
479 });
480479
481 NextCalculatedRecord::<T>::set(None);480 NextCalculatedRecord::<T>::set(None);
482481
482 // {
483 // let mut stakers_number = stakers_number.unwrap_or(20);
484 // let mut last_id = admin_id;
485 // let mut income_acc = BalanceOf::<T>::default();
486 // let mut amount_acc = BalanceOf::<T>::default();
487
488 // while let Some((
489 // (current_id, staked_block),
490 // (amount, next_recalc_block_for_stake),
491 // )) = storage_iterator.next()
492 // {
493 // if last_id != current_id {
494 // if income_acc != BalanceOf::<T>::default() {
495 // <T::Currency as Currency<T::AccountId>>::transfer(
496 // &T::TreasuryAccountId::get(),
497 // &last_id,
498 // income_acc,
499 // ExistenceRequirement::KeepAlive,
500 // )
501 // .and_then(|_| Self::add_lock_balance(&last_id, income_acc))?;
502
503 // Self::deposit_event(Event::StakingRecalculation(
504 // last_id, amount, income_acc,
505 // ));
506 // }
507
508 // if stakers_number == 0 {
509 // NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
510 // break;
511 // }
512 // stakers_number -= 1;
513 // income_acc = BalanceOf::<T>::default();
514 // last_id = current_id;
515 // };
516 // if current_recalc_block >= next_recalc_block_for_stake {
517 // Self::recalculate_and_insert_stake(
518 // &last_id,
519 // staked_block,
520 // next_recalc_block,
521 // amount,
522 // ((current_recalc_block - next_recalc_block_for_stake)
523 // / T::RecalculationInterval::get())
524 // .into() + 1,
525 // &mut income_acc,
526 // );
527 // }
528 // }
529 // }
530
483 {531 {
484 let mut stakers_number = stakers_number.unwrap_or(20);532 let mut stakers_number = stakers_number.unwrap_or(20);
485 let mut last_id = admin_id;533 let last_id = RefCell::new(None);
486 let mut income_acc = BalanceOf::<T>::default();534 let income_acc = RefCell::new(BalanceOf::<T>::default());
535 let amount_acc = RefCell::new(BalanceOf::<T>::default());
536
537 let flush_stake = || -> DispatchResult {
538 if let Some(last_id) = &*last_id.borrow() {
539 if !income_acc.borrow().is_zero() {
540 <T::Currency as Currency<T::AccountId>>::transfer(
541 &T::TreasuryAccountId::get(),
542 last_id,
543 *income_acc.borrow(),
544 ExistenceRequirement::KeepAlive,
545 )
546 .and_then(|_| Self::add_lock_balance(last_id, *income_acc.borrow()))?;
547
548 Self::deposit_event(Event::StakingRecalculation(
549 last_id.clone(),
550 *amount_acc.borrow(),
551 *income_acc.borrow(),
552 ));
553 }
554
555 *income_acc.borrow_mut() = BalanceOf::<T>::default();
556 *amount_acc.borrow_mut() = BalanceOf::<T>::default();
557 }
558 Ok(())
559 };
487560
488 while let Some(((current_id, staked_block), (amount, next_recalc_block_for_stake))) =561 while let Some((
562 (current_id, staked_block),
563 (amount, next_recalc_block_for_stake),
489 storage_iterator.next()564 )) = storage_iterator.next()
490 {565 {
491 if last_id != current_id {
492 if income_acc != BalanceOf::<T>::default() {
493 <T::Currency as Currency<T::AccountId>>::transfer(
494 &T::TreasuryAccountId::get(),
495 &last_id,
496 income_acc,
497 ExistenceRequirement::KeepAlive,
498 )
499 .and_then(|_| Self::add_lock_balance(&last_id, income_acc))?;
500
501 Self::deposit_event(Event::StakingRecalculation(
502 last_id, amount, income_acc,
503 ));
504 }
505
506 if stakers_number == 0 {566 if stakers_number == 0 {
507 NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));567 NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
508 break;568 break;
509 }569 }
510 stakers_number -= 1;570 stakers_number -= 1;
511 income_acc = BalanceOf::<T>::default();571 if last_id.borrow().as_ref() != Some(&current_id) {
572 flush_stake()?;
573 };
512 last_id = current_id;574 *last_id.borrow_mut() = Some(current_id.clone());
513 };
514 if current_recalc_block >= next_recalc_block_for_stake {575 if current_recalc_block >= next_recalc_block_for_stake {
576 *amount_acc.borrow_mut() += amount;
515 Self::recalculate_and_insert_stake(577 Self::recalculate_and_insert_stake(
516 &last_id,578 &current_id,
517 staked_block,579 staked_block,
518 next_recalc_block,580 next_recalc_block,
519 amount,581 amount,
520 ((current_recalc_block - next_recalc_block_for_stake)582 ((current_recalc_block - next_recalc_block_for_stake)
521 / T::RecalculationInterval::get())583 / T::RecalculationInterval::get())
522 .into() + 1,584 .into() + 1,
523 &mut income_acc,585 &mut *income_acc.borrow_mut(),
524 );586 );
525 }587 }
526 }588 }
589 flush_stake()?;
527 }590 }
591
528592
modifiedruntime/common/config/pallets/app_promotion.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -30,7 +30,7 @@
 parameter_types! {
 	pub const AppPromotionId: PalletId = PalletId(*b"appstake");
 	pub const RecalculationInterval: BlockNumber = 20;
-	pub const PendingInterval: BlockNumber = 20;
+	pub const PendingInterval: BlockNumber = 10;
 	pub const Nominal: Balance = UNIQUE;
 	pub const Day: BlockNumber = DAYS;
 	pub IntervalIncome: Perbill = Perbill::from_rational(RecalculationInterval::get(), RELAY_DAYS) * Perbill::from_rational(5u32, 10_000);