Browse Source

migration: revet removing staked roles (storage providers, council members and curators)

Mokhtar Naamani 4 years ago
parent
commit
93e8a2f72a

+ 0 - 33
runtime-modules/content-working-group/src/lib.rs

@@ -290,9 +290,6 @@ pub enum CuratorExitInitiationOrigin {
 
     /// The curator exiting is the origin.
     Curator,
-
-    /// The system is initiating exit of a curator
-    Root,
 }
 
 /// The exit stage of a curators involvement in the working group.
@@ -1913,31 +1910,6 @@ decl_module! {
             );
         }
 
-        /// Lead can terminate and active curator
-        pub fn terminate_curator_role_as_root(
-            origin,
-            curator_id: CuratorId<T>,
-            rationale_text: Vec<u8>
-        ) {
-
-            // Ensure origin is root
-            ensure_root(origin)?;
-
-            // Ensuring curator actually exists and is active
-            let curator = Self::ensure_active_curator_exists(&curator_id)?;
-
-            //
-            // == MUTATION SAFE ==
-            //
-
-            Self::deactivate_curator(
-                &curator_id,
-                &curator,
-                &CuratorExitInitiationOrigin::Root,
-                &rationale_text
-            );
-        }
-
         /// Replace the current lead. First unsets the active lead if there is one.
         /// If a value is provided for new_lead it will then set that new lead.
         /// It is responsibility of the caller to ensure the new lead can be set
@@ -2697,7 +2669,6 @@ impl<T: Trait> Module<T> {
                 let unstaking_period = match curator_exit_summary.origin {
                     CuratorExitInitiationOrigin::Lead => stake_profile.termination_unstaking_period,
                     CuratorExitInitiationOrigin::Curator => stake_profile.exit_unstaking_period,
-                    CuratorExitInitiationOrigin::Root => stake_profile.termination_unstaking_period,
                 };
 
                 (
@@ -2716,9 +2687,6 @@ impl<T: Trait> Module<T> {
                         CuratorExitInitiationOrigin::Curator => {
                             RawEvent::CuratorExited(curator_id.clone())
                         }
-                        CuratorExitInitiationOrigin::Root => {
-                            RawEvent::TerminatedCurator(curator_id.clone())
-                        }
                     },
                 )
             };
@@ -2869,7 +2837,6 @@ impl<T: Trait> Module<T> {
         let event = match curator_exit_summary.origin {
             CuratorExitInitiationOrigin::Lead => RawEvent::TerminatedCurator(curator_id),
             CuratorExitInitiationOrigin::Curator => RawEvent::CuratorExited(curator_id),
-            CuratorExitInitiationOrigin::Root => RawEvent::TerminatedCurator(curator_id),
         };
 
         Self::deposit_event(event);

+ 0 - 24
runtime-modules/governance/src/election.rs

@@ -228,30 +228,6 @@ impl<T: Trait> Module<T> {
         }
     }
 
-    pub fn stop_election_and_dissolve_council() -> Result {
-        // Stop running election
-        if Self::is_election_running() {
-            // cannot fail since we checked that election is running and we are using root
-            // origin.
-            Self::force_stop_election(system::RawOrigin::Root.into())?;
-        }
-
-        // Return stakes from the council seat to their stake holders
-        Self::initialize_transferable_stakes(<council::Module<T>>::active_council());
-        Self::unlock_transferable_stakes();
-        Self::clear_transferable_stakes();
-
-        // Clear the council seats
-        // Cannot fail when passing root origin
-        council::Module::<T>::set_council(system::RawOrigin::Root.into(), vec![])?;
-        council::TermEndsAt::<T>::put(system::Module::<T>::block_number());
-
-        // Start a new election after clearing the council
-        Self::start_election(vec![])?;
-
-        Ok(())
-    }
-
     // PRIVATE MUTABLES
 
     /// Starts an election. Will fail if an election is already running

+ 6 - 6
runtime/src/lib.rs

@@ -871,11 +871,11 @@ impl proposals_codex::Trait for Runtime {
 }
 
 construct_runtime!(
-	pub enum Runtime where
-		Block = Block,
-		NodeBlock = opaque::Block,
-		UncheckedExtrinsic = UncheckedExtrinsic
-	{
+    pub enum Runtime where
+        Block = Block,
+        NodeBlock = opaque::Block,
+        UncheckedExtrinsic = UncheckedExtrinsic
+    {
         // Substrate
         System: system::{Module, Call, Storage, Config, Event},
         Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
@@ -917,7 +917,7 @@ construct_runtime!(
         ProposalsDiscussion: proposals_discussion::{Module, Call, Storage, Event<T>},
         ProposalsCodex: proposals_codex::{Module, Call, Storage, Error, Config<T>},
         // ---
-	}
+    }
 );
 
 /// The address format for describing accounts.

+ 6 - 68
runtime/src/migration.rs

@@ -30,13 +30,6 @@ impl<T: Trait> Module<T> {
                 );
             });
 
-        // Reset Council
-        governance::election::Module::<T>::stop_election_and_dissolve_council()
-            .err()
-            .map(|err| {
-                debug::warn!("Failed to dissolve council during migration: {:?}", err);
-            });
-
         // Reset working group mint capacity
         content_working_group::Module::<T>::set_mint_capacity(
             system::RawOrigin::Root.into(),
@@ -50,66 +43,6 @@ impl<T: Trait> Module<T> {
             );
         });
 
-        // Deactivate active curators
-        let termination_reason = "resetting curators".as_bytes().to_vec();
-
-        for (curator_id, ref curator) in content_working_group::CuratorById::<T>::enumerate() {
-            // Skip non-active curators
-            if curator.stage != content_working_group::CuratorRoleStage::Active {
-                continue;
-            }
-
-            content_working_group::Module::<T>::terminate_curator_role_as_root(
-                system::RawOrigin::Root.into(),
-                curator_id,
-                termination_reason.clone(),
-            )
-            .err()
-            .map(|err| {
-                debug::warn!(
-                    "Failed to terminate curator {:?} during migration: {:?}",
-                    curator_id,
-                    err
-                );
-            });
-        }
-
-        // Deactivate all storage providers, except Joystream providers (member id 0 in Rome runtime)
-        let joystream_providers =
-            roles::actors::AccountIdsByMemberId::<T>::get(T::MemberId::from(0));
-
-        // Is there an intersect() like call to check if vector contains some elements from
-        // another vector?.. below implementation just seems
-        // silly to have to do in a filter predicate.
-        let storage_providers_to_remove: Vec<T::AccountId> =
-            roles::actors::Module::<T>::actor_account_ids()
-                .into_iter()
-                .filter(|account| {
-                    for provider in joystream_providers.as_slice() {
-                        if *account == *provider {
-                            return false;
-                        }
-                    }
-                    return true;
-                })
-                .collect();
-
-        for provider in storage_providers_to_remove {
-            roles::actors::Module::<T>::remove_actor(system::RawOrigin::Root.into(), provider)
-                .err()
-                .map(|err| {
-                    debug::warn!(
-                        "Failed to remove storage provider during migration: {:?}",
-                        err
-                    );
-                });
-        }
-
-        // Remove any pending storage entry requests, no stake is lost because only a fee is paid
-        // to make a request.
-        let no_requests: roles::actors::Requests<T> = vec![];
-        roles::actors::RoleEntryRequests::<T>::put(no_requests);
-
         // Set Storage Role reward to zero
         if let Some(parameters) =
             roles::actors::Parameters::<T>::get(roles::actors::Role::StorageProvider)
@@ -130,6 +63,7 @@ impl<T: Trait> Module<T> {
                 );
             });
         }
+
         proposals_codex::Module::<T>::set_default_config_values();
 
         Self::deposit_event(RawEvent::Migrated(
@@ -140,7 +74,11 @@ impl<T: Trait> Module<T> {
 }
 
 pub trait Trait:
-    system::Trait + governance::election::Trait + content_working_group::Trait + roles::actors::Trait + proposals_codex::Trait
+    system::Trait
+    + governance::election::Trait
+    + content_working_group::Trait
+    + roles::actors::Trait
+    + proposals_codex::Trait
 {
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
 }