|
@@ -151,6 +151,7 @@ use sp_std::vec::Vec;
|
|
|
|
|
|
use common::constraints::BoundedValueConstraint;
|
|
|
use common::working_group::WorkingGroup;
|
|
|
+use common::working_group::WorkingGroupAuthenticator;
|
|
|
|
|
|
use random_buckets::DistributionBucketPicker;
|
|
|
use random_buckets::StorageBucketPicker;
|
|
@@ -350,35 +351,12 @@ pub trait Trait: frame_system::Trait + balances::Trait + common::MembershipTypes
|
|
|
/// Max data object size in bytes.
|
|
|
type MaxDataObjectSize: Get<u64>;
|
|
|
|
|
|
- /// Demand the storage working group leader authorization.
|
|
|
- /// TODO: Refactor after merging with the Olympia release.
|
|
|
- fn ensure_storage_working_group_leader_origin(origin: Self::Origin) -> DispatchResult;
|
|
|
+ /// Storage working group pallet integration.
|
|
|
+ type StorageWorkingGroup: common::working_group::WorkingGroupAuthenticator<Self>
|
|
|
+ + common::working_group::WorkingGroupBudgetHandler<Self>;
|
|
|
|
|
|
- /// Validate origin for the storage worker.
|
|
|
- /// TODO: Refactor after merging with the Olympia release.
|
|
|
- fn ensure_storage_worker_origin(
|
|
|
- origin: Self::Origin,
|
|
|
- worker_id: WorkerId<Self>,
|
|
|
- ) -> DispatchResult;
|
|
|
-
|
|
|
- /// Validate storage worker existence.
|
|
|
- /// TODO: Refactor after merging with the Olympia release.
|
|
|
- fn ensure_storage_worker_exists(worker_id: &WorkerId<Self>) -> DispatchResult;
|
|
|
-
|
|
|
- /// Demand the distribution group leader authorization.
|
|
|
- /// TODO: Refactor after merging with the Olympia release.
|
|
|
- fn ensure_distribution_working_group_leader_origin(origin: Self::Origin) -> DispatchResult;
|
|
|
-
|
|
|
- /// Validate origin for the distribution worker.
|
|
|
- /// TODO: Refactor after merging with the Olympia release.
|
|
|
- fn ensure_distribution_worker_origin(
|
|
|
- origin: Self::Origin,
|
|
|
- worker_id: WorkerId<Self>,
|
|
|
- ) -> DispatchResult;
|
|
|
-
|
|
|
- /// Validate distribution worker existence.
|
|
|
- /// TODO: Refactor after merging with the Olympia release.
|
|
|
- fn ensure_distribution_worker_exists(worker_id: &WorkerId<Self>) -> DispatchResult;
|
|
|
+ type DistributionWorkingGroup: common::working_group::WorkingGroupAuthenticator<Self>
|
|
|
+ + common::working_group::WorkingGroupBudgetHandler<Self>;
|
|
|
}
|
|
|
|
|
|
/// Operations with local pallet account.
|
|
@@ -1311,6 +1289,30 @@ decl_event! {
|
|
|
DistributionBucketFamilyId,
|
|
|
Vec<u8>
|
|
|
),
|
|
|
+
|
|
|
+ /// Emits on Storage Operator making a remark
|
|
|
+ /// Params
|
|
|
+ /// - operator's worker id
|
|
|
+ /// - storage bucket id
|
|
|
+ /// - remark message
|
|
|
+ StorageOperatorRemarked(
|
|
|
+ WorkerId,
|
|
|
+ StorageBucketId,
|
|
|
+ Vec<u8>,
|
|
|
+ ),
|
|
|
+
|
|
|
+ /// Emits on Distribution Operator making a remark
|
|
|
+ /// Params
|
|
|
+ /// - operator's worker id
|
|
|
+ /// - distribution bucket id
|
|
|
+ /// - remark message
|
|
|
+ DistributionOperatorRemarked(
|
|
|
+ WorkerId,
|
|
|
+ DistributionBucketId,
|
|
|
+ Vec<u8>,
|
|
|
+ ),
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1544,7 +1546,7 @@ decl_module! {
|
|
|
origin,
|
|
|
storage_bucket_id: T::StorageBucketId,
|
|
|
){
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -1570,7 +1572,7 @@ decl_module! {
|
|
|
/// Updates global uploading flag.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn update_uploading_blocked_status(origin, new_status: bool) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
//
|
|
|
// == MUTATION SAFE ==
|
|
@@ -1584,7 +1586,7 @@ decl_module! {
|
|
|
/// Updates size-based pricing of new objects uploaded.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn update_data_size_fee(origin, new_data_size_fee: BalanceOf<T>) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
//
|
|
|
// == MUTATION SAFE ==
|
|
@@ -1598,7 +1600,7 @@ decl_module! {
|
|
|
/// Updates "Storage buckets per bag" number limit.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn update_storage_buckets_per_bag_limit(origin, new_limit: u64) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
T::StorageBucketsPerBagValueConstraint::get().ensure_valid(
|
|
|
new_limit,
|
|
@@ -1622,7 +1624,7 @@ decl_module! {
|
|
|
new_objects_size: u64,
|
|
|
new_objects_number: u64,
|
|
|
) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
//
|
|
|
// == MUTATION SAFE ==
|
|
@@ -1643,7 +1645,7 @@ decl_module! {
|
|
|
dynamic_bag_type: DynamicBagType,
|
|
|
number_of_storage_buckets: u64,
|
|
|
) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
//
|
|
|
// == MUTATION SAFE ==
|
|
@@ -1670,7 +1672,7 @@ decl_module! {
|
|
|
remove_hashes: BTreeSet<Cid>,
|
|
|
add_hashes: BTreeSet<Cid>
|
|
|
){
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
// Get only hashes that exist in the blacklist.
|
|
|
let verified_remove_hashes = Self::get_existing_hashes(&remove_hashes);
|
|
@@ -1713,7 +1715,7 @@ decl_module! {
|
|
|
size_limit: u64,
|
|
|
objects_limit: u64,
|
|
|
) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let voucher = Voucher {
|
|
|
size_limit,
|
|
@@ -1763,7 +1765,7 @@ decl_module! {
|
|
|
add_buckets: BTreeSet<T::StorageBucketId>,
|
|
|
remove_buckets: BTreeSet<T::StorageBucketId>,
|
|
|
) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::ensure_bag_exists(&bag_id)?;
|
|
|
|
|
@@ -1808,7 +1810,7 @@ decl_module! {
|
|
|
/// Cancel pending storage bucket invite. An invitation must be pending.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn cancel_storage_bucket_operator_invite(origin, storage_bucket_id: T::StorageBucketId){
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -1834,7 +1836,7 @@ decl_module! {
|
|
|
storage_bucket_id: T::StorageBucketId,
|
|
|
operator_id: WorkerId<T>,
|
|
|
){
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -1862,7 +1864,7 @@ decl_module! {
|
|
|
origin,
|
|
|
storage_bucket_id: T::StorageBucketId,
|
|
|
){
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -1889,7 +1891,7 @@ decl_module! {
|
|
|
storage_bucket_id: T::StorageBucketId,
|
|
|
accepting_new_bags: bool
|
|
|
) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -1914,7 +1916,7 @@ decl_module! {
|
|
|
new_objects_size_limit: u64,
|
|
|
new_objects_number_limit: u64,
|
|
|
) {
|
|
|
- T::ensure_storage_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -1961,7 +1963,7 @@ decl_module! {
|
|
|
storage_bucket_id: T::StorageBucketId,
|
|
|
transactor_account_id: T::AccountId,
|
|
|
) {
|
|
|
- T::ensure_storage_worker_origin(origin, worker_id)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_worker_origin(origin, &worker_id)?;
|
|
|
|
|
|
let bucket = Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -1996,7 +1998,7 @@ decl_module! {
|
|
|
storage_bucket_id: T::StorageBucketId,
|
|
|
metadata: Vec<u8>
|
|
|
) {
|
|
|
- T::ensure_storage_worker_origin(origin, worker_id)?;
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_worker_origin(origin, &worker_id)?;
|
|
|
|
|
|
let bucket = Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
|
|
@@ -2060,7 +2062,7 @@ decl_module! {
|
|
|
/// Create a distribution bucket family.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn create_distribution_bucket_family(origin) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
ensure!(
|
|
|
Self::distribution_bucket_family_number() <
|
|
@@ -2088,7 +2090,7 @@ decl_module! {
|
|
|
/// Deletes a distribution bucket family.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn delete_distribution_bucket_family(origin, family_id: T::DistributionBucketFamilyId) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::ensure_distribution_bucket_family_exists(&family_id)?;
|
|
|
|
|
@@ -2122,7 +2124,7 @@ decl_module! {
|
|
|
family_id: T::DistributionBucketFamilyId,
|
|
|
accepting_new_bags: bool,
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let family = Self::ensure_distribution_bucket_family_exists(&family_id)?;
|
|
|
|
|
@@ -2159,7 +2161,7 @@ decl_module! {
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
accepting_new_bags: bool
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2186,7 +2188,7 @@ decl_module! {
|
|
|
origin,
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
){
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2219,7 +2221,7 @@ decl_module! {
|
|
|
add_buckets_indices: BTreeSet<T::DistributionBucketIndex>,
|
|
|
remove_buckets_indices: BTreeSet<T::DistributionBucketIndex>,
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::validate_update_distribution_buckets_for_bag_params(
|
|
|
&bag_id,
|
|
@@ -2264,7 +2266,7 @@ decl_module! {
|
|
|
/// Updates "Distribution buckets per bag" number limit.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn update_distribution_buckets_per_bag_limit(origin, new_limit: u64) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
T::DistributionBucketsPerBagValueConstraint::get().ensure_valid(
|
|
|
new_limit,
|
|
@@ -2288,7 +2290,7 @@ decl_module! {
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
distributing: bool
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2316,7 +2318,7 @@ decl_module! {
|
|
|
dynamic_bag_type: DynamicBagType,
|
|
|
families: BTreeMap<T::DistributionBucketFamilyId, u32>
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::validate_update_families_in_dynamic_bag_creation_policy_params(&families)?;
|
|
|
|
|
@@ -2345,7 +2347,7 @@ decl_module! {
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
operator_worker_id: WorkerId<T>
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2375,7 +2377,7 @@ decl_module! {
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
operator_worker_id: WorkerId<T>
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2411,7 +2413,7 @@ decl_module! {
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
operator_worker_id: WorkerId<T>,
|
|
|
){
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
let bucket = Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2445,7 +2447,7 @@ decl_module! {
|
|
|
family_id: T::DistributionBucketFamilyId,
|
|
|
metadata: Vec<u8>,
|
|
|
) {
|
|
|
- T::ensure_distribution_working_group_leader_origin(origin)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_leader_origin(origin)?;
|
|
|
|
|
|
Self::ensure_distribution_bucket_family_exists(&family_id)?;
|
|
|
|
|
@@ -2471,7 +2473,7 @@ decl_module! {
|
|
|
worker_id: WorkerId<T>,
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
) {
|
|
|
- T::ensure_distribution_worker_origin(origin, worker_id)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_worker_origin(origin, &worker_id)?;
|
|
|
|
|
|
let bucket = Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2506,7 +2508,7 @@ decl_module! {
|
|
|
bucket_id: DistributionBucketId<T>,
|
|
|
metadata: Vec<u8>,
|
|
|
) {
|
|
|
- T::ensure_distribution_worker_origin(origin, worker_id)?;
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_worker_origin(origin, &worker_id)?;
|
|
|
|
|
|
let bucket = Self::ensure_distribution_bucket_exists(&bucket_id)?;
|
|
|
|
|
@@ -2545,6 +2547,48 @@ decl_module! {
|
|
|
|
|
|
Self::create_dynamic_bag(bag_id, deletion_prize)?;
|
|
|
}
|
|
|
+
|
|
|
+ /// Create a dynamic bag. Development mode.
|
|
|
+ #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ pub fn storage_operator_remark(
|
|
|
+ origin,
|
|
|
+ worker_id: WorkerId<T>,
|
|
|
+ storage_bucket_id: T::StorageBucketId,
|
|
|
+ msg: Vec<u8>,
|
|
|
+ ) {
|
|
|
+ <T as Trait>::StorageWorkingGroup::ensure_worker_origin(origin, &worker_id)?;
|
|
|
+ let bucket = Self::ensure_storage_bucket_exists(&storage_bucket_id)?;
|
|
|
+ Self::ensure_bucket_invitation_accepted(&bucket, worker_id)?;
|
|
|
+
|
|
|
+ //
|
|
|
+ // == MUTATION SAFE ==
|
|
|
+ //
|
|
|
+
|
|
|
+ Self::deposit_event(RawEvent::StorageOperatorRemarked(worker_id, storage_bucket_id, msg));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Create a dynamic bag. Development mode.
|
|
|
+ #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ pub fn distribution_operator_remark(
|
|
|
+ origin,
|
|
|
+ worker_id: WorkerId<T>,
|
|
|
+ distribution_bucket_id: DistributionBucketId<T>,
|
|
|
+ msg: Vec<u8>,
|
|
|
+ ) {
|
|
|
+ <T as Trait>::DistributionWorkingGroup::ensure_worker_origin(origin, &worker_id)?;
|
|
|
+ let bucket = Self::ensure_distribution_bucket_exists(&distribution_bucket_id)?;
|
|
|
+ ensure!(
|
|
|
+ bucket.operators.contains(&worker_id),
|
|
|
+ Error::<T>::MustBeDistributionProviderOperatorForBucket
|
|
|
+ );
|
|
|
+
|
|
|
+ //
|
|
|
+ // == MUTATION SAFE ==
|
|
|
+ //
|
|
|
+
|
|
|
+ Self::deposit_event(RawEvent::DistributionOperatorRemarked(worker_id, distribution_bucket_id, msg));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -3631,7 +3675,7 @@ impl<T: Trait> Module<T> {
|
|
|
// Verifies storage operator existence.
|
|
|
fn ensure_storage_provider_operator_exists(operator_id: &WorkerId<T>) -> DispatchResult {
|
|
|
ensure!(
|
|
|
- T::ensure_storage_worker_exists(operator_id).is_ok(),
|
|
|
+ <T as Trait>::StorageWorkingGroup::worker_exists(&operator_id),
|
|
|
Error::<T>::StorageProviderOperatorDoesntExist
|
|
|
);
|
|
|
|
|
@@ -3828,7 +3872,7 @@ impl<T: Trait> Module<T> {
|
|
|
worker_id: &WorkerId<T>,
|
|
|
) -> DispatchResult {
|
|
|
ensure!(
|
|
|
- T::ensure_distribution_worker_exists(worker_id).is_ok(),
|
|
|
+ <T as Trait>::DistributionWorkingGroup::worker_exists(worker_id),
|
|
|
Error::<T>::DistributionProviderOperatorDoesntExist
|
|
|
);
|
|
|
|