Browse Source

runtime: fix unstaking from operations and gateway working groups

Mokhtar Naamani 3 years ago
parent
commit
90ab4c2063

+ 1 - 1
.github/workflows/run-network-tests.yml

@@ -103,7 +103,7 @@ jobs:
       - name: Ensure tests are runnable
         run: yarn workspace network-tests build
       - name: Execute network tests
-        run: RUNTIME=antioch tests/network-tests/run-tests.sh full
+        run: RUNTIME=sumer tests/network-tests/run-tests.sh full
 
   basic_runtime:
     name: Integration Tests (New Chain)

+ 2 - 2
Cargo.lock

@@ -2332,7 +2332,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node"
-version = "5.5.0"
+version = "5.6.0"
 dependencies = [
  "frame-benchmarking",
  "frame-benchmarking-cli",
@@ -2393,7 +2393,7 @@ dependencies = [
 
 [[package]]
 name = "joystream-node-runtime"
-version = "9.7.0"
+version = "9.8.0"
 dependencies = [
  "frame-benchmarking",
  "frame-executive",

+ 1 - 1
node/Cargo.toml

@@ -3,7 +3,7 @@ authors = ['Joystream contributors']
 build = 'build.rs'
 edition = '2018'
 name = 'joystream-node'
-version = '5.5.0'
+version = '5.6.0'
 default-run = "joystream-node"
 
 [[bin]]

+ 0 - 14
runtime-modules/content/src/lib.rs

@@ -1363,20 +1363,6 @@ impl<T: Trait> Module<T> {
     }
 }
 
-// Some initial config for the module on runtime upgrade
-impl<T: Trait> Module<T> {
-    pub fn on_runtime_upgrade() {
-        <NextChannelCategoryId<T>>::put(T::ChannelCategoryId::one());
-        <NextVideoCategoryId<T>>::put(T::VideoCategoryId::one());
-        <NextVideoId<T>>::put(T::VideoId::one());
-        <NextChannelId<T>>::put(T::ChannelId::one());
-        <NextPlaylistId<T>>::put(T::PlaylistId::one());
-        <NextSeriesId<T>>::put(T::SeriesId::one());
-        <NextPersonId<T>>::put(T::PersonId::one());
-        <NextChannelOwnershipTransferRequestId<T>>::put(T::ChannelOwnershipTransferRequestId::one());
-    }
-}
-
 decl_event!(
     pub enum Event<T>
     where

+ 1 - 1
runtime/Cargo.toml

@@ -4,7 +4,7 @@ edition = '2018'
 name = 'joystream-node-runtime'
 # Follow convention: https://github.com/Joystream/substrate-runtime-joystream/issues/1
 # {Authoring}.{Spec}.{Impl} of the RuntimeVersion
-version = '9.7.0'
+version = '9.8.0'
 
 [dependencies]
 # Third-party dependencies

+ 94 - 3
runtime/src/integration/working_group.rs

@@ -1,17 +1,20 @@
 use frame_support::StorageMap;
 use sp_std::marker::PhantomData;
 
-use crate::{ContentDirectoryWorkingGroupInstance, StorageWorkingGroupInstance};
+use crate::{
+    ContentDirectoryWorkingGroupInstance, GatewayWorkingGroupInstance,
+    OperationsWorkingGroupInstance, StorageWorkingGroupInstance,
+};
 use stake::{BalanceOf, NegativeImbalance};
 
 // Will be removed in the next releases.
 #[allow(clippy::upper_case_acronyms)]
-pub struct ContentDirectoryWGStakingEventsHandler<T> {
+pub struct ContentDirectoryWgStakingEventsHandler<T> {
     pub marker: PhantomData<T>,
 }
 
 impl<T: stake::Trait + working_group::Trait<ContentDirectoryWorkingGroupInstance>>
-    stake::StakingEventsHandler<T> for ContentDirectoryWGStakingEventsHandler<T>
+    stake::StakingEventsHandler<T> for ContentDirectoryWgStakingEventsHandler<T>
 {
     /// Unstake remaining sum back to the source_account_id
     fn unstaked(
@@ -93,3 +96,91 @@ impl<T: stake::Trait + working_group::Trait<StorageWorkingGroupInstance>>
         remaining_imbalance
     }
 }
+
+pub struct OperationsWgStakingEventsHandler<T> {
+    pub marker: PhantomData<T>,
+}
+
+impl<T: stake::Trait + working_group::Trait<OperationsWorkingGroupInstance>>
+    stake::StakingEventsHandler<T> for OperationsWgStakingEventsHandler<T>
+{
+    /// Unstake remaining sum back to the source_account_id
+    fn unstaked(
+        stake_id: &<T as stake::Trait>::StakeId,
+        _unstaked_amount: BalanceOf<T>,
+        remaining_imbalance: NegativeImbalance<T>,
+    ) -> NegativeImbalance<T> {
+        // Stake not related to a staked role managed by the hiring module.
+        if !hiring::ApplicationIdByStakingId::<T>::contains_key(*stake_id) {
+            return remaining_imbalance;
+        }
+
+        let hiring_application_id = hiring::ApplicationIdByStakingId::<T>::get(*stake_id);
+
+        if working_group::MemberIdByHiringApplicationId::<T, OperationsWorkingGroupInstance>::contains_key(
+            hiring_application_id,
+        ) {
+            return <working_group::Module<T, OperationsWorkingGroupInstance>>::refund_working_group_stake(
+				*stake_id,
+				remaining_imbalance,
+			);
+        }
+
+        remaining_imbalance
+    }
+
+    /// Empty handler for the slashing.
+    fn slashed(
+        _: &<T as stake::Trait>::StakeId,
+        _: Option<<T as stake::Trait>::SlashId>,
+        _: BalanceOf<T>,
+        _: BalanceOf<T>,
+        remaining_imbalance: NegativeImbalance<T>,
+    ) -> NegativeImbalance<T> {
+        remaining_imbalance
+    }
+}
+
+pub struct GatewayWgStakingEventsHandler<T> {
+    pub marker: PhantomData<T>,
+}
+
+impl<T: stake::Trait + working_group::Trait<GatewayWorkingGroupInstance>>
+    stake::StakingEventsHandler<T> for GatewayWgStakingEventsHandler<T>
+{
+    /// Unstake remaining sum back to the source_account_id
+    fn unstaked(
+        stake_id: &<T as stake::Trait>::StakeId,
+        _unstaked_amount: BalanceOf<T>,
+        remaining_imbalance: NegativeImbalance<T>,
+    ) -> NegativeImbalance<T> {
+        // Stake not related to a staked role managed by the hiring module.
+        if !hiring::ApplicationIdByStakingId::<T>::contains_key(*stake_id) {
+            return remaining_imbalance;
+        }
+
+        let hiring_application_id = hiring::ApplicationIdByStakingId::<T>::get(*stake_id);
+
+        if working_group::MemberIdByHiringApplicationId::<T, GatewayWorkingGroupInstance>::contains_key(
+            hiring_application_id,
+        ) {
+            return <working_group::Module<T, GatewayWorkingGroupInstance>>::refund_working_group_stake(
+				*stake_id,
+				remaining_imbalance,
+			);
+        }
+
+        remaining_imbalance
+    }
+
+    /// Empty handler for the slashing.
+    fn slashed(
+        _: &<T as stake::Trait>::StakeId,
+        _: Option<<T as stake::Trait>::SlashId>,
+        _: BalanceOf<T>,
+        _: BalanceOf<T>,
+        remaining_imbalance: NegativeImbalance<T>,
+    ) -> NegativeImbalance<T> {
+        remaining_imbalance
+    }
+}

+ 10 - 3
runtime/src/lib.rs

@@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
     spec_name: create_runtime_str!("joystream-node"),
     impl_name: create_runtime_str!("joystream-node"),
     authoring_version: 9,
-    spec_version: 7,
+    spec_version: 8,
     impl_version: 0,
     apis: crate::runtime_api::EXPORTED_RUNTIME_API_VERSIONS,
     transaction_version: 1,
@@ -469,14 +469,21 @@ parameter_types! {
     pub const StakePoolId: [u8; 8] = *b"joystake";
 }
 
+#[allow(clippy::type_complexity)]
 impl stake::Trait for Runtime {
     type Currency = <Self as common::currency::GovernanceCurrency>::Currency;
     type StakePoolId = StakePoolId;
     type StakingEventsHandler = (
         crate::integration::proposals::StakingEventsHandler<Self>,
         (
-            crate::integration::working_group::ContentDirectoryWGStakingEventsHandler<Self>,
-            crate::integration::working_group::StorageWgStakingEventsHandler<Self>,
+            (
+                crate::integration::working_group::ContentDirectoryWgStakingEventsHandler<Self>,
+                crate::integration::working_group::StorageWgStakingEventsHandler<Self>,
+            ),
+            (
+                crate::integration::working_group::OperationsWgStakingEventsHandler<Self>,
+                crate::integration::working_group::GatewayWgStakingEventsHandler<Self>,
+            ),
         ),
     );
     type StakeId = u64;

+ 13 - 66
runtime/src/runtime_api.rs

@@ -10,16 +10,16 @@ use sp_runtime::traits::{BlakeTwo256, Block as BlockT, NumberFor};
 use sp_runtime::{generic, ApplyExtrinsicResult};
 use sp_std::vec::Vec;
 
-use crate::{
-    ContentDirectoryWorkingGroupInstance, DataDirectory, GatewayWorkingGroupInstance,
-    OperationsWorkingGroupInstance, StorageWorkingGroupInstance,
-};
+// use crate::{
+//     ContentDirectoryWorkingGroupInstance, GatewayWorkingGroupInstance,
+//     OperationsWorkingGroupInstance, StorageWorkingGroupInstance,
+// };
 
 use crate::constants::PRIMARY_PROBABILITY;
 
 use crate::{
-    content, data_directory, AccountId, AuthorityDiscoveryId, Balance, BlockNumber, EpochDuration,
-    GrandpaAuthorityList, GrandpaId, Hash, Index, RuntimeVersion, Signature, VERSION,
+    AccountId, AuthorityDiscoveryId, Balance, BlockNumber, EpochDuration, GrandpaAuthorityList,
+    GrandpaId, Hash, Index, RuntimeVersion, Signature, VERSION,
 };
 use crate::{
     AllModules, AuthorityDiscovery, Babe, Call, Grandpa, Historical, InherentDataExt,
@@ -60,71 +60,18 @@ pub type BlockId = generic::BlockId<Block>;
 pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<AccountId, Call, Signature, SignedExtra>;
 
 // Default Executive type without the RuntimeUpgrade
-// pub type Executive =
-//     frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllModules>;
-
-// Alias for the builder working group
-pub(crate) type OperationsWorkingGroup<T> =
-    working_group::Module<T, OperationsWorkingGroupInstance>;
-
-// Alias for the gateway working group
-pub(crate) type GatewayWorkingGroup<T> = working_group::Module<T, GatewayWorkingGroupInstance>;
-
-// Alias for the storage working group
-pub(crate) type StorageWorkingGroup<T> = working_group::Module<T, StorageWorkingGroupInstance>;
-
-// Alias for the content working group
-pub(crate) type ContentDirectoryWorkingGroup<T> =
-    working_group::Module<T, ContentDirectoryWorkingGroupInstance>;
+// pub type Executive = frame_executive::Executive<
+//     Runtime,
+//     Block,
+//     frame_system::ChainContext<Runtime>,
+//     Runtime,
+//     AllModules,
+// >;
 
 /// Custom runtime upgrade handler.
 pub struct CustomOnRuntimeUpgrade;
 impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
     fn on_runtime_upgrade() -> Weight {
-        content::Module::<Runtime>::on_runtime_upgrade();
-
-        let default_text_constraint = crate::working_group::default_text_constraint();
-
-        let default_storage_size_constraint =
-            crate::working_group::default_storage_size_constraint();
-
-        let default_content_working_group_mint_capacity = 0;
-
-        // Initialize new groups
-        OperationsWorkingGroup::<Runtime>::initialize_working_group(
-            default_text_constraint,
-            default_text_constraint,
-            default_text_constraint,
-            default_storage_size_constraint,
-            default_content_working_group_mint_capacity,
-        );
-
-        GatewayWorkingGroup::<Runtime>::initialize_working_group(
-            default_text_constraint,
-            default_text_constraint,
-            default_text_constraint,
-            default_storage_size_constraint,
-            default_content_working_group_mint_capacity,
-        );
-
-        DataDirectory::initialize_data_directory(
-            Vec::new(),
-            data_directory::DEFAULT_VOUCHER_SIZE_LIMIT_UPPER_BOUND,
-            data_directory::DEFAULT_VOUCHER_OBJECTS_LIMIT_UPPER_BOUND,
-            data_directory::DEFAULT_GLOBAL_VOUCHER,
-            data_directory::DEFAULT_VOUCHER,
-            data_directory::DEFAULT_UPLOADING_BLOCKED_STATUS,
-        );
-
-        // Initialize existing groups
-        StorageWorkingGroup::<Runtime>::set_worker_storage_size_constraint(
-            default_storage_size_constraint,
-        );
-
-        ContentDirectoryWorkingGroup::<Runtime>::set_worker_storage_size_constraint(
-            default_storage_size_constraint,
-        );
-
         10_000_000 // TODO: adjust weight
     }
 }