diff --git a/pallet/account-migration/src/mock.rs b/pallet/account-migration/src/mock.rs index 6956cc447..b30caa9f3 100644 --- a/pallet/account-migration/src/mock.rs +++ b/pallet/account-migration/src/mock.rs @@ -168,7 +168,6 @@ impl darwinia_deposit::Config for Runtime { impl darwinia_staking::Config for Runtime { type Deposit = Deposit; type Kton = Dummy; - type MaxCommission = (); type MaxDeposits = (); type MaxUnstakings = (); type MinStakingDuration = (); diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index dfd3f5795..7c0361b44 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -110,10 +110,6 @@ pub mod pallet { /// Deposit [`StakeExt`] interface. type Deposit: StakeExt; - /// Maximum commission rate. - #[pallet::constant] - type MaxCommission: Get; - /// Minimum time to stake at least. #[pallet::constant] type MinStakingDuration: Get; @@ -168,8 +164,6 @@ pub mod pallet { #[pallet::error] pub enum Error { - /// Commission rate must be less than maximum commission rate. - CommissionTooHigh, /// Exceed maximum deposit count. ExceedMaxDeposits, /// Exceed maximum unstaking/unbonding count. @@ -464,10 +458,6 @@ pub mod pallet { pub fn collect(origin: OriginFor, commission: Perbill) -> DispatchResult { let who = ensure_signed(origin)?; - if commission > T::MaxCommission::get() { - Err(>::CommissionTooHigh)?; - } - >::mutate(&who, |c| *c = Some(commission)); Self::deposit_event(Event::CommissionUpdated { who, commission }); @@ -859,7 +849,7 @@ pub mod pallet { for n_exposure in c_exposure.nominators { let n_payout = - Perbill::from_rational(n_exposure.value, c_exposure.total) * n_payout; + Perbill::from_rational(n_exposure.vote, c_exposure.vote) * n_payout; if c == n_exposure.who { // If the collator nominated themselves. @@ -901,24 +891,25 @@ pub mod pallet { /// /// This should only be called by the [`pallet_session::SessionManager::new_session`]. pub fn elect() -> Vec { - let mut collators = >::iter_keys() - .map(|c| { - let mut t_power = 0; - let i_exposures = >::iter() + let mut collators = >::iter() + .map(|(c, cm)| { + let scaler = (Perbill::one() - cm); + let mut collator_v = 0; + let nominators = >::iter() .filter_map(|(n, c_)| { if c_ == c { - let n_power = Self::power_of(&n); + let nominator_v = scaler * Self::power_of(&n); - t_power += n_power; + collator_v += nominator_v; - Some(IndividualExposure { who: n, value: n_power }) + Some(IndividualExposure { who: n, vote: nominator_v }) } else { None } }) .collect(); - ((c, Exposure { total: t_power, nominators: i_exposures }), t_power) + ((c, Exposure { vote: collator_v, nominators }), collator_v) }) .collect::>(); @@ -940,6 +931,7 @@ pub use pallet::*; type RewardPoint = u32; type Power = u32; +type Vote = u32; type DepositId = <::Deposit as Stake>::Item; type NegativeImbalance = <::RingCurrency as Currency< @@ -997,18 +989,18 @@ pub struct Exposure where AccountId: PartialEq, { - /// The total power backing this collator. - pub total: Power, - /// Nominators' stake power. + /// The total vote backing this collator. + pub vote: Vote, + /// Nominator staking map. pub nominators: Vec>, } /// A snapshot of the stake backing a single collator in the system. #[cfg(not(feature = "try-runtime"))] #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebug)] pub struct Exposure { - /// The total power backing this collator. - pub total: Power, - /// Nominators' stake power. + /// The total vote backing this collator. + pub vote: Vote, + /// Nominator staking map. pub nominators: Vec>, } /// A snapshot of the staker's state. @@ -1020,8 +1012,8 @@ where { /// Nominator. pub who: AccountId, - /// Nominator's stake power. - pub value: Power, + /// Nominator's staking vote. + pub vote: Vote, } /// A snapshot of the staker's state. #[cfg(not(feature = "try-runtime"))] @@ -1029,8 +1021,8 @@ where pub struct IndividualExposure { /// Nominator. pub who: AccountId, - /// Nominator's stake power. - pub value: Power, + /// Nominator's staking vote. + pub vote: Vote, } // Add reward points to block authors: diff --git a/pallet/staking/src/mock.rs b/pallet/staking/src/mock.rs index 72cc79f37..11acfb7f2 100644 --- a/pallet/staking/src/mock.rs +++ b/pallet/staking/src/mock.rs @@ -245,13 +245,11 @@ impl darwinia_staking::Stake for KtonStaking { } } frame_support::parameter_types! { - pub const MaxCommission: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(99); pub const PayoutFraction: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(40); } impl darwinia_staking::Config for Runtime { type Deposit = Deposit; type Kton = KtonStaking; - type MaxCommission = MaxCommission; type MaxDeposits = ::MaxDeposits; type MaxUnstakings = frame_support::traits::ConstU32<16>; type MinStakingDuration = frame_support::traits::ConstU64<3>; diff --git a/pallet/staking/src/tests.rs b/pallet/staking/src/tests.rs index 2937e4865..a63b271a3 100644 --- a/pallet/staking/src/tests.rs +++ b/pallet/staking/src/tests.rs @@ -363,11 +363,6 @@ fn collect_should_work() { assert_ok!(Staking::collect(RuntimeOrigin::signed(1), c)); assert_eq!(Staking::collator_of(1).unwrap(), c); }); - - assert_noop!( - Staking::collect(RuntimeOrigin::signed(1), Perbill::from_percent(100)), - >::CommissionTooHigh - ); }); } @@ -563,16 +558,16 @@ fn payout_should_work() { let session_duration = Duration::new(6 * 60 * 60, 0).as_millis(); Staking::payout(session_duration, Staking::elapsed_time()); let rewards = [ - 1_366_118_870_124_739_965_121_u128, - 2_550_088_512_393_184_504_844, + 1_366_118_850_452_628_471_390, + 2_550_088_490_535_282_845_143, 3_551_909_019_701_415_672_898, - 4_371_580_342_869_154_734_956, - 5_009_102_454_574_024_616_391, - 4_098_356_544_800_514_916_261, - 2_914_386_902_532_070_376_538, + 4_371_580_329_754_413_739_136, + 5_009_102_470_967_450_861_167, + 4_098_356_559_554_598_536_559, + 2_914_386_924_389_972_036_239, 1_912_566_395_223_839_208_483, - 1_092_895_072_056_100_146_426, - 455_372_960_351_230_264_991, + 1_092_895_081_892_155_893_291, + 455_372_941_225_566_312_752, ]; (1..=10) .zip(rewards.iter()) diff --git a/precompile/staking/src/mock.rs b/precompile/staking/src/mock.rs index 76396ac59..61f5862db 100644 --- a/precompile/staking/src/mock.rs +++ b/precompile/staking/src/mock.rs @@ -230,13 +230,9 @@ impl darwinia_staking::Stake for KtonStaking { } } -frame_support::parameter_types! { - pub const MaxCommission: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(99); -} impl darwinia_staking::Config for TestRuntime { type Deposit = Deposit; type Kton = KtonStaking; - type MaxCommission = MaxCommission; type MaxDeposits = ::MaxDeposits; type MaxUnstakings = frame_support::traits::ConstU32<16>; type MinStakingDuration = frame_support::traits::ConstU64<3>; diff --git a/runtime/crab/src/pallets/staking.rs b/runtime/crab/src/pallets/staking.rs index 73b78050c..e7161784a 100644 --- a/runtime/crab/src/pallets/staking.rs +++ b/runtime/crab/src/pallets/staking.rs @@ -71,14 +71,12 @@ impl darwinia_staking::Stake for KtonStaking { } frame_support::parameter_types! { - pub const MaxCommission: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(30); pub const PayoutFraction: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(40); } impl darwinia_staking::Config for Runtime { type Deposit = Deposit; type Kton = KtonStaking; - type MaxCommission = MaxCommission; type MaxDeposits = ::MaxDeposits; type MaxUnstakings = ConstU32<16>; type MinStakingDuration = MinStakingDuration; diff --git a/runtime/darwinia/src/pallets/staking.rs b/runtime/darwinia/src/pallets/staking.rs index 055228344..1ea8cc964 100644 --- a/runtime/darwinia/src/pallets/staking.rs +++ b/runtime/darwinia/src/pallets/staking.rs @@ -71,14 +71,12 @@ impl darwinia_staking::Stake for KtonStaking { } frame_support::parameter_types! { - pub const MaxCommission: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(30); pub const PayoutFraction: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(40); } impl darwinia_staking::Config for Runtime { type Deposit = Deposit; type Kton = KtonStaking; - type MaxCommission = MaxCommission; type MaxDeposits = ::MaxDeposits; type MaxUnstakings = ConstU32<16>; type MinStakingDuration = MinStakingDuration; diff --git a/runtime/pangolin/src/pallets/staking.rs b/runtime/pangolin/src/pallets/staking.rs index 1b69102c2..f7b268b83 100644 --- a/runtime/pangolin/src/pallets/staking.rs +++ b/runtime/pangolin/src/pallets/staking.rs @@ -67,14 +67,12 @@ impl darwinia_staking::Stake for KtonStaking { } frame_support::parameter_types! { - pub const MaxCommission: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(30); pub const PayoutFraction: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(40); } impl darwinia_staking::Config for Runtime { type Deposit = Deposit; type Kton = KtonStaking; - type MaxCommission = MaxCommission; type MaxDeposits = ::MaxDeposits; type MaxUnstakings = ConstU32<16>; type MinStakingDuration = ConstU32<{ 2 * MINUTES }>; diff --git a/runtime/pangoro/src/pallets/staking.rs b/runtime/pangoro/src/pallets/staking.rs index 9ef8fcf8c..5b0dd749c 100644 --- a/runtime/pangoro/src/pallets/staking.rs +++ b/runtime/pangoro/src/pallets/staking.rs @@ -67,14 +67,12 @@ impl darwinia_staking::Stake for KtonStaking { } frame_support::parameter_types! { - pub const MaxCommission: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(30); pub const PayoutFraction: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(40); } impl darwinia_staking::Config for Runtime { type Deposit = Deposit; type Kton = KtonStaking; - type MaxCommission = MaxCommission; type MaxDeposits = ::MaxDeposits; type MaxUnstakings = ConstU32<16>; type MinStakingDuration = ConstU32<{ 10 * MINUTES }>;