From 834c75ed844b4f6dbc2ca83276dfc269e16024ac Mon Sep 17 00:00:00 2001 From: PraetorP Date: Fri, 02 Sep 2022 11:19:32 +0000 Subject: [PATCH] change unstake and on_initrialize logicc and + added `Reserved` --- --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -250,14 +250,17 @@ mod app_promotion_unique_rpc { use super::*; - + #[rpc(server)] #[async_trait] pub trait AppPromotionApi { /// Returns the total amount of staked tokens. #[method(name = "appPromotion_totalStaked")] - fn total_staked(&self, staker: Option, at: Option) - -> Result; + fn total_staked( + &self, + staker: Option, + at: Option, + ) -> Result; ///Returns the total amount of staked tokens per block when staked. #[method(name = "appPromotion_totalStakedPerBlock")] @@ -269,8 +272,11 @@ /// Returns the total amount locked by staking tokens. #[method(name = "appPromotion_totalStakingLocked")] - fn total_staking_locked(&self, staker: CrossAccountId, at: Option) - -> Result; + fn total_staking_locked( + &self, + staker: CrossAccountId, + at: Option, + ) -> Result; /// Returns the total amount of tokens pending withdrawal from staking. #[method(name = "appPromotion_pendingUnstake")] @@ -590,8 +596,12 @@ } impl - app_promotion_unique_rpc::AppPromotionApiServer<::Hash, BlockNumber, CrossAccountId, AccountId> - for AppPromotion + app_promotion_unique_rpc::AppPromotionApiServer< + ::Hash, + BlockNumber, + CrossAccountId, + AccountId, + > for AppPromotion where Block: BlockT, BlockNumber: Decode + Member + AtLeast32BitUnsigned, --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -148,7 +148,12 @@ C::Api: fp_rpc::ConvertTransactionRuntimeApi, C::Api: up_rpc::UniqueApi::CrossAccountId, AccountId>, - C::Api: app_promotion_rpc::AppPromotionApi::CrossAccountId, AccountId>, + C::Api: app_promotion_rpc::AppPromotionApi< + Block, + BlockNumber, + ::CrossAccountId, + AccountId, + >, C::Api: rmrk_rpc::RmrkApi< Block, AccountId, --- a/pallets/app-promotion/src/benchmarking.rs +++ b/pallets/app-promotion/src/benchmarking.rs @@ -39,13 +39,13 @@ T::BlockNumber: From + Into, <::Currency as Currency>::Balance: Sum + From } - start_app_promotion { + // start_app_promotion { - } : {PromototionPallet::::start_app_promotion(RawOrigin::Root.into(), None)?} + // } : {PromototionPallet::::start_app_promotion(RawOrigin::Root.into(), None)?} - stop_app_promotion{ - PromototionPallet::::start_app_promotion(RawOrigin::Root.into(), Some(25.into()))?; - } : {PromototionPallet::::stop_app_promotion(RawOrigin::Root.into())?} + // stop_app_promotion{ + // PromototionPallet::::start_app_promotion(RawOrigin::Root.into(), Some(25.into()))?; + // } : {PromototionPallet::::stop_app_promotion(RawOrigin::Root.into())?} set_admin_address { let pallet_admin = account::("admin", 0, SEED); @@ -58,6 +58,10 @@ PromototionPallet::::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?; let _ = ::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); let staker: T::AccountId = account("caller", 0, SEED); + let stakers: Vec = (0..100).map(|index| account("staker", index, SEED)).collect(); + stakers.iter().for_each(|staker| { + ::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); + }); let _ = ::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); let _ = PromototionPallet::::stake(RawOrigin::Signed(staker.clone()).into(), share * ::Currency::total_balance(&staker))?; } : {PromototionPallet::::payout_stakers(RawOrigin::Signed(pallet_admin.clone()).into(), Some(1))?} @@ -70,9 +74,9 @@ unstake { let caller = account::("caller", 0, SEED); - let share = Perbill::from_rational(1u32, 10); + let share = Perbill::from_rational(1u32, 20); let _ = ::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); - let _ = PromototionPallet::::stake(RawOrigin::Signed(caller.clone()).into(), share * ::Currency::total_balance(&caller))?; + (0..10).map(|_| PromototionPallet::::stake(RawOrigin::Signed(caller.clone()).into(), share * ::Currency::total_balance(&caller))).collect::, _>>()?; } : {PromototionPallet::::unstake(RawOrigin::Signed(caller.clone()).into())?} --- a/pallets/app-promotion/src/lib.rs +++ b/pallets/app-promotion/src/lib.rs @@ -36,7 +36,12 @@ pub mod types; pub mod weights; -use sp_std::{vec::Vec, iter::Sum, borrow::ToOwned}; +use sp_std::{ + vec::{Vec}, + vec, + iter::Sum, + borrow::ToOwned, +}; use sp_core::H160; use codec::EncodeLike; use pallet_balances::BalanceLock; @@ -63,6 +68,9 @@ ArithmeticError, }; +pub const LOCK_IDENTIFIER: [u8; 8] = *b"appstake"; +const PENDING_LIMIT_PER_BLOCK: u32 = 3; + type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -71,18 +79,20 @@ // const WEEK: u32 = 7 * DAY; // const TWO_WEEK: u32 = 2 * WEEK; // const YEAR: u32 = DAY * 365; - -pub const LOCK_IDENTIFIER: [u8; 8] = *b"appstake"; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::{Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, PalletId}; + use frame_support::{ + Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, PalletId, + traits::ReservableCurrency, + }; use frame_system::pallet_prelude::*; #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::account::Config { - type Currency: ExtendedLockableCurrency; + type Currency: ExtendedLockableCurrency + + ReservableCurrency; type CollectionHandler: CollectionHandler< AccountId = Self::AccountId, @@ -149,6 +159,7 @@ NoPermission, /// Insufficient funds to perform an action NotSufficientFounds, + PendingForBlockOverflow, /// An error related to the fact that an invalid argument was passed to perform an action InvalidArgument, } @@ -175,25 +186,33 @@ StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>; /// Amount of tokens pending unstake per user per block. + // #[pallet::storage] + // pub type PendingUnstake = StorageNMap< + // Key = ( + // Key, + // Key, + // ), + // Value = BalanceOf, + // QueryKind = ValueQuery, + // >; #[pallet::storage] - pub type PendingUnstake = StorageNMap< - Key = ( - Key, - Key, - ), - Value = BalanceOf, - QueryKind = ValueQuery, + pub type PendingUnstake = StorageMap< + _, + Twox64Concat, + T::BlockNumber, + BoundedVec<(T::AccountId, BalanceOf), ConstU32>, + ValueQuery, >; /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`. #[pallet::storage] pub type StartBlock = StorageValue; - /// Next target block when interest is recalculated - #[pallet::storage] - #[pallet::getter(fn get_interest_block)] - pub type NextInterestBlock = - StorageValue; + // /// Next target block when interest is recalculated + // #[pallet::storage] + // #[pallet::getter(fn get_interest_block)] + // pub type NextInterestBlock = + // StorageValue; /// Stores hash a record for which the last revenue recalculation was performed. /// If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers. @@ -204,59 +223,26 @@ #[pallet::hooks] impl Hooks> for Pallet { - fn on_initialize(current_block: T::BlockNumber) -> Weight + fn on_initialize(current_block_number: T::BlockNumber) -> Weight where ::BlockNumber: From, { let mut consumed_weight = 0; - // let mut add_weight = |reads, writes, weight| { - // consumed_weight += T::DbWeight::get().reads_writes(reads, writes); - // consumed_weight += weight; - // }; + let mut add_weight = |reads, writes, weight| { + consumed_weight += T::DbWeight::get().reads_writes(reads, writes); + consumed_weight += weight; + }; - let current_relay_block = T::RelayBlockNumberProvider::current_block_number(); - PendingUnstake::::iter() - .filter_map(|((staker, block), amount)| { - if block <= current_relay_block { - Some((staker, block, amount)) - } else { - None - } - }) - .for_each(|(staker, block, amount)| { - Self::unlock_balance_unchecked(&staker, amount); - >::remove((staker, block)); - }); + let block_pending = PendingUnstake::::take(current_block_number); - // let next_interest_block = Self::get_interest_block(); - // let current_relay_block = T::RelayBlockNumberProvider::current_block_number(); - // if next_interest_block != 0.into() && current_relay_block >= next_interest_block { - // let mut acc = >::default(); - // let mut base_acc = >::default(); + add_weight(0, 1, 0); - // NextInterestBlock::::set( - // NextInterestBlock::::get() + T::RecalculationInterval::get(), - // ); - // add_weight(0, 1, 0); - - // Staked::::iter() - // .filter(|((_, block), _)| { - // *block + T::RecalculationInterval::get() <= current_relay_block - // }) - // .for_each(|((staker, block), amount)| { - // Self::recalculate_stake(&staker, block, amount, &mut acc); - // add_weight(0, 0, T::WeightInfo::recalculate_stake()); - // base_acc += amount; - // }); - // >::get() - // .checked_add(&acc) - // .map(|res| >::set(res)); + if !block_pending.is_empty() { + block_pending.into_iter().for_each(|(staker, amount)| { + >::unreserve(&staker, amount); + }); + } - // Self::deposit_event(Event::StakingRecalculation(base_acc, acc)); - // add_weight(0, 1, 0); - // } else { - // add_weight(1, 0, 0) - // }; consumed_weight } } @@ -275,44 +261,44 @@ Ok(()) } - #[pallet::weight(T::WeightInfo::start_app_promotion())] - pub fn start_app_promotion( - origin: OriginFor, - promotion_start_relay_block: Option, - ) -> DispatchResult - where - ::BlockNumber: From, - { - ensure_root(origin)?; + // #[pallet::weight(T::WeightInfo::start_app_promotion())] + // pub fn start_app_promotion( + // origin: OriginFor, + // promotion_start_relay_block: Option, + // ) -> DispatchResult + // where + // ::BlockNumber: From, + // { + // ensure_root(origin)?; - // Start app-promotion mechanics if it has not been yet initialized - if >::get() == 0u32.into() { - let start_block = promotion_start_relay_block - .unwrap_or(T::RelayBlockNumberProvider::current_block_number()); + // // Start app-promotion mechanics if it has not been yet initialized + // if >::get() == 0u32.into() { + // let start_block = promotion_start_relay_block + // .unwrap_or(T::RelayBlockNumberProvider::current_block_number()); - // Set promotion global start block - >::set(start_block); + // // Set promotion global start block + // >::set(start_block); - >::set(start_block + T::RecalculationInterval::get()); - } + // >::set(start_block + T::RecalculationInterval::get()); + // } - Ok(()) - } + // Ok(()) + // } - #[pallet::weight(T::WeightInfo::stop_app_promotion())] - pub fn stop_app_promotion(origin: OriginFor) -> DispatchResult - where - ::BlockNumber: From, - { - ensure_root(origin)?; + // #[pallet::weight(T::WeightInfo::stop_app_promotion())] + // pub fn stop_app_promotion(origin: OriginFor) -> DispatchResult + // where + // ::BlockNumber: From, + // { + // ensure_root(origin)?; - if >::get() != 0u32.into() { - >::set(T::BlockNumber::default()); - >::set(T::BlockNumber::default()); - } + // if >::get() != 0u32.into() { + // >::set(T::BlockNumber::default()); + // >::set(T::BlockNumber::default()); + // } - Ok(()) - } + // Ok(()) + // } #[pallet::weight(T::WeightInfo::stake())] pub fn stake(staker: OriginFor, amount: BalanceOf) -> DispatchResult { @@ -369,6 +355,10 @@ #[pallet::weight(T::WeightInfo::unstake())] pub fn unstake(staker: OriginFor) -> DispatchResultWithPostInfo { let staker_id = ensure_signed(staker)?; + let block = >::block_number() + T::PendingInterval::get(); + let mut pendings = >::get(block); + + ensure!(pendings.is_full(), Error::::PendingForBlockOverflow); let mut total_stakes = 0u64; @@ -382,15 +372,17 @@ if total_staked.is_zero() { return Ok(None.into()); } - let block = - T::RelayBlockNumberProvider::current_block_number() + T::PendingInterval::get(); - >::insert( - (&staker_id, block), - >::get((&staker_id, block)) - .checked_add(&total_staked) - .ok_or(ArithmeticError::Overflow)?, - ); + pendings + .try_push((staker_id.clone(), total_staked)) + .map_err(|_| Error::::PendingForBlockOverflow)?; + + >::insert(block, pendings); + + Self::unlock_balance_unchecked(&staker_id, total_staked); + + >::reserve(&staker_id, total_staked)?; + TotalStaked::::set( TotalStaked::::get() .checked_sub(&total_staked) @@ -671,17 +663,37 @@ <::Currency as Currency>::Balance: Sum, { pub fn cross_id_pending_unstake(staker: Option) -> BalanceOf { - staker.map_or(PendingUnstake::::iter_values().sum(), |s| { - PendingUnstake::::iter_prefix_values((s.as_sub(),)).sum() - }) + staker.map_or( + PendingUnstake::::iter_values() + .flat_map(|pendings| pendings.into_iter().map(|(_, amount)| amount)) + .sum(), + |s| { + PendingUnstake::::iter_values() + .flatten() + .filter_map(|(id, amount)| { + if id == *s.as_sub() { + Some(amount) + } else { + None + } + }) + .sum() + }, + ) } pub fn cross_id_pending_unstake_per_block( staker: T::CrossAccountId, ) -> Vec<(T::BlockNumber, BalanceOf)> { - let mut unsorted_res = PendingUnstake::::iter_prefix((staker.as_sub(),)) - .into_iter() - .collect::>(); + let mut unsorted_res = vec![]; + PendingUnstake::::iter().for_each(|(block, pendings)| { + pendings.into_iter().for_each(|(id, amount)| { + if id == *staker.as_sub() { + unsorted_res.push((block, amount)); + }; + }) + }); + unsorted_res.sort_by_key(|(block, _)| *block); unsorted_res } --- a/pallets/app-promotion/src/tests.rs +++ b/pallets/app-promotion/src/tests.rs @@ -16,20 +16,20 @@ #![cfg(test)] #![allow(clippy::from_over_into)] -use crate as pallet_promotion; +// use crate as pallet_promotion; -use frame_benchmarking::{add_benchmark, BenchmarkBatch}; -use frame_support::{ - assert_ok, parameter_types, - traits::{Currency, OnInitialize, Everything, ConstU32}, -}; -use frame_system::RawOrigin; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup}, - testing::Header, - Perbill, Perquintill, -}; +// use frame_benchmarking::{add_benchmark, BenchmarkBatch}; +// use frame_support::{ +// assert_ok, parameter_types, +// traits::{Currency, OnInitialize, Everything, ConstU32}, +// }; +// use frame_system::RawOrigin; +// use sp_core::H256; +// use sp_runtime::{ +// traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup}, +// testing::Header, +// Perbill, Perquintill, +// }; // type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; // type Block = frame_system::mocking::MockBlock; @@ -127,24 +127,24 @@ // } ) // } -#[test] -fn test_perbill() { - const ONE_UNIQE: u128 = 1_000_000_000_000_000_000; - const SECONDS_TO_BLOCK: u32 = 12; - const DAY: u32 = 60 * 60 * 24 / SECONDS_TO_BLOCK; - const RECALCULATION_INTERVAL: u32 = 10; - let day_rate = Perbill::from_rational(5u64, 10_000); - let interval_rate = - Perbill::from_rational::(RECALCULATION_INTERVAL.into(), DAY.into()) * day_rate; - println!("{:?}", interval_rate * ONE_UNIQE + ONE_UNIQE); - println!("{:?}", day_rate * ONE_UNIQE); - println!("{:?}", Perbill::one() * ONE_UNIQE); - println!("{:?}", ONE_UNIQE); - let mut next_iters = ONE_UNIQE + interval_rate * ONE_UNIQE; - next_iters += interval_rate * next_iters; - println!("{:?}", next_iters); - let day_income = day_rate * ONE_UNIQE; - let interval_income = interval_rate * ONE_UNIQE; - let ratio = day_income / interval_income; - println!("{:?} || {:?}", ratio, DAY / RECALCULATION_INTERVAL); -} +// #[test] +// fn test_perbill() { +// const ONE_UNIQE: u128 = 1_000_000_000_000_000_000; +// const SECONDS_TO_BLOCK: u32 = 12; +// const DAY: u32 = 60 * 60 * 24 / SECONDS_TO_BLOCK; +// const RECALCULATION_INTERVAL: u32 = 10; +// let day_rate = Perbill::from_rational(5u64, 10_000); +// let interval_rate = +// Perbill::from_rational::(RECALCULATION_INTERVAL.into(), DAY.into()) * day_rate; +// println!("{:?}", interval_rate * ONE_UNIQE + ONE_UNIQE); +// println!("{:?}", day_rate * ONE_UNIQE); +// println!("{:?}", Perbill::one() * ONE_UNIQE); +// println!("{:?}", ONE_UNIQE); +// let mut next_iters = ONE_UNIQE + interval_rate * ONE_UNIQE; +// next_iters += interval_rate * next_iters; +// println!("{:?}", next_iters); +// let day_income = day_rate * ONE_UNIQE; +// let interval_income = interval_rate * ONE_UNIQE; +// let ratio = day_income / interval_income; +// println!("{:?} || {:?}", ratio, DAY / RECALCULATION_INTERVAL); +// } --- a/pallets/app-promotion/src/weights.rs +++ b/pallets/app-promotion/src/weights.rs @@ -3,7 +3,7 @@ //! Autogenerated weights for pallet_app_promotion //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-31, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-09-01, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -34,8 +34,6 @@ /// Weight functions needed for pallet_app_promotion. pub trait WeightInfo { - fn start_app_promotion() -> Weight; - fn stop_app_promotion() -> Weight; fn set_admin_address() -> Weight; fn payout_stakers() -> Weight; fn stake() -> Weight; @@ -49,24 +47,9 @@ /// Weights for pallet_app_promotion using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Promotion StartBlock (r:1 w:1) - // Storage: ParachainSystem ValidationData (r:1 w:0) - // Storage: Promotion NextInterestBlock (r:0 w:1) - fn start_app_promotion() -> Weight { - (3_995_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - // Storage: Promotion StartBlock (r:1 w:1) - // Storage: Promotion NextInterestBlock (r:0 w:1) - fn stop_app_promotion() -> Weight { - (3_623_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } // Storage: Promotion Admin (r:0 w:1) fn set_admin_address() -> Weight { - (1_203_000 as Weight) + (515_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) @@ -74,54 +57,56 @@ // Storage: Promotion NextCalculatedRecord (r:1 w:1) // Storage: Promotion Staked (r:2 w:0) fn payout_stakers() -> Weight { - (10_859_000 as Weight) + (8_475_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: System Account (r:1 w:1) + // Storage: Promotion StakesPerAccount (r:1 w:1) // Storage: Balances Locks (r:1 w:1) // Storage: ParachainSystem ValidationData (r:1 w:0) // Storage: Promotion Staked (r:1 w:1) // Storage: Promotion TotalStaked (r:1 w:1) fn stake() -> Weight { - (14_789_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + (12_266_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) } // Storage: Promotion Staked (r:2 w:1) // Storage: ParachainSystem ValidationData (r:1 w:0) // Storage: Promotion PendingUnstake (r:1 w:1) // Storage: Promotion TotalStaked (r:1 w:1) + // Storage: Promotion StakesPerAccount (r:0 w:1) fn unstake() -> Weight { - (16_889_000 as Weight) + (10_663_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: Common CollectionById (r:1 w:1) fn sponsor_collection() -> Weight { - (18_377_000 as Weight) + (10_879_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: Common CollectionById (r:1 w:1) fn stop_sponsoring_collection() -> Weight { - (13_989_000 as Weight) + (10_548_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: EvmContractHelpers Sponsoring (r:0 w:1) fn sponsor_contract() -> Weight { - (4_162_000 as Weight) + (2_130_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: EvmContractHelpers Sponsoring (r:1 w:1) fn stop_sponsoring_contract() -> Weight { - (5_457_000 as Weight) + (3_509_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -129,24 +114,9 @@ // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Promotion StartBlock (r:1 w:1) - // Storage: ParachainSystem ValidationData (r:1 w:0) - // Storage: Promotion NextInterestBlock (r:0 w:1) - fn start_app_promotion() -> Weight { - (3_995_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) - } - // Storage: Promotion StartBlock (r:1 w:1) - // Storage: Promotion NextInterestBlock (r:0 w:1) - fn stop_app_promotion() -> Weight { - (3_623_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) - } // Storage: Promotion Admin (r:0 w:1) fn set_admin_address() -> Weight { - (1_203_000 as Weight) + (515_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) @@ -154,54 +124,56 @@ // Storage: Promotion NextCalculatedRecord (r:1 w:1) // Storage: Promotion Staked (r:2 w:0) fn payout_stakers() -> Weight { - (10_859_000 as Weight) + (8_475_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: System Account (r:1 w:1) + // Storage: Promotion StakesPerAccount (r:1 w:1) // Storage: Balances Locks (r:1 w:1) // Storage: ParachainSystem ValidationData (r:1 w:0) // Storage: Promotion Staked (r:1 w:1) // Storage: Promotion TotalStaked (r:1 w:1) fn stake() -> Weight { - (14_789_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + (12_266_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } // Storage: Promotion Staked (r:2 w:1) // Storage: ParachainSystem ValidationData (r:1 w:0) // Storage: Promotion PendingUnstake (r:1 w:1) // Storage: Promotion TotalStaked (r:1 w:1) + // Storage: Promotion StakesPerAccount (r:0 w:1) fn unstake() -> Weight { - (16_889_000 as Weight) + (10_663_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: Common CollectionById (r:1 w:1) fn sponsor_collection() -> Weight { - (18_377_000 as Weight) + (10_879_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: Common CollectionById (r:1 w:1) fn stop_sponsoring_collection() -> Weight { - (13_989_000 as Weight) + (10_548_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: EvmContractHelpers Sponsoring (r:0 w:1) fn sponsor_contract() -> Weight { - (4_162_000 as Weight) + (2_130_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Promotion Admin (r:1 w:0) // Storage: EvmContractHelpers Sponsoring (r:1 w:1) fn stop_sponsoring_contract() -> Weight { - (5_457_000 as Weight) + (3_509_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } --- a/runtime/common/runtime_apis.rs +++ b/runtime/common/runtime_apis.rs @@ -197,11 +197,11 @@ #[cfg(feature = "app-promotion")] return Ok(>::cross_id_total_staked(staker).unwrap_or_default()); } - + fn total_staked_per_block(staker: CrossAccountId) -> Result, DispatchError> { #[cfg(not(feature = "app-promotion"))] return unsupported!(); - + #[cfg(feature = "app-promotion")] return Ok(>::cross_id_total_staked_per_block(staker)); } @@ -209,7 +209,7 @@ fn total_staking_locked(staker: CrossAccountId) -> Result { #[cfg(not(feature = "app-promotion"))] return unsupported!(); - + #[cfg(feature = "app-promotion")] return Ok(>::cross_id_locked_balance(staker)); } @@ -217,7 +217,7 @@ fn pending_unstake(staker: Option) -> Result { #[cfg(not(feature = "app-promotion"))] return unsupported!(); - + #[cfg(feature = "app-promotion")] return Ok(>::cross_id_pending_unstake(staker)); } @@ -225,7 +225,7 @@ fn pending_unstake_per_block(staker: CrossAccountId) -> Result, DispatchError> { #[cfg(not(feature = "app-promotion"))] return unsupported!(); - + #[cfg(feature = "app-promotion")] return Ok(>::cross_id_pending_unstake_per_block(staker)) } -- gitstuff