From 883e559a931fd3e548d30024edbf569c6be8815d Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 8 Sep 2020 21:59:14 +0300 Subject: [PATCH 01/13] Add content directory dependency --- runtime-modules/content-directory/src/lib.rs | 7 ++++--- runtime/Cargo.toml | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime-modules/content-directory/src/lib.rs b/runtime-modules/content-directory/src/lib.rs index 8de950c573..47dc1ee71a 100755 --- a/runtime-modules/content-directory/src/lib.rs +++ b/runtime-modules/content-directory/src/lib.rs @@ -145,15 +145,16 @@ use frame_support::storage::IterableStorageMap; use frame_support::{ decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure, traits::Get, Parameter, }; +#[cfg(feature = "std")] +pub use serde::{Deserialize, Serialize}; use sp_arithmetic::traits::{BaseArithmetic, One, Zero}; use sp_runtime::traits::{MaybeSerializeDeserialize, Member}; +use sp_std::borrow::ToOwned; use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; +use sp_std::vec; use sp_std::vec::Vec; use system::ensure_signed; -#[cfg(feature = "std")] -pub use serde::{Deserialize, Serialize}; - pub use errors::Error; use core::debug_assert; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 4c68a0f426..da77c1a837 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -77,6 +77,7 @@ service-discovery = { package = 'pallet-service-discovery', default-features = f proposals-engine = { package = 'pallet-proposals-engine', default-features = false, path = '../runtime-modules/proposals/engine'} proposals-discussion = { package = 'pallet-proposals-discussion', default-features = false, path = '../runtime-modules/proposals/discussion'} proposals-codex = { package = 'pallet-proposals-codex', default-features = false, path = '../runtime-modules/proposals/codex'} +content-directory = { package = 'pallet-content-directory', default-features = false, path = '../runtime-modules/content-directory' } [dev-dependencies] sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'} @@ -152,6 +153,7 @@ std = [ 'proposals-engine/std', 'proposals-discussion/std', 'proposals-codex/std', + 'content-directory/std', ] runtime-benchmarks = [ "system/runtime-benchmarks", From ed03e80723bb87b826aa37eede7d3daf836f2359 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 8 Sep 2020 22:33:17 +0300 Subject: [PATCH 02/13] Cont dir initial runtime integration work --- Cargo.lock | 1 + runtime/src/lib.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7f748e8162..ba86651823 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2040,6 +2040,7 @@ dependencies = [ "pallet-balances", "pallet-collective", "pallet-common", + "pallet-content-directory", "pallet-content-working-group", "pallet-finality-tracker", "pallet-forum", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b8fc167ab5..a1b2246a7b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -62,6 +62,11 @@ pub use proposals_codex::ProposalsConfigParameters; pub use versioned_store; pub use working_group; +pub use content_directory; +pub use content_directory::{ + HashedTextMaxLength, InputValidationLengthConstraint, MaxNumber, TextMaxLength, VecMaxLength, +}; + /// This runtime version. pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("joystream-node"), @@ -372,6 +377,77 @@ impl versioned_store_permissions::Trait for Runtime { integration::versioned_store_permissions::ContentLeadOrSudoKeyCanCreateClasses; } +impl content_directory::ActorAuthenticator for Runtime { + type CuratorId = u64; + type MemberId = u64; + type CuratorGroupId = u64; + + fn is_lead() -> bool { + true + } + + fn is_curator(curator_id: &Self::CuratorId, account_id: &Self::AccountId) -> bool { + true + } + + fn is_member(member_id: &Self::MemberId, account_id: &Self::AccountId) -> bool { + true + } +} + +type EntityId = ::EntityId; + +parameter_types! { + pub const PropertyNameLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 49); + pub const PropertyDescriptionLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 500); + pub const ClassNameLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 49); + pub const ClassDescriptionLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 500); + + pub const MaxNumberOfClasses: MaxNumber = 100; + pub const MaxNumberOfMaintainersPerClass: MaxNumber = 10; + pub const MaxNumberOfSchemasPerClass: MaxNumber = 20; + pub const MaxNumberOfPropertiesPerSchema: MaxNumber = 40; + pub const MaxNumberOfEntitiesPerClass: MaxNumber = 400; + + pub const MaxNumberOfCuratorsPerGroup: MaxNumber = 50; + + pub const MaxNumberOfOperationsDuringAtomicBatching: MaxNumber = 500; + + pub const VecMaxLengthConstraint: VecMaxLength = 200; + pub const TextMaxLengthConstraint: TextMaxLength = 5000; + pub const HashedTextMaxLengthConstraint: HashedTextMaxLength = Some(25000); + + pub const IndividualEntitiesCreationLimit: EntityId = 50; +} + +impl content_directory::Trait for Runtime { + type Event = Event; + type Nonce = u64; + type ClassId = u64; + type EntityId = u64; + + type PropertyNameLengthConstraint = PropertyNameLengthConstraint; + type PropertyDescriptionLengthConstraint = PropertyDescriptionLengthConstraint; + type ClassNameLengthConstraint = ClassNameLengthConstraint; + type ClassDescriptionLengthConstraint = ClassDescriptionLengthConstraint; + + type MaxNumberOfClasses = MaxNumberOfClasses; + type MaxNumberOfMaintainersPerClass = MaxNumberOfMaintainersPerClass; + type MaxNumberOfSchemasPerClass = MaxNumberOfSchemasPerClass; + type MaxNumberOfPropertiesPerSchema = MaxNumberOfPropertiesPerSchema; + type MaxNumberOfEntitiesPerClass = MaxNumberOfEntitiesPerClass; + + type MaxNumberOfCuratorsPerGroup = MaxNumberOfCuratorsPerGroup; + + type MaxNumberOfOperationsDuringAtomicBatching = MaxNumberOfOperationsDuringAtomicBatching; + + type VecMaxLengthConstraint = VecMaxLengthConstraint; + type TextMaxLengthConstraint = TextMaxLengthConstraint; + type HashedTextMaxLengthConstraint = HashedTextMaxLengthConstraint; + + type IndividualEntitiesCreationLimit = IndividualEntitiesCreationLimit; +} + impl hiring::Trait for Runtime { type OpeningId = u64; type ApplicationId = u64; From af305a80b3aebcb22ec148d0b528659bb2d4d31b Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 10 Sep 2020 10:02:28 +0300 Subject: [PATCH 03/13] make MaxNumber type public --- runtime-modules/content-directory/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-modules/content-directory/src/lib.rs b/runtime-modules/content-directory/src/lib.rs index 47dc1ee71a..8ffee90395 100755 --- a/runtime-modules/content-directory/src/lib.rs +++ b/runtime-modules/content-directory/src/lib.rs @@ -160,7 +160,7 @@ pub use errors::Error; use core::debug_assert; /// Type, used in diffrent numeric constraints representations -type MaxNumber = u32; +pub type MaxNumber = u32; /// Module configuration trait for this Substrate module. pub trait Trait: system::Trait + ActorAuthenticator + Clone { From 33a8c890d4f791691c7c911155075fd3aa91239f Mon Sep 17 00:00:00 2001 From: iorveth Date: Sun, 13 Sep 2020 14:14:08 +0300 Subject: [PATCH 04/13] Remove redundant traits from content directory trait associated types --- Cargo.lock | 4 ++-- runtime-modules/content-directory/src/helpers.rs | 2 +- runtime-modules/content-directory/src/lib.rs | 7 ------- runtime-modules/content-directory/src/operations.rs | 1 - runtime-modules/content-directory/src/permissions.rs | 2 -- runtime-modules/content-directory/src/permissions/class.rs | 1 - .../content-directory/src/permissions/entity.rs | 1 - runtime-modules/content-directory/src/schema.rs | 1 - runtime-modules/content-directory/src/schema/input.rs | 4 +--- runtime/src/lib.rs | 7 ++++--- 10 files changed, 8 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba86651823..d2d94733da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3949,9 +3949,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "1.2.0" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0ec292e92e8ec7c58e576adacc1e3f399c597c8f263c42f18420abe58e7245" +checksum = "198db82bb1c18fc00176004462dd809b2a6d851669550aa17af6dacd21ae0c14" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/runtime-modules/content-directory/src/helpers.rs b/runtime-modules/content-directory/src/helpers.rs index f7056f8def..d8a2e1ca4a 100644 --- a/runtime-modules/content-directory/src/helpers.rs +++ b/runtime-modules/content-directory/src/helpers.rs @@ -185,7 +185,7 @@ pub struct InputValidationLengthConstraint { impl InputValidationLengthConstraint { /// Create new `InputValidationLengthConstraint` constraint - pub fn new(min: u16, max_min_diff: u16) -> Self { + pub const fn new(min: u16, max_min_diff: u16) -> Self { Self { min, max_min_diff } } diff --git a/runtime-modules/content-directory/src/lib.rs b/runtime-modules/content-directory/src/lib.rs index 8ffee90395..3a48bcd4da 100755 --- a/runtime-modules/content-directory/src/lib.rs +++ b/runtime-modules/content-directory/src/lib.rs @@ -135,7 +135,6 @@ pub use operations::*; pub use permissions::*; pub use schema::*; -use core::fmt::Debug; use core::hash::Hash; use core::ops::AddAssign; @@ -175,8 +174,6 @@ pub trait Trait: system::Trait + ActorAuthenticator + Clone { + Default + Copy + Clone - + One - + Zero + MaybeSerializeDeserialize + Eq + PartialEq @@ -191,9 +188,7 @@ pub trait Trait: system::Trait + ActorAuthenticator + Clone { + Default + Copy + Clone - + One + Hash - + Zero + MaybeSerializeDeserialize + Eq + PartialEq @@ -208,8 +203,6 @@ pub trait Trait: system::Trait + ActorAuthenticator + Clone { + Copy + Clone + Hash - + One - + Zero + MaybeSerializeDeserialize + Eq + PartialEq diff --git a/runtime-modules/content-directory/src/operations.rs b/runtime-modules/content-directory/src/operations.rs index cf2b82d217..a23fa2b068 100644 --- a/runtime-modules/content-directory/src/operations.rs +++ b/runtime-modules/content-directory/src/operations.rs @@ -69,7 +69,6 @@ pub enum OperationType { } impl core::fmt::Debug for OperationType { - #[cfg(feature = "std")] fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(formatter, "OperationType {:?}", self) } diff --git a/runtime-modules/content-directory/src/permissions.rs b/runtime-modules/content-directory/src/permissions.rs index 2d42a45842..8ac03c1c4e 100644 --- a/runtime-modules/content-directory/src/permissions.rs +++ b/runtime-modules/content-directory/src/permissions.rs @@ -51,7 +51,6 @@ pub trait ActorAuthenticator: system::Trait { + Member + BaseArithmetic + Codec - + One + Default + Copy + Clone @@ -122,7 +121,6 @@ impl Default for Actor { } impl core::fmt::Debug for Actor { - #[cfg(feature = "std")] fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(formatter, "Actor {:?}", self) } diff --git a/runtime-modules/content-directory/src/permissions/class.rs b/runtime-modules/content-directory/src/permissions/class.rs index a866eeeacc..9b00346baf 100644 --- a/runtime-modules/content-directory/src/permissions/class.rs +++ b/runtime-modules/content-directory/src/permissions/class.rs @@ -24,7 +24,6 @@ pub struct ClassPermissions { } impl core::fmt::Debug for ClassPermissions { - #[cfg(feature = "std")] fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(formatter, "ClassPermissions {:?}", self) } diff --git a/runtime-modules/content-directory/src/permissions/entity.rs b/runtime-modules/content-directory/src/permissions/entity.rs index 0f06980adf..54d0366f27 100644 --- a/runtime-modules/content-directory/src/permissions/entity.rs +++ b/runtime-modules/content-directory/src/permissions/entity.rs @@ -27,7 +27,6 @@ impl Default for EntityController { } impl core::fmt::Debug for EntityController { - #[cfg(feature = "std")] fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(formatter, "EntityController {:?}", self) } diff --git a/runtime-modules/content-directory/src/schema.rs b/runtime-modules/content-directory/src/schema.rs index ddda7fa959..9b951559c9 100644 --- a/runtime-modules/content-directory/src/schema.rs +++ b/runtime-modules/content-directory/src/schema.rs @@ -287,7 +287,6 @@ impl Default for Property { } impl core::fmt::Debug for Property { - #[cfg(feature = "std")] fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(formatter, "Property {:?}", self) } diff --git a/runtime-modules/content-directory/src/schema/input.rs b/runtime-modules/content-directory/src/schema/input.rs index 74d4fefe2d..f67df24319 100644 --- a/runtime-modules/content-directory/src/schema/input.rs +++ b/runtime-modules/content-directory/src/schema/input.rs @@ -9,7 +9,6 @@ pub enum InputPropertyValue { } impl core::fmt::Debug for InputPropertyValue { - #[cfg(feature = "std")] fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(formatter, "InputPropertyValue {:?}", self) } @@ -81,8 +80,7 @@ pub enum InputValue { } impl core::fmt::Debug for InputValue { - #[cfg(feature = "std")] - fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> sp_std::fmt::Result { write!(formatter, "InputValue {:?}", self) } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a1b2246a7b..f85190481b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -382,15 +382,15 @@ impl content_directory::ActorAuthenticator for Runtime { type MemberId = u64; type CuratorGroupId = u64; - fn is_lead() -> bool { + fn is_lead(account_id: &AccountId) -> bool { true } - fn is_curator(curator_id: &Self::CuratorId, account_id: &Self::AccountId) -> bool { + fn is_curator(curator_id: &Self::CuratorId, account_id: &AccountId) -> bool { true } - fn is_member(member_id: &Self::MemberId, account_id: &Self::AccountId) -> bool { + fn is_member(member_id: &Self::MemberId, account_id: &AccountId) -> bool { true } } @@ -679,6 +679,7 @@ construct_runtime!( RecurringRewards: recurring_rewards::{Module, Call, Storage}, Hiring: hiring::{Module, Call, Storage}, ContentWorkingGroup: content_wg::{Module, Call, Storage, Event, Config}, + ContentDirectory: content_directory::{Module, Call, Storage, Event, Config}, // --- Storage DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event, Config}, DataDirectory: data_directory::{Module, Call, Storage, Event}, From 35165d29a6c2972cee8672937b69c3567d6a926f Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 14 Sep 2020 00:21:46 +0300 Subject: [PATCH 05/13] Add content directory config --- node/src/chain_spec.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 5376413019..bed2cc8a49 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -29,12 +29,14 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; use sp_runtime::Perbill; use node_runtime::{ + content_directory::InputValidationLengthConstraint as CdInputValidation, versioned_store::InputValidationLengthConstraint as VsInputValidation, - AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig, ContentWorkingGroupConfig, - CouncilConfig, CouncilElectionConfig, DataObjectStorageRegistryConfig, - DataObjectTypeRegistryConfig, ElectionParameters, GrandpaConfig, ImOnlineConfig, MembersConfig, - ProposalsCodexConfig, SessionConfig, SessionKeys, Signature, StakerStatus, StakingConfig, - StorageWorkingGroupConfig, SudoConfig, SystemConfig, VersionedStoreConfig, DAYS, WASM_BINARY, + AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig, ContentDirectoryConfig, + ContentWorkingGroupConfig, CouncilConfig, CouncilElectionConfig, + DataObjectStorageRegistryConfig, DataObjectTypeRegistryConfig, ElectionParameters, + GrandpaConfig, ImOnlineConfig, MembersConfig, ProposalsCodexConfig, SessionConfig, SessionKeys, + Signature, StakerStatus, StakingConfig, StorageWorkingGroupConfig, SudoConfig, SystemConfig, + VersionedStoreConfig, DAYS, WASM_BINARY, }; pub use node_runtime::{AccountId, GenesisConfig}; @@ -326,6 +328,16 @@ pub fn testnet_genesis( channel_banner_constraint: InputValidationLengthConstraint::new(5, 1024), channel_title_constraint: InputValidationLengthConstraint::new(5, 1024), }), + content_directory: Some({ + ContentDirectoryConfig { + class_by_id: vec![], + entity_by_id: vec![], + curator_group_by_id: vec![], + next_class_id: 1, + next_entity_id: 1, + next_curator_group_id: 1, + } + }), proposals_codex: Some(ProposalsCodexConfig { set_validator_count_proposal_voting_period: cpcp .set_validator_count_proposal_voting_period, From 04ae232976dfbd182a18153047900df1b7b75621 Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 14 Sep 2020 00:22:57 +0300 Subject: [PATCH 06/13] Chainspec: Remove unnecessary import --- node/src/chain_spec.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index bed2cc8a49..e917d19f55 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -29,7 +29,6 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; use sp_runtime::Perbill; use node_runtime::{ - content_directory::InputValidationLengthConstraint as CdInputValidation, versioned_store::InputValidationLengthConstraint as VsInputValidation, AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig, ContentDirectoryConfig, ContentWorkingGroupConfig, CouncilConfig, CouncilElectionConfig, From 48d4e30d25363872861723e22563e90347fa55e7 Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 14 Sep 2020 22:54:03 +0300 Subject: [PATCH 07/13] Remove class_by_id & entity_by_id from chainspec config --- node/src/chain_spec.rs | 2 -- runtime-modules/content-directory/src/lib.rs | 4 ++-- runtime-modules/content-directory/src/mock.rs | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index e917d19f55..aed186cbaa 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -329,8 +329,6 @@ pub fn testnet_genesis( }), content_directory: Some({ ContentDirectoryConfig { - class_by_id: vec![], - entity_by_id: vec![], curator_group_by_id: vec![], next_class_id: 1, next_entity_id: 1, diff --git a/runtime-modules/content-directory/src/lib.rs b/runtime-modules/content-directory/src/lib.rs index 3a48bcd4da..2caa1f56c4 100755 --- a/runtime-modules/content-directory/src/lib.rs +++ b/runtime-modules/content-directory/src/lib.rs @@ -260,10 +260,10 @@ decl_storage! { trait Store for Module as ContentDirectory { /// Map, representing ClassId -> Class relation - pub ClassById get(fn class_by_id) config(): map hasher(blake2_128_concat) T::ClassId => Class; + pub ClassById get(fn class_by_id): map hasher(blake2_128_concat) T::ClassId => Class; /// Map, representing EntityId -> Entity relation - pub EntityById get(fn entity_by_id) config(): map hasher(blake2_128_concat) T::EntityId => Entity; + pub EntityById get(fn entity_by_id): map hasher(blake2_128_concat) T::EntityId => Entity; /// Map, representing CuratorGroupId -> CuratorGroup relation pub CuratorGroupById get(fn curator_group_by_id) config(): map hasher(blake2_128_concat) T::CuratorGroupId => CuratorGroup; diff --git a/runtime-modules/content-directory/src/mock.rs b/runtime-modules/content-directory/src/mock.rs index 152c6f362d..604d628ebb 100644 --- a/runtime-modules/content-directory/src/mock.rs +++ b/runtime-modules/content-directory/src/mock.rs @@ -405,8 +405,6 @@ impl ExtBuilder { fn default_content_directory_genesis_config() -> GenesisConfig { GenesisConfig { - class_by_id: vec![], - entity_by_id: vec![], curator_group_by_id: vec![], next_class_id: 1, next_entity_id: 1, From ae2ef29eb38893d22248a021a5d484254e5bb201 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 15 Sep 2020 00:29:33 +0300 Subject: [PATCH 08/13] content_directory integration - initial implementation --- runtime-modules/working-group/src/lib.rs | 2 +- runtime/src/integration/mod.rs | 1 + runtime/src/lib.rs | 22 +++------------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/runtime-modules/working-group/src/lib.rs b/runtime-modules/working-group/src/lib.rs index d4206a67c5..c933d597b0 100644 --- a/runtime-modules/working-group/src/lib.rs +++ b/runtime-modules/working-group/src/lib.rs @@ -1298,7 +1298,7 @@ impl, I: Instance> Module { Ok(worker) } - fn ensure_worker_exists(worker_id: &WorkerId) -> Result, Error> { + pub fn ensure_worker_exists(worker_id: &WorkerId) -> Result, Error> { ensure!( WorkerById::::contains_key(worker_id), Error::::WorkerDoesNotExist diff --git a/runtime/src/integration/mod.rs b/runtime/src/integration/mod.rs index 35774a7c6c..3777efda4f 100644 --- a/runtime/src/integration/mod.rs +++ b/runtime/src/integration/mod.rs @@ -1,3 +1,4 @@ +pub mod content_directory; pub mod content_working_group; pub mod forum; pub mod proposals; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index f85190481b..201b74820c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -377,24 +377,6 @@ impl versioned_store_permissions::Trait for Runtime { integration::versioned_store_permissions::ContentLeadOrSudoKeyCanCreateClasses; } -impl content_directory::ActorAuthenticator for Runtime { - type CuratorId = u64; - type MemberId = u64; - type CuratorGroupId = u64; - - fn is_lead(account_id: &AccountId) -> bool { - true - } - - fn is_curator(curator_id: &Self::CuratorId, account_id: &AccountId) -> bool { - true - } - - fn is_member(member_id: &Self::MemberId, account_id: &AccountId) -> bool { - true - } -} - type EntityId = ::EntityId; parameter_types! { @@ -530,9 +512,11 @@ impl storage::data_object_storage_registry::Trait for Runtime { type ContentIdExists = DataDirectory; } +pub type MemberId = u64; + impl membership::Trait for Runtime { type Event = Event; - type MemberId = u64; + type MemberId = MemberId; type PaidTermId = u64; type SubscriptionId = u64; type ActorId = ActorId; From 5202cbaab2b834747dc140bc5d80723b548e696d Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 15 Sep 2020 00:30:22 +0300 Subject: [PATCH 09/13] Add content_directory integration file --- runtime/src/integration/content_directory.rs | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 runtime/src/integration/content_directory.rs diff --git a/runtime/src/integration/content_directory.rs b/runtime/src/integration/content_directory.rs new file mode 100644 index 0000000000..9214f786fe --- /dev/null +++ b/runtime/src/integration/content_directory.rs @@ -0,0 +1,32 @@ +use crate::{AccountId, MemberId, Runtime}; + +// The storage working group instance alias. +pub type StorageWorkingGroupInstance = working_group::Instance2; + +// Alias for storage working group +pub(crate) type StorageWorkingGroup = working_group::Module; + +impl content_directory::ActorAuthenticator for Runtime { + type CuratorId = u64; + type MemberId = MemberId; + type CuratorGroupId = u64; + + fn is_lead(account_id: &AccountId) -> bool { + >::key() == *account_id + } + + fn is_curator(curator_id: &Self::CuratorId, account_id: &AccountId) -> bool { + if let Ok(worker) = StorageWorkingGroup::::ensure_worker_exists(curator_id) { + *account_id == worker.role_account_id + } else { + false + } + } + + fn is_member(member_id: &Self::MemberId, account_id: &AccountId) -> bool { + membership::Module::::ensure_is_controller_account_for_member( + member_id, account_id, + ) + .is_ok() + } +} From 905fe9eaf468d57d7f6c9f482b955e1a447d5659 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 15 Sep 2020 13:46:15 +0300 Subject: [PATCH 10/13] content_directory integration: fix is_lead implementation --- runtime/src/integration/content_directory.rs | 27 +++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/runtime/src/integration/content_directory.rs b/runtime/src/integration/content_directory.rs index 9214f786fe..150b14ae75 100644 --- a/runtime/src/integration/content_directory.rs +++ b/runtime/src/integration/content_directory.rs @@ -1,10 +1,11 @@ use crate::{AccountId, MemberId, Runtime}; -// The storage working group instance alias. -pub type StorageWorkingGroupInstance = working_group::Instance2; +// The content directory working group instance alias. +pub type ContentDirectoryWorkingGroupInstance = working_group::Instance2; -// Alias for storage working group -pub(crate) type StorageWorkingGroup = working_group::Module; +// Alias for content directory working group +pub(crate) type ContentDirectoryWorkingGroup = + working_group::Module; impl content_directory::ActorAuthenticator for Runtime { type CuratorId = u64; @@ -12,11 +13,25 @@ impl content_directory::ActorAuthenticator for Runtime { type CuratorGroupId = u64; fn is_lead(account_id: &AccountId) -> bool { - >::key() == *account_id + // get current lead id + let maybe_current_lead_id = ContentDirectoryWorkingGroup::::current_lead(); + if let Some(ref current_lead_id) = maybe_current_lead_id { + if let Ok(worker) = + ContentDirectoryWorkingGroup::::ensure_worker_exists(current_lead_id) + { + *account_id == worker.role_account_id + } else { + false + } + } else { + false + } } fn is_curator(curator_id: &Self::CuratorId, account_id: &AccountId) -> bool { - if let Ok(worker) = StorageWorkingGroup::::ensure_worker_exists(curator_id) { + if let Ok(worker) = + ContentDirectoryWorkingGroup::::ensure_worker_exists(curator_id) + { *account_id == worker.role_account_id } else { false From b9c741ed8b0adecd6ee1b13e67fba8604574e787 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 15 Sep 2020 17:00:56 +0300 Subject: [PATCH 11/13] Introduce ContentDirectoryWorkingGroup - Instance3 --- node/src/chain_spec.rs | 17 ++++++++++++----- runtime/src/integration/content_directory.rs | 5 +---- runtime/src/lib.rs | 9 +++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index aed186cbaa..5856b57c37 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -31,11 +31,11 @@ use sp_runtime::Perbill; use node_runtime::{ versioned_store::InputValidationLengthConstraint as VsInputValidation, AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig, ContentDirectoryConfig, - ContentWorkingGroupConfig, CouncilConfig, CouncilElectionConfig, - DataObjectStorageRegistryConfig, DataObjectTypeRegistryConfig, ElectionParameters, - GrandpaConfig, ImOnlineConfig, MembersConfig, ProposalsCodexConfig, SessionConfig, SessionKeys, - Signature, StakerStatus, StakingConfig, StorageWorkingGroupConfig, SudoConfig, SystemConfig, - VersionedStoreConfig, DAYS, WASM_BINARY, + ContentDirectoryWorkingGroupConfig, ContentWorkingGroupConfig, CouncilConfig, + CouncilElectionConfig, DataObjectStorageRegistryConfig, DataObjectTypeRegistryConfig, + ElectionParameters, GrandpaConfig, ImOnlineConfig, MembersConfig, ProposalsCodexConfig, + SessionConfig, SessionKeys, Signature, StakerStatus, StakingConfig, StorageWorkingGroupConfig, + SudoConfig, SystemConfig, VersionedStoreConfig, DAYS, WASM_BINARY, }; pub use node_runtime::{AccountId, GenesisConfig}; @@ -293,6 +293,13 @@ pub fn testnet_genesis( worker_application_human_readable_text_constraint: default_text_constraint, worker_exit_rationale_text_constraint: default_text_constraint, }), + working_group_Instance3: Some(ContentDirectoryWorkingGroupConfig { + phantom: Default::default(), + storage_working_group_mint_capacity: 0, + 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, + }), versioned_store: Some(VersionedStoreConfig { class_by_id: vec![], entity_by_id: vec![], diff --git a/runtime/src/integration/content_directory.rs b/runtime/src/integration/content_directory.rs index 150b14ae75..99f476ec4a 100644 --- a/runtime/src/integration/content_directory.rs +++ b/runtime/src/integration/content_directory.rs @@ -1,7 +1,4 @@ -use crate::{AccountId, MemberId, Runtime}; - -// The content directory working group instance alias. -pub type ContentDirectoryWorkingGroupInstance = working_group::Instance2; +use crate::{AccountId, ContentDirectoryWorkingGroupInstance, MemberId, Runtime}; // Alias for content directory working group pub(crate) type ContentDirectoryWorkingGroup = diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 201b74820c..83b07eb25f 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -532,6 +532,9 @@ impl forum::Trait for Runtime { // The storage working group instance alias. pub type StorageWorkingGroupInstance = working_group::Instance2; +// The content directory working group instance alias. +pub type ContentDirectoryWorkingGroupInstance = working_group::Instance3; + parameter_types! { pub const MaxWorkerNumberLimit: u32 = 100; } @@ -541,6 +544,11 @@ impl working_group::Trait for Runtime { type MaxWorkerNumberLimit = MaxWorkerNumberLimit; } +impl working_group::Trait for Runtime { + type Event = Event; + type MaxWorkerNumberLimit = MaxWorkerNumberLimit; +} + impl service_discovery::Trait for Runtime { type Event = Event; } @@ -676,5 +684,6 @@ construct_runtime!( // --- Working groups // reserved for the future use: ForumWorkingGroup: working_group::::{Module, Call, Storage, Event}, StorageWorkingGroup: working_group::::{Module, Call, Storage, Config, Event}, + ContentDirectoryWorkingGroup: working_group::::{Module, Call, Storage, Config, Event}, } ); From 9d6bbb08706503ef06060959476baf0028b1fdf8 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 15 Sep 2020 17:05:26 +0300 Subject: [PATCH 12/13] WorkingGroup: Add missing comment --- runtime-modules/working-group/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime-modules/working-group/src/lib.rs b/runtime-modules/working-group/src/lib.rs index c933d597b0..79744c45e4 100644 --- a/runtime-modules/working-group/src/lib.rs +++ b/runtime-modules/working-group/src/lib.rs @@ -1298,6 +1298,7 @@ impl, I: Instance> Module { Ok(worker) } + /// Ensures worker under given id already exists pub fn ensure_worker_exists(worker_id: &WorkerId) -> Result, Error> { ensure!( WorkerById::::contains_key(worker_id), From d993a64a39c491aad16e4c3d0f1b041496d41f37 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 15 Sep 2020 18:28:22 +0300 Subject: [PATCH 13/13] Content directory refactoring: remove unnecessary spaces --- runtime-modules/content-directory/src/mock.rs | 29 ------------------- runtime/src/lib.rs | 11 ------- 2 files changed, 40 deletions(-) diff --git a/runtime-modules/content-directory/src/mock.rs b/runtime-modules/content-directory/src/mock.rs index 604d628ebb..b9c5b92fc0 100644 --- a/runtime-modules/content-directory/src/mock.rs +++ b/runtime-modules/content-directory/src/mock.rs @@ -89,21 +89,16 @@ thread_local! { static PROPERTY_DESCRIPTION_CONSTRAINT: RefCell = RefCell::new(InputValidationLengthConstraint::default()); static CLASS_NAME_CONSTRAINT: RefCell = RefCell::new(InputValidationLengthConstraint::default()); static CLASS_DESCRIPTION_CONSTRAINT: RefCell = RefCell::new(InputValidationLengthConstraint::default()); - static MAX_NUMBER_OF_CLASSES: RefCell = RefCell::new(0); static MAX_NUMBER_OF_MAINTAINERS_PER_CLASS: RefCell = RefCell::new(0); static MAX_NUMBER_OF_SCHEMAS_PER_CLASS: RefCell = RefCell::new(0); static MAX_NUMBER_OF_PROPERTIES_PER_CLASS: RefCell = RefCell::new(0); static MAX_NUMBER_OF_ENTITIES_PER_CLASS: RefCell = RefCell::new(0); - static MAX_NUMBER_OF_CURATORS_PER_GROUP: RefCell = RefCell::new(0); - static MAX_NUMBER_OF_OPERATIONS_DURING_ATOMIC_BATCHING: RefCell = RefCell::new(0); - static VEC_MAX_LENGTH_CONSTRAINT: RefCell = RefCell::new(0); static TEXT_MAX_LENGTH_CONSTRAINT: RefCell = RefCell::new(0); static HASHED_TEXT_MAX_LENGTH_CONSTRAINT: RefCell = RefCell::new(Some(0)); - static INDIVIDUAL_ENTITIES_CREATION_LIMIT: RefCell = RefCell::new(0); } @@ -252,31 +247,23 @@ impl_outer_event! { impl Trait for Runtime { type Event = TestEvent; - type Nonce = u64; - type ClassId = u64; type EntityId = u64; - type PropertyNameLengthConstraint = PropertyNameLengthConstraint; type PropertyDescriptionLengthConstraint = PropertyDescriptionLengthConstraint; type ClassNameLengthConstraint = ClassNameLengthConstraint; type ClassDescriptionLengthConstraint = ClassDescriptionLengthConstraint; - type MaxNumberOfClasses = MaxNumberOfClasses; type MaxNumberOfMaintainersPerClass = MaxNumberOfMaintainersPerClass; type MaxNumberOfSchemasPerClass = MaxNumberOfSchemasPerClass; type MaxNumberOfPropertiesPerSchema = MaxNumberOfPropertiesPerSchema; type MaxNumberOfEntitiesPerClass = MaxNumberOfEntitiesPerClass; - type MaxNumberOfCuratorsPerGroup = MaxNumberOfCuratorsPerGroup; - type MaxNumberOfOperationsDuringAtomicBatching = MaxNumberOfOperationsDuringAtomicBatching; - type VecMaxLengthConstraint = VecMaxLengthConstraint; type TextMaxLengthConstraint = TextMaxLengthConstraint; type HashedTextMaxLengthConstraint = HashedTextMaxLengthConstraint; - type IndividualEntitiesCreationLimit = IndividualEntitiesCreationLimit; } @@ -311,21 +298,16 @@ pub struct ExtBuilder { property_description_constraint: InputValidationLengthConstraint, class_name_constraint: InputValidationLengthConstraint, class_description_constraint: InputValidationLengthConstraint, - max_number_of_classes: MaxNumber, max_number_of_maintainers_per_class: MaxNumber, max_number_of_schemas_per_class: MaxNumber, max_number_of_properties_per_class: MaxNumber, max_number_of_entities_per_class: EntityId, - max_number_of_curators_per_group: MaxNumber, - max_number_of_operations_during_atomic_batching: MaxNumber, - vec_max_length_constraint: VecMaxLength, text_max_length_constraint: TextMaxLength, hashed_text_max_length_constraint: HashedTextMaxLength, - individual_entities_creation_limit: EntityId, } @@ -336,21 +318,16 @@ impl Default for ExtBuilder { property_description_constraint: InputValidationLengthConstraint::new(1, 500), class_name_constraint: InputValidationLengthConstraint::new(1, 49), class_description_constraint: InputValidationLengthConstraint::new(1, 500), - max_number_of_classes: 100, max_number_of_maintainers_per_class: 10, max_number_of_schemas_per_class: 20, max_number_of_properties_per_class: 40, max_number_of_entities_per_class: 400, - max_number_of_curators_per_group: 50, - max_number_of_operations_during_atomic_batching: 500, - vec_max_length_constraint: 200, text_max_length_constraint: 5000, hashed_text_max_length_constraint: Some(25000), - individual_entities_creation_limit: 50, } } @@ -363,7 +340,6 @@ impl ExtBuilder { .with(|v| *v.borrow_mut() = self.property_description_constraint); CLASS_NAME_CONSTRAINT.with(|v| *v.borrow_mut() = self.class_name_constraint); CLASS_DESCRIPTION_CONSTRAINT.with(|v| *v.borrow_mut() = self.class_description_constraint); - MAX_NUMBER_OF_CLASSES.with(|v| *v.borrow_mut() = self.max_number_of_classes); MAX_NUMBER_OF_MAINTAINERS_PER_CLASS .with(|v| *v.borrow_mut() = self.max_number_of_maintainers_per_class); @@ -373,19 +349,14 @@ impl ExtBuilder { .with(|v| *v.borrow_mut() = self.max_number_of_properties_per_class); MAX_NUMBER_OF_ENTITIES_PER_CLASS .with(|v| *v.borrow_mut() = self.max_number_of_entities_per_class); - MAX_NUMBER_OF_CURATORS_PER_GROUP .with(|v| *v.borrow_mut() = self.max_number_of_curators_per_group); - MAX_NUMBER_OF_OPERATIONS_DURING_ATOMIC_BATCHING .with(|v| *v.borrow_mut() = self.max_number_of_operations_during_atomic_batching); - VEC_MAX_LENGTH_CONSTRAINT.with(|v| *v.borrow_mut() = self.vec_max_length_constraint); TEXT_MAX_LENGTH_CONSTRAINT.with(|v| *v.borrow_mut() = self.text_max_length_constraint); - HASHED_TEXT_MAX_LENGTH_CONSTRAINT .with(|v| *v.borrow_mut() = self.hashed_text_max_length_constraint); - INDIVIDUAL_ENTITIES_CREATION_LIMIT .with(|v| *v.borrow_mut() = self.individual_entities_creation_limit); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 83b07eb25f..436addca7e 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -384,21 +384,16 @@ parameter_types! { pub const PropertyDescriptionLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 500); pub const ClassNameLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 49); pub const ClassDescriptionLengthConstraint: InputValidationLengthConstraint = InputValidationLengthConstraint::new(1, 500); - pub const MaxNumberOfClasses: MaxNumber = 100; pub const MaxNumberOfMaintainersPerClass: MaxNumber = 10; pub const MaxNumberOfSchemasPerClass: MaxNumber = 20; pub const MaxNumberOfPropertiesPerSchema: MaxNumber = 40; pub const MaxNumberOfEntitiesPerClass: MaxNumber = 400; - pub const MaxNumberOfCuratorsPerGroup: MaxNumber = 50; - pub const MaxNumberOfOperationsDuringAtomicBatching: MaxNumber = 500; - pub const VecMaxLengthConstraint: VecMaxLength = 200; pub const TextMaxLengthConstraint: TextMaxLength = 5000; pub const HashedTextMaxLengthConstraint: HashedTextMaxLength = Some(25000); - pub const IndividualEntitiesCreationLimit: EntityId = 50; } @@ -407,26 +402,20 @@ impl content_directory::Trait for Runtime { type Nonce = u64; type ClassId = u64; type EntityId = u64; - type PropertyNameLengthConstraint = PropertyNameLengthConstraint; type PropertyDescriptionLengthConstraint = PropertyDescriptionLengthConstraint; type ClassNameLengthConstraint = ClassNameLengthConstraint; type ClassDescriptionLengthConstraint = ClassDescriptionLengthConstraint; - type MaxNumberOfClasses = MaxNumberOfClasses; type MaxNumberOfMaintainersPerClass = MaxNumberOfMaintainersPerClass; type MaxNumberOfSchemasPerClass = MaxNumberOfSchemasPerClass; type MaxNumberOfPropertiesPerSchema = MaxNumberOfPropertiesPerSchema; type MaxNumberOfEntitiesPerClass = MaxNumberOfEntitiesPerClass; - type MaxNumberOfCuratorsPerGroup = MaxNumberOfCuratorsPerGroup; - type MaxNumberOfOperationsDuringAtomicBatching = MaxNumberOfOperationsDuringAtomicBatching; - type VecMaxLengthConstraint = VecMaxLengthConstraint; type TextMaxLengthConstraint = TextMaxLengthConstraint; type HashedTextMaxLengthConstraint = HashedTextMaxLengthConstraint; - type IndividualEntitiesCreationLimit = IndividualEntitiesCreationLimit; }