Browse Source

storage: introduce default_storage_size_constraint

iorveth 4 years ago
parent
commit
9f1d0ce17a

+ 6 - 4
node/src/chain_spec/mod.rs

@@ -225,6 +225,8 @@ pub fn testnet_genesis(
 
     let default_text_constraint = node_runtime::working_group::default_text_constraint();
 
+    let default_storage_size_constraint = node_runtime::working_group::default_storage_size_constraint();
+
     GenesisConfig {
         system: Some(SystemConfig {
             code: WASM_BINARY.to_vec(),
@@ -311,7 +313,7 @@ pub fn testnet_genesis(
             opening_human_readable_text_constraint: default_text_constraint,
             worker_application_human_readable_text_constraint: default_text_constraint,
             worker_exit_rationale_text_constraint: default_text_constraint,
-            worker_storage_text_constraint: default_text_constraint,
+            worker_storage_size_constraint: default_storage_size_constraint,
         }),
         working_group_Instance3: Some(ContentDirectoryWorkingGroupConfig {
             phantom: Default::default(),
@@ -319,7 +321,7 @@ pub fn testnet_genesis(
             opening_human_readable_text_constraint: default_text_constraint,
             worker_application_human_readable_text_constraint: default_text_constraint,
             worker_exit_rationale_text_constraint: default_text_constraint,
-            worker_storage_text_constraint: default_text_constraint,
+            worker_storage_size_constraint: default_storage_size_constraint,
         }),
         working_group_Instance4: Some(BuilderWorkingGroupConfig {
             phantom: Default::default(),
@@ -327,7 +329,7 @@ pub fn testnet_genesis(
             opening_human_readable_text_constraint: default_text_constraint,
             worker_application_human_readable_text_constraint: default_text_constraint,
             worker_exit_rationale_text_constraint: default_text_constraint,
-            worker_storage_text_constraint: default_text_constraint,
+            worker_storage_size_constraint: default_storage_size_constraint,
         }),
         working_group_Instance5: Some(GatewayWorkingGroupConfig {
             phantom: Default::default(),
@@ -335,7 +337,7 @@ pub fn testnet_genesis(
             opening_human_readable_text_constraint: default_text_constraint,
             worker_application_human_readable_text_constraint: default_text_constraint,
             worker_exit_rationale_text_constraint: default_text_constraint,
-            worker_storage_text_constraint: default_text_constraint,
+            worker_storage_size_constraint: default_storage_size_constraint,
         }),
         content: Some({
             ContentConfig {

+ 1 - 0
runtime-modules/service-discovery/src/mock.rs

@@ -167,6 +167,7 @@ pub(crate) fn hire_storage_provider() -> (u64, u64) {
         role_account_id,
         reward_relationship: None,
         role_stake_profile: None,
+        storage: Vec::new(),
     };
 
     <working_group::WorkerById<Test, StorageWorkingGroupInstance>>::insert(

+ 12 - 7
runtime-modules/working-group/src/lib.rs

@@ -328,7 +328,7 @@ decl_storage! {
         pub WorkerExitRationaleText get(fn worker_exit_rationale_text) : InputValidationLengthConstraint;
 
         /// Worker storage text length limits.
-        pub WorkerStorageText get(fn worker_storage_text) : InputValidationLengthConstraint;
+        pub WorkerStorageText get(fn worker_storage_size) : InputValidationLengthConstraint;
 
         /// Map member id by hiring application id.
         /// Required by StakingEventsHandler callback call to refund the balance on unstaking.
@@ -341,13 +341,13 @@ decl_storage! {
         config(opening_human_readable_text_constraint): InputValidationLengthConstraint;
         config(worker_application_human_readable_text_constraint): InputValidationLengthConstraint;
         config(worker_exit_rationale_text_constraint): InputValidationLengthConstraint;
-        config(worker_storage_text_constraint): InputValidationLengthConstraint;
+        config(worker_storage_size_constraint): InputValidationLengthConstraint;
         build(|config: &GenesisConfig<T, I>| {
             Module::<T, I>::initialize_working_group(
                 config.opening_human_readable_text_constraint,
                 config.worker_application_human_readable_text_constraint,
                 config.worker_exit_rationale_text_constraint,
-                config.worker_storage_text_constraint,
+                config.worker_storage_size_constraint,
                 config.working_group_mint_capacity)
         });
     }
@@ -1367,7 +1367,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
     }
 
     fn ensure_worker_role_storage_text_is_valid(text: &[u8]) -> DispatchResult {
-        Self::worker_storage_text()
+        Self::worker_storage_size()
             .ensure_valid(
                 text.len(),
                 Error::<T, I>::WorkerStorageTextTooShort.into(),
@@ -1379,7 +1379,12 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
 
 /// Creates default text constraint.
 pub fn default_text_constraint() -> InputValidationLengthConstraint {
-    InputValidationLengthConstraint::new(1, 2048)
+    InputValidationLengthConstraint::new(1, 1024)
+}
+
+/// Creates default storage size constraint.
+pub fn default_storage_size_constraint() -> InputValidationLengthConstraint {
+    InputValidationLengthConstraint::new(0, 2048)
 }
 
 impl<T: Trait<I>, I: Instance> Module<T, I> {
@@ -1534,7 +1539,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         opening_human_readable_text_constraint: InputValidationLengthConstraint,
         worker_application_human_readable_text_constraint: InputValidationLengthConstraint,
         worker_exit_rationale_text_constraint: InputValidationLengthConstraint,
-        worker_storage_text_constraint: InputValidationLengthConstraint,
+        worker_storage_size_constraint: InputValidationLengthConstraint,
         working_group_mint_capacity: minting::BalanceOf<T>,
     ) {
         // Create a mint.
@@ -1552,7 +1557,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
             worker_application_human_readable_text_constraint,
         );
         <WorkerExitRationaleText<I>>::put(worker_exit_rationale_text_constraint);
-        <WorkerStorageText<I>>::put(worker_storage_text_constraint);
+        <WorkerStorageText<I>>::put(worker_storage_size_constraint);
     }
 
     // Set worker id as a leader id.

+ 1 - 1
runtime-modules/working-group/src/tests/mock.rs

@@ -169,7 +169,7 @@ pub fn build_test_externalities() -> sp_io::TestExternalities {
             WORKING_GROUP_CONSTRAINT_MIN,
             WORKING_GROUP_CONSTRAINT_DIFF,
         ),
-        worker_storage_text_constraint: InputValidationLengthConstraint::new(
+        worker_storage_size_constraint: InputValidationLengthConstraint::new(
             WORKING_GROUP_CONSTRAINT_MIN,
             WORKING_GROUP_CONSTRAINT_DIFF,
         ),

+ 6 - 2
runtime/src/runtime_api.rs

@@ -71,13 +71,17 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
         content::Module::<Runtime>::on_runtime_upgrade();
 
         let default_text_constraint = crate::working_group::default_text_constraint();
+
+        let default_storage_size_constraint =
+            crate::working_group::default_storage_size_constraint();
+
         let default_content_working_group_mint_capacity = 0;
 
         BuilderWorkingGroup::<Runtime>::initialize_working_group(
             default_text_constraint,
             default_text_constraint,
             default_text_constraint,
-            default_text_constraint,
+            default_storage_size_constraint,
             default_content_working_group_mint_capacity,
         );
 
@@ -85,7 +89,7 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
             default_text_constraint,
             default_text_constraint,
             default_text_constraint,
-            default_text_constraint,
+            default_storage_size_constraint,
             default_content_working_group_mint_capacity,
         );