Skip to content

Commit

Permalink
Merge collator payout (#200)
Browse files Browse the repository at this point in the history
* Merge collator payout

* Bump runtime version

* Improve code

* Doc
  • Loading branch information
AurevoirXavier committed Jan 12, 2023
1 parent 0fae7a1 commit 943d7c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,29 +875,24 @@ pub mod pallet {
continue;
};
let c_total_payout = Perbill::from_rational(p, total_points) * payout;
let c_commission_payout = commission * c_total_payout;
let n_payout = c_total_payout - c_commission_payout;
let mut c_payout = commission * c_total_payout;
let n_payout = c_total_payout - c_payout;
let Some(c_exposure) = <Exposures<T>>::get(&c) else {
log::error!("[pallet::staking] exposure({c:?}) must be found; qed");

continue;
};

if let Ok(_i) = T::RingCurrency::deposit_into_existing(&c, c_commission_payout) {
actual_payout += c_commission_payout;

Self::deposit_event(Event::Payout {
staker: c,
ring_amount: c_commission_payout,
});
}

for n_exposure in c_exposure.nominators {
let n_payout =
Perbill::from_rational(n_exposure.value, c_exposure.total) * n_payout;

if let Ok(_i) =
T::RingCurrency::deposit_into_existing(&n_exposure.who, n_payout)
if c == n_exposure.who {
// If the collator nominated themselves.

c_payout += n_payout;
} else if T::RingCurrency::deposit_into_existing(&n_exposure.who, n_payout)
.is_ok()
{
actual_payout += n_payout;

Expand All @@ -907,6 +902,12 @@ pub mod pallet {
});
}
}

if T::RingCurrency::deposit_into_existing(&c, c_payout).is_ok() {
actual_payout += c_payout;

Self::deposit_event(Event::Payout { staker: c, ring_amount: c_payout });
}
}

T::RewardRemainder::on_unbalanced(T::RingCurrency::issue(inflation - actual_payout));
Expand Down
2 changes: 1 addition & 1 deletion runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: sp_runtime::create_runtime_str!("Pangolin2"),
impl_name: sp_runtime::create_runtime_str!("DarwiniaOfficialRust"),
authoring_version: 0,
spec_version: 6_0_0_0,
spec_version: 6_0_0_1,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 0,
Expand Down

0 comments on commit 943d7c4

Please sign in to comment.