Repository: chainx-org/ChainX (language: rust)

Issue:
Remove imortal validators once network is stable
https://github.com/chainx-org/ChainX/blob/80f98efe0359dfe18f3419659bfd1fe3b30c60ef/xpallets/mining/staking/src/election.rs#L85


Discussion / hints:

Fix patch:
diff --git a/xpallets/mining/staking/src/election.rs b/xpallets/mining/staking/src/election.rs
index abbbffb1f..5626d8e68 100644
--- a/xpallets/mining/staking/src/election.rs
+++ b/xpallets/mining/staking/src/election.rs
@@ -82,37 +82,6 @@ impl<T: Trait> Module<T> {
             .map(|(_, v)| v)
             .collect::<Vec<_>>();
 
-        // Remove the immortals once Sudo is removed.
-        if let Some(immortals) = Self::immortals() {
-            // since the genesis validators have the same votes, it's ok to not sort them.
-            let unwanted_losers = immortals
-                .iter()
-                .filter(|i| !validators.contains(i))
-                .collect::<Vec<_>>();
-
-            // If we are here, the returned validators are not ensured to be sorted.
-            if !unwanted_losers.is_empty() {
-                let mut validators_without_immortals = validators
-                    .into_iter()
-                    .filter(|v| !immortals.contains(v))
-                    .collect::<Vec<_>>();
-
-                for _ in unwanted_losers {
-                    if !validators_without_immortals.is_empty() {
-                        // Pop out the validator with fewest votes.
-                        validators_without_immortals.pop();
-                    }
-                }
-
-                let mut validators =
-                    Vec::with_capacity(validators_without_immortals.len() + immortals.len());
-                validators.extend_from_slice(&validators_without_immortals);
-                validators.extend_from_slice(&immortals);
-
-                return Some(validators);
-            }
-        }
-
         // Always return Some(new_validators).
         Some(validators)
     }
diff --git a/xpallets/mining/staking/src/lib.rs b/xpallets/mining/staking/src/lib.rs
index f3cfa7872..4a4a961d3 100644
--- a/xpallets/mining/staking/src/lib.rs
+++ b/xpallets/mining/staking/src/lib.rs
@@ -340,6 +340,11 @@ decl_module! {
 
         fn deposit_event() = default;
 
+        fn on_runtime_upgrade() -> frame_support::weights::Weight {
+            Immortals::<T>::kill();
+            1
+        }
+
         /// Nominate the `target` with `value` of the origin account's balance locked.
         #[weight = T::WeightInfo::bond()]
         pub fn bond(origin, target: <T::Lookup as StaticLookup>::Source, #[compact] value: BalanceOf<T>) {


Test patch: