From 697f1992d18536b54b2dc4a342cd5c759eda70c9 Mon Sep 17 00:00:00 2001 From: vedhavyas Date: Mon, 20 May 2024 13:22:44 +0530 Subject: [PATCH] remove switch domain operator completely --- crates/pallet-domains/src/benchmarking.rs | 25 ---------- crates/pallet-domains/src/lib.rs | 6 --- crates/pallet-domains/src/staking.rs | 16 ++---- crates/pallet-domains/src/staking_epoch.rs | 58 +--------------------- 4 files changed, 4 insertions(+), 101 deletions(-) diff --git a/crates/pallet-domains/src/benchmarking.rs b/crates/pallet-domains/src/benchmarking.rs index afbba0f5e8..f9191f710e 100644 --- a/crates/pallet-domains/src/benchmarking.rs +++ b/crates/pallet-domains/src/benchmarking.rs @@ -651,31 +651,6 @@ mod benchmarks { assert!(!operator.deposits_in_epoch.is_zero()); } - // TODO: `switch_domain` is not supported currently due to incompatible with lazily slashing - // enable this test when `switch_domain` is ready - // #[benchmark] - // fn switch_domain() { - // let domain1_id = register_domain::(); - // let domain2_id = register_domain::(); - - // let (operator_owner, operator_id) = - // register_helper_operator::(domain1_id, T::Currency::minimum_balance()); - - // #[extrinsic_call] - // _( - // RawOrigin::Signed(operator_owner.clone()), - // operator_id, - // domain2_id, - // ); - - // let operator = Operators::::get(operator_id).expect("operator must exist"); - // assert_eq!(operator.next_domain_id, domain2_id); - - // let pending_switch = - // PendingOperatorSwitches::::get(domain1_id).expect("pending switch must exist"); - // assert!(pending_switch.contains(&operator_id)); - // } - #[benchmark] fn deregister_operator() { let domain_id = register_domain::(); diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index f19b42ab55..001aad3aee 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -488,12 +488,6 @@ mod pallet { OptionQuery, >; - /// Temporary hold of all the operators who decided to switch to another domain. - /// Once epoch is complete, these operators are added to new domains under next_operators. - #[pallet::storage] - pub(super) type PendingOperatorSwitches = - StorageMap<_, Identity, DomainId, BTreeSet, OptionQuery>; - /// Share price for the operator pool at the end of Domain epoch. // TODO: currently unbounded storage. #[pallet::storage] diff --git a/crates/pallet-domains/src/staking.rs b/crates/pallet-domains/src/staking.rs index d33ad94a34..75edff5bce 100644 --- a/crates/pallet-domains/src/staking.rs +++ b/crates/pallet-domains/src/staking.rs @@ -6,8 +6,8 @@ extern crate alloc; use crate::bundle_storage_fund::{self, deposit_reserve_for_storage_fund}; use crate::pallet::{ Deposits, DomainRegistry, DomainStakingSummary, NextOperatorId, NominatorCount, - OperatorIdOwner, OperatorSigningKey, Operators, PendingOperatorSwitches, PendingSlashes, - PendingStakingOperationCount, Withdrawals, + OperatorIdOwner, OperatorSigningKey, Operators, PendingSlashes, PendingStakingOperationCount, + Withdrawals, }; use crate::staking_epoch::{mint_funds, mint_into_treasury}; use crate::{ @@ -1244,16 +1244,6 @@ pub(crate) fn do_slash_operators( operator.update_status(OperatorStatus::Slashed); stake_summary.next_operators.remove(operator_id); - // remove any current operator switches - PendingOperatorSwitches::::mutate( - operator.current_domain_id, - |maybe_switching_operators| { - if let Some(switching_operators) = maybe_switching_operators.as_mut() { - switching_operators.remove(operator_id); - } - }, - ); - pending_slashes.insert(*operator_id); PendingSlashes::::insert(operator.current_domain_id, pending_slashes); Pallet::::deposit_event(Event::OperatorSlashed { @@ -1772,7 +1762,7 @@ pub(crate) mod tests { ) ); - // domain switch will not work since the operator is frozen + // operator nomination will not work since the operator is already de-registered let new_domain_id = DomainId::new(1); let domain_config = DomainConfig { domain_name: String::from_utf8(vec![0; 1024]).unwrap(), diff --git a/crates/pallet-domains/src/staking_epoch.rs b/crates/pallet-domains/src/staking_epoch.rs index 1d0718cc53..38a0e5cdf1 100644 --- a/crates/pallet-domains/src/staking_epoch.rs +++ b/crates/pallet-domains/src/staking_epoch.rs @@ -2,8 +2,7 @@ use crate::bundle_storage_fund::deposit_reserve_for_storage_fund; use crate::pallet::{ AccumulatedTreasuryFunds, Deposits, DomainStakingSummary, LastEpochStakingDistribution, - OperatorIdOwner, Operators, PendingOperatorSwitches, PendingSlashes, - PendingStakingOperationCount, Withdrawals, + OperatorIdOwner, Operators, PendingSlashes, PendingStakingOperationCount, Withdrawals, }; use crate::staking::{ do_convert_previous_epoch_deposits, do_convert_previous_epoch_withdrawal, DomainEpoch, @@ -29,7 +28,6 @@ use sp_std::collections::btree_set::BTreeSet; #[derive(TypeInfo, Encode, Decode, PalletError, Debug, PartialEq)] pub enum Error { - FinalizeSwitchOperatorDomain(TransitionError), FinalizeDomainEpochStaking(TransitionError), OperatorRewardStaking(TransitionError), SlashOperator(TransitionError), @@ -57,9 +55,6 @@ pub(crate) fn do_finalize_domain_current_epoch( let slashed_nominator_count = do_finalize_slashed_operators::(domain_id).map_err(Error::SlashOperator)?; - // finalize any operator switches - do_finalize_switch_operator_domain::(domain_id)?; - // finalize any withdrawals and then deposits let (completed_epoch_index, finalized_operator_count) = do_finalize_domain_epoch_staking::(domain_id)?; @@ -159,57 +154,6 @@ pub(crate) fn operator_take_reward_tax_and_stake( Ok(rewarded_operator_count) } -/// Add all the switched operators to new domain as next operators. -/// Once the new domain's epoch is complete, operators are included in the next epoch. -fn do_finalize_switch_operator_domain(domain_id: DomainId) -> Result<(), Error> { - if let Some(operators) = PendingOperatorSwitches::::take(domain_id) { - operators.into_iter().try_for_each(|operator_id| { - switch_operator::(domain_id, operator_id) - .map_err(Error::FinalizeSwitchOperatorDomain) - })?; - } - - Ok(()) -} - -fn switch_operator( - domain_id: DomainId, - operator_id: OperatorId, -) -> Result<(), TransitionError> { - let previous_domain_summary = - DomainStakingSummary::::get(domain_id).ok_or(TransitionError::DomainNotInitialized)?; - - // finalize operator staking before moving to next domain - // this also sets the operator epoch price. - do_finalize_operator_epoch_staking::( - domain_id, - operator_id, - previous_domain_summary.current_epoch_index, - )?; - - Operators::::try_mutate(operator_id, |maybe_operator| { - let operator = maybe_operator - .as_mut() - .ok_or(TransitionError::UnknownOperator)?; - - // operator is not registered, just no-op - if *operator.status::(operator_id) != OperatorStatus::Registered { - return Ok(()); - } - - operator.current_domain_id = operator.next_domain_id; - DomainStakingSummary::::try_mutate(operator.current_domain_id, |maybe_stake_summary| { - let stake_summary = maybe_stake_summary - .as_mut() - .ok_or(TransitionError::DomainNotInitialized)?; - - stake_summary.next_operators.insert(operator_id); - - Ok(()) - }) - }) -} - pub(crate) fn do_finalize_domain_epoch_staking( domain_id: DomainId, ) -> Result<(EpochIndex, u32), Error> {