diff --git a/pallet/account-migration/src/benchmarking.rs b/pallet/account-migration/src/benchmarking.rs index f92f845aa..967879e6e 100644 --- a/pallet/account-migration/src/benchmarking.rs +++ b/pallet/account-migration/src/benchmarking.rs @@ -126,8 +126,7 @@ mod benchmarks { Default::default(), Default::default() ); - ::MaxUnstakings::get() - as usize + 16 ]), ..Default::default() }, diff --git a/pallet/account-migration/src/lib.rs b/pallet/account-migration/src/lib.rs index db70bcfda..50d5c53bb 100644 --- a/pallet/account-migration/src/lib.rs +++ b/pallet/account-migration/src/lib.rs @@ -463,7 +463,16 @@ pub mod pallet { migration::put_storage_value(b"Identity", b"Registrars", &[], rs); } - if let Some(mut l) = >::take(from) { + if let Some(l) = >::take(from) { + if l.staked_ring > 0 { + as Currency<_>>::transfer( + to, + &darwinia_staking::account_id(), + l.staked_ring, + AllowDeath, + )?; + } + if let Some(ds) = >::take(from) { as Currency<_>>::transfer( to, @@ -477,33 +486,9 @@ pub mod pallet { ); } - let now = >::block_number(); - - l.unstaking_ring.retain(|(_, t)| t > &now); - - let staking_pot = darwinia_staking::account_id(); - let r = l.staked_ring + l.unstaking_ring.iter().map(|(r, _)| r).sum::(); - - // To calculated the worst case in benchmark. - debug_assert!(r > 0); - - if r > 0 { - as Currency<_>>::transfer( - to, - &staking_pot, - r, - AllowDeath, - )?; - } - >::insert( to, - Ledger { - staked_ring: l.staked_ring, - staked_deposits: l.staked_deposits, - unstaking_ring: l.unstaking_ring, - unstaking_deposits: l.unstaking_deposits, - }, + Ledger { ring: l.staked_ring, deposits: l.staked_deposits }, ); } diff --git a/pallet/account-migration/src/mock.rs b/pallet/account-migration/src/mock.rs index b2b6df46e..fdacda554 100644 --- a/pallet/account-migration/src/mock.rs +++ b/pallet/account-migration/src/mock.rs @@ -167,8 +167,6 @@ impl darwinia_staking::Config for Runtime { type KtonRewardDistributionContract = (); type KtonStakerNotifier = (); type MaxDeposits = (); - type MaxUnstakings = (); - type MinStakingDuration = (); type Ring = Dummy; type RuntimeEvent = RuntimeEvent; type ShouldEndSession = (); diff --git a/pallet/staking/src/benchmarking.rs b/pallet/staking/src/benchmarking.rs index 4e604c122..f6f01c8ef 100644 --- a/pallet/staking/src/benchmarking.rs +++ b/pallet/staking/src/benchmarking.rs @@ -36,7 +36,7 @@ mod benchmarks { where T: Config + darwinia_deposit::Config, { - (0..count.min(<::MaxUnstakings>::get()) as u8) + (0..count.min(<::MaxDeposits>::get()) as u16) .map(|x| { >::lock( RawOrigin::Signed(who.to_owned()).into(), @@ -62,7 +62,7 @@ mod benchmarks { // Worst-case scenario: // - // The total number of deposit items has reached `Config::MaxUnstakings`. + // The total number of deposit items has reached `darwinia_deposits::Config::MaxDeposits`. #[extrinsic_call] _(RawOrigin::Signed(a), UNIT, deposits); } @@ -81,60 +81,11 @@ mod benchmarks { // Worst-case scenario: // - // The total number of deposit items has reached `Config::MaxUnstakings`. + // The total number of deposit items has reached `darwinia_deposits::Config::MaxDeposits`. #[extrinsic_call] _(RawOrigin::Signed(a), UNIT, deposits); } - #[benchmark] - fn restake(x: Linear<0, 1_023>) { - let a = frame_benchmarking::whitelisted_caller(); - - // Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655. - ::Ring::make_free_balance_be(&a, 1_024 * UNIT + 1); - ::Kton::mint(&a, UNIT).unwrap(); - - let deposits = deposit_for::(&a, x); - - >::stake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits.clone()).unwrap(); - >::unstake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits.clone()).unwrap(); - - // Worst-case scenario: - // - // The total number of deposit items has reached `Config::MaxUnstakings`. - #[extrinsic_call] - _(RawOrigin::Signed(a), UNIT, deposits); - } - - #[benchmark] - fn claim() { - let a = frame_benchmarking::whitelisted_caller(); - - // Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655. - ::Ring::make_free_balance_be(&a, 1_024 * UNIT + 1); - ::Kton::mint(&a, UNIT).unwrap(); - - let deposits = deposit_for::(&a, ::MaxUnstakings::get()); - - >::stake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits.clone()).unwrap(); - >::unstake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits).unwrap(); - - >::set_block_number( - >::block_number() + T::MinStakingDuration::get(), - ); - - assert!(>::contains_key(&a)); - - // Worst-case scenario: - // - // The total number of deposit items has reached `Config::MaxUnstakings`. - // In addition, all `RING` and `KTON` should be claimed, to make ledger get killed. - #[extrinsic_call] - _(RawOrigin::Signed(a.clone())); - - assert!(!>::contains_key(&a)); - } - #[benchmark] fn collect() { let a = frame_benchmarking::whitelisted_caller(); diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index 89de74106..225760e1b 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -135,18 +135,10 @@ pub mod pallet { /// Pass [`pallet_session::Config::ShouldEndSession`]'s result to here. type ShouldEndSession: Get; - /// Minimum time to stake at least. - #[pallet::constant] - type MinStakingDuration: Get>; - /// Maximum deposit count. #[pallet::constant] type MaxDeposits: Get; - /// Maximum unstaking/unbonding count. - #[pallet::constant] - type MaxUnstakings: Get; - /// The address of KTON reward distribution contract. #[pallet::constant] type KtonRewardDistributionContract: Get; @@ -373,18 +365,13 @@ pub mod pallet { } else { >::inc_consumers(&who)?; - *l = Some(Ledger { - staked_ring: Default::default(), - staked_deposits: Default::default(), - unstaking_ring: Default::default(), - unstaking_deposits: Default::default(), - }); + *l = Some(Ledger { ring: Default::default(), deposits: Default::default() }); l.as_mut().expect("[pallet::staking] `l` must be some; qed") }; if ring_amount != 0 { - Self::stake_ring(&who, &mut l.staked_ring, ring_amount)?; + Self::stake_ring(&who, &mut l.ring, ring_amount)?; } for d in deposits.clone() { @@ -417,60 +404,28 @@ pub mod pallet { let l = l.as_mut().ok_or(>::NotStaker)?; if ring_amount != 0 { - Self::unstake_ring(&mut l.staked_ring, &mut l.unstaking_ring, ring_amount)?; - } + l.ring = l + .ring + .checked_sub(ring_amount) + .ok_or("[pallet::staking] `u128` must not be overflowed; qed")?; - for d in deposits { - Self::unstake_deposit(l, d)?; - } - - DispatchResult::Ok(()) - })?; - - Ok(()) - } - - /// Cancel the `unstake` operation. - /// - /// Re-stake the unstaking assets immediately. - #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::restake(deposits.len() as _))] - pub fn restake( - origin: OriginFor, - ring_amount: Balance, - deposits: Vec>, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - - if ring_amount == 0 && deposits.is_empty() { - return Ok(()); - } - - >::try_mutate(&who, |l| { - let l = l.as_mut().ok_or(>::NotStaker)?; - - if ring_amount != 0 { - Self::restake_ring(&mut l.staked_ring, &mut l.unstaking_ring, ring_amount)?; + ::Ring::unstake(&who, ring_amount)?; } for d in deposits { - Self::restake_deposit(l, d)?; + l.deposits.remove( + l.deposits + .iter() + .position(|d_| d_ == &d) + .ok_or(>::DepositNotFound)?, + ); + + T::Deposit::unstake(&who, d)?; } DispatchResult::Ok(()) })?; - Ok(()) - } - - /// Claim the stakes from the pallet/contract account. - #[pallet::call_index(3)] - #[pallet::weight(::WeightInfo::claim())] - pub fn claim(origin: OriginFor) -> DispatchResult { - let who = ensure_signed(origin)?; - - // Deposit doesn't need to be claimed. - Self::claim_unstakings(&who)?; Self::try_clean_ledger_of(&who); Ok(()) @@ -578,140 +533,11 @@ pub mod pallet { ) -> DispatchResult { T::Deposit::stake(who, deposit)?; - ledger.staked_deposits.try_push(deposit).map_err(|_| >::ExceedMaxDeposits)?; - - Ok(()) - } - - fn unstake_ring( - staked: &mut Balance, - unstaking: &mut BoundedVec<(Balance, BlockNumberFor), T::MaxUnstakings>, - amount: Balance, - ) -> DispatchResult { - *staked = staked - .checked_sub(amount) - .ok_or("[pallet::staking] `u128` must not be overflowed; qed")?; - - unstaking - .try_push(( - amount, - >::block_number() + T::MinStakingDuration::get(), - )) - .map_err(|_| >::ExceedMaxUnstakings)?; + ledger.deposits.try_push(deposit).map_err(|_| >::ExceedMaxDeposits)?; Ok(()) } - fn unstake_deposit(ledger: &mut Ledger, deposit: DepositId) -> DispatchResult { - ledger - .unstaking_deposits - .try_push(( - ledger.staked_deposits.remove( - ledger - .staked_deposits - .iter() - .position(|d| d == &deposit) - .ok_or(>::DepositNotFound)?, - ), - >::block_number() + T::MinStakingDuration::get(), - )) - .map_err(|_| >::ExceedMaxUnstakings)?; - - Ok(()) - } - - fn restake_ring( - staked: &mut Balance, - unstaking: &mut BoundedVec<(Balance, BlockNumberFor), T::MaxUnstakings>, - mut amount: Balance, - ) -> DispatchResult { - let mut actual_restake = 0; - - // Cancel the latest `unstake` first. - while let Some((u, _)) = unstaking.last_mut() { - if let Some(k) = u.checked_sub(amount) { - actual_restake += amount; - *u = k; - - if k == 0 { - unstaking - .pop() - .ok_or("[pallet::staking] record must exist, due to `last_mut`; qed")?; - } - - break; - } else { - actual_restake += *u; - amount -= *u; - - unstaking - .pop() - .ok_or("[pallet::staking] record must exist, due to `last_mut`; qed")?; - } - } - - *staked += actual_restake; - - Ok(()) - } - - fn restake_deposit(ledger: &mut Ledger, deposit: DepositId) -> DispatchResult { - ledger - .staked_deposits - .try_push( - ledger - .unstaking_deposits - .remove( - ledger - .unstaking_deposits - .iter() - .position(|(d, _)| d == &deposit) - .ok_or(>::DepositNotFound)?, - ) - .0, - ) - .map_err(|_| >::ExceedMaxDeposits)?; - - Ok(()) - } - - fn claim_unstakings(who: &T::AccountId) -> DispatchResult { - >::try_mutate(who, |l| { - let l = l.as_mut().ok_or(>::NotStaker)?; - let now = >::block_number(); - let mut r_claimed = 0; - - l.unstaking_ring.retain(|(a, t)| { - if t <= &now { - r_claimed += a; - - false - } else { - true - } - }); - ::Ring::unstake(who, r_claimed)?; - - let mut d_claimed = Vec::new(); - - l.unstaking_deposits.retain(|(d, t)| { - if t <= &now { - d_claimed.push(*d); - - false - } else { - true - } - }); - - for d in d_claimed { - T::Deposit::unstake(who, d)?; - } - - Ok(()) - }) - } - fn try_clean_ledger_of(who: &T::AccountId) { let _ = >::try_mutate(who, |maybe_l| { let l = maybe_l.as_mut().ok_or(())?; @@ -743,8 +569,8 @@ pub mod pallet { pub fn stake_of(who: &T::AccountId) -> Balance { >::get(who) .map(|l| { - l.staked_ring - + l.staked_deposits + l.ring + + l.deposits .into_iter() // We don't care if the deposit exists here. // It was guaranteed by the `stake`/`unstake`/`restake` functions. @@ -973,23 +799,16 @@ where T: Config, { /// Staked RING. - pub staked_ring: Balance, + pub ring: Balance, /// Staked deposits. - pub staked_deposits: BoundedVec, ::MaxDeposits>, - /// The RING in unstaking process. - pub unstaking_ring: BoundedVec<(Balance, BlockNumberFor), T::MaxUnstakings>, - /// The deposit in unstaking process. - pub unstaking_deposits: BoundedVec<(DepositId, BlockNumberFor), T::MaxUnstakings>, + pub deposits: BoundedVec, ::MaxDeposits>, } impl Ledger where T: Config, { fn is_empty(&self) -> bool { - self.staked_ring == 0 - && self.staked_deposits.is_empty() - && self.unstaking_ring.is_empty() - && self.unstaking_deposits.is_empty() + self.ring == 0 && self.deposits.is_empty() } } diff --git a/pallet/staking/src/migration/v2.rs b/pallet/staking/src/migration/v2.rs index 00fe97b7a..353240d49 100644 --- a/pallet/staking/src/migration/v2.rs +++ b/pallet/staking/src/migration/v2.rs @@ -33,9 +33,9 @@ where pub staked_ring: Balance, pub staked_kton: Balance, pub staked_deposits: BoundedVec, ::MaxDeposits>, - pub unstaking_ring: BoundedVec<(Balance, BlockNumberFor), T::MaxUnstakings>, - pub unstaking_kton: BoundedVec<(Balance, BlockNumberFor), T::MaxUnstakings>, - pub unstaking_deposits: BoundedVec<(DepositId, BlockNumberFor), T::MaxUnstakings>, + pub unstaking_ring: BoundedVec<(Balance, BlockNumberFor), ConstU32<16>>, + pub unstaking_kton: BoundedVec<(Balance, BlockNumberFor), ConstU32<16>>, + pub unstaking_deposits: BoundedVec<(DepositId, BlockNumberFor), ConstU32<16>>, } #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebug)] @@ -83,19 +83,27 @@ where >::kill(); >::kill(); >::translate::, _>(|a, o| { - w += 2; + w += 6; + let unstaking_ring = o.unstaking_ring.into_iter().fold(0, |s, (v, _)| s + v); + + // Release the unstaking RING immediately. + if unstaking_ring != 0 { + let _ = ::Ring::unstake(&a, unstaking_ring); + } + + // Release all KTON immediately. let _ = ::Kton::unstake( &a, o.staked_kton + o.unstaking_kton.into_iter().fold(0, |s, (v, _)| s + v), ); - Some(Ledger { - staked_ring: o.staked_ring, - staked_deposits: o.staked_deposits, - unstaking_ring: o.unstaking_ring, - unstaking_deposits: o.unstaking_deposits, - }) + // Release the unstaking deposits immediately. + for (d, _) in o.unstaking_deposits { + let _ = T::Deposit::unstake(&a, d); + } + + Some(Ledger { ring: o.staked_ring, deposits: o.staked_deposits }) }); >::translate_values::, _>(|o| { w += 1; diff --git a/pallet/staking/src/mock.rs b/pallet/staking/src/mock.rs index db2cbab44..8a5168b60 100644 --- a/pallet/staking/src/mock.rs +++ b/pallet/staking/src/mock.rs @@ -295,8 +295,6 @@ impl darwinia_staking::Config for Runtime { type KtonRewardDistributionContract = (); type KtonStakerNotifier = (); type MaxDeposits = ::MaxDeposits; - type MaxUnstakings = frame_support::traits::ConstU32<16>; - type MinStakingDuration = frame_support::traits::ConstU64<3>; type Ring = RingStaking; type RuntimeEvent = RuntimeEvent; type ShouldEndSession = ShouldEndSession; @@ -317,20 +315,6 @@ frame_support::construct_runtime! { } } -pub trait ZeroDefault { - fn default() -> Self; -} -impl ZeroDefault for darwinia_staking::Ledger { - fn default() -> Self { - Self { - staked_ring: Default::default(), - staked_deposits: Default::default(), - unstaking_ring: Default::default(), - unstaking_deposits: Default::default(), - } - } -} - pub enum Efflux {} impl Efflux { pub fn time(milli_secs: Moment) { diff --git a/pallet/staking/src/tests.rs b/pallet/staking/src/tests.rs index 1da057a96..377dfa3c8 100644 --- a/pallet/staking/src/tests.rs +++ b/pallet/staking/src/tests.rs @@ -20,7 +20,7 @@ use core::time::Duration; // darwinia use crate::{mock::*, *}; -use darwinia_deposit::Error as DepositError; +use darwinia_deposit::{Deposit as DepositS, Error as DepositError}; use dc_types::UNIT; // substrate use frame_support::{assert_noop, assert_ok, BoundedVec}; @@ -124,7 +124,7 @@ fn stake_should_work() { assert_eq!(System::account(1).consumers, 1); assert_eq!( Staking::ledger_of(1).unwrap(), - Ledger { staked_ring: UNIT, ..ZeroDefault::default() } + Ledger { ring: UNIT, deposits: Default::default() } ); assert_eq!(Balances::free_balance(1), 999 * UNIT); @@ -140,11 +140,7 @@ fn stake_should_work() { assert_ok!(Staking::stake(RuntimeOrigin::signed(1), 0, vec![0])); assert_eq!( Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: UNIT, - staked_deposits: BoundedVec::truncate_from(vec![0]), - ..ZeroDefault::default() - } + Ledger { ring: UNIT, deposits: BoundedVec::truncate_from(vec![0]) } ); // Stake 500 RING and 2 deposits. @@ -155,11 +151,7 @@ fn stake_should_work() { assert_eq!(Balances::free_balance(1), 98 * UNIT); assert_eq!( Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: 501 * UNIT, - staked_deposits: BoundedVec::truncate_from(vec![0, 1, 2]), - ..ZeroDefault::default() - } + Ledger { ring: 501 * UNIT, deposits: BoundedVec::truncate_from(vec![0, 1, 2]) } ); }); } @@ -174,23 +166,43 @@ fn unstake_should_work() { assert_eq!(Balances::free_balance(1), 994 * UNIT); assert_eq!( Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: 3 * UNIT, - staked_deposits: BoundedVec::truncate_from(vec![0, 1, 2]), - ..ZeroDefault::default() - } + Ledger { ring: 3 * UNIT, deposits: BoundedVec::truncate_from(vec![0, 1, 2]) } + ); + assert_eq!( + Deposit::deposit_of(1).unwrap(), + ::MaxDeposits>>::truncate_from( + vec![ + DepositS { + id: 0, + value: UNIT, + start_time: 3, + expired_time: 2635200003, + in_use: true + }, + DepositS { + id: 1, + value: UNIT, + start_time: 3, + expired_time: 2635200003, + in_use: true + }, + DepositS { + id: 2, + value: UNIT, + start_time: 3, + expired_time: 2635200003, + in_use: true + } + ] + ) ); // Unstake 1 RING. assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), UNIT, Vec::new())); + assert_eq!(Balances::free_balance(1), 995 * UNIT); assert_eq!( Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: 2 * UNIT, - staked_deposits: BoundedVec::truncate_from(vec![0, 1, 2]), - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 6)]), - ..ZeroDefault::default() - } + Ledger { ring: 2 * UNIT, deposits: BoundedVec::truncate_from(vec![0, 1, 2]) } ); // Unstake invalid deposit. @@ -204,151 +216,51 @@ fn unstake_should_work() { assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), 0, vec![1])); assert_eq!( Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: 2 * UNIT, - staked_deposits: BoundedVec::truncate_from(vec![0, 2]), - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 6)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(1, 7)]) - } - ); - - // Unstake 2 RING and 2 deposits. - Efflux::block(1); - assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), 2 * UNIT, vec![0, 2])); - assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 6), (2 * UNIT, 8)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(1, 7), (0, 8), (2, 8)]), - ..ZeroDefault::default() - } - ); - - // Keep the stakes for at least `MinStakingDuration`. - assert_eq!(Balances::free_balance(1), 994 * UNIT); - }); -} - -#[test] -fn restake_should_work() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(Deposit::lock(RuntimeOrigin::signed(1), UNIT, 1)); - assert_ok!(Deposit::lock(RuntimeOrigin::signed(1), UNIT, 1)); - assert_ok!(Deposit::lock(RuntimeOrigin::signed(1), UNIT, 1)); - assert_ok!(Staking::stake(RuntimeOrigin::signed(1), 3 * UNIT, vec![0, 1, 2])); - assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), UNIT, vec![0, 1, 2])); - Efflux::block(1); - assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), UNIT, Vec::new())); - Efflux::block(1); - assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), UNIT, Vec::new())); - assert_eq!(Balances::free_balance(1), 994 * UNIT); - assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 6), (UNIT, 7), (UNIT, 8)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(0, 6), (1, 6), (2, 6)]), - ..ZeroDefault::default() - } - ); - - // Restake 1.5 RING. - assert_ok!(Staking::restake(RuntimeOrigin::signed(1), 3 * UNIT / 2, Vec::new())); - assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: 3 * UNIT / 2, - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 6), (UNIT / 2, 7)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(0, 6), (1, 6), (2, 6)]), - ..ZeroDefault::default() - } - ); - - // Restake invalid deposit. - assert_noop!( - Staking::unstake(RuntimeOrigin::signed(1), 0, vec![3]), - >::DepositNotFound - ); - - // Restake 1 deposit. - assert_ok!(Staking::restake(RuntimeOrigin::signed(1), 0, vec![1])); - assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: 3 * UNIT / 2, - staked_deposits: BoundedVec::truncate_from(vec![1]), - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 6), (UNIT / 2, 7)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(0, 6), (2, 6)]), - ..ZeroDefault::default() - } + Ledger { ring: 2 * UNIT, deposits: BoundedVec::truncate_from(vec![0, 2]) } ); - - // Restake 1.5 RING and 2 deposits. - Efflux::block(1); - assert_ok!(Staking::restake(RuntimeOrigin::signed(1), 3 * UNIT / 2, vec![0, 2])); assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - staked_ring: 3 * UNIT, - staked_deposits: BoundedVec::truncate_from(vec![1, 0, 2]), - ..ZeroDefault::default() - } - ); - }); -} - -#[test] -fn claim_should_work() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(Deposit::lock(RuntimeOrigin::signed(1), UNIT, 1)); - assert_ok!(Deposit::lock(RuntimeOrigin::signed(1), UNIT, 1)); - assert_ok!(Deposit::lock(RuntimeOrigin::signed(1), UNIT, 1)); - assert_ok!(Staking::stake(RuntimeOrigin::signed(1), 2 * UNIT, vec![0, 1, 2])); - assert_eq!(System::account(1).consumers, 2); - assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), UNIT, Vec::new())); - Efflux::block(1); - assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), 0, vec![0])); - Efflux::block(1); - assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), UNIT, vec![1, 2])); - assert_eq!(Balances::free_balance(1), 995 * UNIT); - assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 6), (UNIT, 8)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(0, 7), (1, 8), (2, 8)]), - ..ZeroDefault::default() - } - ); - - Efflux::block(1); - assert_ok!(Staking::claim(RuntimeOrigin::signed(1))); - assert_eq!(System::account(1).consumers, 2); - assert_eq!(Balances::free_balance(1), 996 * UNIT); - assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 8)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(0, 7), (1, 8), (2, 8)]), - ..ZeroDefault::default() - } + Deposit::deposit_of(1).unwrap(), + ::MaxDeposits>>::truncate_from( + vec![ + DepositS { + id: 0, + value: UNIT, + start_time: 3, + expired_time: 2635200003, + in_use: true + }, + DepositS { + id: 1, + value: UNIT, + start_time: 3, + expired_time: 2635200003, + in_use: false + }, + DepositS { + id: 2, + value: UNIT, + start_time: 3, + expired_time: 2635200003, + in_use: true + } + ] + ) ); + // Unstake 2 RING and 2 deposits. Efflux::block(1); - assert_ok!(Staking::claim(RuntimeOrigin::signed(1))); - assert_eq!(System::account(1).consumers, 2); + assert_ok!(Staking::unstake(RuntimeOrigin::signed(1), 2 * UNIT, vec![0, 2])); + assert!(Staking::ledger_of(1).is_none()); assert_eq!( - Staking::ledger_of(1).unwrap(), - Ledger { - unstaking_ring: BoundedVec::truncate_from(vec![(UNIT, 8)]), - unstaking_deposits: BoundedVec::truncate_from(vec![(1, 8), (2, 8)]), - ..ZeroDefault::default() - } + Deposit::deposit_of(1).unwrap(), + ::MaxDeposits>>::truncate_from( + vec![ + DepositS { id: 0, value: UNIT, start_time: 3, expired_time: 2635200003, in_use: false }, + DepositS { id: 1, value: UNIT, start_time: 3, expired_time: 2635200003, in_use: false }, + DepositS { id: 2, value: UNIT, start_time: 3, expired_time: 2635200003, in_use: false } + ] + ) ); - - Efflux::block(2); - assert_ok!(Staking::claim(RuntimeOrigin::signed(1))); - assert_eq!(System::account(1).consumers, 1); - assert_eq!(Balances::free_balance(1), 997 * UNIT); - assert!(Staking::ledger_of(1).is_none()); }); } diff --git a/pallet/staking/src/weights.rs b/pallet/staking/src/weights.rs index 09896a781..397832e76 100644 --- a/pallet/staking/src/weights.rs +++ b/pallet/staking/src/weights.rs @@ -54,8 +54,6 @@ use core::marker::PhantomData; pub trait WeightInfo { fn stake(x: u32, ) -> Weight; fn unstake(x: u32, ) -> Weight; - fn restake(x: u32, ) -> Weight; - fn claim() -> Weight; fn collect() -> Weight; fn nominate() -> Weight; fn chill() -> Weight; @@ -114,47 +112,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `DarwiniaStaking::RingPool` (r:1 w:1) - /// Proof: `DarwiniaStaking::RingPool` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) - /// Storage: `DarwiniaStaking::KtonPool` (r:1 w:1) - /// Proof: `DarwiniaStaking::KtonPool` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:0) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - /// The range of component `x` is `[0, 1023]`. - fn restake(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1693` - // Estimated: `29615` - // Minimum execution time: 10_061 nanoseconds. - Weight::from_parts(43_375_019, 0) - .saturating_add(Weight::from_parts(29615, 0)) - // Standard Error: 750 - .saturating_add(Weight::from_parts(3_582, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) - /// Storage: `Assets::Asset` (r:1 w:1) - /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(166), added: 2641, mode: `MaxEncodedLen`) - /// Storage: `Assets::Account` (r:2 w:2) - /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:1) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - fn claim() -> Weight { - // Proof Size summary in bytes: - // Measured: `2215` - // Estimated: `29615` - // Minimum execution time: 87_073 nanoseconds. - Weight::from_parts(89_352_000, 0) - .saturating_add(Weight::from_parts(29615, 0)) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) - } /// Storage: `DarwiniaStaking::Collators` (r:1 w:1) /// Proof: `DarwiniaStaking::Collators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) fn collect() -> Weight { @@ -277,47 +234,6 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `DarwiniaStaking::RingPool` (r:1 w:1) - /// Proof: `DarwiniaStaking::RingPool` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) - /// Storage: `DarwiniaStaking::KtonPool` (r:1 w:1) - /// Proof: `DarwiniaStaking::KtonPool` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:0) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - /// The range of component `x` is `[0, 1023]`. - fn restake(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1693` - // Estimated: `29615` - // Minimum execution time: 10_061 nanoseconds. - Weight::from_parts(43_375_019, 0) - .saturating_add(Weight::from_parts(29615, 0)) - // Standard Error: 750 - .saturating_add(Weight::from_parts(3_582, 0).saturating_mul(x.into())) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) - } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) - /// Storage: `Assets::Asset` (r:1 w:1) - /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(166), added: 2641, mode: `MaxEncodedLen`) - /// Storage: `Assets::Account` (r:2 w:2) - /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:1) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - fn claim() -> Weight { - // Proof Size summary in bytes: - // Measured: `2215` - // Estimated: `29615` - // Minimum execution time: 87_073 nanoseconds. - Weight::from_parts(89_352_000, 0) - .saturating_add(Weight::from_parts(29615, 0)) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) - } /// Storage: `DarwiniaStaking::Collators` (r:1 w:1) /// Proof: `DarwiniaStaking::Collators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) fn collect() -> Weight { diff --git a/pallet/staking/traits/src/lib.rs b/pallet/staking/traits/src/lib.rs index 11b31a35d..2ca6967bc 100644 --- a/pallet/staking/traits/src/lib.rs +++ b/pallet/staking/traits/src/lib.rs @@ -47,7 +47,7 @@ pub trait Stake { + Copy + Debug + Default - + From + + From + PartialEq + FullCodec + MaxEncodedLen diff --git a/precompile/staking/src/lib.rs b/precompile/staking/src/lib.rs index 931d6633d..1eb4706a3 100644 --- a/precompile/staking/src/lib.rs +++ b/precompile/staking/src/lib.rs @@ -93,38 +93,6 @@ where Ok(true) } - #[precompile::public("restake(uint256,uint16[])")] - fn restake( - handle: &mut impl PrecompileHandle, - ring_amount: U256, - deposits: Vec, - ) -> EvmResult { - let origin = handle.context().caller.into(); - let deposits = deposits.into_iter().map(|i| i.into()).collect(); - - RuntimeHelper::::try_dispatch( - handle, - Some(origin).into(), - darwinia_staking::Call::::restake { - ring_amount: ring_amount.as_u128(), - deposits, - }, - )?; - Ok(true) - } - - #[precompile::public("claim()")] - fn claim(handle: &mut impl PrecompileHandle) -> EvmResult { - let origin = handle.context().caller.into(); - - RuntimeHelper::::try_dispatch( - handle, - Some(origin).into(), - darwinia_staking::Call::::claim {}, - )?; - Ok(true) - } - #[precompile::public("collect(uint32)")] fn collect(handle: &mut impl PrecompileHandle, commission: u32) -> EvmResult { let origin = handle.context().caller.into(); diff --git a/precompile/staking/src/mock.rs b/precompile/staking/src/mock.rs index 92c39f686..8b5817f5a 100644 --- a/precompile/staking/src/mock.rs +++ b/precompile/staking/src/mock.rs @@ -236,8 +236,6 @@ impl darwinia_staking::Config for Runtime { type KtonRewardDistributionContract = (); type KtonStakerNotifier = (); type MaxDeposits = ::MaxDeposits; - type MaxUnstakings = frame_support::traits::ConstU32<16>; - type MinStakingDuration = frame_support::traits::ConstU64<3>; type Ring = RingStaking; type RuntimeEvent = RuntimeEvent; type ShouldEndSession = (); diff --git a/precompile/staking/src/tests.rs b/precompile/staking/src/tests.rs index 6ebefa1b5..dda93804b 100644 --- a/precompile/staking/src/tests.rs +++ b/precompile/staking/src/tests.rs @@ -19,7 +19,7 @@ // darwinia use crate::mock::{ Account::{Alice, Bob, Precompile}, - ExtBuilder, PCall, PrecompilesValue, Runtime, Staking, System, TestPrecompiles, + ExtBuilder, PCall, PrecompilesValue, Runtime, Staking, TestPrecompiles, }; use sp_runtime::Perbill; // moonbeam @@ -35,8 +35,6 @@ fn precompiles() -> TestPrecompiles { fn selectors() { assert!(PCall::stake_selectors().contains(&0x88FD3D50)); assert!(PCall::unstake_selectors().contains(&0xE198447)); - assert!(PCall::restake_selectors().contains(&0x1ED0818E)); - assert!(PCall::claim_selectors().contains(&0x4e71d92d)); assert!(PCall::nominate_selectors().contains(&0xb332180b)); assert!(PCall::collect_selectors().contains(&0x10a66536)); assert!(PCall::chill_selectors().contains(&0x2b8a3ae6)); @@ -55,7 +53,7 @@ fn stake_unstake_restake() { PCall::stake { ring_amount: 200.into(), deposits: vec![] }, ) .execute_returns(true); - assert_eq!(Staking::ledger_of(alice).unwrap().staked_ring, 200); + assert_eq!(Staking::ledger_of(alice).unwrap().ring, 200); // unstake precompiles() @@ -65,47 +63,6 @@ fn stake_unstake_restake() { PCall::unstake { ring_amount: 200.into(), deposits: vec![] }, ) .execute_returns(true); - assert_eq!(Staking::ledger_of(alice).unwrap().staked_ring, 0); - assert_eq!(Staking::ledger_of(alice).unwrap().unstaking_ring.len(), 1); - - // restake - precompiles() - .prepare_test( - alice, - Precompile, - PCall::restake { ring_amount: 200.into(), deposits: vec![] }, - ) - .execute_returns(true); - assert_eq!(Staking::ledger_of(alice).unwrap().staked_ring, 200); - assert_eq!(Staking::ledger_of(alice).unwrap().unstaking_ring.len(), 0); - }); -} - -#[test] -fn claim() { - let alice: H160 = Alice.into(); - ExtBuilder::default().with_balances(vec![(alice, 300)]).build().execute_with(|| { - // stake - precompiles() - .prepare_test( - alice, - Precompile, - PCall::stake { ring_amount: 200.into(), deposits: vec![] }, - ) - .execute_returns(true); - - // unstake - precompiles() - .prepare_test( - alice, - Precompile, - PCall::unstake { ring_amount: 200.into(), deposits: vec![] }, - ) - .execute_returns(true); - - // You have to wait for MinStakingDuration to claim - System::set_block_number(5); - precompiles().prepare_test(alice, Precompile, PCall::claim {}).execute_returns(true); assert!(Staking::ledger_of(alice).is_none()); }); } diff --git a/runtime/common/src/test.rs b/runtime/common/src/test.rs index 11dfef512..4caf6cc9d 100644 --- a/runtime/common/src/test.rs +++ b/runtime/common/src/test.rs @@ -321,7 +321,7 @@ macro_rules! impl_account_migration_tests { ); assert_eq!(Deposit::deposit_of(to).unwrap().len(), 2); assert_eq!(Assets::maybe_balance(KTON_ID, to).unwrap(), 100); - assert_eq!(DarwiniaStaking::ledger_of(to).unwrap().staked_ring, 20); + assert_eq!(DarwiniaStaking::ledger_of(to).unwrap().ring, 20); }); } #[test] diff --git a/runtime/crab/src/pallets/staking.rs b/runtime/crab/src/pallets/staking.rs index f9063551e..76c51f47f 100644 --- a/runtime/crab/src/pallets/staking.rs +++ b/runtime/crab/src/pallets/staking.rs @@ -23,8 +23,6 @@ use frame_support::traits::Currency; fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); -type MinStakingDuration = ConstU32<{ DURATION }>; - pub enum RingStaking {} impl darwinia_staking::Stake for RingStaking { type AccountId = AccountId; @@ -108,8 +106,6 @@ impl darwinia_staking::Config for Runtime { type KtonRewardDistributionContract = darwinia_staking::KtonRewardDistributionContract; type KtonStakerNotifier = darwinia_staking::KtonStakerNotifier; type MaxDeposits = ::MaxDeposits; - type MaxUnstakings = ConstU32<16>; - type MinStakingDuration = MinStakingDuration; type Ring = RingStaking; type RuntimeEvent = RuntimeEvent; type ShouldEndSession = ShouldEndSession; diff --git a/runtime/crab/src/weights/darwinia_staking.rs b/runtime/crab/src/weights/darwinia_staking.rs index 6c218fc33..590d2384e 100644 --- a/runtime/crab/src/weights/darwinia_staking.rs +++ b/runtime/crab/src/weights/darwinia_staking.rs @@ -109,41 +109,6 @@ impl darwinia_staking::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(7)) } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `DarwiniaStaking::RingPool` (r:1 w:1) - /// Proof: `DarwiniaStaking::RingPool` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:0) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - /// The range of component `x` is `[0, 1023]`. - fn restake(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1570` - // Estimated: `29615` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(53_542_194, 0) - .saturating_add(Weight::from_parts(0, 29615)) - // Standard Error: 966 - .saturating_add(Weight::from_parts(4_864, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) - } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:1) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - fn claim() -> Weight { - // Proof Size summary in bytes: - // Measured: `1658` - // Estimated: `29615` - // Minimum execution time: 81_000_000 picoseconds. - Weight::from_parts(83_000_000, 0) - .saturating_add(Weight::from_parts(0, 29615)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } /// Storage: `DarwiniaStaking::Collators` (r:1 w:1) /// Proof: `DarwiniaStaking::Collators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) fn collect() -> Weight { diff --git a/runtime/darwinia/src/pallets/staking.rs b/runtime/darwinia/src/pallets/staking.rs index 1d10f0e6a..82cceb2ed 100644 --- a/runtime/darwinia/src/pallets/staking.rs +++ b/runtime/darwinia/src/pallets/staking.rs @@ -23,8 +23,6 @@ use frame_support::traits::Currency; fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); -type MinStakingDuration = ConstU32<{ DURATION }>; - pub enum RingStaking {} impl darwinia_staking::Stake for RingStaking { type AccountId = AccountId; @@ -119,8 +117,6 @@ impl darwinia_staking::Config for Runtime { type KtonRewardDistributionContract = darwinia_staking::KtonRewardDistributionContract; type KtonStakerNotifier = darwinia_staking::KtonStakerNotifier; type MaxDeposits = ::MaxDeposits; - type MaxUnstakings = ConstU32<16>; - type MinStakingDuration = MinStakingDuration; type Ring = RingStaking; type RuntimeEvent = RuntimeEvent; type ShouldEndSession = ShouldEndSession; diff --git a/runtime/darwinia/src/weights/darwinia_staking.rs b/runtime/darwinia/src/weights/darwinia_staking.rs index 23bf73a78..ebc10730e 100644 --- a/runtime/darwinia/src/weights/darwinia_staking.rs +++ b/runtime/darwinia/src/weights/darwinia_staking.rs @@ -109,41 +109,6 @@ impl darwinia_staking::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(7)) } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `DarwiniaStaking::RingPool` (r:1 w:1) - /// Proof: `DarwiniaStaking::RingPool` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:0) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - /// The range of component `x` is `[0, 1023]`. - fn restake(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1637` - // Estimated: `29615` - // Minimum execution time: 10_000_000 picoseconds. - Weight::from_parts(52_307_173, 0) - .saturating_add(Weight::from_parts(0, 29615)) - // Standard Error: 931 - .saturating_add(Weight::from_parts(5_747, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) - } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:1) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - fn claim() -> Weight { - // Proof Size summary in bytes: - // Measured: `1725` - // Estimated: `29615` - // Minimum execution time: 81_000_000 picoseconds. - Weight::from_parts(81_000_000, 0) - .saturating_add(Weight::from_parts(0, 29615)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } /// Storage: `DarwiniaStaking::Collators` (r:1 w:1) /// Proof: `DarwiniaStaking::Collators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) fn collect() -> Weight { diff --git a/runtime/pangolin/src/pallets/staking.rs b/runtime/pangolin/src/pallets/staking.rs index de9baa44e..251f986c2 100644 --- a/runtime/pangolin/src/pallets/staking.rs +++ b/runtime/pangolin/src/pallets/staking.rs @@ -102,8 +102,6 @@ impl darwinia_staking::Config for Runtime { type KtonRewardDistributionContract = darwinia_staking::KtonRewardDistributionContract; type KtonStakerNotifier = darwinia_staking::KtonStakerNotifier; type MaxDeposits = ::MaxDeposits; - type MaxUnstakings = ConstU32<16>; - type MinStakingDuration = ConstU32<{ 2 * MINUTES }>; type Ring = RingStaking; type RuntimeEvent = RuntimeEvent; type ShouldEndSession = ShouldEndSession; diff --git a/runtime/pangolin/src/weights/darwinia_staking.rs b/runtime/pangolin/src/weights/darwinia_staking.rs index 85f5c3714..07b1d4b49 100644 --- a/runtime/pangolin/src/weights/darwinia_staking.rs +++ b/runtime/pangolin/src/weights/darwinia_staking.rs @@ -109,41 +109,6 @@ impl darwinia_staking::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(7)) } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `DarwiniaStaking::RingPool` (r:1 w:1) - /// Proof: `DarwiniaStaking::RingPool` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:0) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - /// The range of component `x` is `[0, 1023]`. - fn restake(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1637` - // Estimated: `29615` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(53_351_430, 0) - .saturating_add(Weight::from_parts(0, 29615)) - // Standard Error: 969 - .saturating_add(Weight::from_parts(4_963, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) - } - /// Storage: `DarwiniaStaking::Ledgers` (r:1 w:1) - /// Proof: `DarwiniaStaking::Ledgers` (`max_values`: None, `max_size`: Some(1833), added: 4308, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) - /// Storage: `Deposit::Deposits` (r:1 w:1) - /// Proof: `Deposit::Deposits` (`max_values`: None, `max_size`: Some(26150), added: 28625, mode: `MaxEncodedLen`) - fn claim() -> Weight { - // Proof Size summary in bytes: - // Measured: `1725` - // Estimated: `29615` - // Minimum execution time: 81_000_000 picoseconds. - Weight::from_parts(82_000_000, 0) - .saturating_add(Weight::from_parts(0, 29615)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } /// Storage: `DarwiniaStaking::Collators` (r:1 w:1) /// Proof: `DarwiniaStaking::Collators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) fn collect() -> Weight {