diff --git a/pallet/account-migration/src/mock.rs b/pallet/account-migration/src/mock.rs index 656158ed0..e9a138182 100644 --- a/pallet/account-migration/src/mock.rs +++ b/pallet/account-migration/src/mock.rs @@ -127,7 +127,6 @@ impl darwinia_deposit::Config for Runtime { type DepositMigrator = (); type Kton = Dummy; type MaxDeposits = frame_support::traits::ConstU32<512>; - type MinLockingAmount = (); type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = (); diff --git a/pallet/deposit/src/lib.rs b/pallet/deposit/src/lib.rs index e7e7693c1..2c54708d0 100644 --- a/pallet/deposit/src/lib.rs +++ b/pallet/deposit/src/lib.rs @@ -86,10 +86,6 @@ pub mod pallet { #[pallet::constant] type Treasury: Get; - /// Minimum amount to lock at least. - #[pallet::constant] - type MinLockingAmount: Get; - /// Maximum deposit count. /// /// In currently design, this should not be greater than `u16::MAX`. @@ -165,7 +161,7 @@ pub mod pallet { pub fn lock(origin: OriginFor, amount: Balance, months: u8) -> DispatchResult { let who = ensure_signed(origin)?; - if amount < T::MinLockingAmount::get() { + if amount == 0 { Err(>::LockAtLeastSome)?; } if months == 0 { diff --git a/pallet/deposit/src/mock.rs b/pallet/deposit/src/mock.rs index 3689e8a12..597aa70f3 100644 --- a/pallet/deposit/src/mock.rs +++ b/pallet/deposit/src/mock.rs @@ -90,7 +90,6 @@ impl crate::Config for Runtime { type DepositMigrator = (); type Kton = KtonMinting; type MaxDeposits = frame_support::traits::ConstU32<16>; - type MinLockingAmount = frame_support::traits::ConstU128; type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = (); diff --git a/pallet/staking/src/benchmarking.rs b/pallet/staking/src/benchmarking.rs index 5cf257aec..5a93666e8 100644 --- a/pallet/staking/src/benchmarking.rs +++ b/pallet/staking/src/benchmarking.rs @@ -138,7 +138,7 @@ mod benchmarks { let a = frame_benchmarking::whitelisted_caller::(); let a_cloned = a.clone(); - call_on_exposure!(>::insert( + call_on_cache_v1!(>::insert( &a, Exposure { commission: Perbill::zero(), diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index 24b9b5c98..53af7c9cc 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -50,7 +50,7 @@ pub use darwinia_staking_traits::*; use codec::FullCodec; use ethabi::{Function, Param, ParamType, StateMutability, Token}; // darwinia -use dc_types::{Balance, Moment, UNIT}; +use dc_types::{Balance, Moment}; // polkadot-sdk use frame_support::{ pallet_prelude::*, @@ -68,7 +68,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; /// Make it easier to call a function on a specific exposure storage. #[macro_export] -macro_rules! call_on_exposure { +macro_rules! call_on_cache_v1 { ($s_e:expr, <$s:ident<$t:ident>>$($f:tt)*) => {{ match $s_e { ($crate::CacheState::$s, _, _) => Ok(<$crate::ExposureCache0<$t>>$($f)*), @@ -84,12 +84,12 @@ macro_rules! call_on_exposure { (<$s:ident<$t:ident>>$($f:tt)*) => {{ let s = <$crate::CacheStates<$t>>::get(); - $crate::call_on_exposure!(s, <$s<$t>>$($f)*) + $crate::call_on_cache_v1!(s, <$s<$t>>$($f)*) }}; } /// Make it easier to call a function on a specific collators storage. #[macro_export] -macro_rules! call_on_cache { +macro_rules! call_on_cache_v2 { ($s_e:expr, <$s:ident<$t:ident>>$($f:tt)*) => {{ match $s_e { ($crate::CacheState::$s, _, _) => Ok(<$crate::CollatorsCache0<$t>>$($f)*), @@ -105,7 +105,7 @@ macro_rules! call_on_cache { (<$s:ident<$t:ident>>$($f:tt)*) => {{ let s = <$crate::CacheStates<$t>>::get(); - $crate::call_on_cache!(s, <$s<$t>>$($f)*) + $crate::call_on_cache_v2!(s, <$s<$t>>$($f)*) }}; } @@ -398,12 +398,29 @@ pub mod pallet { // There are already plenty of tasks to handle during the new session, // so refrain from assigning any additional ones here. if !T::ShouldEndSession::get() { - call_on_exposure!(>::iter_keys() - // TODO?: make this value adjustable + let w2 = call_on_cache_v2!(>::get()) + .map(|cs| { + let mut cs = cs.into_iter(); + let w = cs + .by_ref() + // ? make this value adjustable. + .take(1) + .fold(Weight::zero(), |acc, c| { + acc + Self::payout_inner(c).unwrap_or(Zero::zero()) + }); + let _ = call_on_cache_v2!(>::put(cs.collect::>())); + + w + }) + .unwrap_or_default(); + let w1 = call_on_cache_v1!(>::iter_keys() + // ? make this value adjustable. .take(1) - .fold(Zero::zero(), |acc, e| acc - + Self::payout_inner(e).unwrap_or(Zero::zero()))) - .unwrap_or_default() + .fold(Weight::zero(), |acc, c| acc + + Self::payout_inner(c).unwrap_or(Zero::zero()))) + .unwrap_or_default(); + + w1 + w2 } else { Zero::zero() } @@ -721,16 +738,11 @@ pub mod pallet { let reward_r = amount.saturating_div(2); let reward_k = amount.saturating_sub(reward_r); let (b_total, map) = >::take(); - let collators_v2 = call_on_cache!(>::get()).unwrap_or_default(); map.into_iter().for_each(|(c, b)| { let r = Perbill::from_rational(b, b_total).mul_floor(reward_r); - if collators_v2.contains(&c) { - T::RingStaking::distribute(Some(c), r); - } else { - >::mutate(c, |u| *u = u.map(|u| u + r).or(Some(r))); - } + >::mutate(c, |u| *u = u.map(|u| u + r).or(Some(r))); }); T::KtonStaking::distribute(None, reward_k); @@ -738,30 +750,49 @@ pub mod pallet { /// Pay the reward to the collator and its nominators. pub fn payout_inner(collator: T::AccountId) -> Result { - let c_exposure = - call_on_exposure!(>::take(&collator).ok_or(>::NoReward)?)?; - let c_total_payout = - >::take(&collator).ok_or(>::NoReward)?; - let mut c_payout = c_exposure.commission * c_total_payout; - let n_payout = c_total_payout - c_payout; - for n_exposure in c_exposure.nominators { - let n_payout = Perbill::from_rational(n_exposure.vote, c_exposure.vote) * n_payout; - - if collator == n_exposure.who { - // If the collator nominated themselves. - - c_payout += n_payout; - } else if T::IssuingManager::reward(&n_exposure.who, n_payout).is_ok() { - Self::deposit_event(Event::Payout { who: n_exposure.who, amount: n_payout }); - } else { - Self::deposit_event(Event::Unpaid { who: n_exposure.who, amount: n_payout }); - } + // Pay to V2. + if call_on_cache_v2!(>::get()).unwrap_or_default().contains(&collator) { + T::RingStaking::distribute( + Some(collator.clone()), + >::take(&collator).ok_or(>::NoReward)?, + ); } + // Pay to V1. + else if let Ok(Some(c_exposure)) = call_on_cache_v1!(>::take(&collator)) { + let c_total_payout = + >::take(&collator).ok_or(>::NoReward)?; + let mut c_payout = c_exposure.commission * c_total_payout; + let n_payout = c_total_payout - c_payout; + for n_exposure in c_exposure.nominators { + let n_payout = + Perbill::from_rational(n_exposure.vote, c_exposure.vote) * n_payout; + + if collator == n_exposure.who { + // If the collator nominated themselves. + + c_payout += n_payout; + } else if T::IssuingManager::reward(&n_exposure.who, n_payout).is_ok() { + Self::deposit_event(Event::Payout { + who: n_exposure.who, + amount: n_payout, + }); + } else { + Self::deposit_event(Event::Unpaid { + who: n_exposure.who, + amount: n_payout, + }); + } + } - if T::IssuingManager::reward(&collator, c_payout).is_ok() { - Self::deposit_event(Event::Payout { who: collator, amount: c_payout }); + if T::IssuingManager::reward(&collator, c_payout).is_ok() { + Self::deposit_event(Event::Payout { who: collator, amount: c_payout }); + } else { + Self::deposit_event(Event::Unpaid { who: collator, amount: c_payout }); + } } else { - Self::deposit_event(Event::Unpaid { who: collator, amount: c_payout }); + // Impossible case. + + Err(>::NoReward)?; } Ok(::WeightInfo::payout()) @@ -773,8 +804,8 @@ pub mod pallet { >::shift_cache_states(); #[allow(deprecated)] - call_on_exposure!(>::remove_all(None)).ok()?; - call_on_cache!(>::kill()).ok()?; + call_on_cache_v1!(>::remove_all(None)).ok()?; + call_on_cache_v2!(>::kill()).ok()?; let bn = >::block_number(); @@ -794,7 +825,7 @@ pub mod pallet { if cs.is_empty() { // TODO: update this once the migration is completed. - // Possible case under the hyper election mode. + // Possible case under the hybrid election mode. // Impossible case. // @@ -857,7 +888,7 @@ pub mod pallet { .into_iter() .take(n as _) .map(|((c, e), _)| { - call_on_exposure!(cache_states, >::insert(&c, e)).map(|_| c).ok() + call_on_cache_v1!(cache_states, >::insert(&c, e)).map(|_| c).ok() }) .collect() } @@ -895,7 +926,7 @@ pub mod pallet { fn elect_from_contract(n: u32) -> Option> { let winners = T::RingStaking::elect(n)?; - call_on_cache!(>::put(winners.clone())).ok()?; + call_on_cache_v2!(>::put(winners.clone())).ok()?; Some(winners) } @@ -1083,13 +1114,14 @@ where } /// Transfer issued token from pallet-treasury. -pub struct TreasuryIssuing(PhantomData); -impl IssuingManager for TreasuryIssuing +pub struct TreasuryIssuing(PhantomData<(T, R)>); +impl IssuingManager for TreasuryIssuing where T: Config, + R: Get, { fn calculate_reward(_: Balance) -> Balance { - 20_000 * UNIT + R::get() } fn reward(who: &T::AccountId, amount: Balance) -> DispatchResult { diff --git a/pallet/staking/src/mock.rs b/pallet/staking/src/mock.rs index f8981074d..966b87e99 100644 --- a/pallet/staking/src/mock.rs +++ b/pallet/staking/src/mock.rs @@ -24,6 +24,7 @@ use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; // darwinia use crate::*; +use dc_types::UNIT; // polkadot-sdk use frame_support::{assert_ok, derive_impl, traits::OnInitialize}; use sp_core::H160; @@ -105,7 +106,6 @@ impl darwinia_deposit::Config for Runtime { type DepositMigrator = (); type Kton = KtonMinting; type MaxDeposits = frame_support::traits::ConstU32<16>; - type MinLockingAmount = frame_support::traits::ConstU128; type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = TreasuryAcct; @@ -216,7 +216,7 @@ impl crate::IssuingManager for StatedOnSessionEnd { if INFLATION_TYPE.with(|v| *v.borrow()) == 0 { >::inflate() } else { - >::inflate() + >>::inflate() } } @@ -224,7 +224,7 @@ impl crate::IssuingManager for StatedOnSessionEnd { if INFLATION_TYPE.with(|v| *v.borrow()) == 0 { >::calculate_reward(issued) } else { - >::calculate_reward(issued) + >>::calculate_reward(issued) } } @@ -232,7 +232,7 @@ impl crate::IssuingManager for StatedOnSessionEnd { if INFLATION_TYPE.with(|v| *v.borrow()) == 0 { >::reward(who, amount) } else { - >::reward(who, amount) + >>::reward(who, amount) } } } @@ -454,7 +454,11 @@ pub fn new_session() { } pub fn payout() { - crate::call_on_exposure!(>::iter_keys().for_each(|c| { + crate::call_on_cache_v2!(>::get().into_iter().for_each(|c| { + let _ = Staking::payout_inner(c); + })) + .unwrap(); + crate::call_on_cache_v1!(>::iter_keys().for_each(|c| { let _ = Staking::payout_inner(c); })) .unwrap(); diff --git a/pallet/staking/src/tests.rs b/pallet/staking/src/tests.rs index 3cf3531dd..c43fa927e 100644 --- a/pallet/staking/src/tests.rs +++ b/pallet/staking/src/tests.rs @@ -21,6 +21,7 @@ use core::time::Duration; // darwinia use crate::{mock::*, *}; use darwinia_deposit::Error as DepositError; +use dc_types::UNIT; // polkadot-sdk use frame_support::{assert_noop, assert_ok, BoundedVec}; use sp_runtime::{assert_eq_error_rate, DispatchError, Perbill}; @@ -46,15 +47,15 @@ fn exposure_cache_states_should_work() { >::insert(AccountId(2), e); } - assert!(call_on_exposure!(>::get(AccountId(0)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_some()).unwrap()); assert_eq!( >::get(), (CacheState::Previous, CacheState::Current, CacheState::Next) @@ -62,15 +63,15 @@ fn exposure_cache_states_should_work() { Staking::shift_cache_states(); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); assert_eq!( >::get(), (CacheState::Next, CacheState::Previous, CacheState::Current) @@ -78,15 +79,15 @@ fn exposure_cache_states_should_work() { Staking::shift_cache_states(); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); assert_eq!( >::get(), (CacheState::Current, CacheState::Next, CacheState::Previous) @@ -94,15 +95,15 @@ fn exposure_cache_states_should_work() { Staking::shift_cache_states(); - assert!(call_on_exposure!(>::get(AccountId(0)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_some()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(0)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); - assert!(call_on_exposure!(>::get(AccountId(2)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_some()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(0)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(1)).is_none()).unwrap()); + assert!(call_on_cache_v1!(>::get(AccountId(2)).is_some()).unwrap()); assert_eq!( >::get(), (CacheState::Previous, CacheState::Current, CacheState::Next) @@ -606,15 +607,15 @@ fn auto_payout_should_work() { fn on_new_session_should_work() { ExtBuilder::default().collator_count(2).genesis_collator().build().execute_with(|| { assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(1), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(1), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(1), AccountId(2)] ); @@ -625,15 +626,15 @@ fn on_new_session_should_work() { new_session(); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(1), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(1), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(3), AccountId(2)] ); @@ -645,15 +646,15 @@ fn on_new_session_should_work() { new_session(); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(1), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(3), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(4), AccountId(2)] ); @@ -665,15 +666,15 @@ fn on_new_session_should_work() { new_session(); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(3), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(4), AccountId(2)] ); assert_eq!( - crate::call_on_exposure!(>::iter_keys().collect::>()).unwrap(), + crate::call_on_cache_v1!(>::iter_keys().collect::>()).unwrap(), [AccountId(5), AccountId(2)] ); }); @@ -857,8 +858,6 @@ fn hybrid_payout_should_work() { assert_eq!(collators, >::get()); let collators_balances = collators.iter().map(Balances::free_balance).collect::>(); - let session_duration = Duration::new(12 * 600, 0).as_millis(); - Efflux::time(session_duration - >::get() as Moment); Staking::note_authors(&collators); new_session(); payout(); @@ -875,6 +874,56 @@ fn hybrid_payout_should_work() { }); } +#[test] +fn hybrid_auto_payout_should_work() { + ExtBuilder::default().collator_count(4).inflation_type(1).build().execute_with(|| { + mock::preset_collator_wait_list(4); + Timestamp::set_timestamp(30 * DAY_IN_MILLIS); + new_session(); + new_session(); + + let collators = + (100..102).map(AccountId).chain((12..14).rev().map(AccountId)).collect::>(); + assert_eq!(collators, >::get()); + + let collators_balances = collators.iter().map(Balances::free_balance).collect::>(); + Staking::note_authors(&collators); + new_session(); + + assert_eq!( + vec![0, 0, 0, 0], + collators + .iter() + .map(Balances::free_balance) + .zip(collators_balances.clone()) + .map(|(a, b)| a - b) + .collect::>() + ); + + Efflux::block(1); + assert_eq!( + vec![2_500 * UNIT, 0, 0, 2_500 * UNIT], + collators + .iter() + .map(Balances::free_balance) + .zip(collators_balances.clone()) + .map(|(a, b)| a - b) + .collect::>() + ); + + Efflux::block(1); + assert_eq!( + vec![2_500 * UNIT, 2_500 * UNIT, 2_500 * UNIT, 2_500 * UNIT], + collators + .iter() + .map(Balances::free_balance) + .zip(collators_balances.clone()) + .map(|(a, b)| a - b) + .collect::>() + ); + }); +} + #[test] fn get_top_collators_should_work() { const ZERO: [u8; 20] = [0; 20]; diff --git a/precompile/deposit/src/mock.rs b/precompile/deposit/src/mock.rs index 58bbd1cb5..c1134fb1f 100644 --- a/precompile/deposit/src/mock.rs +++ b/precompile/deposit/src/mock.rs @@ -87,7 +87,6 @@ impl darwinia_deposit::Config for Runtime { type DepositMigrator = (); type Kton = KtonMinting; type MaxDeposits = frame_support::traits::ConstU32<16>; - type MinLockingAmount = frame_support::traits::ConstU128<100>; type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = (); diff --git a/precompile/staking/src/mock.rs b/precompile/staking/src/mock.rs index ddcd0f520..721957a12 100644 --- a/precompile/staking/src/mock.rs +++ b/precompile/staking/src/mock.rs @@ -86,7 +86,6 @@ impl darwinia_deposit::Config for Runtime { type DepositMigrator = (); type Kton = KtonMinting; type MaxDeposits = frame_support::traits::ConstU32<512>; - type MinLockingAmount = frame_support::traits::ConstU128<100>; type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = TreasuryAcct; diff --git a/runtime/crab/src/pallets/deposit.rs b/runtime/crab/src/pallets/deposit.rs index f8e9081b6..d0fe9ad76 100644 --- a/runtime/crab/src/pallets/deposit.rs +++ b/runtime/crab/src/pallets/deposit.rs @@ -47,7 +47,6 @@ impl darwinia_deposit::Config for Runtime { type DepositMigrator = darwinia_deposit::DepositMigrator; type Kton = KtonMinting; type MaxDeposits = ConstU32<512>; - type MinLockingAmount = ConstU128; type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = pallet_config::TreasuryAccount; diff --git a/runtime/crab/src/pallets/staking.rs b/runtime/crab/src/pallets/staking.rs index a8bf1f698..b119edc4c 100644 --- a/runtime/crab/src/pallets/staking.rs +++ b/runtime/crab/src/pallets/staking.rs @@ -73,7 +73,7 @@ impl darwinia_staking::Stake for KtonStaking { impl darwinia_staking::Config for Runtime { type Currency = Balances; type Deposit = Deposit; - type IssuingManager = darwinia_staking::TreasuryIssuing; + type IssuingManager = darwinia_staking::TreasuryIssuing>; type KtonStaking = darwinia_staking::KtonStaking; type MaxDeposits = ::MaxDeposits; type Ring = RingStaking; diff --git a/runtime/darwinia/src/pallets/deposit.rs b/runtime/darwinia/src/pallets/deposit.rs index 169e1ffe3..2fd603bff 100644 --- a/runtime/darwinia/src/pallets/deposit.rs +++ b/runtime/darwinia/src/pallets/deposit.rs @@ -47,7 +47,6 @@ impl darwinia_deposit::Config for Runtime { type DepositMigrator = darwinia_deposit::DepositMigrator; type Kton = KtonMinting; type MaxDeposits = ConstU32<512>; - type MinLockingAmount = ConstU128; type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = pallet_config::TreasuryAccount; diff --git a/runtime/koi/src/pallets/deposit.rs b/runtime/koi/src/pallets/deposit.rs index 69fba65e9..fe014b61c 100644 --- a/runtime/koi/src/pallets/deposit.rs +++ b/runtime/koi/src/pallets/deposit.rs @@ -47,7 +47,6 @@ impl darwinia_deposit::Config for Runtime { type DepositMigrator = darwinia_deposit::DepositMigrator; type Kton = KtonMinting; type MaxDeposits = ConstU32<512>; - type MinLockingAmount = ConstU128; type Ring = Balances; type RuntimeEvent = RuntimeEvent; type Treasury = pallet_config::TreasuryAccount;