difftreelog
fix runtime benchmarks, `payout_stakers` logic, bencmarkr for payout_stakers
in: master
15 files changed
pallets/app-promotion/Cargo.tomldiffbeforeafterboth--- a/pallets/app-promotion/Cargo.toml
+++ b/pallets/app-promotion/Cargo.toml
@@ -20,18 +20,23 @@
'frame-benchmarking',
'frame-support/runtime-benchmarks',
'frame-system/runtime-benchmarks',
+ # 'pallet-unique/runtime-benchmarks',
]
std = [
'codec/std',
- 'serde/std',
+ 'frame-benchmarking/std',
'frame-support/std',
'frame-system/std',
'pallet-balances/std',
'pallet-timestamp/std',
'pallet-randomness-collective-flip/std',
+ 'pallet-evm/std',
+ 'sp-io/std',
'sp-std/std',
'sp-runtime/std',
- 'frame-benchmarking/std',
+ 'sp-core/std',
+ 'serde/std',
+
]
################################################################################
@@ -108,24 +113,24 @@
# local dependencies
[dependencies.up-data-structs]
default-features = false
-path = "../../primitives/data-structs"
+path = "../../primitives/data-structs"
[dependencies.pallet-common]
default-features = false
-path = "../common"
+path = "../common"
[dependencies.pallet-unique]
default-features = false
-path = "../unique"
+path = "../unique"
[dependencies.pallet-evm-contract-helpers]
default-features = false
-path = "../evm-contract-helpers"
+path = "../evm-contract-helpers"
[dev-dependencies]
[dependencies.pallet-evm-migration]
default-features = false
-path = "../evm-migration"
+path = "../evm-migration"
################################################################################
pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -28,11 +28,8 @@
use pallet_unique::benchmarking::create_nft_collection;
use pallet_evm_migration::Pallet as EvmMigrationPallet;
-// trait BenchmarkingConfig: Config + pallet_unique::Config { }
-
-// impl<T: Config + pallet_unique::Config> BenchmarkingConfig for T { }
+const SEED: u32 = 0;
-const SEED: u32 = 0;
benchmarks! {
where_clause{
where T: Config + pallet_unique::Config + pallet_evm_migration::Config ,
@@ -53,18 +50,32 @@
} : {PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin))?}
payout_stakers{
+ let b in 1..101;
+
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
- let share = Perbill::from_rational(1u32, 100);
+ let share = Perbill::from_rational(1u32, 20);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+
let staker: T::AccountId = account("caller", 0, SEED);
- let stakers: Vec<T::AccountId> = (0..100).map(|index| account("staker", index, SEED)).collect();
+ <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let stakers: Vec<T::AccountId> = (0..b).map(|index| account("staker", index, SEED)).collect();
stakers.iter().for_each(|staker| {
<T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
});
- let _ = <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), share * <T as Config>::Currency::total_balance(&staker))?;
- } : {PromototionPallet::<T>::payout_stakers(RawOrigin::Signed(pallet_admin.clone()).into(), Some(1))?}
+ (0..10).try_for_each(|_| {
+ stakers.iter()
+ .map(|staker| {
+
+ PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())
+ }).collect::<Result<Vec<_>, _>>()?;
+ <frame_system::Pallet<T>>::finalize();
+ Result::<(), sp_runtime::DispatchError>::Ok(())
+ })?;
+
+ // let _ = <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ // let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), share * <T as Config>::Currency::total_balance(&staker))?;
+ } : {PromototionPallet::<T>::payout_stakers(RawOrigin::Signed(pallet_admin.clone()).into(), Some(b as u8))?}
stake {
let caller = account::<T::AccountId>("caller", 0, SEED);
@@ -76,7 +87,10 @@
let caller = account::<T::AccountId>("caller", 0, SEED);
let share = Perbill::from_rational(1u32, 20);
let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- (0..10).map(|_| PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))).collect::<Result<Vec<_>, _>>()?;
+ (0..10).map(|_| {
+ <frame_system::Pallet<T>>::finalize();
+ PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))
+ }).collect::<Result<Vec<_>, _>>()?;
} : {PromototionPallet::<T>::unstake(RawOrigin::Signed(caller.clone()).into())?}
pallets/app-promotion/src/lib.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -157,7 +157,7 @@
/// No permission to perform an action
NoPermission,
/// Insufficient funds to perform an action
- NotSufficientFounds,
+ NotSufficientFunds,
PendingForBlockOverflow,
/// An error related to the fact that an invalid argument was passed to perform an action
InvalidArgument,
@@ -285,14 +285,23 @@
<<T as Config>::Currency as Currency<T::AccountId>>::ensure_can_withdraw(
&staker_id,
amount,
- WithdrawReasons::all(),
+ WithdrawReasons::RESERVE,
balance - amount,
)?;
Self::add_lock_balance(&staker_id, amount)?;
let block_number = T::RelayBlockNumberProvider::current_block_number();
- let recalc_block = (block_number / T::RecalculationInterval::get() + 2u32.into())
+
+ let recalculate_after_interval: T::BlockNumber =
+ if block_number % T::RecalculationInterval::get() == 0u32.into() {
+ 1u32.into()
+ } else {
+ 2u32.into()
+ };
+
+ let recalc_block = (block_number / T::RecalculationInterval::get()
+ + recalculate_after_interval)
* T::RecalculationInterval::get();
<Staked<T>>::insert((&staker_id, block_number), {
@@ -428,7 +437,7 @@
T::ContractHandler::remove_contract_sponsor(contract_id)
}
- #[pallet::weight(0)]
+ #[pallet::weight(T::WeightInfo::payout_stakers(stakers_number.unwrap_or(20) as u32))]
pub fn payout_stakers(admin: OriginFor<T>, stakers_number: Option<u8>) -> DispatchResult {
let admin_id = ensure_signed(admin)?;
@@ -495,6 +504,74 @@
// }
// }
+ // {
+ // let mut stakers_number = stakers_number.unwrap_or(20);
+ // let last_id = RefCell::new(None);
+ // let income_acc = RefCell::new(BalanceOf::<T>::default());
+ // let amount_acc = RefCell::new(BalanceOf::<T>::default());
+
+ // let flush_stake = || -> DispatchResult {
+ // if let Some(last_id) = &*last_id.borrow() {
+ // if !income_acc.borrow().is_zero() {
+ // <T::Currency as Currency<T::AccountId>>::transfer(
+ // &T::TreasuryAccountId::get(),
+ // last_id,
+ // *income_acc.borrow(),
+ // ExistenceRequirement::KeepAlive,
+ // )
+ // .and_then(|_| {
+ // Self::add_lock_balance(last_id, *income_acc.borrow());
+ // <TotalStaked<T>>::try_mutate(|staked| {
+ // staked
+ // .checked_add(&*income_acc.borrow())
+ // .ok_or(ArithmeticError::Overflow.into())
+ // })
+ // })?;
+
+ // Self::deposit_event(Event::StakingRecalculation(
+ // last_id.clone(),
+ // *amount_acc.borrow(),
+ // *income_acc.borrow(),
+ // ));
+ // }
+
+ // *income_acc.borrow_mut() = BalanceOf::<T>::default();
+ // *amount_acc.borrow_mut() = BalanceOf::<T>::default();
+ // }
+ // Ok(())
+ // };
+
+ // while let Some((
+ // (current_id, staked_block),
+ // (amount, next_recalc_block_for_stake),
+ // )) = storage_iterator.next()
+ // {
+ // if stakers_number == 0 {
+ // NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
+ // break;
+ // }
+ // stakers_number -= 1;
+ // if last_id.borrow().as_ref() != Some(¤t_id) {
+ // flush_stake()?;
+ // };
+ // *last_id.borrow_mut() = Some(current_id.clone());
+ // if current_recalc_block >= next_recalc_block_for_stake {
+ // *amount_acc.borrow_mut() += amount;
+ // Self::recalculate_and_insert_stake(
+ // ¤t_id,
+ // staked_block,
+ // next_recalc_block,
+ // amount,
+ // ((current_recalc_block - next_recalc_block_for_stake)
+ // / T::RecalculationInterval::get())
+ // .into() + 1,
+ // &mut *income_acc.borrow_mut(),
+ // );
+ // }
+ // }
+ // flush_stake()?;
+ // }
+
{
let mut stakers_number = stakers_number.unwrap_or(20);
let last_id = RefCell::new(None);
@@ -510,7 +587,14 @@
*income_acc.borrow(),
ExistenceRequirement::KeepAlive,
)
- .and_then(|_| Self::add_lock_balance(last_id, *income_acc.borrow()))?;
+ .and_then(|_| {
+ Self::add_lock_balance(last_id, *income_acc.borrow())?;
+ <TotalStaked<T>>::try_mutate(|staked| {
+ staked
+ .checked_add(&*income_acc.borrow())
+ .ok_or(ArithmeticError::Overflow.into())
+ })
+ })?;
Self::deposit_event(Event::StakingRecalculation(
last_id.clone(),
@@ -534,11 +618,11 @@
NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
break;
}
- stakers_number -= 1;
if last_id.borrow().as_ref() != Some(¤t_id) {
flush_stake()?;
+ *last_id.borrow_mut() = Some(current_id.clone());
+ stakers_number -= 1;
};
- *last_id.borrow_mut() = Some(current_id.clone());
if current_recalc_block >= next_recalc_block_for_stake {
*amount_acc.borrow_mut() += amount;
Self::recalculate_and_insert_stake(
pallets/app-promotion/src/types.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/types.rs
+++ b/pallets/app-promotion/src/types.rs
@@ -1,7 +1,5 @@
use codec::EncodeLike;
-use frame_support::{
- traits::LockableCurrency, WeakBoundedVec, Parameter, dispatch::DispatchResult, ensure,
-};
+use frame_support::{traits::LockableCurrency, WeakBoundedVec, Parameter, dispatch::DispatchResult};
use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};
use pallet_common::CollectionHandle;
pallets/app-promotion/src/weights.rsdiffbeforeafterboth1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_app_promotion4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-09-01, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// pallet13// --pallet14// pallet-app-promotion15// --wasm-execution16// compiled17// --extrinsic18// *19// --template20// .maintain/frame-weight-template.hbs21// --steps=5022// --repeat=8023// --heap-pages=409624// --output=./pallets/app-promotion/src/weights.rs2526#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]28#![allow(unused_imports)]29#![allow(missing_docs)]30#![allow(clippy::unnecessary_cast)]3132use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};33use sp_std::marker::PhantomData;3435/// Weight functions needed for pallet_app_promotion.36pub trait WeightInfo {37 fn set_admin_address() -> Weight;38 fn payout_stakers() -> Weight;39 fn stake() -> Weight;40 fn unstake() -> Weight;41 fn sponsor_collection() -> Weight;42 fn stop_sponsoring_collection() -> Weight;43 fn sponsor_contract() -> Weight;44 fn stop_sponsoring_contract() -> Weight;45}4647/// Weights for pallet_app_promotion using the Substrate node and recommended hardware.48pub struct SubstrateWeight<T>(PhantomData<T>);49impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {50 // Storage: Promotion Admin (r:0 w:1)51 fn set_admin_address() -> Weight {52 (515_000 as Weight)53 .saturating_add(T::DbWeight::get().writes(1 as Weight))54 }55 // Storage: Promotion Admin (r:1 w:0)56 // Storage: ParachainSystem ValidationData (r:1 w:0)57 // Storage: Promotion NextCalculatedRecord (r:1 w:1)58 // Storage: Promotion Staked (r:2 w:0)59 fn payout_stakers() -> Weight {60 (8_475_000 as Weight)61 .saturating_add(T::DbWeight::get().reads(5 as Weight))62 .saturating_add(T::DbWeight::get().writes(1 as Weight))63 }64 // Storage: System Account (r:1 w:1)65 // Storage: Promotion StakesPerAccount (r:1 w:1)66 // Storage: Balances Locks (r:1 w:1)67 // Storage: ParachainSystem ValidationData (r:1 w:0)68 // Storage: Promotion Staked (r:1 w:1)69 // Storage: Promotion TotalStaked (r:1 w:1)70 fn stake() -> Weight {71 (12_266_000 as Weight)72 .saturating_add(T::DbWeight::get().reads(6 as Weight))73 .saturating_add(T::DbWeight::get().writes(5 as Weight))74 }75 // Storage: Promotion Staked (r:2 w:1)76 // Storage: ParachainSystem ValidationData (r:1 w:0)77 // Storage: Promotion PendingUnstake (r:1 w:1)78 // Storage: Promotion TotalStaked (r:1 w:1)79 // Storage: Promotion StakesPerAccount (r:0 w:1)80 fn unstake() -> Weight {81 (10_663_000 as Weight)82 .saturating_add(T::DbWeight::get().reads(5 as Weight))83 .saturating_add(T::DbWeight::get().writes(4 as Weight))84 }85 // Storage: Promotion Admin (r:1 w:0)86 // Storage: Common CollectionById (r:1 w:1)87 fn sponsor_collection() -> Weight {88 (10_879_000 as Weight)89 .saturating_add(T::DbWeight::get().reads(2 as Weight))90 .saturating_add(T::DbWeight::get().writes(1 as Weight))91 }92 // Storage: Promotion Admin (r:1 w:0)93 // Storage: Common CollectionById (r:1 w:1)94 fn stop_sponsoring_collection() -> Weight {95 (10_548_000 as Weight)96 .saturating_add(T::DbWeight::get().reads(2 as Weight))97 .saturating_add(T::DbWeight::get().writes(1 as Weight))98 }99 // Storage: Promotion Admin (r:1 w:0)100 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)101 fn sponsor_contract() -> Weight {102 (2_130_000 as Weight)103 .saturating_add(T::DbWeight::get().reads(1 as Weight))104 .saturating_add(T::DbWeight::get().writes(1 as Weight))105 }106 // Storage: Promotion Admin (r:1 w:0)107 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)108 fn stop_sponsoring_contract() -> Weight {109 (3_509_000 as Weight)110 .saturating_add(T::DbWeight::get().reads(2 as Weight))111 .saturating_add(T::DbWeight::get().writes(1 as Weight))112 }113}114115// For backwards compatibility and tests116impl WeightInfo for () {117 // Storage: Promotion Admin (r:0 w:1)118 fn set_admin_address() -> Weight {119 (515_000 as Weight)120 .saturating_add(RocksDbWeight::get().writes(1 as Weight))121 }122 // Storage: Promotion Admin (r:1 w:0)123 // Storage: ParachainSystem ValidationData (r:1 w:0)124 // Storage: Promotion NextCalculatedRecord (r:1 w:1)125 // Storage: Promotion Staked (r:2 w:0)126 fn payout_stakers() -> Weight {127 (8_475_000 as Weight)128 .saturating_add(RocksDbWeight::get().reads(5 as Weight))129 .saturating_add(RocksDbWeight::get().writes(1 as Weight))130 }131 // Storage: System Account (r:1 w:1)132 // Storage: Promotion StakesPerAccount (r:1 w:1)133 // Storage: Balances Locks (r:1 w:1)134 // Storage: ParachainSystem ValidationData (r:1 w:0)135 // Storage: Promotion Staked (r:1 w:1)136 // Storage: Promotion TotalStaked (r:1 w:1)137 fn stake() -> Weight {138 (12_266_000 as Weight)139 .saturating_add(RocksDbWeight::get().reads(6 as Weight))140 .saturating_add(RocksDbWeight::get().writes(5 as Weight))141 }142 // Storage: Promotion Staked (r:2 w:1)143 // Storage: ParachainSystem ValidationData (r:1 w:0)144 // Storage: Promotion PendingUnstake (r:1 w:1)145 // Storage: Promotion TotalStaked (r:1 w:1)146 // Storage: Promotion StakesPerAccount (r:0 w:1)147 fn unstake() -> Weight {148 (10_663_000 as Weight)149 .saturating_add(RocksDbWeight::get().reads(5 as Weight))150 .saturating_add(RocksDbWeight::get().writes(4 as Weight))151 }152 // Storage: Promotion Admin (r:1 w:0)153 // Storage: Common CollectionById (r:1 w:1)154 fn sponsor_collection() -> Weight {155 (10_879_000 as Weight)156 .saturating_add(RocksDbWeight::get().reads(2 as Weight))157 .saturating_add(RocksDbWeight::get().writes(1 as Weight))158 }159 // Storage: Promotion Admin (r:1 w:0)160 // Storage: Common CollectionById (r:1 w:1)161 fn stop_sponsoring_collection() -> Weight {162 (10_548_000 as Weight)163 .saturating_add(RocksDbWeight::get().reads(2 as Weight))164 .saturating_add(RocksDbWeight::get().writes(1 as Weight))165 }166 // Storage: Promotion Admin (r:1 w:0)167 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)168 fn sponsor_contract() -> Weight {169 (2_130_000 as Weight)170 .saturating_add(RocksDbWeight::get().reads(1 as Weight))171 .saturating_add(RocksDbWeight::get().writes(1 as Weight))172 }173 // Storage: Promotion Admin (r:1 w:0)174 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)175 fn stop_sponsoring_contract() -> Weight {176 (3_509_000 as Weight)177 .saturating_add(RocksDbWeight::get().reads(2 as Weight))178 .saturating_add(RocksDbWeight::get().writes(1 as Weight))179 }180}1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_app_promotion4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-09-06, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// pallet13// --pallet14// pallet-app-promotion15// --wasm-execution16// compiled17// --extrinsic18// *19// --template20// .maintain/frame-weight-template.hbs21// --steps=5022// --repeat=8023// --heap-pages=409624// --output=./pallets/app-promotion/src/weights.rs2526#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]28#![allow(unused_imports)]29#![allow(missing_docs)]30#![allow(clippy::unnecessary_cast)]3132use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};33use sp_std::marker::PhantomData;3435/// Weight functions needed for pallet_app_promotion.36pub trait WeightInfo {37 fn set_admin_address() -> Weight;38 fn payout_stakers(b: u32, ) -> Weight;39 fn stake() -> Weight;40 fn unstake() -> Weight;41 fn sponsor_collection() -> Weight;42 fn stop_sponsoring_collection() -> Weight;43 fn sponsor_contract() -> Weight;44 fn stop_sponsoring_contract() -> Weight;45}4647/// Weights for pallet_app_promotion using the Substrate node and recommended hardware.48pub struct SubstrateWeight<T>(PhantomData<T>);49impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {50 // Storage: AppPromotion Admin (r:0 w:1)51 fn set_admin_address() -> Weight {52 (5_297_000 as Weight)53 .saturating_add(T::DbWeight::get().writes(1 as Weight))54 }55 // Storage: AppPromotion Admin (r:1 w:0)56 // Storage: ParachainSystem ValidationData (r:1 w:0)57 // Storage: AppPromotion NextCalculatedRecord (r:1 w:1)58 // Storage: AppPromotion Staked (r:2 w:0)59 fn payout_stakers(b: u32, ) -> Weight {60 (8_045_000 as Weight)61 // Standard Error: 19_00062 .saturating_add((4_778_000 as Weight).saturating_mul(b as Weight))63 .saturating_add(T::DbWeight::get().reads(4 as Weight))64 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))65 .saturating_add(T::DbWeight::get().writes(1 as Weight))66 }67 // Storage: System Account (r:1 w:1)68 // Storage: AppPromotion StakesPerAccount (r:1 w:1)69 // Storage: Balances Locks (r:1 w:1)70 // Storage: ParachainSystem ValidationData (r:1 w:0)71 // Storage: AppPromotion Staked (r:1 w:1)72 // Storage: AppPromotion TotalStaked (r:1 w:1)73 fn stake() -> Weight {74 (17_623_000 as Weight)75 .saturating_add(T::DbWeight::get().reads(6 as Weight))76 .saturating_add(T::DbWeight::get().writes(5 as Weight))77 }78 // Storage: AppPromotion PendingUnstake (r:1 w:1)79 // Storage: AppPromotion Staked (r:2 w:1)80 // Storage: Balances Locks (r:1 w:1)81 // Storage: System Account (r:1 w:1)82 // Storage: AppPromotion TotalStaked (r:1 w:1)83 // Storage: AppPromotion StakesPerAccount (r:0 w:1)84 fn unstake() -> Weight {85 (27_190_000 as Weight)86 .saturating_add(T::DbWeight::get().reads(6 as Weight))87 .saturating_add(T::DbWeight::get().writes(6 as Weight))88 }89 // Storage: AppPromotion Admin (r:1 w:0)90 // Storage: Common CollectionById (r:1 w:1)91 fn sponsor_collection() -> Weight {92 (11_351_000 as Weight)93 .saturating_add(T::DbWeight::get().reads(2 as Weight))94 .saturating_add(T::DbWeight::get().writes(1 as Weight))95 }96 // Storage: AppPromotion Admin (r:1 w:0)97 // Storage: Common CollectionById (r:1 w:1)98 fn stop_sponsoring_collection() -> Weight {99 (10_687_000 as Weight)100 .saturating_add(T::DbWeight::get().reads(2 as Weight))101 .saturating_add(T::DbWeight::get().writes(1 as Weight))102 }103 // Storage: AppPromotion Admin (r:1 w:0)104 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)105 fn sponsor_contract() -> Weight {106 (2_332_000 as Weight)107 .saturating_add(T::DbWeight::get().reads(1 as Weight))108 .saturating_add(T::DbWeight::get().writes(1 as Weight))109 }110 // Storage: AppPromotion Admin (r:1 w:0)111 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)112 fn stop_sponsoring_contract() -> Weight {113 (3_712_000 as Weight)114 .saturating_add(T::DbWeight::get().reads(2 as Weight))115 .saturating_add(T::DbWeight::get().writes(1 as Weight))116 }117}118119// For backwards compatibility and tests120impl WeightInfo for () {121 // Storage: AppPromotion Admin (r:0 w:1)122 fn set_admin_address() -> Weight {123 (5_297_000 as Weight)124 .saturating_add(RocksDbWeight::get().writes(1 as Weight))125 }126 // Storage: AppPromotion Admin (r:1 w:0)127 // Storage: ParachainSystem ValidationData (r:1 w:0)128 // Storage: AppPromotion NextCalculatedRecord (r:1 w:1)129 // Storage: AppPromotion Staked (r:2 w:0)130 fn payout_stakers(b: u32, ) -> Weight {131 (8_045_000 as Weight)132 // Standard Error: 19_000133 .saturating_add((4_778_000 as Weight).saturating_mul(b as Weight))134 .saturating_add(RocksDbWeight::get().reads(4 as Weight))135 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))136 .saturating_add(RocksDbWeight::get().writes(1 as Weight))137 }138 // Storage: System Account (r:1 w:1)139 // Storage: AppPromotion StakesPerAccount (r:1 w:1)140 // Storage: Balances Locks (r:1 w:1)141 // Storage: ParachainSystem ValidationData (r:1 w:0)142 // Storage: AppPromotion Staked (r:1 w:1)143 // Storage: AppPromotion TotalStaked (r:1 w:1)144 fn stake() -> Weight {145 (17_623_000 as Weight)146 .saturating_add(RocksDbWeight::get().reads(6 as Weight))147 .saturating_add(RocksDbWeight::get().writes(5 as Weight))148 }149 // Storage: AppPromotion PendingUnstake (r:1 w:1)150 // Storage: AppPromotion Staked (r:2 w:1)151 // Storage: Balances Locks (r:1 w:1)152 // Storage: System Account (r:1 w:1)153 // Storage: AppPromotion TotalStaked (r:1 w:1)154 // Storage: AppPromotion StakesPerAccount (r:0 w:1)155 fn unstake() -> Weight {156 (27_190_000 as Weight)157 .saturating_add(RocksDbWeight::get().reads(6 as Weight))158 .saturating_add(RocksDbWeight::get().writes(6 as Weight))159 }160 // Storage: AppPromotion Admin (r:1 w:0)161 // Storage: Common CollectionById (r:1 w:1)162 fn sponsor_collection() -> Weight {163 (11_351_000 as Weight)164 .saturating_add(RocksDbWeight::get().reads(2 as Weight))165 .saturating_add(RocksDbWeight::get().writes(1 as Weight))166 }167 // Storage: AppPromotion Admin (r:1 w:0)168 // Storage: Common CollectionById (r:1 w:1)169 fn stop_sponsoring_collection() -> Weight {170 (10_687_000 as Weight)171 .saturating_add(RocksDbWeight::get().reads(2 as Weight))172 .saturating_add(RocksDbWeight::get().writes(1 as Weight))173 }174 // Storage: AppPromotion Admin (r:1 w:0)175 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)176 fn sponsor_contract() -> Weight {177 (2_332_000 as Weight)178 .saturating_add(RocksDbWeight::get().reads(1 as Weight))179 .saturating_add(RocksDbWeight::get().writes(1 as Weight))180 }181 // Storage: AppPromotion Admin (r:1 w:0)182 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)183 fn stop_sponsoring_contract() -> Weight {184 (3_712_000 as Weight)185 .saturating_add(RocksDbWeight::get().reads(2 as Weight))186 .saturating_add(RocksDbWeight::get().writes(1 as Weight))187 }188}pallets/common/Cargo.tomldiffbeforeafterboth--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -40,4 +40,7 @@
"up-data-structs/std",
"pallet-evm/std",
]
-runtime-benchmarks = ["frame-benchmarking"]
+runtime-benchmarks = [
+ "frame-benchmarking/runtime-benchmarks",
+ "up-data-structs/runtime-benchmarks",
+]
runtime/common/config/pallets/app_promotion.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -22,7 +22,7 @@
use frame_support::{parameter_types, PalletId};
use sp_arithmetic::Perbill;
use up_common::{
- constants::{ UNIQUE, RELAY_DAYS},
+ constants::{UNIQUE, RELAY_DAYS},
types::Balance,
};
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -680,7 +680,7 @@
list_benchmark!(list, extra, pallet_unique, Unique);
list_benchmark!(list, extra, pallet_structure, Structure);
list_benchmark!(list, extra, pallet_inflation, Inflation);
- list_benchmark!(list, extra, pallet_app_promotion, Promotion);
+ list_benchmark!(list, extra, pallet_app_promotion, AppPromotion);
list_benchmark!(list, extra, pallet_fungible, Fungible);
list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
@@ -736,7 +736,7 @@
add_benchmark!(params, batches, pallet_unique, Unique);
add_benchmark!(params, batches, pallet_structure, Structure);
add_benchmark!(params, batches, pallet_inflation, Inflation);
- add_benchmark!(params, batches, pallet_app_promotion, Promotion);
+ add_benchmark!(params, batches, pallet_app_promotion, AppPromotion);
add_benchmark!(params, batches, pallet_fungible, Fungible);
add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
tests/src/interfaces/augment-api-consts.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-consts.ts
+++ b/tests/src/interfaces/augment-api-consts.ts
@@ -16,10 +16,6 @@
declare module '@polkadot/api-base/types/consts' {
interface AugmentedConsts<ApiType extends ApiTypes> {
appPromotion: {
- /**
- * In chain blocks.
- **/
- day: u32 & AugmentedConst<ApiType>;
intervalIncome: Perbill & AugmentedConst<ApiType>;
nominal: u128 & AugmentedConst<ApiType>;
/**
tests/src/interfaces/augment-api-errors.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-errors.ts
+++ b/tests/src/interfaces/augment-api-errors.ts
@@ -27,7 +27,7 @@
/**
* Insufficient funds to perform an action
**/
- NotSufficientFounds: AugmentedError<ApiType>;
+ NotSufficientFunds: AugmentedError<ApiType>;
PendingForBlockOverflow: AugmentedError<ApiType>;
/**
* Generic error
tests/src/interfaces/augment-api-events.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-events.ts
+++ b/tests/src/interfaces/augment-api-events.ts
@@ -16,7 +16,10 @@
declare module '@polkadot/api-base/types/events' {
interface AugmentedEvents<ApiType extends ApiTypes> {
appPromotion: {
+ SetAdmin: AugmentedEvent<ApiType, [AccountId32]>;
+ Stake: AugmentedEvent<ApiType, [AccountId32, u128]>;
StakingRecalculation: AugmentedEvent<ApiType, [AccountId32, u128, u128]>;
+ Unstake: AugmentedEvent<ApiType, [AccountId32, u128]>;
/**
* Generic event
**/
tests/src/interfaces/augment-api-query.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-query.ts
+++ b/tests/src/interfaces/augment-api-query.ts
@@ -36,10 +36,6 @@
* Amount of stakes for an Account
**/
stakesPerAccount: AugmentedQuery<ApiType, (arg: AccountId32 | string | Uint8Array) => Observable<u8>, [AccountId32]> & QueryableStorageEntry<ApiType, [AccountId32]>;
- /**
- * A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.
- **/
- startBlock: AugmentedQuery<ApiType, () => Observable<u32>, []> & QueryableStorageEntry<ApiType, []>;
totalStaked: AugmentedQuery<ApiType, () => Observable<u128>, []> & QueryableStorageEntry<ApiType, []>;
/**
* Generic query
tests/src/interfaces/default/types.tsdiffbeforeafterboth--- a/tests/src/interfaces/default/types.ts
+++ b/tests/src/interfaces/default/types.ts
@@ -844,17 +844,23 @@
export interface PalletAppPromotionError extends Enum {
readonly isAdminNotSet: boolean;
readonly isNoPermission: boolean;
- readonly isNotSufficientFounds: boolean;
+ readonly isNotSufficientFunds: boolean;
readonly isPendingForBlockOverflow: boolean;
readonly isInvalidArgument: boolean;
- readonly type: 'AdminNotSet' | 'NoPermission' | 'NotSufficientFounds' | 'PendingForBlockOverflow' | 'InvalidArgument';
+ readonly type: 'AdminNotSet' | 'NoPermission' | 'NotSufficientFunds' | 'PendingForBlockOverflow' | 'InvalidArgument';
}
/** @name PalletAppPromotionEvent */
export interface PalletAppPromotionEvent extends Enum {
readonly isStakingRecalculation: boolean;
readonly asStakingRecalculation: ITuple<[AccountId32, u128, u128]>;
- readonly type: 'StakingRecalculation';
+ readonly isStake: boolean;
+ readonly asStake: ITuple<[AccountId32, u128]>;
+ readonly isUnstake: boolean;
+ readonly asUnstake: ITuple<[AccountId32, u128]>;
+ readonly isSetAdmin: boolean;
+ readonly asSetAdmin: AccountId32;
+ readonly type: 'StakingRecalculation' | 'Stake' | 'Unstake' | 'SetAdmin';
}
/** @name PalletBalancesAccountData */
tests/src/interfaces/lookup.tsdiffbeforeafterboth--- a/tests/src/interfaces/lookup.ts
+++ b/tests/src/interfaces/lookup.ts
@@ -1061,7 +1061,10 @@
**/
PalletAppPromotionEvent: {
_enum: {
- StakingRecalculation: '(AccountId32,u128,u128)'
+ StakingRecalculation: '(AccountId32,u128,u128)',
+ Stake: '(AccountId32,u128)',
+ Unstake: '(AccountId32,u128)',
+ SetAdmin: 'AccountId32'
}
},
/**
@@ -3102,7 +3105,7 @@
* Lookup415: pallet_app_promotion::pallet::Error<T>
**/
PalletAppPromotionError: {
- _enum: ['AdminNotSet', 'NoPermission', 'NotSufficientFounds', 'PendingForBlockOverflow', 'InvalidArgument']
+ _enum: ['AdminNotSet', 'NoPermission', 'NotSufficientFunds', 'PendingForBlockOverflow', 'InvalidArgument']
},
/**
* Lookup418: pallet_evm::pallet::Error<T>
tests/src/interfaces/types-lookup.tsdiffbeforeafterboth--- a/tests/src/interfaces/types-lookup.ts
+++ b/tests/src/interfaces/types-lookup.ts
@@ -1202,7 +1202,13 @@
interface PalletAppPromotionEvent extends Enum {
readonly isStakingRecalculation: boolean;
readonly asStakingRecalculation: ITuple<[AccountId32, u128, u128]>;
- readonly type: 'StakingRecalculation';
+ readonly isStake: boolean;
+ readonly asStake: ITuple<[AccountId32, u128]>;
+ readonly isUnstake: boolean;
+ readonly asUnstake: ITuple<[AccountId32, u128]>;
+ readonly isSetAdmin: boolean;
+ readonly asSetAdmin: AccountId32;
+ readonly type: 'StakingRecalculation' | 'Stake' | 'Unstake' | 'SetAdmin';
}
/** @name PalletEvmEvent (104) */
@@ -3290,10 +3296,10 @@
interface PalletAppPromotionError extends Enum {
readonly isAdminNotSet: boolean;
readonly isNoPermission: boolean;
- readonly isNotSufficientFounds: boolean;
+ readonly isNotSufficientFunds: boolean;
readonly isPendingForBlockOverflow: boolean;
readonly isInvalidArgument: boolean;
- readonly type: 'AdminNotSet' | 'NoPermission' | 'NotSufficientFounds' | 'PendingForBlockOverflow' | 'InvalidArgument';
+ readonly type: 'AdminNotSet' | 'NoPermission' | 'NotSufficientFunds' | 'PendingForBlockOverflow' | 'InvalidArgument';
}
/** @name PalletEvmError (418) */