Browse Source

Merge branch 'olympia' into working-groups-schemas

Leszek Wiesner 3 years ago
parent
commit
b3fe6622f7

+ 14 - 18
runtime-modules/working-group/src/lib.rs

@@ -50,9 +50,9 @@ use sp_std::vec::Vec;
 pub use errors::Error;
 pub use types::{
     Application, ApplicationId, ApplyOnOpeningParameters, BalanceOf, Opening, OpeningId,
-    OpeningType, StakeParameters, StakePolicy, Worker, WorkerId,
+    OpeningType, RewardPaymentType, StakeParameters, StakePolicy, Worker, WorkerId,
 };
-use types::{ApplicationInfo, RewardPaymentType, WorkerInfo};
+use types::{ApplicationInfo, WorkerInfo};
 
 pub use checks::{ensure_worker_exists, ensure_worker_signed};
 
@@ -263,15 +263,11 @@ decl_event!(
 
         /// Emits on paying the reward.
         /// Params:
+        /// - Id of the worker.
         /// - Receiver Account Id.
         /// - Reward
-        RewardPaid(AccountId, Balance),
-
-        /// Emits on paying the missed reward.
-        /// Params:
-        /// - Receiver Account Id.
-        /// - Missed reward
-        MissedRewardPaid(AccountId, Balance),
+        /// - Payment type (missed reward or regular one)
+        RewardPaid(WorkerId, AccountId, Balance, RewardPaymentType),
 
         /// Emits on reaching new missed reward.
         /// Params:
@@ -1322,6 +1318,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
             // Check whether the budget is not zero.
             if actual_reward > Zero::zero() {
                 Self::pay_reward(
+                    worker_id,
                     &worker.reward_account_id,
                     actual_reward,
                     RewardPaymentType::RegularReward,
@@ -1350,20 +1347,18 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
 
     // Helper-function joining the reward payment with the event.
     fn pay_reward(
+        worker_id: &WorkerId<T>,
         account_id: &T::AccountId,
         amount: BalanceOf<T>,
         reward_payment_type: RewardPaymentType,
     ) {
         Self::pay_from_budget(account_id, amount);
-
-        let event = match reward_payment_type {
-            RewardPaymentType::MissedReward => {
-                RawEvent::MissedRewardPaid(account_id.clone(), amount)
-            }
-            RewardPaymentType::RegularReward => RawEvent::RewardPaid(account_id.clone(), amount),
-        };
-
-        Self::deposit_event(event);
+        Self::deposit_event(RawEvent::RewardPaid(
+            *worker_id,
+            account_id.clone(),
+            amount,
+            reward_payment_type,
+        ));
     }
 
     // Tries to pay missed reward if the reward is enabled for worker and there is enough of group budget.
@@ -1375,6 +1370,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
             // Checks if the budget allows any payment.
             if could_be_paid_reward > Zero::zero() {
                 Self::pay_reward(
+                    worker_id,
                     &worker.reward_account_id,
                     could_be_paid_reward,
                     RewardPaymentType::MissedReward,

+ 11 - 2
runtime-modules/working-group/src/tests/mod.rs

@@ -16,7 +16,9 @@ use crate::tests::mock::{
     STAKING_ACCOUNT_ID_FOR_CONFLICTING_STAKES, STAKING_ACCOUNT_ID_NOT_BOUND_TO_MEMBER,
 };
 use crate::types::StakeParameters;
-use crate::{DefaultInstance, Error, OpeningType, RawEvent, StakePolicy, Trait, Worker};
+use crate::{
+    DefaultInstance, Error, OpeningType, RawEvent, RewardPaymentType, StakePolicy, Trait, Worker,
+};
 use common::working_group::WorkingGroupAuthenticator;
 use fixtures::{
     increase_total_balance_issuance_using_account_id, AddOpeningFixture, ApplyOnOpeningFixture,
@@ -632,7 +634,12 @@ fn leave_worker_role_succeeds_with_paying_missed_reward() {
             worker_id,
             Some(missed_reward),
         ));
-        EventFixture::contains_crate_event(RawEvent::MissedRewardPaid(account_id, missed_reward));
+        EventFixture::contains_crate_event(RawEvent::RewardPaid(
+            worker_id,
+            account_id,
+            missed_reward,
+            RewardPaymentType::MissedReward,
+        ));
 
         // Didn't get the last reward period: leaving earlier than rewarding.
         let reward_block_count = leaving_block - reward_period;
@@ -1923,8 +1930,10 @@ fn rewards_payments_are_successful() {
 
         let reward_period: u64 = <Test as Trait>::RewardPeriod::get().into();
         EventFixture::assert_last_crate_event(RawEvent::RewardPaid(
+            worker_id,
             account_id,
             reward_per_block * reward_period,
+            RewardPaymentType::RegularReward,
         ));
     });
 }

+ 6 - 4
runtime-modules/working-group/src/types.rs

@@ -259,11 +259,13 @@ pub type ApplyOnOpeningParameters<T> = ApplyOnOpeningParams<
     BalanceOf<T>,
 >;
 
-// Reward payment type enum.
-pub(crate) enum RewardPaymentType {
-    // The reward was missed.
+/// Reward payment type enum.
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, Copy)]
+pub enum RewardPaymentType {
+    /// The reward was missed.
     MissedReward,
 
-    // The reward was paid in time.
+    /// The reward was paid in time.
     RegularReward,
 }