Parcourir la source

Introduce data directory UploadingBlocked bool flag

iorveth il y a 4 ans
Parent
commit
f5d21cd319

+ 4 - 0
node/src/chain_spec/content_config.rs

@@ -71,6 +71,8 @@ struct EncodedContentData {
     quota_objects_limit_upper_bound: String,
     /// hex encoded GlobalQuota
     global_quota: String,
+    /// hex encoded UploadingBlocked flag
+    uploading_blocked: String
 }
 
 fn parse_content_data(data_file: &Path) -> EncodedContentData {
@@ -119,6 +121,7 @@ pub fn empty_data_directory_config() -> DataDirectoryConfig {
         quota_size_limit_upper_bound: 20000,
         quota_objects_limit_upper_bound: 200,
         global_quota: Quota::new(2000000, 2000),
+        uploading_blocked: false
     }
 }
 
@@ -147,5 +150,6 @@ pub fn data_directory_config_from_json(data_file: &Path) -> DataDirectoryConfig
         quota_size_limit_upper_bound: content.quota_size_limit_upper_bound,
         quota_objects_limit_upper_bound: content.quota_objects_limit_upper_bound,
         global_quota: content.global_quota,
+        uploading_blocked: content.uploading_blocked
     }
 }

+ 17 - 0
runtime-modules/storage/src/data_directory.rs

@@ -106,6 +106,9 @@ decl_error! {
 
         /// Contant uploading failed. Actor quota objects limit exceeded.
         GlobalQuotaObjectsLimitExceeded,
+
+        /// Content uploading blocked.
+        ContentUploadingBlocked,
     }
 }
 
@@ -260,6 +263,9 @@ decl_storage! {
 
         /// Global quota.
         pub GlobalQuota get(fn global_quota) config(): Quota;
+
+        /// If all new uploads blocked
+        pub UploadingBlocked get(fn uploading_blocked) config(): bool;
     }
 }
 
@@ -333,6 +339,8 @@ decl_module! {
                 ensure_root(origin)?;
             };
 
+            Self::ensure_uploading_is_not_blocked()?;
+
             Self::ensure_content_is_valid(&content)?;
 
             let owner_quota = Self::get_quota(&owner);
@@ -499,6 +507,15 @@ impl<T: Trait> Module<T> {
         }
     }
 
+    // Ensure content uploading is not blocked
+    fn ensure_uploading_is_not_blocked() -> DispatchResult {
+        ensure!(
+            !Self::uploading_blocked(),
+            Error::<T>::ContentUploadingBlocked
+        );
+        Ok(())
+    }
+
     // Ensure owner quota constraints satisfied, returns total object length and total size delta for this upload.
     fn ensure_owner_quota_constraints_satisfied(
         owner_quota: Quota,