diff --git a/pallets/chain-space/src/lib.rs b/pallets/chain-space/src/lib.rs index f1ab03e86..f5434fdbc 100644 --- a/pallets/chain-space/src/lib.rs +++ b/pallets/chain-space/src/lib.rs @@ -125,7 +125,7 @@ pub type SpaceAuthorizationOf = SpaceAuthorization, SpaceCreatorOf>; type SpaceCreatorId: Parameter + MaxEncodedLen; type ChainSpaceOrigin: EnsureOrigin; + type NetworkPermission: IsPermissioned; #[pallet::constant] type MaxSpaceDelegates: Get; @@ -261,6 +262,8 @@ pub mod pallet { CapacityLimitExceeded, /// The new capacity value is lower than the current usage CapacityLessThanUsage, + /// Capacity value missing + CapacityValueMissing, /// Type capacity overflow TypeCapacityOverflow, } @@ -549,6 +552,8 @@ pub mod pallet { }, ); + let approved = !T::NetworkPermission::is_permissioned(); + >::insert( &identifier, SpaceDetailsOf:: { @@ -557,7 +562,7 @@ pub mod pallet { txn_capacity: 0, txn_reserve: 0, txn_count: 0, - approved: false, + approved, archive: false, parent: identifier.clone(), }, @@ -799,18 +804,18 @@ pub mod pallet { // Ensure the new capacity is greater than the current usage ensure!( - (parent_details.txn_capacity >= - (parent_details.txn_count + - parent_details.txn_reserve + new_txn_capacity - - space_details.txn_capacity)), + (parent_details.txn_capacity + >= (parent_details.txn_count + + parent_details.txn_reserve + new_txn_capacity + - space_details.txn_capacity)), Error::::CapacityLessThanUsage ); >::insert( &space_details.parent.clone(), SpaceDetailsOf:: { - txn_reserve: parent_details.txn_reserve - space_details.txn_capacity + - new_txn_capacity, + txn_reserve: parent_details.txn_reserve - space_details.txn_capacity + + new_txn_capacity, ..parent_details.clone() }, ); @@ -993,7 +998,7 @@ pub mod pallet { pub fn subspace_create( origin: OriginFor, space_code: SpaceCodeOf, - count: u64, + count: Option, space_id: SpaceIdOf, ) -> DispatchResult { let creator = ::EnsureOrigin::ensure_origin(origin)?.subject(); @@ -1003,11 +1008,21 @@ pub mod pallet { ensure!(space_details.approved, Error::::SpaceNotApproved); ensure!(space_details.creator == creator.clone(), Error::::UnauthorizedOperation); + // Check if the network is permissioned + let is_permissioned = T::NetworkPermission::is_permissioned(); + + // Ensure count is provided for permissioned networks, else set default for permissionless + let count = match count { + Some(value) => value, + None if is_permissioned => return Err(Error::::CapacityValueMissing.into()), + None => 0, + }; + // Ensure the new capacity is greater than the current usage ensure!( - count <= - (space_details.txn_capacity - - (space_details.txn_count + space_details.txn_reserve)), + count + <= (space_details.txn_capacity + - (space_details.txn_count + space_details.txn_reserve)), Error::::CapacityLimitExceeded ); @@ -1139,17 +1154,17 @@ pub mod pallet { // Ensure the new capacity is greater than the current usage ensure!( - (parent_details.txn_capacity >= - (parent_details.txn_count + parent_details.txn_reserve + new_txn_capacity - - space_details.txn_capacity)), + (parent_details.txn_capacity + >= (parent_details.txn_count + parent_details.txn_reserve + new_txn_capacity + - space_details.txn_capacity)), Error::::CapacityLessThanUsage ); >::insert( &space_details.parent.clone(), SpaceDetailsOf:: { - txn_reserve: parent_details.txn_reserve - space_details.txn_capacity + - new_txn_capacity, + txn_reserve: parent_details.txn_reserve - space_details.txn_capacity + + new_txn_capacity, ..parent_details.clone() }, ); diff --git a/pallets/config/src/lib.rs b/pallets/config/src/lib.rs index ddaea197b..5404ed609 100644 --- a/pallets/config/src/lib.rs +++ b/pallets/config/src/lib.rs @@ -40,7 +40,7 @@ pub mod pallet { // Stores the network configuration type #[pallet::storage] - pub type NetworkPermission = StorageValue<_, bool, ValueQuery>; + pub type NetworkPermissioned = StorageValue<_, bool, ValueQuery>; #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] @@ -52,7 +52,7 @@ pub mod pallet { #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { - NetworkPermission::::put(&self.permissioned); + NetworkPermissioned::::put(&self.permissioned); } } } @@ -60,7 +60,7 @@ pub mod pallet { impl Pallet { /// check if the network is permissioned pub fn is_permissioned() -> bool { - NetworkPermission::::get() + NetworkPermissioned::::get() } } diff --git a/runtimes/braid/src/lib.rs b/runtimes/braid/src/lib.rs index 63b892874..6b173ea22 100644 --- a/runtimes/braid/src/lib.rs +++ b/runtimes/braid/src/lib.rs @@ -728,6 +728,7 @@ impl pallet_chain_space::Config for Runtime { type OriginSuccess = pallet_did::DidRawOrigin; type RuntimeEvent = RuntimeEvent; type ChainSpaceOrigin = EnsureRoot; + type NetworkPermission = NetworkParameters; type MaxSpaceDelegates = MaxSpaceDelegates; type WeightInfo = weights::pallet_chain_space::WeightInfo; } diff --git a/runtimes/loom/src/lib.rs b/runtimes/loom/src/lib.rs index 9c533fab3..fee86ceaa 100644 --- a/runtimes/loom/src/lib.rs +++ b/runtimes/loom/src/lib.rs @@ -869,6 +869,7 @@ impl pallet_chain_space::Config for Runtime { type OriginSuccess = pallet_did::DidRawOrigin; type RuntimeEvent = RuntimeEvent; type ChainSpaceOrigin = MoreThanHalfCouncil; + type NetworkPermission = NetworkParameters; type MaxSpaceDelegates = MaxSpaceDelegates; type WeightInfo = weights::pallet_chain_space::WeightInfo; } diff --git a/runtimes/weave/src/lib.rs b/runtimes/weave/src/lib.rs index b373dbe7b..8466950ca 100644 --- a/runtimes/weave/src/lib.rs +++ b/runtimes/weave/src/lib.rs @@ -869,6 +869,7 @@ impl pallet_chain_space::Config for Runtime { type OriginSuccess = pallet_did::DidRawOrigin; type RuntimeEvent = RuntimeEvent; type ChainSpaceOrigin = MoreThanHalfCouncil; + type NetworkPermission = NetworkParameters; type MaxSpaceDelegates = MaxSpaceDelegates; type WeightInfo = weights::pallet_chain_space::WeightInfo; }