diff --git a/crates/pallet-domains/src/benchmarking.rs b/crates/pallet-domains/src/benchmarking.rs index ad0556922b..7a1919c12a 100644 --- a/crates/pallet-domains/src/benchmarking.rs +++ b/crates/pallet-domains/src/benchmarking.rs @@ -419,31 +419,6 @@ mod benchmarks { ); } - #[benchmark] - fn auto_stake_block_rewards() { - let nominator = account("nominator", 1, SEED); - let minimum_nominator_stake = T::Currency::minimum_balance(); - T::Currency::set_balance( - &nominator, - minimum_nominator_stake + T::Currency::minimum_balance(), - ); - - let domain_id = register_domain::(); - let (_, operator_id) = register_helper_operator::(domain_id, minimum_nominator_stake); - assert_ok!(Domains::::nominate_operator( - RawOrigin::Signed(nominator.clone()).into(), - operator_id, - minimum_nominator_stake, - )); - do_finalize_domain_staking::(domain_id, 1u32.into()) - .expect("finalize domain staking should success"); - - #[extrinsic_call] - _(RawOrigin::Signed(nominator.clone()), operator_id); - - assert_eq!(PreferredOperator::::get(nominator), Some(operator_id)); - } - fn register_runtime() -> RuntimeId { let runtime_blob = include_bytes!("../res/evm_domain_test_runtime.compact.compressed.wasm").to_vec(); diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index 08b207bb9c..b8f412b408 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -35,7 +35,7 @@ pub mod weights; extern crate alloc; use crate::block_tree::verify_execution_receipt; -use crate::staking::{do_nominate_operator, OperatorStatus}; +use crate::staking::OperatorStatus; use codec::{Decode, Encode}; use frame_support::ensure; use frame_support::traits::fungible::{Inspect, InspectHold}; @@ -128,9 +128,9 @@ mod pallet { #[cfg(not(feature = "runtime-benchmarks"))] use crate::staking::do_reward_operators; use crate::staking::{ - do_auto_stake_block_rewards, do_deregister_operator, do_nominate_operator, - do_register_operator, do_slash_operators, do_switch_operator_domain, do_withdraw_stake, - Error as StakingError, Nominator, Operator, OperatorConfig, StakingSummary, Withdraw, + do_deregister_operator, do_nominate_operator, do_register_operator, do_slash_operators, + do_switch_operator_domain, do_withdraw_stake, Error as StakingError, Nominator, Operator, + OperatorConfig, StakingSummary, Withdraw, }; #[cfg(not(feature = "runtime-benchmarks"))] use crate::staking_epoch::do_unlock_pending_withdrawals; @@ -574,12 +574,6 @@ mod pallet { pub(super) type LastEpochStakingDistribution = StorageMap<_, Identity, DomainId, ElectionVerificationParams>, OptionQuery>; - /// A preferred Operator for a given Farmer, enabling automatic staking of block rewards. - /// For the auto-staking to succeed, the Farmer must also be a Nominator of the preferred Operator. - #[pallet::storage] - pub(super) type PreferredOperator = - StorageMap<_, Identity, NominatorId, OperatorId, OptionQuery>; - #[derive(TypeInfo, Encode, Decode, PalletError, Debug, PartialEq)] pub enum BundleError { /// Can not find the operator for given operator id. @@ -1149,24 +1143,6 @@ mod pallet { Ok(()) } - #[pallet::call_index(10)] - #[pallet::weight(T::WeightInfo::auto_stake_block_rewards())] - pub fn auto_stake_block_rewards( - origin: OriginFor, - operator_id: OperatorId, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - - do_auto_stake_block_rewards::(who.clone(), operator_id).map_err(Error::::from)?; - - Self::deposit_event(Event::PreferredOperator { - operator_id, - nominator_id: who, - }); - - Ok(()) - } - /// Extrinsic to update domain's operator allow list. /// Note: /// - If the previous allowed list is set to specific operators and new allow list is set @@ -1174,7 +1150,7 @@ mod pallet { /// - If the previous allowed list is set to `Anyone` or specific operators and the new /// allow list is set to specific operators, then all the registered not allowed operators /// will continue to operate until they de-register themselves. - #[pallet::call_index(12)] + #[pallet::call_index(10)] #[pallet::weight(Weight::from_all(10_000))] pub fn update_domain_operator_allow_list( origin: OriginFor, @@ -1784,22 +1760,6 @@ impl Pallet { }) } - /// Increase the nomination stake by `reward` to the preferred operator of `who`. - /// Preference is removed if the nomination fails. - pub fn on_block_reward(who: NominatorId, reward: BalanceOf) { - PreferredOperator::::mutate_exists(who.clone(), |maybe_preferred_operator_id| { - if let Some(operator_id) = maybe_preferred_operator_id { - if let Err(err) = do_nominate_operator::(*operator_id, who, reward) { - log::trace!( - target: "runtime::domains", - "Failed to stake the reward amount to preferred operator: {err:?}. Removing preference." - ); - maybe_preferred_operator_id.take(); - } - } - }); - } - /// Returns if there are any ERs in the challenge period that have non empty extrinsics. /// Note that Genesis ER is also considered special and hence non empty pub fn non_empty_er_exists(domain_id: DomainId) -> bool { diff --git a/crates/pallet-domains/src/staking.rs b/crates/pallet-domains/src/staking.rs index 39c6f1fa0b..c937687ea7 100644 --- a/crates/pallet-domains/src/staking.rs +++ b/crates/pallet-domains/src/staking.rs @@ -4,7 +4,7 @@ use crate::pallet::{ DomainRegistry, DomainStakingSummary, NextOperatorId, NominatorCount, Nominators, OperatorIdOwner, Operators, PendingDeposits, PendingNominatorUnlocks, PendingOperatorDeregistrations, PendingOperatorSwitches, PendingOperatorUnlocks, - PendingSlashes, PendingStakingOperationCount, PendingWithdrawals, PreferredOperator, + PendingSlashes, PendingStakingOperationCount, PendingWithdrawals, }; use crate::staking_epoch::{mint_funds, PendingNominatorUnlock, PendingOperatorSlashInfo}; use crate::{BalanceOf, Config, Event, HoldIdentifier, NominatorId, Pallet}; @@ -529,29 +529,6 @@ pub(crate) fn do_reward_operators( }) } -/// Sets Operator as the preferred one to auto stake the block rewards. -/// Caller must be nominator of the Operator. -pub(crate) fn do_auto_stake_block_rewards( - nominator_id: NominatorId, - operator_id: OperatorId, -) -> Result<(), Error> { - // must be a nominator of this operator - ensure!( - Nominators::::contains_key(operator_id, nominator_id.clone()), - Error::UnknownNominator - ); - - let operator = Operators::::get(operator_id).ok_or(Error::UnknownOperator)?; - - ensure!( - operator.status == OperatorStatus::Registered, - Error::OperatorNotRegistered - ); - - PreferredOperator::::insert(nominator_id, operator_id); - Ok(()) -} - /// Freezes the slashed operators and moves the operator to be removed once the domain they are /// operating finishes the epoch. pub(crate) fn do_slash_operators>( @@ -636,7 +613,7 @@ pub(crate) mod tests { Config, DomainRegistry, DomainStakingSummary, NextOperatorId, NominatorCount, OperatorIdOwner, Operators, PendingDeposits, PendingNominatorUnlocks, PendingOperatorDeregistrations, PendingOperatorSwitches, PendingSlashes, - PendingStakingOperationCount, PendingUnlocks, PendingWithdrawals, PreferredOperator, + PendingStakingOperationCount, PendingUnlocks, PendingWithdrawals, }; use crate::staking::{ do_nominate_operator, do_reward_operators, do_slash_operators, do_withdraw_stake, @@ -1677,69 +1654,6 @@ pub(crate) mod tests { }); } - #[test] - fn auto_stake_block_rewards() { - let domain_id = DomainId::new(0); - let operator_account = 1; - let operator_free_balance = 1500 * SSC; - let operator_stake = 1000 * SSC; - let pair = OperatorPair::from_seed(&U256::from(0u32).into()); - - let nominator_account = 2; - let nominator_free_balance = 150 * SSC; - let nominator_stake = 100 * SSC; - let nominators = BTreeMap::from_iter(vec![( - nominator_account, - (nominator_free_balance, nominator_stake), - )]); - - let mut ext = new_test_ext(); - ext.execute_with(|| { - let (operator_id, _) = register_operator( - domain_id, - operator_account, - operator_free_balance, - operator_stake, - 10 * SSC, - pair.public(), - nominators, - ); - - // Finalize pending deposit - do_finalize_domain_current_epoch::(domain_id, 0).unwrap(); - assert!(!PreferredOperator::::contains_key(nominator_account)); - - let res = Domains::auto_stake_block_rewards( - RuntimeOrigin::signed(nominator_account), - operator_id, - ); - assert_ok!(res); - - assert_eq!( - operator_id, - PreferredOperator::::get(nominator_account).unwrap() - ); - - // should auto deposit - Domains::on_block_reward(nominator_account, 10 * SSC); - let deposit = PendingDeposits::::get(operator_id, nominator_account).unwrap(); - assert_eq!(deposit, 10 * SSC); - - // an issues with nominator will lead to removal of preference - Operators::::mutate(operator_id, |maybe_operator| { - let operator = maybe_operator.as_mut().unwrap(); - operator.status = OperatorStatus::Deregistered; - }); - Domains::on_block_reward(nominator_account, 10 * SSC); - - // deposit is still 10 SSC - let deposit = PendingDeposits::::get(operator_id, nominator_account).unwrap(); - assert_eq!(deposit, 10 * SSC); - // no preference - assert!(!PreferredOperator::::contains_key(nominator_account)); - }); - } - #[test] fn pending_staking_operation_limit() { let domain_id = DomainId::new(0); diff --git a/crates/pallet-domains/src/staking_epoch.rs b/crates/pallet-domains/src/staking_epoch.rs index 6dd5002fed..44b3791fca 100644 --- a/crates/pallet-domains/src/staking_epoch.rs +++ b/crates/pallet-domains/src/staking_epoch.rs @@ -4,7 +4,7 @@ use crate::pallet::{ DomainStakingSummary, LastEpochStakingDistribution, Nominators, OperatorIdOwner, Operators, PendingDeposits, PendingNominatorUnlocks, PendingOperatorDeregistrations, PendingOperatorSwitches, PendingOperatorUnlocks, PendingSlashes, PendingStakingOperationCount, - PendingUnlocks, PendingWithdrawals, PreferredOperator, + PendingUnlocks, PendingWithdrawals, }; use crate::staking::{Error as TransitionError, Nominator, OperatorStatus, Withdraw}; use crate::{ @@ -246,8 +246,6 @@ fn unlock_operator(operator_id: OperatorId) -> Result<(), Error> { ) .map_err(|_| TransitionError::RemoveLock)?; - remove_preferred_operator::(nominator_id, &operator_id); - // update pool's remaining shares and stake total_shares = total_shares .checked_sub(&nominator.shares) @@ -457,17 +455,6 @@ pub(crate) fn mint_funds( Ok(()) } -/// Remove the preference if the operator id matches -fn remove_preferred_operator(nominator_id: NominatorId, operator_id: &OperatorId) { - PreferredOperator::::mutate_exists(nominator_id, |maybe_preferred_operator| { - if let Some(preferred_operator_id) = maybe_preferred_operator { - if preferred_operator_id == operator_id { - maybe_preferred_operator.take(); - } - } - }); -} - #[allow(clippy::too_many_arguments)] fn finalize_nominator_withdrawal( domain_id: DomainId, @@ -504,7 +491,6 @@ fn finalize_nominator_withdrawal( ) .map_err(|_| TransitionError::RemoveLock)?; - remove_preferred_operator::(nominator_id.clone(), &operator_id); (nominator_staked_amount, nominator.shares) } Withdraw::Some(withdraw_amount) => { @@ -693,8 +679,6 @@ pub(crate) fn do_finalize_slashed_operators( .checked_sub(&locked_amount) .ok_or(TransitionError::BalanceUnderflow)?; - remove_preferred_operator::(nominator_id, &operator_id); - Ok(()) })?; @@ -749,12 +733,11 @@ mod tests { use crate::pallet::{ DomainRegistry, DomainStakingSummary, LastEpochStakingDistribution, NominatorCount, Nominators, OperatorIdOwner, Operators, PendingDeposits, PendingOperatorSwitches, - PendingOperatorUnlocks, PendingUnlocks, PendingWithdrawals, PreferredOperator, + PendingOperatorUnlocks, PendingUnlocks, PendingWithdrawals, }; use crate::staking::tests::register_operator; use crate::staking::{ - do_auto_stake_block_rewards, do_deregister_operator, do_nominate_operator, - do_reward_operators, StakingSummary, + do_deregister_operator, do_nominate_operator, do_reward_operators, StakingSummary, }; use crate::staking_epoch::{ do_finalize_domain_current_epoch, do_finalize_operator_deregistrations, @@ -897,16 +880,6 @@ mod tests { .unwrap() } - for nominator in &nominators { - if !nominator.1 .1.is_zero() { - do_auto_stake_block_rewards::(*nominator.0, operator_id).unwrap(); - assert_eq!( - operator_id, - PreferredOperator::::get(nominator.0).unwrap() - ) - } - } - // de-register operator do_deregister_operator::(operator_account, operator_id).unwrap(); @@ -935,10 +908,6 @@ mod tests { PendingWithdrawals::::get(operator_id, *nominator.0), None ); - - if !nominator.1 .0.is_zero() { - assert!(!PreferredOperator::::contains_key(nominator.0)) - } } assert_eq!(Operators::::get(operator_id), None); diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index b601a63691..bd880ef681 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -107,7 +107,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_version: 1, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 0, + transaction_version: 1, state_version: 0, }; @@ -637,14 +637,6 @@ impl pallet_domains::Config for Runtime { type SudoId = SudoId; } -pub struct StakingOnReward; - -impl pallet_rewards::OnReward for StakingOnReward { - fn on_reward(account: AccountId, reward: Balance) { - Domains::on_block_reward(account, reward); - } -} - parameter_types! { pub const BlockReward: Balance = SSC / (ExpectedVotesPerBlock::get() as Balance + 1); pub const VoteReward: Balance = SSC / (ExpectedVotesPerBlock::get() as Balance + 1); @@ -658,7 +650,7 @@ impl pallet_rewards::Config for Runtime { type FindBlockRewardAddress = Subspace; type FindVotingRewardAddresses = Subspace; type WeightInfo = (); - type OnReward = StakingOnReward; + type OnReward = (); } impl pallet_runtime_configs::Config for Runtime {