Browse Source

init worker storage size limit for existing groups on runtime upgrade

Mokhtar Naamani 3 years ago
parent
commit
ff569b37dc
6 changed files with 33 additions and 8 deletions
  1. 4 2
      Cargo.lock
  2. 1 1
      node/Cargo.toml
  3. 6 1
      runtime-modules/working-group/src/lib.rs
  4. 1 1
      runtime/Cargo.toml
  5. 1 1
      runtime/src/lib.rs
  6. 20 2
      runtime/src/runtime_api.rs

+ 4 - 2
Cargo.lock

@@ -1,5 +1,7 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
+version = 3
+
 [[package]]
 name = "Inflector"
 version = "0.11.4"
@@ -2330,7 +2332,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node"
-version = "5.3.0"
+version = "5.4.0"
 dependencies = [
  "frame-benchmarking",
  "frame-benchmarking-cli",
@@ -2391,7 +2393,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node-runtime"
-version = "9.5.0"
+version = "9.6.0"
 dependencies = [
  "frame-benchmarking",
  "frame-executive",

+ 1 - 1
node/Cargo.toml

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

+ 6 - 1
runtime-modules/working-group/src/lib.rs

@@ -337,7 +337,7 @@ decl_storage! {
         pub WorkerExitRationaleText get(fn worker_exit_rationale_text) : InputValidationLengthConstraint;
 
         /// Worker storage size upper bound.
-        pub WorkerStorageSize get(fn worker_storage_size) : u16;
+        pub WorkerStorageSize get(fn worker_storage_size) : u16 = default_storage_size_constraint();
 
         /// Map member id by hiring application id.
         /// Required by StakingEventsHandler callback call to refund the balance on unstaking.
@@ -1566,6 +1566,11 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         <WorkerStorageSize<I>>::put(worker_storage_size_constraint);
     }
 
+    /// Set storage size constraint
+    pub fn set_worker_storage_size_constraint(worker_storage_size_constraint: u16) {
+        <WorkerStorageSize<I>>::put(worker_storage_size_constraint);
+    }
+
     // Set worker id as a leader id.
     pub(crate) fn set_lead(worker_id: WorkerId<T>) {
         // Update current lead

+ 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 = '9.5.0'
+version = '9.6.0'
 
 [dependencies]
 # Third-party dependencies

+ 1 - 1
runtime/src/lib.rs

@@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
     spec_name: create_runtime_str!("joystream-node"),
     impl_name: create_runtime_str!("joystream-node"),
     authoring_version: 9,
-    spec_version: 5,
+    spec_version: 6,
     impl_version: 0,
     apis: crate::runtime_api::EXPORTED_RUNTIME_API_VERSIONS,
     transaction_version: 1,

+ 20 - 2
runtime/src/runtime_api.rs

@@ -10,7 +10,10 @@ use sp_runtime::traits::{BlakeTwo256, Block as BlockT, NumberFor};
 use sp_runtime::{generic, ApplyExtrinsicResult};
 use sp_std::vec::Vec;
 
-use crate::{DataDirectory, GatewayWorkingGroupInstance, OperationsWorkingGroupInstance};
+use crate::{
+    ContentDirectoryWorkingGroupInstance, DataDirectory, GatewayWorkingGroupInstance,
+    OperationsWorkingGroupInstance, StorageWorkingGroupInstance,
+};
 
 use crate::constants::PRIMARY_PROBABILITY;
 
@@ -67,6 +70,13 @@ pub(crate) type OperationsWorkingGroup<T> =
 // Alias for the gateway working group
 pub(crate) type GatewayWorkingGroup<T> = working_group::Module<T, GatewayWorkingGroupInstance>;
 
+// Alias for the storage working group
+pub(crate) type StorageWorkingGroup<T> = working_group::Module<T, StorageWorkingGroupInstance>;
+
+// Alias for the content working group
+pub(crate) type ContentDirectoryWorkingGroup<T> =
+    working_group::Module<T, ContentDirectoryWorkingGroupInstance>;
+
 /// Custom runtime upgrade handler.
 pub struct CustomOnRuntimeUpgrade;
 impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
@@ -80,6 +90,7 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
 
         let default_content_working_group_mint_capacity = 0;
 
+        // Initialize new groups
         OperationsWorkingGroup::<Runtime>::initialize_working_group(
             default_text_constraint,
             default_text_constraint,
@@ -105,7 +116,14 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
             data_directory::DEFAULT_UPLOADING_BLOCKED_STATUS,
         );
 
-        // TODO: storage / data_directory migration or clear all data objects
+        // Initialize existing groups
+        StorageWorkingGroup::<Runtime>::set_worker_storage_size_constraint(
+            default_storage_size_constraint,
+        );
+
+        ContentDirectoryWorkingGroup::<Runtime>::set_worker_storage_size_constraint(
+            default_storage_size_constraint,
+        );
 
         10_000_000 // TODO: adjust weight
     }