|
@@ -63,9 +63,6 @@ pub trait Trait:
|
|
|
/// _Data directory_ event type.
|
|
|
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
|
|
|
|
|
- /// Provides random storage provider id.
|
|
|
- type StorageProviderHelper: StorageProviderHelper<Self>;
|
|
|
-
|
|
|
/// Active data object type validator.
|
|
|
type IsActiveDataObjectType: data_object_type_registry::IsActiveDataObjectType<Self>;
|
|
|
|
|
@@ -79,9 +76,6 @@ decl_error! {
|
|
|
/// Content with this ID not found.
|
|
|
CidNotFound,
|
|
|
|
|
|
- /// Only the liaison for the content may modify its status.
|
|
|
- LiaisonRequired,
|
|
|
-
|
|
|
/// Cannot create content for inactive or missing data object type.
|
|
|
DataObjectTypeMustBeActive,
|
|
|
|
|
@@ -112,9 +106,6 @@ decl_error! {
|
|
|
/// Provided owner should be equal o the data object owner under given content id
|
|
|
OwnersAreNotEqual,
|
|
|
|
|
|
- /// No storage provider available to service the request
|
|
|
- NoProviderAvailable,
|
|
|
-
|
|
|
/// New voucher limit being set is less than used.
|
|
|
VoucherLimitLessThanUsed,
|
|
|
|
|
@@ -123,7 +114,7 @@ decl_error! {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/// The decision of the storage provider when it acts as liaison.
|
|
|
+/// The status of the content which can be updated by a storage provider.
|
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
|
#[derive(Clone, Encode, Decode, PartialEq, Debug)]
|
|
|
pub enum LiaisonJudgement {
|
|
@@ -132,9 +123,6 @@ pub enum LiaisonJudgement {
|
|
|
|
|
|
/// Content accepted.
|
|
|
Accepted,
|
|
|
-
|
|
|
- /// Content rejected.
|
|
|
- Rejected,
|
|
|
}
|
|
|
|
|
|
impl Default for LiaisonJudgement {
|
|
@@ -178,10 +166,10 @@ pub struct DataObjectInternal<
|
|
|
/// Content size in bytes.
|
|
|
pub size: u64,
|
|
|
|
|
|
- /// Storage provider id of the liaison.
|
|
|
- pub liaison: StorageProviderId,
|
|
|
+ /// Storage provider which first accepted the content.
|
|
|
+ pub liaison: Option<StorageProviderId>,
|
|
|
|
|
|
- /// Storage provider as liaison judgment.
|
|
|
+ /// The liaison judgment.
|
|
|
pub liaison_judgement: LiaisonJudgement,
|
|
|
|
|
|
/// IPFS content id.
|
|
@@ -425,7 +413,7 @@ decl_module! {
|
|
|
type Error = Error<T>;
|
|
|
|
|
|
/// Adds the content to the system. The created DataObject
|
|
|
- /// awaits liaison to accept or reject it.
|
|
|
+ /// awaits liaison to accept it.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn add_content(
|
|
|
origin,
|
|
@@ -443,8 +431,6 @@ decl_module! {
|
|
|
// Ensure owner and global voucher constraints satisfied.
|
|
|
let (new_owner_voucher, new_global_voucher) = Self::ensure_voucher_constraints_satisfied(&owner, &content)?;
|
|
|
|
|
|
- let liaison = T::StorageProviderHelper::get_random_storage_provider()?;
|
|
|
-
|
|
|
//
|
|
|
// == MUTATION SAFE ==
|
|
|
//
|
|
@@ -455,7 +441,7 @@ decl_module! {
|
|
|
// Update global voucher
|
|
|
<GlobalVoucher>::put(new_global_voucher);
|
|
|
|
|
|
- Self::upload_content(liaison, content.clone(), owner.clone());
|
|
|
+ Self::upload_content(content.clone(), owner.clone());
|
|
|
|
|
|
Self::deposit_event(RawEvent::ContentAdded(content, owner));
|
|
|
}
|
|
@@ -652,7 +638,8 @@ decl_module! {
|
|
|
}
|
|
|
|
|
|
/// Storage provider accepts a content. Requires signed storage provider account and its id.
|
|
|
- /// The LiaisonJudgement can be updated, but only by the liaison.
|
|
|
+ /// The LiaisonJudgement can only be updated once from Pending to Accepted.
|
|
|
+ /// Subsequent calls are a no-op.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub(crate) fn accept_content(
|
|
|
origin,
|
|
@@ -661,27 +648,19 @@ decl_module! {
|
|
|
) {
|
|
|
<StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
|
|
|
|
|
|
- // == MUTATION SAFE ==
|
|
|
-
|
|
|
- Self::update_content_judgement(&storage_provider_id, content_id, LiaisonJudgement::Accepted)?;
|
|
|
-
|
|
|
- Self::deposit_event(RawEvent::ContentAccepted(content_id, storage_provider_id));
|
|
|
- }
|
|
|
-
|
|
|
- /// Storage provider rejects a content. Requires signed storage provider account and its id.
|
|
|
- /// The LiaisonJudgement can be updated, but only by the liaison.
|
|
|
- #[weight = 10_000_000] // TODO: adjust weight
|
|
|
- pub(crate) fn reject_content(
|
|
|
- origin,
|
|
|
- storage_provider_id: StorageProviderId<T>,
|
|
|
- content_id: T::ContentId
|
|
|
- ) {
|
|
|
- <StorageWorkingGroup<T>>::ensure_worker_signed(origin, &storage_provider_id)?;
|
|
|
+ let mut data = Self::get_data_object(&content_id)?;
|
|
|
|
|
|
// == MUTATION SAFE ==
|
|
|
|
|
|
- Self::update_content_judgement(&storage_provider_id, content_id, LiaisonJudgement::Rejected)?;
|
|
|
- Self::deposit_event(RawEvent::ContentRejected(content_id, storage_provider_id));
|
|
|
+ if data.liaison_judgement == LiaisonJudgement::Pending {
|
|
|
+ // Set the liaison which is updating the judgement
|
|
|
+ data.liaison = Some(storage_provider_id);
|
|
|
+
|
|
|
+ // Set the judgement
|
|
|
+ data.liaison_judgement = LiaisonJudgement::Accepted;
|
|
|
+ <DataByContentId<T>>::insert(content_id, data);
|
|
|
+ Self::deposit_event(RawEvent::ContentAccepted(content_id, storage_provider_id));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// Locks / unlocks content uploading
|
|
@@ -806,9 +785,8 @@ impl<T: Trait> Module<T> {
|
|
|
Ok((new_owner_voucher, new_global_voucher))
|
|
|
}
|
|
|
|
|
|
- // Complete content upload, update vouchers
|
|
|
+ // Complete content upload
|
|
|
fn upload_content(
|
|
|
- liaison: StorageProviderId<T>,
|
|
|
multi_content: Vec<ContentParameters<T::ContentId, DataObjectTypeId<T>>>,
|
|
|
owner: ObjectOwner<T>,
|
|
|
) {
|
|
@@ -818,7 +796,7 @@ impl<T: Trait> Module<T> {
|
|
|
size: content.size,
|
|
|
added_at: common::current_block_time::<T>(),
|
|
|
owner: owner.clone(),
|
|
|
- liaison,
|
|
|
+ liaison: None,
|
|
|
liaison_judgement: LiaisonJudgement::Pending,
|
|
|
ipfs_content_id: content.ipfs_content_id,
|
|
|
};
|
|
@@ -843,31 +821,6 @@ impl<T: Trait> Module<T> {
|
|
|
}
|
|
|
Ok(())
|
|
|
}
|
|
|
-
|
|
|
- fn update_content_judgement(
|
|
|
- storage_provider_id: &StorageProviderId<T>,
|
|
|
- content_id: T::ContentId,
|
|
|
- judgement: LiaisonJudgement,
|
|
|
- ) -> DispatchResult {
|
|
|
- let mut data = Self::get_data_object(&content_id)?;
|
|
|
-
|
|
|
- // Make sure the liaison matches
|
|
|
- ensure!(
|
|
|
- data.liaison == *storage_provider_id,
|
|
|
- Error::<T>::LiaisonRequired
|
|
|
- );
|
|
|
-
|
|
|
- data.liaison_judgement = judgement;
|
|
|
- <DataByContentId<T>>::insert(content_id, data);
|
|
|
-
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/// Provides random storage provider id. We use it when assign the content to the storage provider.
|
|
|
-pub trait StorageProviderHelper<T: Trait> {
|
|
|
- /// Provides random storage provider id.
|
|
|
- fn get_random_storage_provider() -> Result<StorageProviderId<T>, Error<T>>;
|
|
|
}
|
|
|
|
|
|
/// Content access helper.
|
|
@@ -906,8 +859,6 @@ impl<T: Trait> common::storage::StorageSystem<T> for Module<T> {
|
|
|
let (new_owner_voucher, new_global_voucher) =
|
|
|
Self::ensure_voucher_constraints_satisfied(&owner, &content)?;
|
|
|
|
|
|
- let liaison = T::StorageProviderHelper::get_random_storage_provider()?;
|
|
|
-
|
|
|
//
|
|
|
// == MUTATION SAFE ==
|
|
|
//
|
|
@@ -918,7 +869,7 @@ impl<T: Trait> common::storage::StorageSystem<T> for Module<T> {
|
|
|
// Update global voucher
|
|
|
<GlobalVoucher>::put(new_global_voucher);
|
|
|
|
|
|
- Self::upload_content(liaison, content, owner);
|
|
|
+ Self::upload_content(content, owner);
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
@@ -958,8 +909,6 @@ impl<T: Trait> common::storage::StorageSystem<T> for Module<T> {
|
|
|
) -> DispatchResult {
|
|
|
Self::ensure_uploading_is_not_blocked()?;
|
|
|
|
|
|
- T::StorageProviderHelper::get_random_storage_provider()?;
|
|
|
-
|
|
|
let _ = Self::ensure_voucher_constraints_satisfied(&owner, &content)?;
|
|
|
|
|
|
Self::ensure_content_is_valid(&content)
|