From 943d7c4b9cb689e7d69106d1298f5d49bb78bcd4 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 12 Jan 2023 14:57:36 +0800 Subject: [PATCH] Merge collator payout (#200) * Merge collator payout * Bump runtime version * Improve code * Doc --- pallet/staking/src/lib.rs | 27 ++++++++++++++------------- runtime/pangolin/src/lib.rs | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index 1ecd660fe..ff4a29832 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -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) = >::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; @@ -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)); diff --git a/runtime/pangolin/src/lib.rs b/runtime/pangolin/src/lib.rs index 01202daf4..a4b055299 100644 --- a/runtime/pangolin/src/lib.rs +++ b/runtime/pangolin/src/lib.rs @@ -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,