diff --git a/pallets/dapp-staking-v3/rpc/runtime-api/src/lib.rs b/pallets/dapp-staking-v3/rpc/runtime-api/src/lib.rs index d9911c45a4..ed4b1c77f7 100644 --- a/pallets/dapp-staking-v3/rpc/runtime-api/src/lib.rs +++ b/pallets/dapp-staking-v3/rpc/runtime-api/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use astar_primitives::dapp_staking::{DAppId, EraNumber, PeriodNumber, TierId}; +use astar_primitives::dapp_staking::{DAppId, EraNumber, PeriodNumber, RankedTier, TierId}; use astar_primitives::BlockNumber; pub use sp_std::collections::btree_map::BTreeMap; @@ -27,6 +27,7 @@ sp_api::decl_runtime_apis! { /// dApp Staking Api. /// /// Used to provide information otherwise not available via RPC. + #[api_version(2)] pub trait DappStakingApi { /// How many periods are there in one cycle. @@ -42,6 +43,10 @@ sp_api::decl_runtime_apis! { fn blocks_per_era() -> BlockNumber; /// Get dApp tier assignment for the given dApp. + #[changed_in(2)] fn get_dapp_tier_assignment() -> BTreeMap; + + /// Get dApp ranked tier assignment for the given dApp. + fn get_dapp_tier_assignment() -> BTreeMap; } } diff --git a/pallets/dapp-staking-v3/src/benchmarking/mod.rs b/pallets/dapp-staking-v3/src/benchmarking/mod.rs index b7b348806c..939b963690 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/mod.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/mod.rs @@ -999,7 +999,7 @@ mod benchmarks { #[block] { - let (dapp_tiers, _) = Pallet::::get_dapp_tier_assignment_and_rewards( + let (dapp_tiers, _count) = Pallet::::get_dapp_tier_assignment_and_rewards( reward_era, reward_period, reward_pool, @@ -1041,14 +1041,17 @@ mod benchmarks { &cleanup_marker.dapp_tiers_index, DAppTierRewardsFor:: { dapps: (0..T::MaxNumberOfContracts::get()) - .map(|dapp_id| (dapp_id as DAppId, 0)) - .collect::>() + .map(|dapp_id| (dapp_id as DAppId, RankedTier::new_saturated(0, 0))) + .collect::>() .try_into() .expect("Using `MaxNumberOfContracts` as length; QED."), rewards: vec![1_000_000_000_000; T::NumberOfTiers::get() as usize] .try_into() .expect("Using `NumberOfTiers` as length; QED."), period: 1, + rank_rewards: vec![0; T::NumberOfTiers::get() as usize] + .try_into() + .expect("Using `NumberOfTiers` as length; QED."), }, ); diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index 9c64c3e010..efd59cf16b 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -54,7 +54,8 @@ pub use sp_std::vec::Vec; use astar_primitives::{ dapp_staking::{ AccountCheck, CycleConfiguration, DAppId, EraNumber, Observer as DAppStakingObserver, - PeriodNumber, SmartContractHandle, StakingRewardHandler, TierId, TierSlots as TierSlotFunc, + PeriodNumber, Rank, RankedTier, SmartContractHandle, StakingRewardHandler, TierId, + TierSlots as TierSlotFunc, }, oracle::PriceProvider, Balance, BlockNumber, @@ -71,7 +72,9 @@ mod benchmarking; mod types; pub use types::*; +pub mod migration; pub mod weights; + pub use weights::WeightInfo; const LOG_TARGET: &str = "dapp-staking"; @@ -91,7 +94,7 @@ pub mod pallet { use super::*; /// The current storage version. - pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(6); + pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(7); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] @@ -198,6 +201,10 @@ pub mod pallet { #[pallet::constant] type NumberOfTiers: Get; + /// Tier ranking enabled. + #[pallet::constant] + type RankingEnabled: Get; + /// Weight info for various calls & operations in the pallet. type WeightInfo: WeightInfo; @@ -289,6 +296,7 @@ pub mod pallet { beneficiary: T::AccountId, smart_contract: T::SmartContract, tier_id: TierId, + rank: Rank, era: EraNumber, amount: Balance, }, @@ -1403,7 +1411,7 @@ pub mod pallet { Error::::RewardExpired ); - let (amount, tier_id) = + let (amount, ranked_tier) = dapp_tiers .try_claim(dapp_info.id) .map_err(|error| match error { @@ -1411,6 +1419,8 @@ pub mod pallet { _ => Error::::InternalClaimDAppError, })?; + let (tier_id, rank) = ranked_tier.deconstruct(); + // Get reward destination, and deposit the reward. let beneficiary = dapp_info.reward_beneficiary(); T::StakingRewardHandler::payout_reward(&beneficiary, amount) @@ -1423,6 +1433,7 @@ pub mod pallet { beneficiary: beneficiary.clone(), smart_contract, tier_id, + rank, era, amount, }); @@ -1670,7 +1681,7 @@ pub mod pallet { } /// Returns the dApp tier assignment for the current era, based on the current stake amounts. - pub fn get_dapp_tier_assignment() -> BTreeMap { + pub fn get_dapp_tier_assignment() -> BTreeMap { let protocol_state = ActiveProtocolState::::get(); let (dapp_tiers, _count) = Self::get_dapp_tier_assignment_and_rewards( @@ -1691,7 +1702,11 @@ pub mod pallet { /// /// 2. Sort the entries by the score, in descending order - the top score dApp comes first. /// - /// 3. Read in tier configuration. This contains information about how many slots per tier there are, + /// 3. Calculate rewards for each tier. + /// This is done by dividing the total reward pool into tier reward pools, + /// after which the tier reward pool is divided by the number of available slots in the tier. + /// + /// 4. Read in tier configuration. This contains information about how many slots per tier there are, /// as well as the threshold for each tier. Threshold is the minimum amount of stake required to be eligible for a tier. /// Iterate over tier thresholds & capacities, starting from the top tier, and assign dApps to them. /// @@ -1705,10 +1720,6 @@ pub mod pallet { /// ``` /// (Sort the entries by dApp ID, in ascending order. This is so we can efficiently search for them using binary search.) /// - /// 4. Calculate rewards for each tier. - /// This is done by dividing the total reward pool into tier reward pools, - /// after which the tier reward pool is divided by the number of available slots in the tier. - /// /// The returned object contains information about each dApp that made it into a tier. /// Alongside tier assignment info, number of read DB contract stake entries is returned. pub(crate) fn get_dapp_tier_assignment_and_rewards( @@ -1737,39 +1748,8 @@ pub mod pallet { // Sort by amount staked, in reverse - top dApp will end in the first place, 0th index. dapp_stakes.sort_unstable_by(|(_, amount_1), (_, amount_2)| amount_2.cmp(amount_1)); - // 3. - // Iterate over configured tier and potential dApps. - // Each dApp will be assigned to the best possible tier if it satisfies the required condition, - // and tier capacity hasn't been filled yet. - let mut dapp_tiers = BTreeMap::new(); let tier_config = TierConfig::::get(); - let mut global_idx = 0; - let mut tier_id = 0; - for (tier_capacity, tier_threshold) in tier_config - .slots_per_tier - .iter() - .zip(tier_config.tier_thresholds.iter()) - { - let max_idx = global_idx - .saturating_add(*tier_capacity as usize) - .min(dapp_stakes.len()); - - // Iterate over dApps until one of two conditions has been met: - // 1. Tier has no more capacity - // 2. dApp doesn't satisfy the tier threshold (since they're sorted, none of the following dApps will satisfy the condition either) - for (dapp_id, stake_amount) in dapp_stakes[global_idx..max_idx].iter() { - if tier_threshold.is_satisfied(*stake_amount) { - global_idx.saturating_inc(); - dapp_tiers.insert(*dapp_id, tier_id); - } else { - break; - } - } - - tier_id.saturating_inc(); - } - // In case when tier has 1 more free slot, but two dApps with exactly same score satisfy the threshold, // one of them will be assigned to the tier, and the other one will be assigned to the lower tier, if it exists. // @@ -1777,7 +1757,7 @@ pub mod pallet { // There is no guarantee this will persist in the future, so it's best for dApps to do their // best to avoid getting themselves into such situations. - // 4. Calculate rewards. + // 3. Calculate rewards. let tier_rewards = tier_config .reward_portion .iter() @@ -1791,6 +1771,67 @@ pub mod pallet { }) .collect::>(); + // 4. + // Iterate over configured tier and potential dApps. + // Each dApp will be assigned to the best possible tier if it satisfies the required condition, + // and tier capacity hasn't been filled yet. + let mut dapp_tiers = BTreeMap::new(); + let mut tier_slots = BTreeMap::new(); + + let mut upper_bound = Balance::zero(); + let mut rank_rewards = Vec::new(); + + for (tier_id, (tier_capacity, tier_threshold)) in tier_config + .slots_per_tier + .iter() + .zip(tier_config.tier_thresholds.iter()) + .enumerate() + { + let lower_bound = tier_threshold.threshold(); + + // Iterate over dApps until one of two conditions has been met: + // 1. Tier has no more capacity + // 2. dApp doesn't satisfy the tier threshold (since they're sorted, none of the following dApps will satisfy the condition either) + for (dapp_id, staked_amount) in dapp_stakes + .iter() + .skip(dapp_tiers.len()) + .take_while(|(_, amount)| tier_threshold.is_satisfied(*amount)) + .take(*tier_capacity as usize) + { + let rank = if T::RankingEnabled::get() { + RankedTier::find_rank(lower_bound, upper_bound, *staked_amount) + } else { + 0 + }; + tier_slots.insert(*dapp_id, RankedTier::new_saturated(tier_id as u8, rank)); + } + + // sum of all ranks for this tier + let ranks_sum = tier_slots + .iter() + .fold(0u32, |accum, (_, x)| accum.saturating_add(x.rank().into())); + + let reward_per_rank = if ranks_sum.is_zero() { + Balance::zero() + } else { + // calculate reward per rank + let tier_reward = tier_rewards.get(tier_id).copied().unwrap_or_default(); + let empty_slots = tier_capacity.saturating_sub(tier_slots.len() as u16); + let remaining_reward = tier_reward.saturating_mul(empty_slots.into()); + // make sure required reward doesn't exceed remaining reward + let reward_per_rank = tier_reward.saturating_div(RankedTier::MAX_RANK.into()); + let expected_reward_for_ranks = + reward_per_rank.saturating_mul(ranks_sum.into()); + let reward_for_ranks = expected_reward_for_ranks.min(remaining_reward); + // re-calculate reward per rank based on available reward + reward_for_ranks.saturating_div(ranks_sum.into()) + }; + + rank_rewards.push(reward_per_rank); + dapp_tiers.append(&mut tier_slots); + upper_bound = lower_bound; // current threshold becomes upper bound for next tier + } + // 5. // Prepare and return tier & rewards info. // In case rewards creation fails, we just write the default value. This should never happen though. @@ -1799,6 +1840,7 @@ pub mod pallet { dapp_tiers, tier_rewards, period, + rank_rewards, ) .unwrap_or_default(), counter, diff --git a/pallets/dapp-staking-v3/src/migration.rs b/pallets/dapp-staking-v3/src/migration.rs new file mode 100644 index 0000000000..51e198e1cb --- /dev/null +++ b/pallets/dapp-staking-v3/src/migration.rs @@ -0,0 +1,118 @@ +// This file is part of Astar. + +// Copyright (C) Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see . + +use super::*; +use frame_support::traits::OnRuntimeUpgrade; + +#[cfg(feature = "try-runtime")] +use sp_std::vec::Vec; + +#[cfg(feature = "try-runtime")] +use sp_runtime::TryRuntimeError; + +/// Exports for versioned migration `type`s for this pallet. +pub mod versioned_migrations { + use super::*; + + /// Migration V6 to V7 wrapped in a [`frame_support::migrations::VersionedMigration`], ensuring + /// the migration is only performed when on-chain version is 6. + pub type V6ToV7 = frame_support::migrations::VersionedMigration< + 6, + 7, + v7::VersionMigrateV6ToV7, + Pallet, + ::DbWeight, + >; +} + +/// Translate DAppTiers to include rank rewards. +mod v7 { + use super::*; + use crate::migration::v6::DAppTierRewards as DAppTierRewardsV6; + + pub struct VersionMigrateV6ToV7(PhantomData); + + impl OnRuntimeUpgrade for VersionMigrateV6ToV7 { + fn on_runtime_upgrade() -> Weight { + let current = Pallet::::current_storage_version(); + + let mut translated = 0usize; + DAppTiers::::translate::< + DAppTierRewardsV6, + _, + >(|_key, old_value| { + translated.saturating_inc(); + + // fill rank_rewards with zero + let mut rank_rewards = Vec::new(); + rank_rewards.resize_with(old_value.rewards.len(), || Balance::zero()); + + Some(DAppTierRewards { + dapps: old_value.dapps, + rewards: old_value.rewards, + period: old_value.period, + rank_rewards: BoundedVec::::try_from(rank_rewards) + .unwrap_or_default(), + }) + }); + + current.put::>(); + + log::info!("Upgraded {translated} dAppTiers to {current:?}"); + + T::DbWeight::get().reads_writes(1 + translated as u64, 1 + translated as u64) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, TryRuntimeError> { + Ok(Vec::new()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_data: Vec) -> Result<(), TryRuntimeError> { + ensure!( + Pallet::::on_chain_storage_version() >= 7, + "dapp-staking-v3::migration::v7: wrong storage version" + ); + Ok(()) + } + } +} + +pub mod v6 { + use astar_primitives::{ + dapp_staking::{DAppId, PeriodNumber, RankedTier}, + Balance, + }; + use frame_support::{ + pallet_prelude::{Decode, Get}, + BoundedBTreeMap, BoundedVec, + }; + + /// Information about all of the dApps that got into tiers, and tier rewards + #[derive(Decode)] + pub struct DAppTierRewards, NT: Get> { + /// DApps and their corresponding tiers (or `None` if they have been claimed in the meantime) + pub dapps: BoundedBTreeMap, + /// Rewards for each tier. First entry refers to the first tier, and so on. + pub rewards: BoundedVec, + /// Period during which this struct was created. + #[codec(compact)] + pub period: PeriodNumber, + } +} diff --git a/pallets/dapp-staking-v3/src/test/mock.rs b/pallets/dapp-staking-v3/src/test/mock.rs index 4551a0be79..aeb6dc7a63 100644 --- a/pallets/dapp-staking-v3/src/test/mock.rs +++ b/pallets/dapp-staking-v3/src/test/mock.rs @@ -24,7 +24,7 @@ use crate::{ use frame_support::{ construct_runtime, parameter_types, - traits::{fungible::Mutate as FunMutate, ConstU128, ConstU32}, + traits::{fungible::Mutate as FunMutate, ConstBool, ConstU128, ConstU32}, weights::Weight, }; use sp_arithmetic::fixed_point::FixedU128; @@ -221,6 +221,7 @@ impl pallet_dapp_staking::Config for Test { type MaxNumberOfStakedContracts = ConstU32<5>; type MinimumStakeAmount = ConstU128<3>; type NumberOfTiers = ConstU32<4>; + type RankingEnabled = ConstBool; type WeightInfo = weights::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper; diff --git a/pallets/dapp-staking-v3/src/test/testing_utils.rs b/pallets/dapp-staking-v3/src/test/testing_utils.rs index 7f869778d7..130bef2419 100644 --- a/pallets/dapp-staking-v3/src/test/testing_utils.rs +++ b/pallets/dapp-staking-v3/src/test/testing_utils.rs @@ -1015,7 +1015,7 @@ pub(crate) fn assert_claim_dapp_reward( .get(&era) .expect("Entry must exist.") .clone(); - let (expected_reward, expected_tier_id) = { + let (expected_reward, expected_ranked_tier) = { let mut info = pre_reward_info.clone(); info.try_claim(dapp_info.id).unwrap() }; @@ -1029,7 +1029,8 @@ pub(crate) fn assert_claim_dapp_reward( System::assert_last_event(RuntimeEvent::DappStaking(Event::DAppReward { beneficiary: beneficiary.clone(), smart_contract: smart_contract.clone(), - tier_id: expected_tier_id, + tier_id: expected_ranked_tier.tier(), + rank: expected_ranked_tier.rank(), era, amount: expected_reward, })); diff --git a/pallets/dapp-staking-v3/src/test/tests.rs b/pallets/dapp-staking-v3/src/test/tests.rs index 3e64d853be..13de8e6407 100644 --- a/pallets/dapp-staking-v3/src/test/tests.rs +++ b/pallets/dapp-staking-v3/src/test/tests.rs @@ -18,9 +18,9 @@ use crate::test::{mock::*, testing_utils::*}; use crate::{ - pallet::Config, ActiveProtocolState, ContractStake, DAppId, EraRewards, Error, Event, - ForcingType, GenesisConfig, IntegratedDApps, Ledger, NextDAppId, PeriodNumber, Permill, - Safeguard, StakerInfo, Subperiod, TierConfig, TierThreshold, + pallet::Config, ActiveProtocolState, ContractStake, DAppId, DAppTierRewardsFor, DAppTiers, + EraRewards, Error, Event, ForcingType, GenesisConfig, IntegratedDApps, Ledger, NextDAppId, + PeriodNumber, Permill, Safeguard, StakerInfo, Subperiod, TierConfig, TierThreshold, }; use frame_support::{ @@ -32,13 +32,18 @@ use frame_support::{ }, BoundedVec, }; -use sp_runtime::{traits::Zero, FixedU128}; +use sp_runtime::{ + traits::{ConstU32, Zero}, + BoundedBTreeMap, FixedU128, +}; use astar_primitives::{ - dapp_staking::{CycleConfiguration, EraNumber, SmartContractHandle, TierSlots}, + dapp_staking::{CycleConfiguration, EraNumber, RankedTier, SmartContractHandle, TierSlots}, Balance, BlockNumber, }; +use std::collections::BTreeMap; + #[test] fn maintenances_mode_works() { ExtBuilder::build().execute_with(|| { @@ -2470,6 +2475,13 @@ fn get_dapp_tier_assignment_and_rewards_basic_example_works() { dapp_reward_pool, ); + // There's enough reward to satisfy 100% reward per rank. + // Slot reward is 60_000 therefore expected rank reward is 6_000 + assert_eq!( + tier_assignment.rank_rewards, + BoundedVec::>::try_from(vec![0, 6_000, 0, 0]).unwrap() + ); + // Basic checks let number_of_tiers: u32 = ::NumberOfTiers::get(); assert_eq!(tier_assignment.period, protocol_state.period_number()); @@ -2483,18 +2495,18 @@ fn get_dapp_tier_assignment_and_rewards_basic_example_works() { // 1st tier checks let (dapp_1_tier, dapp_2_tier) = (tier_assignment.dapps[&0], tier_assignment.dapps[&1]); - assert_eq!(dapp_1_tier, 0); - assert_eq!(dapp_2_tier, 0); + assert_eq!(dapp_1_tier, RankedTier::new_saturated(0, 0)); + assert_eq!(dapp_2_tier, RankedTier::new_saturated(0, 0)); // 2nd tier checks let (dapp_3_tier, dapp_4_tier) = (tier_assignment.dapps[&2], tier_assignment.dapps[&3]); - assert_eq!(dapp_3_tier, 1); - assert_eq!(dapp_4_tier, 1); + assert_eq!(dapp_3_tier, RankedTier::new_saturated(1, 10)); + assert_eq!(dapp_4_tier, RankedTier::new_saturated(1, 9)); // 4th tier checks let (dapp_5_tier, dapp_6_tier) = (tier_assignment.dapps[&4], tier_assignment.dapps[&5]); - assert_eq!(dapp_5_tier, 3); - assert_eq!(dapp_6_tier, 3); + assert_eq!(dapp_5_tier, RankedTier::new_saturated(3, 0)); + assert_eq!(dapp_6_tier, RankedTier::new_saturated(3, 0)); // Sanity check - last dapp should not exists in the tier assignment assert!(tier_assignment @@ -3120,3 +3132,113 @@ fn base_number_of_slots_is_respected() { ); }) } + +#[test] +fn ranking_will_calc_reward_correctly() { + ExtBuilder::build().execute_with(|| { + // Tier config is specially adapted for this test. + TierConfig::::mutate(|config| { + config.slots_per_tier = BoundedVec::try_from(vec![2, 3, 2, 20]).unwrap(); + }); + + // Register smart contracts + let smart_contracts: Vec<_> = (1..=8u32) + .map(|x| { + let smart_contract = MockSmartContract::Wasm(x.into()); + assert_register(x.into(), &smart_contract); + smart_contract + }) + .collect(); + + fn lock_and_stake(account: usize, smart_contract: &MockSmartContract, amount: Balance) { + let account = account.try_into().unwrap(); + Balances::make_free_balance_be(&account, amount); + assert_lock(account, amount); + assert_stake(account, smart_contract, amount); + } + + for (idx, amount) in [101, 102, 100, 99, 15, 49, 35, 14].into_iter().enumerate() { + lock_and_stake(idx, &smart_contracts[idx], amount) + } + + // Finally, the actual test + let protocol_state = ActiveProtocolState::::get(); + let (tier_assignment, counter) = DappStaking::get_dapp_tier_assignment_and_rewards( + protocol_state.era + 1, + protocol_state.period_number(), + 1_000_000, + ); + + assert_eq!( + tier_assignment, + DAppTierRewardsFor:: { + dapps: BoundedBTreeMap::try_from(BTreeMap::from([ + (0, RankedTier::new_saturated(0, 0)), + (1, RankedTier::new_saturated(0, 0)), + (2, RankedTier::new_saturated(1, 10)), + (3, RankedTier::new_saturated(1, 9)), + (5, RankedTier::new_saturated(2, 9)), + (6, RankedTier::new_saturated(2, 5)), + (4, RankedTier::new_saturated(3, 0)), + ])) + .unwrap(), + rewards: BoundedVec::try_from(vec![200_000, 100_000, 100_000, 5_000]).unwrap(), + period: 1, + // Tier 0 has no ranking therefore no rank reward. + // For tier 1 there's not enough reward to satisfy 100% reward per rank. + // Only one slot is empty. Slot reward is 100_000 therefore expected rank reward is 100_000 / 19 (ranks_sum). + // Tier 2 has ranking but there's no empty slot therefore no rank reward. + // Tier 3 has no ranking therefore no rank reward. + rank_rewards: BoundedVec::try_from(vec![0, 5_263, 0, 0]).unwrap() + } + ); + + // one didn't make it + assert_eq!(counter, 8); + }) +} + +#[test] +fn claim_dapp_reward_with_rank() { + ExtBuilder::build().execute_with(|| { + // Register smart contract, lock&stake some amount + let smart_contract = MockSmartContract::wasm(1 as AccountId); + assert_register(1, &smart_contract); + + let alice = 2; + let amount = 99; // very close to tier 0 so will enter tier 1 with rank 9 + assert_lock(alice, amount); + assert_stake(alice, &smart_contract, amount); + + // Advance 2 eras so we have an entry for reward claiming + advance_to_era(ActiveProtocolState::::get().era + 2); + + let era = ActiveProtocolState::::get().era - 1; + let tiers = DAppTiers::::get(era).unwrap(); + + let slot_reward = tiers.rewards[1]; + let rank_reward = tiers.rank_rewards[1]; + + // Claim dApp reward & verify event + assert_ok!(DappStaking::claim_dapp_reward( + RuntimeOrigin::signed(alice), + smart_contract.clone(), + era, + )); + + let expected_rank = 9; + let expected_total_reward = slot_reward + expected_rank * rank_reward; + assert_eq!(slot_reward, 15_000_000); + assert_eq!(rank_reward, 1_500_000); // slot_reward / 10 + assert_eq!(expected_total_reward, 28_500_000); + + System::assert_last_event(RuntimeEvent::DappStaking(Event::DAppReward { + beneficiary: 1, + smart_contract: smart_contract.clone(), + tier_id: 1, + rank: 9, + era, + amount: expected_total_reward, + })); + }) +} diff --git a/pallets/dapp-staking-v3/src/test/tests_types.rs b/pallets/dapp-staking-v3/src/test/tests_types.rs index 72ead8fd56..be41dfc6cb 100644 --- a/pallets/dapp-staking-v3/src/test/tests_types.rs +++ b/pallets/dapp-staking-v3/src/test/tests_types.rs @@ -16,7 +16,10 @@ // You should have received a copy of the GNU General Public License // along with Astar. If not, see . -use astar_primitives::{dapp_staking::StandardTierSlots, Balance}; +use astar_primitives::{ + dapp_staking::{RankedTier, StandardTierSlots}, + Balance, +}; use frame_support::{assert_ok, parameter_types}; use sp_arithmetic::fixed_point::FixedU128; use sp_runtime::Permill; @@ -2907,7 +2910,13 @@ fn dapp_tier_rewards_basic_tests() { get_u32_type!(NumberOfTiers, 3); // Example dApps & rewards - let dapps = BTreeMap::from([(1 as DAppId, 0 as TierId), (2, 0), (3, 1), (5, 1), (6, 2)]); + let dapps = BTreeMap::::from([ + (1, RankedTier::new_saturated(0, 0)), + (2, RankedTier::new_saturated(0, 0)), + (3, RankedTier::new_saturated(1, 0)), + (5, RankedTier::new_saturated(1, 0)), + (6, RankedTier::new_saturated(2, 0)), + ]); let tier_rewards = vec![300, 20, 1]; let period = 2; @@ -2915,20 +2924,21 @@ fn dapp_tier_rewards_basic_tests() { dapps.clone(), tier_rewards.clone(), period, + vec![0, 0, 0], ) .expect("Bounds are respected."); // 1st scenario - claim reward for a dApps - let tier_id = dapps[&1]; + let ranked_tier = dapps[&1]; assert_eq!( dapp_tier_rewards.try_claim(1), - Ok((tier_rewards[tier_id as usize], tier_id)) + Ok((tier_rewards[ranked_tier.tier() as usize], ranked_tier)) ); - let tier_id = dapps[&5]; + let ranked_tier = dapps[&5]; assert_eq!( dapp_tier_rewards.try_claim(5), - Ok((tier_rewards[tier_id as usize], tier_id)) + Ok((tier_rewards[ranked_tier.tier() as usize], ranked_tier)) ); // 2nd scenario - try to claim already claimed reward @@ -2981,3 +2991,55 @@ fn cleanup_marker_works() { "There are pending cleanups for era reward spans." ); } + +#[test] +fn dapp_tier_rewards_with_rank() { + get_u32_type!(NumberOfDApps, 8); + get_u32_type!(NumberOfTiers, 3); + + // Example dApps & rewards + let dapps = BTreeMap::::from([ + (1, RankedTier::new_saturated(0, 5)), + (2, RankedTier::new_saturated(0, 0)), + (3, RankedTier::new_saturated(1, 10)), + (5, RankedTier::new_saturated(1, 5)), + (6, RankedTier::new_saturated(2, 0)), + ]); + let tier_rewards = vec![300, 20, 1]; + let rank_rewards = vec![0, 2, 0]; + let period = 2; + + let mut dapp_tier_rewards = DAppTierRewards::::new( + dapps.clone(), + tier_rewards.clone(), + period, + rank_rewards.clone(), + ) + .expect("Bounds are respected."); + + // has rank but no reward per rank + // receive only tier reward + let ranked_tier = dapps[&1]; + assert_eq!( + dapp_tier_rewards.try_claim(1), + Ok((tier_rewards[ranked_tier.tier() as usize], ranked_tier)) + ); + + // has no rank, receive only tier reward + let ranked_tier = dapps[&2]; + assert_eq!( + dapp_tier_rewards.try_claim(2), + Ok((tier_rewards[ranked_tier.tier() as usize], ranked_tier)) + ); + + // receives both tier and rank rewards + let ranked_tier = dapps[&3]; + let (tier, rank) = ranked_tier.deconstruct(); + assert_eq!( + dapp_tier_rewards.try_claim(3), + Ok(( + tier_rewards[tier as usize] + rank_rewards[tier as usize] * rank as Balance, + ranked_tier + )) + ); +} diff --git a/pallets/dapp-staking-v3/src/types.rs b/pallets/dapp-staking-v3/src/types.rs index a0062eaa58..c211af517d 100644 --- a/pallets/dapp-staking-v3/src/types.rs +++ b/pallets/dapp-staking-v3/src/types.rs @@ -75,7 +75,7 @@ use sp_runtime::{ pub use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, vec::Vec}; use astar_primitives::{ - dapp_staking::{DAppId, EraNumber, PeriodNumber, TierId, TierSlots as TierSlotsFunc}, + dapp_staking::{DAppId, EraNumber, PeriodNumber, RankedTier, TierSlots as TierSlotsFunc}, Balance, BlockNumber, }; @@ -1742,12 +1742,14 @@ impl, T: TierSlotsFunc, P: Get> TiersConfiguration, NT: Get> { /// DApps and their corresponding tiers (or `None` if they have been claimed in the meantime) - pub dapps: BoundedBTreeMap, + pub dapps: BoundedBTreeMap, /// Rewards for each tier. First entry refers to the first tier, and so on. pub rewards: BoundedVec, /// Period during which this struct was created. #[codec(compact)] pub period: PeriodNumber, + /// Rank reward for each tier. First entry refers to the first tier, and so on. + pub rank_rewards: BoundedVec, } impl, NT: Get> Default for DAppTierRewards { @@ -1756,6 +1758,7 @@ impl, NT: Get> Default for DAppTierRewards { dapps: BoundedBTreeMap::default(), rewards: BoundedVec::default(), period: 0, + rank_rewards: BoundedVec::default(), } } } @@ -1764,34 +1767,46 @@ impl, NT: Get> DAppTierRewards { /// Attempt to construct `DAppTierRewards` struct. /// If the provided arguments exceed the allowed capacity, return an error. pub fn new( - dapps: BTreeMap, + dapps: BTreeMap, rewards: Vec, period: PeriodNumber, + rank_rewards: Vec, ) -> Result { let dapps = BoundedBTreeMap::try_from(dapps).map_err(|_| ())?; let rewards = BoundedVec::try_from(rewards).map_err(|_| ())?; + let rank_rewards = BoundedVec::try_from(rank_rewards).map_err(|_| ())?; Ok(Self { dapps, rewards, period, + rank_rewards, }) } /// Consume reward for the specified dapp id, returning its amount and tier Id. /// In case dapp isn't applicable for rewards, or they have already been consumed, returns `None`. - pub fn try_claim(&mut self, dapp_id: DAppId) -> Result<(Balance, TierId), DAppTierError> { + pub fn try_claim(&mut self, dapp_id: DAppId) -> Result<(Balance, RankedTier), DAppTierError> { // Check if dApp Id exists. - let tier_id = self + let ranked_tier = self .dapps .remove(&dapp_id) .ok_or(DAppTierError::NoDAppInTiers)?; - Ok(( - self.rewards - .get(tier_id as usize) - .map_or(Balance::zero(), |x| *x), - tier_id, - )) + let (tier_id, rank) = ranked_tier.deconstruct(); + let mut amount = self + .rewards + .get(tier_id as usize) + .map_or(Balance::zero(), |x| *x); + + let reward_per_rank = self + .rank_rewards + .get(tier_id as usize) + .map_or(Balance::zero(), |x| *x); + + let additional_reward = reward_per_rank.saturating_mul(rank.into()); + amount = amount.saturating_add(additional_reward); + + Ok((amount, ranked_tier)) } } diff --git a/precompiles/dapp-staking-v3/src/test/mock.rs b/precompiles/dapp-staking-v3/src/test/mock.rs index fe9596bbd4..999af044f9 100644 --- a/precompiles/dapp-staking-v3/src/test/mock.rs +++ b/precompiles/dapp-staking-v3/src/test/mock.rs @@ -23,7 +23,7 @@ use frame_support::{ assert_ok, construct_runtime, parameter_types, traits::{ fungible::{Mutate as FunMutate, Unbalanced as FunUnbalanced}, - ConstU128, ConstU64, Hooks, + ConstBool, ConstU128, ConstU64, Hooks, }, weights::{RuntimeDbWeight, Weight}, }; @@ -271,6 +271,7 @@ impl pallet_dapp_staking_v3::Config for Test { type MaxNumberOfStakedContracts = ConstU32<5>; type MinimumStakeAmount = ConstU128<3>; type NumberOfTiers = ConstU32<4>; + type RankingEnabled = ConstBool; type WeightInfo = pallet_dapp_staking_v3::weights::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper; diff --git a/primitives/src/dapp_staking.rs b/primitives/src/dapp_staking.rs index eada3e179d..e44c61caf3 100644 --- a/primitives/src/dapp_staking.rs +++ b/primitives/src/dapp_staking.rs @@ -21,8 +21,12 @@ use super::{oracle::CurrencyAmount, Balance, BlockNumber}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use frame_support::pallet_prelude::{RuntimeDebug, Weight}; +use sp_arithmetic::ArithmeticError; use sp_core::H160; -use sp_runtime::{traits::UniqueSaturatedInto, FixedPointNumber}; +use sp_runtime::{ + traits::{UniqueSaturatedInto, Zero}, + FixedPointNumber, +}; use sp_std::hash::Hash; /// Era number type @@ -33,6 +37,8 @@ pub type PeriodNumber = u32; pub type DAppId = u16; /// Tier Id type pub type TierId = u8; +// Tier Rank type +pub type Rank = u8; /// Configuration for cycles, periods, subperiods & eras. /// @@ -191,3 +197,123 @@ impl TierSlots for StandardTierSlots { result.unique_saturated_into() } } + +/// RankedTier is wrapper around u8 to hold both tier and rank. u8 has 2 bytes (8bits) and they're using in this order `0xrank_tier`. +/// First 4 bits are used to hold rank and second 4 bits are used to hold tier. +/// i.e: 0xa1 will hold rank: 10 and tier: 1 (0xa1 & 0xf == 1; 0xa1 >> 4 == 10;) +#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, MaxEncodedLen, scale_info::TypeInfo)] +pub struct RankedTier(u8); + +impl RankedTier { + pub const MAX_RANK: u8 = 10; + + /// Create new encoded RankedTier from tier and rank. + /// Returns Err(ArithmeticError::Overflow) if max value is not respected. + pub fn new(tier: TierId, rank: Rank) -> Result { + if rank > Self::MAX_RANK || tier > 0xf { + return Err(ArithmeticError::Overflow); + } + Ok(Self(rank << 4 | tier & 0x0f)) + } + + /// Create new encoded RankedTier from tier and rank with saturation. + pub fn new_saturated(tier: TierId, rank: Rank) -> Self { + Self(rank.min(Self::MAX_RANK) << 4 | tier.min(0xf) & 0x0f) + } + + #[inline(always)] + pub fn tier(&self) -> TierId { + self.0 & 0x0f + } + + #[inline(always)] + pub fn rank(&self) -> Rank { + (self.0 >> 4).min(Self::MAX_RANK) + } + + #[inline(always)] + pub fn deconstruct(&self) -> (TierId, Rank) { + (self.tier(), self.rank()) + } +} + +impl core::fmt::Debug for RankedTier { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("RankedTier") + .field("tier", &self.tier()) + .field("rank", &self.rank()) + .finish() + } +} + +impl RankedTier { + /// Find rank based on lower/upper bounds and staked amount. + /// Delta between upper and lower bound is divided in 10 and will increase rank + /// by one for each threshold staked amount will reach. + /// i.e. find_rank(10, 20, 10) -> 0 + /// i.e. find_rank(10, 20, 15) -> 5 + /// i.e. find_rank(10, 20, 20) -> 10 + pub fn find_rank(lower_bound: Balance, upper_bound: Balance, stake_amount: Balance) -> Rank { + if upper_bound.is_zero() { + return 0; + } + let rank_threshold = upper_bound + .saturating_sub(lower_bound) + .saturating_div(RankedTier::MAX_RANK.into()); + if rank_threshold.is_zero() { + 0 + } else { + >::try_into( + stake_amount + .saturating_sub(lower_bound) + .saturating_div(rank_threshold), + ) + .unwrap_or_default() + .min(RankedTier::MAX_RANK) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn tier_and_rank() { + let t = RankedTier::new(0, 0).unwrap(); + assert_eq!(t.deconstruct(), (0, 0)); + + let t = RankedTier::new(15, 10).unwrap(); + assert_eq!(t.deconstruct(), (15, 10)); + + assert_eq!(RankedTier::new(16, 10), Err(ArithmeticError::Overflow)); + assert_eq!(RankedTier::new(15, 11), Err(ArithmeticError::Overflow)); + + let t = RankedTier::new_saturated(0, 0); + assert_eq!(t.deconstruct(), (0, 0)); + + let t = RankedTier::new_saturated(1, 1); + assert_eq!(t.deconstruct(), (1, 1)); + + let t = RankedTier::new_saturated(3, 15); + assert_eq!(t.deconstruct(), (3, 10)); + + // max value for tier and rank + let t = RankedTier::new_saturated(16, 16); + assert_eq!(t.deconstruct(), (15, 10)); + } + + #[test] + fn find_rank() { + assert_eq!(RankedTier::find_rank(0, 0, 0), 0); + assert_eq!(RankedTier::find_rank(0, 100, 9), 0); + assert_eq!(RankedTier::find_rank(0, 100, 10), 1); + assert_eq!(RankedTier::find_rank(0, 100, 49), 4); + assert_eq!(RankedTier::find_rank(0, 100, 50), 5); + assert_eq!(RankedTier::find_rank(0, 100, 51), 5); + assert_eq!(RankedTier::find_rank(0, 100, 101), 10); + + assert_eq!(RankedTier::find_rank(100, 100, 100), 0); + assert_eq!(RankedTier::find_rank(200, 100, 100), 0); + } +} diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index a2883f07c8..bdb899619d 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -71,7 +71,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use astar_primitives::{ dapp_staking::{ AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber, - PeriodNumber, SmartContract, StandardTierSlots, TierId, + PeriodNumber, RankedTier, SmartContract, StandardTierSlots, }, evm::EvmRevertCodeHandler, oracle::{CurrencyAmount, CurrencyId, DummyCombineData}, @@ -379,6 +379,7 @@ impl pallet_dapp_staking_v3::Config for Runtime { type MaxNumberOfStakedContracts = ConstU32<16>; type MinimumStakeAmount = MinimumStakingAmount; type NumberOfTiers = ConstU32<4>; + type RankingEnabled = (); type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper, AccountId>; @@ -1173,7 +1174,10 @@ pub type Executive = frame_executive::Executive< /// All migrations that will run on the next runtime upgrade. /// /// Once done, migrations should be removed from the tuple. -pub type Migrations = (); +pub type Migrations = ( + // Migrate to ranking system + pallet_dapp_staking_v3::migration::versioned_migrations::V6ToV7, +); type EventRecord = frame_system::EventRecord< ::RuntimeEvent, @@ -1732,7 +1736,7 @@ impl_runtime_apis! { InflationCycleConfig::blocks_per_era() } - fn get_dapp_tier_assignment() -> BTreeMap { + fn get_dapp_tier_assignment() -> BTreeMap { DappStaking::get_dapp_tier_assignment() } } diff --git a/runtime/astar/src/weights/pallet_dapp_staking_v3.rs b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs index ba92d60e24..66e8a84d1c 100644 --- a/runtime/astar/src/weights/pallet_dapp_staking_v3.rs +++ b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs @@ -55,8 +55,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_275_000 picoseconds. - Weight::from_parts(6_550_000, 0) + // Minimum execution time: 6_901_000 picoseconds. + Weight::from_parts(7_110_000, 0) } /// Storage: `DappStaking::IntegratedDApps` (r:1 w:1) /// Proof: `DappStaking::IntegratedDApps` (`max_values`: Some(65535), `max_size`: Some(116), added: 2096, mode: `MaxEncodedLen`) @@ -68,8 +68,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3086` - // Minimum execution time: 12_188_000 picoseconds. - Weight::from_parts(12_421_000, 3086) + // Minimum execution time: 12_920_000 picoseconds. + Weight::from_parts(13_049_000, 3086) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -79,8 +79,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 11_078_000 picoseconds. - Weight::from_parts(11_242_000, 3086) + // Minimum execution time: 11_575_000 picoseconds. + Weight::from_parts(11_820_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -90,8 +90,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 11_509_000 picoseconds. - Weight::from_parts(11_795_000, 3086) + // Minimum execution time: 12_043_000 picoseconds. + Weight::from_parts(12_399_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -105,8 +105,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 15_050_000 picoseconds. - Weight::from_parts(15_299_000, 3086) + // Minimum execution time: 15_665_000 picoseconds. + Weight::from_parts(15_923_000, 3086) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -124,8 +124,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `138` // Estimated: `4764` - // Minimum execution time: 27_558_000 picoseconds. - Weight::from_parts(28_143_000, 4764) + // Minimum execution time: 28_847_000 picoseconds. + Weight::from_parts(29_269_000, 4764) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -141,8 +141,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `158` // Estimated: `4764` - // Minimum execution time: 31_462_000 picoseconds. - Weight::from_parts(31_799_000, 4764) + // Minimum execution time: 32_150_000 picoseconds. + Weight::from_parts(32_483_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -158,8 +158,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `158` // Estimated: `4764` - // Minimum execution time: 28_350_000 picoseconds. - Weight::from_parts(28_942_000, 4764) + // Minimum execution time: 29_439_000 picoseconds. + Weight::from_parts(30_316_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -176,10 +176,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `190` // Estimated: `4764` - // Minimum execution time: 30_972_000 picoseconds. - Weight::from_parts(32_215_872, 4764) - // Standard Error: 2_399 - .saturating_add(Weight::from_parts(103_494, 0).saturating_mul(x.into())) + // Minimum execution time: 29_286_000 picoseconds. + Weight::from_parts(30_396_033, 4764) + // Standard Error: 2_822 + .saturating_add(Weight::from_parts(117_982, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -195,8 +195,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `200` // Estimated: `4764` - // Minimum execution time: 28_220_000 picoseconds. - Weight::from_parts(28_659_000, 4764) + // Minimum execution time: 26_357_000 picoseconds. + Weight::from_parts(26_804_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -218,8 +218,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `274` // Estimated: `4764` - // Minimum execution time: 39_918_000 picoseconds. - Weight::from_parts(40_583_000, 4764) + // Minimum execution time: 39_953_000 picoseconds. + Weight::from_parts(40_495_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -241,8 +241,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `459` // Estimated: `4764` - // Minimum execution time: 43_189_000 picoseconds. - Weight::from_parts(43_767_000, 4764) + // Minimum execution time: 43_935_000 picoseconds. + Weight::from_parts(44_485_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -261,10 +261,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `541` // Estimated: `4764` - // Minimum execution time: 43_757_000 picoseconds. - Weight::from_parts(42_840_933, 4764) - // Standard Error: 3_343 - .saturating_add(Weight::from_parts(1_914_215, 0).saturating_mul(x.into())) + // Minimum execution time: 44_282_000 picoseconds. + Weight::from_parts(43_704_387, 4764) + // Standard Error: 2_999 + .saturating_add(Weight::from_parts(1_901_320, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -281,10 +281,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `519` // Estimated: `4764` - // Minimum execution time: 41_710_000 picoseconds. - Weight::from_parts(40_832_293, 4764) - // Standard Error: 4_171 - .saturating_add(Weight::from_parts(1_909_528, 0).saturating_mul(x.into())) + // Minimum execution time: 42_099_000 picoseconds. + Weight::from_parts(41_482_351, 4764) + // Standard Error: 3_082 + .saturating_add(Weight::from_parts(1_875_239, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -298,21 +298,21 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `275` // Estimated: `3775` - // Minimum execution time: 34_132_000 picoseconds. - Weight::from_parts(34_857_000, 3775) + // Minimum execution time: 32_801_000 picoseconds. + Weight::from_parts(33_233_000, 3775) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: `DappStaking::IntegratedDApps` (r:1 w:0) /// Proof: `DappStaking::IntegratedDApps` (`max_values`: Some(65535), `max_size`: Some(116), added: 2096, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:1 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2607` - // Estimated: `5048` - // Minimum execution time: 49_123_000 picoseconds. - Weight::from_parts(50_433_000, 5048) + // Measured: `2672` + // Estimated: `5113` + // Minimum execution time: 50_552_000 picoseconds. + Weight::from_parts(51_566_000, 5113) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -332,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `322` // Estimated: `4764` - // Minimum execution time: 35_718_000 picoseconds. - Weight::from_parts(36_261_000, 4764) + // Minimum execution time: 36_548_000 picoseconds. + Weight::from_parts(37_174_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -350,10 +350,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `257 + x * (73 ±0)` // Estimated: `4764 + x * (2653 ±0)` - // Minimum execution time: 37_969_000 picoseconds. - Weight::from_parts(34_795_715, 4764) - // Standard Error: 7_200 - .saturating_add(Weight::from_parts(4_915_109, 0).saturating_mul(x.into())) + // Minimum execution time: 36_536_000 picoseconds. + Weight::from_parts(32_923_068, 4764) + // Standard Error: 7_141 + .saturating_add(Weight::from_parts(4_979_475, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -366,8 +366,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `1486` - // Minimum execution time: 8_422_000 picoseconds. - Weight::from_parts(8_725_000, 1486) + // Minimum execution time: 8_966_000 picoseconds. + Weight::from_parts(9_216_000, 1486) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `DappStaking::CurrentEraInfo` (r:1 w:1) @@ -376,15 +376,17 @@ impl WeightInfo for SubstrateWeight { /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::StaticTierParams` (r:1 w:0) /// Proof: `DappStaking::StaticTierParams` (`max_values`: Some(1), `max_size`: Some(167), added: 662, mode: `MaxEncodedLen`) + /// Storage: `PriceAggregator::ValuesCircularBuffer` (r:1 w:0) + /// Proof: `PriceAggregator::ValuesCircularBuffer` (`max_values`: Some(1), `max_size`: Some(117), added: 612, mode: `MaxEncodedLen`) /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) fn on_initialize_voting_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `330` + // Measured: `334` // Estimated: `4254` - // Minimum execution time: 22_909_000 picoseconds. - Weight::from_parts(23_440_000, 4254) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 25_581_000 picoseconds. + Weight::from_parts(26_206_000, 4254) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: `DappStaking::CurrentEraInfo` (r:1 w:1) @@ -397,17 +399,19 @@ impl WeightInfo for SubstrateWeight { /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::StaticTierParams` (r:1 w:0) /// Proof: `DappStaking::StaticTierParams` (`max_values`: Some(1), `max_size`: Some(167), added: 662, mode: `MaxEncodedLen`) + /// Storage: `PriceAggregator::ValuesCircularBuffer` (r:1 w:0) + /// Proof: `PriceAggregator::ValuesCircularBuffer` (`max_values`: Some(1), `max_size`: Some(117), added: 612, mode: `MaxEncodedLen`) /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `837` + // Measured: `841` // Estimated: `4254` - // Minimum execution time: 36_610_000 picoseconds. - Weight::from_parts(37_596_000, 4254) - .saturating_add(T::DbWeight::get().reads(6_u64)) + // Minimum execution time: 41_102_000 picoseconds. + Weight::from_parts(41_895_000, 4254) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } /// Storage: `DappStaking::CurrentEraInfo` (r:1 w:1) @@ -416,17 +420,19 @@ impl WeightInfo for SubstrateWeight { /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::StaticTierParams` (r:1 w:0) /// Proof: `DappStaking::StaticTierParams` (`max_values`: Some(1), `max_size`: Some(167), added: 662, mode: `MaxEncodedLen`) + /// Storage: `PriceAggregator::ValuesCircularBuffer` (r:1 w:0) + /// Proof: `PriceAggregator::ValuesCircularBuffer` (`max_values`: Some(1), `max_size`: Some(117), added: 612, mode: `MaxEncodedLen`) /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `382` + // Measured: `386` // Estimated: `4254` - // Minimum execution time: 24_517_000 picoseconds. - Weight::from_parts(25_047_000, 4254) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 28_342_000 picoseconds. + Weight::from_parts(28_987_000, 4254) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: `DappStaking::ContractStake` (r:101 w:0) @@ -438,10 +444,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 6_465_000 picoseconds. - Weight::from_parts(10_861_086, 3061) - // Standard Error: 3_452 - .saturating_add(Weight::from_parts(2_283_463, 0).saturating_mul(x.into())) + // Minimum execution time: 6_941_000 picoseconds. + Weight::from_parts(11_645_090, 3061) + // Standard Error: 3_059 + .saturating_add(Weight::from_parts(2_388_533, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -451,13 +457,13 @@ impl WeightInfo for SubstrateWeight { /// Storage: `DappStaking::EraRewards` (r:1 w:1) /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_idle_cleanup() -> Weight { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 7_431_000 picoseconds. - Weight::from_parts(7_562_000, 4254) + // Minimum execution time: 7_727_000 picoseconds. + Weight::from_parts(7_910_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index b4d380717f..efbd234ae8 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -65,8 +65,8 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use astar_primitives::{ dapp_staking::{ - CycleConfiguration, DAppId, EraNumber, PeriodNumber, SmartContract, StandardTierSlots, - TierId, + CycleConfiguration, DAppId, EraNumber, PeriodNumber, RankedTier, SmartContract, + StandardTierSlots, }, evm::{EvmRevertCodeHandler, HashedDefaultMappings}, Address, AssetId, Balance, BlockNumber, Hash, Header, Nonce, @@ -474,6 +474,7 @@ impl pallet_dapp_staking_v3::Config for Runtime { type MaxNumberOfStakedContracts = ConstU32<3>; type MinimumStakeAmount = ConstU128; type NumberOfTiers = ConstU32<4>; + type RankingEnabled = ConstBool; type WeightInfo = pallet_dapp_staking_v3::weights::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper, AccountId>; @@ -1522,7 +1523,7 @@ impl_runtime_apis! { InflationCycleConfig::blocks_per_era() } - fn get_dapp_tier_assignment() -> BTreeMap { + fn get_dapp_tier_assignment() -> BTreeMap { DappStaking::get_dapp_tier_assignment() } } diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 8f40b5123b..770c2f3b59 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -71,7 +71,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use astar_primitives::{ dapp_staking::{ AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber, - PeriodNumber, SmartContract, StandardTierSlots, TierId, + PeriodNumber, RankedTier, SmartContract, StandardTierSlots, }, evm::{EvmRevertCodeHandler, HashedDefaultMappings}, oracle::{CurrencyAmount, CurrencyId, DummyCombineData}, @@ -444,6 +444,7 @@ impl pallet_dapp_staking_v3::Config for Runtime { type MaxNumberOfStakedContracts = ConstU32<8>; type MinimumStakeAmount = MinimumStakingAmount; type NumberOfTiers = ConstU32<4>; + type RankingEnabled = ConstBool; type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper, AccountId>; @@ -1297,7 +1298,11 @@ pub type Executive = frame_executive::Executive< /// All migrations that will run on the next runtime upgrade. /// /// Once done, migrations should be removed from the tuple. -pub type Migrations = (); +pub type Migrations = ( + pallet_preimage::migration::v1::Migration, + // Migrate to ranking system + pallet_dapp_staking_v3::migration::versioned_migrations::V6ToV7, +); type EventRecord = frame_system::EventRecord< ::RuntimeEvent, @@ -1862,7 +1867,7 @@ impl_runtime_apis! { InflationCycleConfig::blocks_per_era() } - fn get_dapp_tier_assignment() -> BTreeMap { + fn get_dapp_tier_assignment() -> BTreeMap { DappStaking::get_dapp_tier_assignment() } } diff --git a/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs b/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs index daac8fb8a0..9cf020149c 100644 --- a/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs +++ b/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs @@ -55,8 +55,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_953_000 picoseconds. - Weight::from_parts(6_130_000, 0) + // Minimum execution time: 6_248_000 picoseconds. + Weight::from_parts(6_411_000, 0) } /// Storage: `DappStaking::IntegratedDApps` (r:1 w:1) /// Proof: `DappStaking::IntegratedDApps` (`max_values`: Some(65535), `max_size`: Some(116), added: 2096, mode: `MaxEncodedLen`) @@ -68,8 +68,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3086` - // Minimum execution time: 12_077_000 picoseconds. - Weight::from_parts(12_378_000, 3086) + // Minimum execution time: 12_268_000 picoseconds. + Weight::from_parts(12_474_000, 3086) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -79,8 +79,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 10_630_000 picoseconds. - Weight::from_parts(10_828_000, 3086) + // Minimum execution time: 10_962_000 picoseconds. + Weight::from_parts(11_245_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -90,8 +90,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 11_064_000 picoseconds. - Weight::from_parts(11_259_000, 3086) + // Minimum execution time: 11_415_000 picoseconds. + Weight::from_parts(11_557_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -105,8 +105,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 14_678_000 picoseconds. - Weight::from_parts(14_986_000, 3086) + // Minimum execution time: 15_054_000 picoseconds. + Weight::from_parts(15_219_000, 3086) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -124,8 +124,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `138` // Estimated: `4764` - // Minimum execution time: 31_103_000 picoseconds. - Weight::from_parts(31_358_000, 4764) + // Minimum execution time: 27_562_000 picoseconds. + Weight::from_parts(27_847_000, 4764) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -141,8 +141,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `156` // Estimated: `4764` - // Minimum execution time: 30_623_000 picoseconds. - Weight::from_parts(31_023_000, 4764) + // Minimum execution time: 30_938_000 picoseconds. + Weight::from_parts(31_494_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -158,8 +158,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `156` // Estimated: `4764` - // Minimum execution time: 27_612_000 picoseconds. - Weight::from_parts(28_332_000, 4764) + // Minimum execution time: 28_608_000 picoseconds. + Weight::from_parts(29_210_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -176,10 +176,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `187` // Estimated: `4764` - // Minimum execution time: 27_956_000 picoseconds. - Weight::from_parts(28_811_940, 4764) - // Standard Error: 4_875 - .saturating_add(Weight::from_parts(195_216, 0).saturating_mul(x.into())) + // Minimum execution time: 28_538_000 picoseconds. + Weight::from_parts(29_479_578, 4764) + // Standard Error: 4_546 + .saturating_add(Weight::from_parts(186_430, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -195,8 +195,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `182` // Estimated: `4764` - // Minimum execution time: 25_300_000 picoseconds. - Weight::from_parts(25_606_000, 4764) + // Minimum execution time: 25_327_000 picoseconds. + Weight::from_parts(25_930_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -218,8 +218,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `272` // Estimated: `4764` - // Minimum execution time: 38_627_000 picoseconds. - Weight::from_parts(39_162_000, 4764) + // Minimum execution time: 38_972_000 picoseconds. + Weight::from_parts(39_410_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -241,8 +241,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `453` // Estimated: `4764` - // Minimum execution time: 43_750_000 picoseconds. - Weight::from_parts(44_381_000, 4764) + // Minimum execution time: 43_013_000 picoseconds. + Weight::from_parts(43_369_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -261,10 +261,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `522` // Estimated: `4764` - // Minimum execution time: 42_554_000 picoseconds. - Weight::from_parts(42_253_711, 4764) - // Standard Error: 3_644 - .saturating_add(Weight::from_parts(1_672_941, 0).saturating_mul(x.into())) + // Minimum execution time: 43_303_000 picoseconds. + Weight::from_parts(42_353_415, 4764) + // Standard Error: 4_034 + .saturating_add(Weight::from_parts(1_894_887, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -281,10 +281,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `501` // Estimated: `4764` - // Minimum execution time: 40_539_000 picoseconds. - Weight::from_parts(39_724_447, 4764) - // Standard Error: 2_788 - .saturating_add(Weight::from_parts(1_669_553, 0).saturating_mul(x.into())) + // Minimum execution time: 40_833_000 picoseconds. + Weight::from_parts(40_376_535, 4764) + // Standard Error: 4_977 + .saturating_add(Weight::from_parts(1_875_635, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -298,21 +298,21 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `271` // Estimated: `3775` - // Minimum execution time: 31_127_000 picoseconds. - Weight::from_parts(31_427_000, 3775) + // Minimum execution time: 31_691_000 picoseconds. + Weight::from_parts(32_123_000, 3775) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: `DappStaking::IntegratedDApps` (r:1 w:0) /// Proof: `DappStaking::IntegratedDApps` (`max_values`: Some(65535), `max_size`: Some(116), added: 2096, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:1 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2607` - // Estimated: `5048` - // Minimum execution time: 47_097_000 picoseconds. - Weight::from_parts(48_451_000, 5048) + // Measured: `2672` + // Estimated: `5113` + // Minimum execution time: 50_729_000 picoseconds. + Weight::from_parts(51_933_000, 5113) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -332,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `317` // Estimated: `4764` - // Minimum execution time: 35_289_000 picoseconds. - Weight::from_parts(35_821_000, 4764) + // Minimum execution time: 35_712_000 picoseconds. + Weight::from_parts(35_993_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -350,10 +350,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `255 + x * (73 ±0)` // Estimated: `4764 + x * (2653 ±0)` - // Minimum execution time: 35_223_000 picoseconds. - Weight::from_parts(31_212_862, 4764) - // Standard Error: 14_956 - .saturating_add(Weight::from_parts(5_068_316, 0).saturating_mul(x.into())) + // Minimum execution time: 35_330_000 picoseconds. + Weight::from_parts(31_912_755, 4764) + // Standard Error: 12_633 + .saturating_add(Weight::from_parts(4_919_251, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -366,8 +366,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `1486` - // Minimum execution time: 8_034_000 picoseconds. - Weight::from_parts(8_224_000, 1486) + // Minimum execution time: 8_737_000 picoseconds. + Weight::from_parts(8_898_000, 1486) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `DappStaking::CurrentEraInfo` (r:1 w:1) @@ -384,8 +384,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `334` // Estimated: `4254` - // Minimum execution time: 23_669_000 picoseconds. - Weight::from_parts(24_216_000, 4254) + // Minimum execution time: 24_461_000 picoseconds. + Weight::from_parts(25_019_000, 4254) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -404,13 +404,13 @@ impl WeightInfo for SubstrateWeight { /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: // Measured: `631` // Estimated: `4254` - // Minimum execution time: 33_437_000 picoseconds. - Weight::from_parts(34_673_000, 4254) + // Minimum execution time: 37_507_000 picoseconds. + Weight::from_parts(38_532_000, 4254) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -425,13 +425,13 @@ impl WeightInfo for SubstrateWeight { /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { // Proof Size summary in bytes: // Measured: `386` // Estimated: `4254` - // Minimum execution time: 25_981_000 picoseconds. - Weight::from_parts(26_548_000, 4254) + // Minimum execution time: 27_753_000 picoseconds. + Weight::from_parts(28_097_000, 4254) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -442,12 +442,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `x` is `[0, 100]`. fn dapp_tier_assignment(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `151 + x * (32 ±0)` + // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 8_343_000 picoseconds. - Weight::from_parts(10_436_285, 3061) - // Standard Error: 2_503 - .saturating_add(Weight::from_parts(2_305_219, 0).saturating_mul(x.into())) + // Minimum execution time: 6_671_000 picoseconds. + Weight::from_parts(11_257_216, 3061) + // Standard Error: 2_748 + .saturating_add(Weight::from_parts(2_393_417, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -457,13 +457,13 @@ impl WeightInfo for SubstrateWeight { /// Storage: `DappStaking::EraRewards` (r:1 w:1) /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_idle_cleanup() -> Weight { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 7_552_000 picoseconds. - Weight::from_parts(7_669_000, 4254) + // Minimum execution time: 7_523_000 picoseconds. + Weight::from_parts(7_623_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index d894665194..f2c31deb67 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -70,7 +70,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use astar_primitives::{ dapp_staking::{ AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber, - PeriodNumber, SmartContract, TierId, TierSlots as TierSlotsFunc, + PeriodNumber, RankedTier, SmartContract, TierSlots as TierSlotsFunc, }, evm::EvmRevertCodeHandler, oracle::{CurrencyAmount, CurrencyId, DummyCombineData}, @@ -391,6 +391,7 @@ impl pallet_dapp_staking_v3::Config for Runtime { type MaxNumberOfStakedContracts = ConstU32<16>; type MinimumStakeAmount = MinimumStakingAmount; type NumberOfTiers = ConstU32<4>; + type RankingEnabled = (); type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper, AccountId>; @@ -1174,7 +1175,10 @@ pub type Executive = frame_executive::Executive< /// All migrations that will run on the next runtime upgrade. /// /// Once done, migrations should be removed from the tuple. -pub type Migrations = (); +pub type Migrations = ( + // Migrate to ranking system + pallet_dapp_staking_v3::migration::versioned_migrations::V6ToV7, +); type EventRecord = frame_system::EventRecord< ::RuntimeEvent, @@ -1735,7 +1739,7 @@ impl_runtime_apis! { InflationCycleConfig::blocks_per_era() } - fn get_dapp_tier_assignment() -> BTreeMap { + fn get_dapp_tier_assignment() -> BTreeMap { DappStaking::get_dapp_tier_assignment() } } diff --git a/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs b/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs index 9503493a24..cf2c9c01cc 100644 --- a/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs +++ b/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs @@ -55,8 +55,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_623_000 picoseconds. - Weight::from_parts(6_817_000, 0) + // Minimum execution time: 6_476_000 picoseconds. + Weight::from_parts(6_714_000, 0) } /// Storage: `DappStaking::IntegratedDApps` (r:1 w:1) /// Proof: `DappStaking::IntegratedDApps` (`max_values`: Some(65535), `max_size`: Some(116), added: 2096, mode: `MaxEncodedLen`) @@ -68,8 +68,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3086` - // Minimum execution time: 12_683_000 picoseconds. - Weight::from_parts(13_128_000, 3086) + // Minimum execution time: 12_385_000 picoseconds. + Weight::from_parts(12_660_000, 3086) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -79,8 +79,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 11_333_000 picoseconds. - Weight::from_parts(11_518_000, 3086) + // Minimum execution time: 11_393_000 picoseconds. + Weight::from_parts(11_638_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -90,8 +90,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 12_016_000 picoseconds. - Weight::from_parts(12_174_000, 3086) + // Minimum execution time: 11_834_000 picoseconds. + Weight::from_parts(12_176_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -105,8 +105,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `97` // Estimated: `3086` - // Minimum execution time: 15_467_000 picoseconds. - Weight::from_parts(15_809_000, 3086) + // Minimum execution time: 15_262_000 picoseconds. + Weight::from_parts(15_764_000, 3086) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -124,8 +124,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `138` // Estimated: `4764` - // Minimum execution time: 28_164_000 picoseconds. - Weight::from_parts(28_529_000, 4764) + // Minimum execution time: 28_006_000 picoseconds. + Weight::from_parts(28_433_000, 4764) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -141,8 +141,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `158` // Estimated: `4764` - // Minimum execution time: 32_219_000 picoseconds. - Weight::from_parts(32_685_000, 4764) + // Minimum execution time: 31_943_000 picoseconds. + Weight::from_parts(32_807_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -158,8 +158,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `158` // Estimated: `4764` - // Minimum execution time: 29_290_000 picoseconds. - Weight::from_parts(29_714_000, 4764) + // Minimum execution time: 29_129_000 picoseconds. + Weight::from_parts(29_684_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -176,10 +176,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `191` // Estimated: `4764` - // Minimum execution time: 31_731_000 picoseconds. - Weight::from_parts(32_963_184, 4764) - // Standard Error: 2_757 - .saturating_add(Weight::from_parts(133_347, 0).saturating_mul(x.into())) + // Minimum execution time: 29_012_000 picoseconds. + Weight::from_parts(30_362_943, 4764) + // Standard Error: 3_354 + .saturating_add(Weight::from_parts(102_645, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -195,8 +195,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `200` // Estimated: `4764` - // Minimum execution time: 28_893_000 picoseconds. - Weight::from_parts(29_595_000, 4764) + // Minimum execution time: 26_355_000 picoseconds. + Weight::from_parts(26_725_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -218,8 +218,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `274` // Estimated: `4764` - // Minimum execution time: 40_108_000 picoseconds. - Weight::from_parts(40_741_000, 4764) + // Minimum execution time: 41_441_000 picoseconds. + Weight::from_parts(42_071_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -241,8 +241,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `459` // Estimated: `4764` - // Minimum execution time: 44_355_000 picoseconds. - Weight::from_parts(45_247_000, 4764) + // Minimum execution time: 45_924_000 picoseconds. + Weight::from_parts(46_305_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -261,10 +261,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `541` // Estimated: `4764` - // Minimum execution time: 44_827_000 picoseconds. - Weight::from_parts(43_946_653, 4764) - // Standard Error: 4_252 - .saturating_add(Weight::from_parts(1_929_031, 0).saturating_mul(x.into())) + // Minimum execution time: 44_845_000 picoseconds. + Weight::from_parts(43_924_635, 4764) + // Standard Error: 4_382 + .saturating_add(Weight::from_parts(1_983_419, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -281,10 +281,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `519` // Estimated: `4764` - // Minimum execution time: 42_489_000 picoseconds. - Weight::from_parts(41_694_539, 4764) - // Standard Error: 4_876 - .saturating_add(Weight::from_parts(1_920_135, 0).saturating_mul(x.into())) + // Minimum execution time: 42_111_000 picoseconds. + Weight::from_parts(41_366_463, 4764) + // Standard Error: 4_231 + .saturating_add(Weight::from_parts(2_000_021, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -298,21 +298,21 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `275` // Estimated: `3775` - // Minimum execution time: 35_956_000 picoseconds. - Weight::from_parts(36_515_000, 3775) + // Minimum execution time: 33_539_000 picoseconds. + Weight::from_parts(33_934_000, 3775) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: `DappStaking::IntegratedDApps` (r:1 w:0) /// Proof: `DappStaking::IntegratedDApps` (`max_values`: Some(65535), `max_size`: Some(116), added: 2096, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:1 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2607` - // Estimated: `5048` - // Minimum execution time: 49_702_000 picoseconds. - Weight::from_parts(51_260_000, 5048) + // Measured: `2672` + // Estimated: `5113` + // Minimum execution time: 51_985_000 picoseconds. + Weight::from_parts(53_149_000, 5113) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -332,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `322` // Estimated: `4764` - // Minimum execution time: 35_957_000 picoseconds. - Weight::from_parts(36_705_000, 4764) + // Minimum execution time: 36_691_000 picoseconds. + Weight::from_parts(37_929_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -350,10 +350,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `256 + x * (73 ±0)` // Estimated: `4764 + x * (2653 ±0)` - // Minimum execution time: 38_640_000 picoseconds. - Weight::from_parts(35_679_946, 4764) - // Standard Error: 7_706 - .saturating_add(Weight::from_parts(4_965_134, 0).saturating_mul(x.into())) + // Minimum execution time: 36_617_000 picoseconds. + Weight::from_parts(33_285_190, 4764) + // Standard Error: 7_701 + .saturating_add(Weight::from_parts(5_001_871, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -366,8 +366,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `1486` - // Minimum execution time: 8_858_000 picoseconds. - Weight::from_parts(8_983_000, 1486) + // Minimum execution time: 8_736_000 picoseconds. + Weight::from_parts(9_057_000, 1486) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `DappStaking::CurrentEraInfo` (r:1 w:1) @@ -376,15 +376,17 @@ impl WeightInfo for SubstrateWeight { /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::StaticTierParams` (r:1 w:0) /// Proof: `DappStaking::StaticTierParams` (`max_values`: Some(1), `max_size`: Some(167), added: 662, mode: `MaxEncodedLen`) + /// Storage: `PriceAggregator::ValuesCircularBuffer` (r:1 w:0) + /// Proof: `PriceAggregator::ValuesCircularBuffer` (`max_values`: Some(1), `max_size`: Some(117), added: 612, mode: `MaxEncodedLen`) /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) fn on_initialize_voting_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `330` + // Measured: `334` // Estimated: `4254` - // Minimum execution time: 22_873_000 picoseconds. - Weight::from_parts(23_448_000, 4254) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 24_552_000 picoseconds. + Weight::from_parts(25_267_000, 4254) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: `DappStaking::CurrentEraInfo` (r:1 w:1) @@ -397,17 +399,19 @@ impl WeightInfo for SubstrateWeight { /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::StaticTierParams` (r:1 w:0) /// Proof: `DappStaking::StaticTierParams` (`max_values`: Some(1), `max_size`: Some(167), added: 662, mode: `MaxEncodedLen`) + /// Storage: `PriceAggregator::ValuesCircularBuffer` (r:1 w:0) + /// Proof: `PriceAggregator::ValuesCircularBuffer` (`max_values`: Some(1), `max_size`: Some(117), added: 612, mode: `MaxEncodedLen`) /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `838` + // Measured: `843` // Estimated: `4254` - // Minimum execution time: 37_126_000 picoseconds. - Weight::from_parts(38_123_000, 4254) - .saturating_add(T::DbWeight::get().reads(6_u64)) + // Minimum execution time: 39_484_000 picoseconds. + Weight::from_parts(40_502_000, 4254) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } /// Storage: `DappStaking::CurrentEraInfo` (r:1 w:1) @@ -416,17 +420,19 @@ impl WeightInfo for SubstrateWeight { /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::StaticTierParams` (r:1 w:0) /// Proof: `DappStaking::StaticTierParams` (`max_values`: Some(1), `max_size`: Some(167), added: 662, mode: `MaxEncodedLen`) + /// Storage: `PriceAggregator::ValuesCircularBuffer` (r:1 w:0) + /// Proof: `PriceAggregator::ValuesCircularBuffer` (`max_values`: Some(1), `max_size`: Some(117), added: 612, mode: `MaxEncodedLen`) /// Storage: `DappStaking::TierConfig` (r:1 w:1) /// Proof: `DappStaking::TierConfig` (`max_values`: Some(1), `max_size`: Some(161), added: 656, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `381` + // Measured: `386` // Estimated: `4254` - // Minimum execution time: 25_108_000 picoseconds. - Weight::from_parts(25_775_000, 4254) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 27_598_000 picoseconds. + Weight::from_parts(28_216_000, 4254) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: `DappStaking::ContractStake` (r:101 w:0) @@ -438,10 +444,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 6_463_000 picoseconds. - Weight::from_parts(11_094_548, 3061) - // Standard Error: 3_157 - .saturating_add(Weight::from_parts(2_330_865, 0).saturating_mul(x.into())) + // Minimum execution time: 6_648_000 picoseconds. + Weight::from_parts(11_329_597, 3061) + // Standard Error: 3_005 + .saturating_add(Weight::from_parts(2_383_797, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -451,13 +457,13 @@ impl WeightInfo for SubstrateWeight { /// Storage: `DappStaking::EraRewards` (r:1 w:1) /// Proof: `DappStaking::EraRewards` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) /// Storage: `DappStaking::DAppTiers` (r:0 w:1) - /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1583), added: 4058, mode: `MaxEncodedLen`) + /// Proof: `DappStaking::DAppTiers` (`max_values`: None, `max_size`: Some(1648), added: 4123, mode: `MaxEncodedLen`) fn on_idle_cleanup() -> Weight { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 7_533_000 picoseconds. - Weight::from_parts(7_744_000, 4254) + // Minimum execution time: 7_521_000 picoseconds. + Weight::from_parts(7_677_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } diff --git a/tests/xcm-simulator/src/mocks/parachain.rs b/tests/xcm-simulator/src/mocks/parachain.rs index d4f95e4bb6..c3bb2846a2 100644 --- a/tests/xcm-simulator/src/mocks/parachain.rs +++ b/tests/xcm-simulator/src/mocks/parachain.rs @@ -735,6 +735,7 @@ impl pallet_dapp_staking_v3::Config for Runtime { type MaxNumberOfStakedContracts = ConstU32<5>; type MinimumStakeAmount = ConstU128<3>; type NumberOfTiers = ConstU32<4>; + type RankingEnabled = ConstBool; type WeightInfo = (); #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper;