Procházet zdrojové kódy

runtime: working-group: Add more unstaking_periods checks.

Shamil Gadelshin před 4 roky
rodič
revize
1708e9700e

+ 3 - 3
Cargo.lock

@@ -1569,7 +1569,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node"
-version = "2.5.0"
+version = "2.5.1"
 dependencies = [
  "ctrlc",
  "derive_more 0.14.1",
@@ -1614,7 +1614,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node-runtime"
-version = "6.19.0"
+version = "6.20.0"
 dependencies = [
  "parity-scale-codec",
  "safe-mix",
@@ -5568,7 +5568,7 @@ dependencies = [
 
 [[package]]
 name = "substrate-working-group-module"
-version = "1.0.1"
+version = "1.0.2"
 dependencies = [
  "parity-scale-codec",
  "serde",

+ 1 - 1
node/Cargo.toml

@@ -3,7 +3,7 @@ authors = ['Joystream']
 build = 'build.rs'
 edition = '2018'
 name = 'joystream-node'
-version = '2.5.0'
+version = '2.5.1'
 default-run = "joystream-node"
 
 [[bin]]

+ 1 - 1
runtime-modules/working-group/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = 'substrate-working-group-module'
-version = '1.0.1'
+version = '1.0.2'
 authors = ['Joystream contributors']
 edition = '2018'
 

+ 32 - 0
runtime-modules/working-group/src/errors.rs

@@ -265,6 +265,38 @@ decl_error! {
         /// Invalid OpeningPolicyCommitment parameter:
         /// fill_opening_successful_applicant_application_stake_unstaking_period should be non-zero.
         FillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter:
+        /// exit_role_stake_unstaking_period should be non-zero.
+        ExitRoleStakeUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter:
+        /// exit_role_application_stake_unstaking_period should be non-zero.
+        ExitRoleApplicationStakeUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter:
+        /// terminate_role_stake_unstaking_period should be non-zero.
+        TerminateRoleStakeUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter:
+        /// terminate_application_stake_unstaking_period should be non-zero.
+        TerminateApplicationStakeUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter (role_staking_policy):
+        /// crowded_out_unstaking_period_length should be non-zero.
+        RoleStakingPolicyCrowdedOutUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter (role_staking_policy):
+        /// review_period_expired_unstaking_period_length should be non-zero.
+        RoleStakingPolicyReviewPeriodUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter (application_staking_policy):
+        /// crowded_out_unstaking_period_length should be non-zero.
+        ApplicationStakingPolicyCrowdedOutUnstakingPeriodIsZero,
+
+        /// Invalid OpeningPolicyCommitment parameter (application_staking_policy):
+        /// review_period_expired_unstaking_period_length should be non-zero.
+        ApplicationStakingPolicyReviewPeriodUnstakingPeriodIsZero,
     }
 }
 

+ 75 - 24
runtime-modules/working-group/src/lib.rs

@@ -993,35 +993,86 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
     fn ensure_opening_policy_commitment_is_valid(
         policy_commitment: &OpeningPolicyCommitment<T::BlockNumber, BalanceOf<T>>,
     ) -> Result<(), Error> {
-        // check fill_opening unstaking periods
-
-        if let Some(unstaking_period) =
-            policy_commitment.fill_opening_failed_applicant_application_stake_unstaking_period
-        {
-            ensure!(
-                unstaking_period != Zero::zero(),
-                Error::FillOpeningFailedApplicantApplicationStakeUnstakingPeriodIsZero
-            );
+        // Helper function. Ensures that unstaking period is None or non-zero.
+        fn check_unstaking_period<BlockNumber: PartialEq + Zero>(
+            unstaking_period: Option<BlockNumber>,
+            error: Error,
+        ) -> Result<(), Error> {
+            if let Some(unstaking_period) = unstaking_period {
+                ensure!(unstaking_period != Zero::zero(), error);
+            }
+            Ok(())
         }
 
-        if let Some(unstaking_period) =
-            policy_commitment.fill_opening_failed_applicant_role_stake_unstaking_period
-        {
-            ensure!(
-                unstaking_period != Zero::zero(),
-                Error::FillOpeningFailedApplicantRoleStakeUnstakingPeriodIsZero
-            );
-        }
+        // Helper function. Ensures that unstaking period is None or non-zero in the staking_policy.
+        fn check_staking_policy<Balance, BlockNumber: PartialEq + Zero>(
+            staking_policy: Option<hiring::StakingPolicy<Balance, BlockNumber>>,
+            crowded_out_unstaking_period_error: Error,
+            review_period_unstaking_period_error: Error,
+        ) -> Result<(), Error> {
+            if let Some(staking_policy) = staking_policy {
+                check_unstaking_period(
+                    staking_policy.crowded_out_unstaking_period_length,
+                    crowded_out_unstaking_period_error,
+                )?;
 
-        if let Some(unstaking_period) =
-            policy_commitment.fill_opening_successful_applicant_application_stake_unstaking_period
-        {
-            ensure!(
-                unstaking_period != Zero::zero(),
-                Error::FillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriodIsZero
-            );
+                check_unstaking_period(
+                    staking_policy.review_period_expired_unstaking_period_length,
+                    review_period_unstaking_period_error,
+                )?;
+            }
+
+            Ok(())
         }
 
+        // Check all fill_opening unstaking periods.
+        check_unstaking_period(
+            policy_commitment.fill_opening_failed_applicant_role_stake_unstaking_period,
+            Error::FillOpeningFailedApplicantRoleStakeUnstakingPeriodIsZero,
+        )?;
+
+        check_unstaking_period(
+            policy_commitment.fill_opening_failed_applicant_application_stake_unstaking_period,
+            Error::FillOpeningFailedApplicantApplicationStakeUnstakingPeriodIsZero,
+        )?;
+
+        check_unstaking_period(
+            policy_commitment.fill_opening_successful_applicant_application_stake_unstaking_period,
+            Error::FillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriodIsZero,
+        )?;
+
+        check_unstaking_period(
+            policy_commitment.exit_role_stake_unstaking_period,
+            Error::ExitRoleStakeUnstakingPeriodIsZero,
+        )?;
+
+        check_unstaking_period(
+            policy_commitment.exit_role_application_stake_unstaking_period,
+            Error::ExitRoleApplicationStakeUnstakingPeriodIsZero,
+        )?;
+
+        check_unstaking_period(
+            policy_commitment.terminate_role_stake_unstaking_period,
+            Error::TerminateRoleStakeUnstakingPeriodIsZero,
+        )?;
+
+        check_unstaking_period(
+            policy_commitment.terminate_application_stake_unstaking_period,
+            Error::TerminateApplicationStakeUnstakingPeriodIsZero,
+        )?;
+
+        check_staking_policy(
+            policy_commitment.role_staking_policy.clone(),
+            Error::RoleStakingPolicyCrowdedOutUnstakingPeriodIsZero,
+            Error::RoleStakingPolicyReviewPeriodUnstakingPeriodIsZero,
+        )?;
+
+        check_staking_policy(
+            policy_commitment.application_staking_policy.clone(),
+            Error::ApplicationStakingPolicyCrowdedOutUnstakingPeriodIsZero,
+            Error::ApplicationStakingPolicyReviewPeriodUnstakingPeriodIsZero,
+        )?;
+
         Ok(())
     }
 

+ 1 - 1
runtime/Cargo.toml

@@ -4,7 +4,7 @@ edition = '2018'
 name = 'joystream-node-runtime'
 # Follow convention: https://github.com/Joystream/substrate-runtime-joystream/issues/1
 # {Authoring}.{Spec}.{Impl} of the RuntimeVersion
-version = '6.19.0'
+version = '6.20.0'
 
 [features]
 default = ['std']

+ 1 - 1
runtime/src/lib.rs

@@ -161,7 +161,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
     spec_name: create_runtime_str!("joystream-node"),
     impl_name: create_runtime_str!("joystream-node"),
     authoring_version: 6,
-    spec_version: 19,
+    spec_version: 20,
     impl_version: 0,
     apis: RUNTIME_API_VERSIONS,
 };