diff --git a/Cargo.lock b/Cargo.lock index 452564a7c6..1c3e62ad02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -456,7 +456,6 @@ dependencies = [ "moonbeam-rpc-primitives-txpool", "moonbeam-rpc-trace", "moonbeam-rpc-txpool", - "pallet-dapp-staking-v3", "pallet-ethereum", "pallet-evm", "pallet-transaction-payment", @@ -2444,17 +2443,6 @@ dependencies = [ "sp-api", ] -[[package]] -name = "dapps-staking-chain-extension-types" -version = "1.1.0" -dependencies = [ - "frame-support", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-runtime", -] - [[package]] name = "darling" version = "0.14.4" @@ -4977,6 +4965,7 @@ dependencies = [ "pallet-balances", "pallet-contracts", "pallet-contracts-primitives", + "pallet-dapp-staking-v3", "pallet-dapps-staking", "pallet-ethereum-checked", "pallet-evm", @@ -6040,7 +6029,6 @@ dependencies = [ "pallet-balances", "pallet-block-rewards-hybrid", "pallet-chain-extension-assets", - "pallet-chain-extension-dapps-staking", "pallet-chain-extension-unified-accounts", "pallet-chain-extension-xvm", "pallet-collective", @@ -7496,25 +7484,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-chain-extension-dapps-staking" -version = "1.1.0" -dependencies = [ - "dapps-staking-chain-extension-types", - "frame-support", - "frame-system", - "log", - "num-traits", - "pallet-contracts", - "pallet-contracts-primitives", - "pallet-dapps-staking", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-chain-extension-unified-accounts" version = "0.1.0" @@ -8318,6 +8287,7 @@ dependencies = [ "serde", "sp-core", "sp-runtime", + "sp-std", ] [[package]] @@ -13178,6 +13148,7 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", + "dapp-staking-v3-runtime-api", "fp-rpc", "fp-self-contained", "frame-benchmarking", @@ -13199,7 +13170,6 @@ dependencies = [ "pallet-aura", "pallet-authorship", "pallet-balances", - "pallet-block-rewards-hybrid", "pallet-chain-extension-assets", "pallet-chain-extension-unified-accounts", "pallet-chain-extension-xvm", @@ -13207,6 +13177,8 @@ dependencies = [ "pallet-collective", "pallet-contracts", "pallet-contracts-primitives", + "pallet-dapp-staking-migration", + "pallet-dapp-staking-v3", "pallet-dapps-staking", "pallet-democracy", "pallet-dynamic-evm-base-fee", @@ -13217,7 +13189,7 @@ dependencies = [ "pallet-evm-precompile-assets-erc20", "pallet-evm-precompile-blake2", "pallet-evm-precompile-bn128", - "pallet-evm-precompile-dapps-staking", + "pallet-evm-precompile-dapp-staking-v3", "pallet-evm-precompile-dispatch", "pallet-evm-precompile-ed25519", "pallet-evm-precompile-modexp", @@ -13229,6 +13201,7 @@ dependencies = [ "pallet-evm-precompile-xcm", "pallet-evm-precompile-xvm", "pallet-identity", + "pallet-inflation", "pallet-insecure-randomness-collective-flip", "pallet-multisig", "pallet-preimage", @@ -13255,6 +13228,7 @@ dependencies = [ "scale-info", "smallvec 1.11.0", "sp-api", + "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", diff --git a/Cargo.toml b/Cargo.toml index ca009583f4..2e5b80db4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ members = [ "primitives", - "chain-extensions/dapps-staking", "chain-extensions/pallet-assets", "chain-extensions/xvm", "chain-extensions/unified-accounts", @@ -298,12 +297,10 @@ pallet-evm-precompile-dapps-staking = { path = "./precompiles/dapps-staking", de pallet-evm-precompile-dapp-staking-v3 = { path = "./precompiles/dapp-staking-v3", default-features = false } pallet-evm-precompile-unified-accounts = { path = "./precompiles/unified-accounts", default-features = false } -pallet-chain-extension-dapps-staking = { path = "./chain-extensions/dapps-staking", default-features = false } pallet-chain-extension-xvm = { path = "./chain-extensions/xvm", default-features = false } pallet-chain-extension-assets = { path = "./chain-extensions/pallet-assets", default-features = false } pallet-chain-extension-unified-accounts = { path = "./chain-extensions/unified-accounts", default-features = false } -dapps-staking-chain-extension-types = { path = "./chain-extensions/types/dapps-staking", default-features = false } xvm-chain-extension-types = { path = "./chain-extensions/types/xvm", default-features = false } assets-chain-extension-types = { path = "./chain-extensions/types/assets", default-features = false } unified-accounts-chain-extension-types = { path = "./chain-extensions/types/unified-accounts", default-features = false } diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index 19c9bdba59..6676a9aa34 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -94,7 +94,6 @@ shiden-runtime = { workspace = true, features = ["std"] } # astar pallets dependencies astar-primitives = { workspace = true } -pallet-dapp-staking-v3 = { workspace = true } # frame dependencies frame-system = { workspace = true, features = ["std"] } diff --git a/bin/collator/src/local/chain_spec.rs b/bin/collator/src/local/chain_spec.rs index d5977cd3ef..8a510b6f67 100644 --- a/bin/collator/src/local/chain_spec.rs +++ b/bin/collator/src/local/chain_spec.rs @@ -22,8 +22,8 @@ use local_runtime::{ wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig, BlockRewardConfig, CouncilConfig, DappStakingConfig, DemocracyConfig, EVMConfig, GenesisConfig, GrandpaConfig, GrandpaId, InflationConfig, InflationParameters, Precompiles, RewardDistributionConfig, - Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TreasuryConfig, VestingConfig, - AST, + Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TierThreshold, TreasuryConfig, + VestingConfig, AST, }; use sc_service::ChainType; use sp_core::{crypto::Ss58Codec, sr25519, Pair, Public}; @@ -32,8 +32,6 @@ use sp_runtime::{ Perbill, Permill, }; -use pallet_dapp_staking_v3::TierThreshold; - type AccountPublic = ::Signer; /// Specialized `ChainSpec` for Shiden Network. diff --git a/bin/collator/src/parachain/chain_spec/shibuya.rs b/bin/collator/src/parachain/chain_spec/shibuya.rs index ac4478afe1..200d324631 100644 --- a/bin/collator/src/parachain/chain_spec/shibuya.rs +++ b/bin/collator/src/parachain/chain_spec/shibuya.rs @@ -21,17 +21,17 @@ use cumulus_primitives_core::ParaId; use sc_service::ChainType; use shibuya_runtime::{ - wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig, BlockRewardConfig, - CollatorSelectionConfig, CouncilConfig, DemocracyConfig, EVMChainIdConfig, EVMConfig, - GenesisConfig, ParachainInfoConfig, Precompiles, RewardDistributionConfig, SessionConfig, - SessionKeys, Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TreasuryConfig, - VestingConfig, SBY, + wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig, + CollatorSelectionConfig, CouncilConfig, DappStakingConfig, DemocracyConfig, EVMChainIdConfig, + EVMConfig, GenesisConfig, InflationConfig, InflationParameters, ParachainInfoConfig, + Precompiles, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, + TechnicalCommitteeConfig, TierThreshold, TreasuryConfig, VestingConfig, SBY, }; use sp_core::{sr25519, Pair, Public}; use sp_runtime::{ traits::{IdentifyAccount, Verify}, - Perbill, + Permill, }; use super::{get_from_seed, Extensions}; @@ -114,17 +114,6 @@ fn make_genesis( }, parachain_info: ParachainInfoConfig { parachain_id }, balances: BalancesConfig { balances }, - block_reward: BlockRewardConfig { - // Make sure sum is 100 - reward_config: RewardDistributionConfig { - treasury_percent: Perbill::from_percent(10), - base_staker_percent: Perbill::from_percent(20), - dapps_percent: Perbill::from_percent(20), - collators_percent: Perbill::from_percent(5), - adjustable_percent: Perbill::from_percent(45), - ideal_dapps_staking_tvl: Perbill::from_percent(40), - }, - }, vesting: VestingConfig { vesting: vec![] }, session: SessionConfig { keys: authorities @@ -174,6 +163,41 @@ fn make_genesis( }, democracy: DemocracyConfig::default(), treasury: TreasuryConfig::default(), + dapp_staking: DappStakingConfig { + reward_portion: vec![ + Permill::from_percent(40), + Permill::from_percent(30), + Permill::from_percent(20), + Permill::from_percent(10), + ], + slot_distribution: vec![ + Permill::from_percent(10), + Permill::from_percent(20), + Permill::from_percent(30), + Permill::from_percent(40), + ], + // TODO: adjust this if needed + tier_thresholds: vec![ + TierThreshold::DynamicTvlAmount { + amount: 100 * SBY, + minimum_amount: 80 * SBY, + }, + TierThreshold::DynamicTvlAmount { + amount: 50 * SBY, + minimum_amount: 40 * SBY, + }, + TierThreshold::DynamicTvlAmount { + amount: 20 * SBY, + minimum_amount: 20 * SBY, + }, + TierThreshold::FixedTvlAmount { amount: 10 * SBY }, + ], + slots_per_tier: vec![10, 20, 30, 40], + }, + // TODO: adjust this if needed + inflation: InflationConfig { + params: InflationParameters::default(), + }, } } diff --git a/chain-extensions/dapps-staking/Cargo.toml b/chain-extensions/dapps-staking/Cargo.toml deleted file mode 100644 index 4169a7bd00..0000000000 --- a/chain-extensions/dapps-staking/Cargo.toml +++ /dev/null @@ -1,43 +0,0 @@ -[package] -name = "pallet-chain-extension-dapps-staking" -version = "1.1.0" -license = "Apache-2.0" -description = "dApps Staking chain extension for WASM contracts" -authors.workspace = true -edition.workspace = true -homepage.workspace = true -repository.workspace = true - -[dependencies] -frame-support = { workspace = true } -frame-system = { workspace = true } -log = { workspace = true } -num-traits = { workspace = true } -pallet-contracts = { workspace = true } -pallet-contracts-primitives = { workspace = true } -parity-scale-codec = { workspace = true } -scale-info = { workspace = true } -sp-core = { workspace = true } -sp-runtime = { workspace = true } -sp-std = { workspace = true } - -# Astar -dapps-staking-chain-extension-types = { workspace = true } -pallet-dapps-staking = { workspace = true } - -[features] -default = ["std"] -std = [ - "parity-scale-codec/std", - "dapps-staking-chain-extension-types/std", - "frame-support/std", - "frame-system/std", - "num-traits/std", - "pallet-contracts/std", - "pallet-contracts-primitives/std", - "pallet-dapps-staking/std", - "scale-info/std", - "sp-std/std", - "sp-core/std", - "sp-runtime/std", -] diff --git a/chain-extensions/dapps-staking/src/lib.rs b/chain-extensions/dapps-staking/src/lib.rs deleted file mode 100644 index 44910e3b0d..0000000000 --- a/chain-extensions/dapps-staking/src/lib.rs +++ /dev/null @@ -1,366 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 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 . - -#![cfg_attr(not(feature = "std"), no_std)] -use sp_runtime::{traits::Zero, DispatchError}; - -use dapps_staking_chain_extension_types::{ - DSError, DappsStakingAccountInput, DappsStakingEraInput, DappsStakingNominationInput, - DappsStakingValueInput, -}; -use frame_support::traits::{Currency, Get}; -use frame_system::RawOrigin; -use pallet_contracts::chain_extension::{ - ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, -}; -use pallet_dapps_staking::{RewardDestination, WeightInfo}; -use parity_scale_codec::Encode; -use sp_std::marker::PhantomData; - -type BalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; - -enum DappsStakingFunc { - CurrentEra, - UnbondingPeriod, - EraRewards, - EraStaked, - StakedAmount, - StakedAmountOnContract, - ReadContractStake, - BondAndStake, - UnbondAndUnstake, - WithdrawUnbonded, - ClaimStaker, - ClaimDapp, - SetRewardDestination, - NominationTransfer, -} - -impl TryFrom for DappsStakingFunc { - type Error = DispatchError; - - fn try_from(value: u16) -> Result { - match value { - 1 => Ok(DappsStakingFunc::CurrentEra), - 2 => Ok(DappsStakingFunc::UnbondingPeriod), - 3 => Ok(DappsStakingFunc::EraRewards), - 4 => Ok(DappsStakingFunc::EraStaked), - 5 => Ok(DappsStakingFunc::StakedAmount), - 6 => Ok(DappsStakingFunc::StakedAmountOnContract), - 7 => Ok(DappsStakingFunc::ReadContractStake), - 8 => Ok(DappsStakingFunc::BondAndStake), - 9 => Ok(DappsStakingFunc::UnbondAndUnstake), - 10 => Ok(DappsStakingFunc::WithdrawUnbonded), - 11 => Ok(DappsStakingFunc::ClaimStaker), - 12 => Ok(DappsStakingFunc::ClaimDapp), - 13 => Ok(DappsStakingFunc::SetRewardDestination), - 14 => Ok(DappsStakingFunc::NominationTransfer), - _ => Err(DispatchError::Other( - "DappsStakingExtension: Unimplemented func_id", - )), - } - } -} - -/// Dapps Staking chain extension. -pub struct DappsStakingExtension(PhantomData); - -impl Default for DappsStakingExtension { - fn default() -> Self { - DappsStakingExtension(PhantomData) - } -} - -impl ChainExtension for DappsStakingExtension -where - T: pallet_dapps_staking::Config + pallet_contracts::Config, - ::SmartContract: From<[u8; 32]>, - ::AccountId: From<[u8; 32]>, -{ - fn call(&mut self, env: Environment) -> Result - where - E: Ext, - { - let func_id = env.func_id().try_into()?; - let mut env = env.buf_in_buf_out(); - - match func_id { - DappsStakingFunc::CurrentEra => { - let base_weight = ::DbWeight::get().reads(1); - env.charge_weight(base_weight)?; - - let era_index = pallet_dapps_staking::CurrentEra::::get(); - env.write(&era_index.encode(), false, None)?; - } - - DappsStakingFunc::UnbondingPeriod => { - let base_weight = ::DbWeight::get().reads(1); - env.charge_weight(base_weight)?; - - let unbonding_period = T::UnbondingPeriod::get(); - env.write(&unbonding_period.encode(), false, None)?; - } - - DappsStakingFunc::EraRewards => { - let arg: u32 = env.read_as()?; - - let base_weight = ::DbWeight::get().reads(1); - env.charge_weight(base_weight)?; - - let era_info = pallet_dapps_staking::GeneralEraInfo::::get(arg); - let reward = era_info.map_or(Zero::zero(), |r| { - r.rewards.stakers.saturating_add(r.rewards.dapps) - }); - env.write(&reward.encode(), false, None)?; - } - - DappsStakingFunc::EraStaked => { - let arg: u32 = env.read_as()?; - - let base_weight = ::DbWeight::get().reads(1); - env.charge_weight(base_weight)?; - - let era_info = pallet_dapps_staking::GeneralEraInfo::::get(arg); - let staked_amount = era_info.map_or(Zero::zero(), |r| r.staked); - env.write(&staked_amount.encode(), false, None)?; - } - - DappsStakingFunc::StakedAmount => { - let staker: T::AccountId = env.read_as()?; - - let base_weight = ::DbWeight::get().reads(1); - env.charge_weight(base_weight)?; - - let ledger = pallet_dapps_staking::Ledger::::get(&staker); - env.write(&ledger.locked.encode(), false, None)?; - } - - DappsStakingFunc::StakedAmountOnContract => { - let args: DappsStakingAccountInput = env.read_as()?; - let staker: T::AccountId = args.staker.into(); - let contract: ::SmartContract = - args.contract.into(); - - let base_weight = ::DbWeight::get().reads(1); - env.charge_weight(base_weight)?; - - let staking_info = - pallet_dapps_staking::GeneralStakerInfo::::get(&staker, &contract); - let staked_amount = staking_info.latest_staked_value(); - env.write(&staked_amount.encode(), false, None)?; - } - - DappsStakingFunc::ReadContractStake => { - let contract_bytes: [u8; 32] = env.read_as()?; - let contract: ::SmartContract = - contract_bytes.into(); - - let base_weight = ::DbWeight::get().reads(1); - env.charge_weight(base_weight.saturating_add(base_weight))?; - - let current_era = pallet_dapps_staking::CurrentEra::::get(); - let staking_info = - pallet_dapps_staking::Pallet::::contract_stake_info(&contract, current_era) - .unwrap_or_default(); - let total = TryInto::::try_into(staking_info.total).unwrap_or(0); - env.write(&total.encode(), false, None)?; - } - - DappsStakingFunc::BondAndStake => { - let args: DappsStakingValueInput> = env.read_as()?; - let contract = args.contract.into(); - let value: BalanceOf = args.value; - - let base_weight = ::WeightInfo::bond_and_stake(); - env.charge_weight(base_weight)?; - - let caller = env.ext().address().clone(); - let call_result = pallet_dapps_staking::Pallet::::bond_and_stake( - RawOrigin::Signed(caller).into(), - contract, - value, - ); - return match call_result { - Err(e) => { - let mapped_error = DSError::try_from(e.error)?; - Ok(RetVal::Converging(mapped_error as u32)) - } - Ok(_) => Ok(RetVal::Converging(DSError::Success as u32)), - }; - } - - DappsStakingFunc::UnbondAndUnstake => { - let args: DappsStakingValueInput> = env.read_as()?; - let contract = args.contract.into(); - let value: BalanceOf = args.value; - - let base_weight = - ::WeightInfo::unbond_and_unstake(); - env.charge_weight(base_weight)?; - - let caller = env.ext().address().clone(); - let call_result = pallet_dapps_staking::Pallet::::unbond_and_unstake( - RawOrigin::Signed(caller).into(), - contract, - value, - ); - return match call_result { - Err(e) => { - let mapped_error = DSError::try_from(e.error)?; - Ok(RetVal::Converging(mapped_error as u32)) - } - Ok(_) => Ok(RetVal::Converging(DSError::Success as u32)), - }; - } - - DappsStakingFunc::WithdrawUnbonded => { - let caller = env.ext().address().clone(); - - let base_weight = - ::WeightInfo::withdraw_unbonded(); - env.charge_weight(base_weight)?; - - let call_result = pallet_dapps_staking::Pallet::::withdraw_unbonded( - RawOrigin::Signed(caller).into(), - ); - return match call_result { - Err(e) => { - let mapped_error = DSError::try_from(e.error)?; - Ok(RetVal::Converging(mapped_error as u32)) - } - Ok(_) => Ok(RetVal::Converging(DSError::Success as u32)), - }; - } - - DappsStakingFunc::ClaimStaker => { - let contract_bytes: [u8; 32] = env.read_as()?; - let contract = contract_bytes.into(); - - let base_weight = ::WeightInfo::claim_staker_with_restake() - .max(::WeightInfo::claim_staker_without_restake()); - let charged_weight = env.charge_weight(base_weight)?; - - let caller = env.ext().address().clone(); - let call_result = pallet_dapps_staking::Pallet::::claim_staker( - RawOrigin::Signed(caller).into(), - contract, - ); - - let actual_weight = match call_result { - Ok(e) => e.actual_weight, - Err(e) => e.post_info.actual_weight, - }; - if let Some(actual_weight) = actual_weight { - env.adjust_weight(charged_weight, actual_weight); - } - - return match call_result { - Err(e) => { - let mapped_error = DSError::try_from(e.error)?; - Ok(RetVal::Converging(mapped_error as u32)) - } - Ok(_) => Ok(RetVal::Converging(DSError::Success as u32)), - }; - } - - DappsStakingFunc::ClaimDapp => { - let args: DappsStakingEraInput = env.read_as()?; - let contract = args.contract.into(); - let era: u32 = args.era; - - let base_weight = ::WeightInfo::claim_dapp(); - env.charge_weight(base_weight)?; - - let caller = env.ext().address().clone(); - let call_result = pallet_dapps_staking::Pallet::::claim_dapp( - RawOrigin::Signed(caller).into(), - contract, - era, - ); - return match call_result { - Err(e) => { - let mapped_error = DSError::try_from(e.error)?; - Ok(RetVal::Converging(mapped_error as u32)) - } - Ok(_) => Ok(RetVal::Converging(DSError::Success as u32)), - }; - } - - DappsStakingFunc::SetRewardDestination => { - let reward_destination_raw: u8 = env.read_as()?; - - let base_weight = - ::WeightInfo::set_reward_destination(); - env.charge_weight(base_weight)?; - - // Transform raw value into dapps staking enum - let reward_destination = if reward_destination_raw == 0 { - RewardDestination::FreeBalance - } else if reward_destination_raw == 1 { - RewardDestination::StakeBalance - } else { - let error = DSError::RewardDestinationValueOutOfBounds; - return Ok(RetVal::Converging(error as u32)); - }; - - let caller = env.ext().address().clone(); - let call_result = pallet_dapps_staking::Pallet::::set_reward_destination( - RawOrigin::Signed(caller).into(), - reward_destination, - ); - return match call_result { - Err(e) => { - let mapped_error = DSError::try_from(e.error)?; - Ok(RetVal::Converging(mapped_error as u32)) - } - Ok(_) => Ok(RetVal::Converging(DSError::Success as u32)), - }; - } - - DappsStakingFunc::NominationTransfer => { - let args: DappsStakingNominationInput> = env.read_as()?; - let origin_smart_contract = args.origin_contract.into(); - let target_smart_contract = args.target_contract.into(); - let value: BalanceOf = args.value; - - let base_weight = - ::WeightInfo::nomination_transfer(); - env.charge_weight(base_weight)?; - - let caller = env.ext().address().clone(); - let call_result = pallet_dapps_staking::Pallet::::nomination_transfer( - RawOrigin::Signed(caller).into(), - origin_smart_contract, - value, - target_smart_contract, - ); - return match call_result { - Err(e) => { - let mapped_error = DSError::try_from(e.error)?; - Ok(RetVal::Converging(mapped_error as u32)) - } - Ok(_) => Ok(RetVal::Converging(DSError::Success as u32)), - }; - } - } - - Ok(RetVal::Converging(DSError::Success as u32)) - } -} diff --git a/chain-extensions/types/dapps-staking/Cargo.toml b/chain-extensions/types/dapps-staking/Cargo.toml deleted file mode 100644 index fcd45a0034..0000000000 --- a/chain-extensions/types/dapps-staking/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "dapps-staking-chain-extension-types" -version = "1.1.0" -license = "Apache-2.0" -description = "Types definitions for dapps-staking chain-extension" -authors.workspace = true -edition.workspace = true -homepage.workspace = true -repository.workspace = true - -[dependencies] -frame-support = { workspace = true } -parity-scale-codec = { workspace = true } -scale-info = { workspace = true } -sp-core = { workspace = true } -sp-runtime = { workspace = true } - -[features] -default = ["std"] -std = [ - "parity-scale-codec/std", - "frame-support/std", - "scale-info/std", - "sp-core/std", - "sp-runtime/std", -] diff --git a/chain-extensions/types/dapps-staking/src/lib.rs b/chain-extensions/types/dapps-staking/src/lib.rs deleted file mode 100644 index 585a15213c..0000000000 --- a/chain-extensions/types/dapps-staking/src/lib.rs +++ /dev/null @@ -1,154 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 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 . - -#![cfg_attr(not(feature = "std"), no_std)] -use frame_support::pallet_prelude::MaxEncodedLen; -use parity_scale_codec::{Decode, Encode}; -use sp_runtime::{DispatchError, ModuleError}; - -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, Debug)] -pub enum DSError { - /// Success - Success = 0, - /// Disabled - Disabled = 1, - /// No change in maintenance mode - NoMaintenanceModeChange = 2, - /// Upgrade is too heavy, reduce the weight parameter. - UpgradeTooHeavy = 3, - /// Can not stake with zero value. - StakingWithNoValue = 4, - /// Can not stake with value less than minimum staking value - InsufficientValue = 5, - /// Number of stakers per contract exceeded. - MaxNumberOfStakersExceeded = 6, - /// Targets must be operated contracts - NotOperatedContract = 7, - /// Contract isn't staked. - NotStakedContract = 8, - /// Contract isn't unregistered. - NotUnregisteredContract = 9, - /// Unclaimed rewards should be claimed before withdrawing stake. - UnclaimedRewardsRemaining = 10, - /// Unstaking a contract with zero value - UnstakingWithNoValue = 11, - /// There are no previously unbonded funds that can be unstaked and withdrawn. - NothingToWithdraw = 12, - /// The contract is already registered by other account - AlreadyRegisteredContract = 13, - /// User attempts to register with address which is not contract - ContractIsNotValid = 14, - /// This account was already used to register contract - AlreadyUsedDeveloperAccount = 15, - /// Smart contract not owned by the account id. - NotOwnedContract = 16, - /// Report issue on github if this is ever emitted - UnknownEraReward = 17, - /// Report issue on github if this is ever emitted - UnexpectedStakeInfoEra = 18, - /// Contract has too many unlocking chunks. Withdraw the existing chunks if possible - /// or wait for current chunks to complete unlocking process to withdraw them. - TooManyUnlockingChunks = 19, - /// Contract already claimed in this era and reward is distributed - AlreadyClaimedInThisEra = 20, - /// Era parameter is out of bounds - EraOutOfBounds = 21, - /// Too many active `EraStake` values for (staker, contract) pairing. - /// Claim existing rewards to fix this problem. - TooManyEraStakeValues = 22, - /// To register a contract, pre-approval is needed for this address - RequiredContractPreApproval = 23, - /// Developer's account is already part of pre-approved list - AlreadyPreApprovedDeveloper = 24, - /// Account is not actively staking - NotActiveStaker = 25, - /// Transfering nomination to the same contract - NominationTransferToSameContract = 26, - /// Unexpected reward destination value - RewardDestinationValueOutOfBounds = 27, - /// Unknown error - UnknownError = 99, -} - -impl TryFrom for DSError { - type Error = DispatchError; - - fn try_from(input: DispatchError) -> Result { - let error_text = match input { - DispatchError::Module(ModuleError { message, .. }) => message, - _ => Some("No module error Info"), - }; - return match error_text { - Some("Disabled") => Ok(DSError::Disabled), - Some("NoMaintenanceModeChange") => Ok(DSError::NoMaintenanceModeChange), - Some("UpgradeTooHeavy") => Ok(DSError::UpgradeTooHeavy), - Some("StakingWithNoValue") => Ok(DSError::StakingWithNoValue), - Some("InsufficientValue") => Ok(DSError::InsufficientValue), - Some("MaxNumberOfStakersExceeded") => Ok(DSError::MaxNumberOfStakersExceeded), - Some("NotOperatedContract") => Ok(DSError::NotOperatedContract), - Some("NotStakedContract") => Ok(DSError::NotStakedContract), - Some("NotUnregisteredContract") => Ok(DSError::NotUnregisteredContract), - Some("UnclaimedRewardsRemaining") => Ok(DSError::UnclaimedRewardsRemaining), - Some("UnstakingWithNoValue") => Ok(DSError::UnstakingWithNoValue), - Some("NothingToWithdraw") => Ok(DSError::NothingToWithdraw), - Some("AlreadyRegisteredContract") => Ok(DSError::AlreadyRegisteredContract), - Some("ContractIsNotValid") => Ok(DSError::ContractIsNotValid), - Some("AlreadyUsedDeveloperAccount") => Ok(DSError::AlreadyUsedDeveloperAccount), - Some("NotOwnedContract") => Ok(DSError::NotOwnedContract), - Some("UnknownEraReward") => Ok(DSError::UnknownEraReward), - Some("UnexpectedStakeInfoEra") => Ok(DSError::UnexpectedStakeInfoEra), - Some("TooManyUnlockingChunks") => Ok(DSError::TooManyUnlockingChunks), - Some("AlreadyClaimedInThisEra") => Ok(DSError::AlreadyClaimedInThisEra), - Some("EraOutOfBounds") => Ok(DSError::EraOutOfBounds), - Some("TooManyEraStakeValues") => Ok(DSError::TooManyEraStakeValues), - Some("RequiredContractPreApproval") => Ok(DSError::RequiredContractPreApproval), - Some("AlreadyPreApprovedDeveloper") => Ok(DSError::AlreadyPreApprovedDeveloper), - Some("NotActiveStaker") => Ok(DSError::NotActiveStaker), - Some("NominationTransferToSameContract") => { - Ok(DSError::NominationTransferToSameContract) - } - _ => Ok(DSError::UnknownError), - }; - } -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] -pub struct DappsStakingValueInput { - pub contract: [u8; 32], - pub value: Balance, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] -pub struct DappsStakingAccountInput { - pub contract: [u8; 32], - pub staker: [u8; 32], -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] -pub struct DappsStakingEraInput { - pub contract: [u8; 32], - pub era: u32, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] -pub struct DappsStakingNominationInput { - pub origin_contract: [u8; 32], - pub target_contract: [u8; 32], - pub value: Balance, -} diff --git a/pallets/dapp-staking-migration/src/benchmarking.rs b/pallets/dapp-staking-migration/src/benchmarking.rs index 6570322068..d26f810241 100644 --- a/pallets/dapp-staking-migration/src/benchmarking.rs +++ b/pallets/dapp-staking-migration/src/benchmarking.rs @@ -19,7 +19,7 @@ use super::{Pallet as Migration, *}; use frame_benchmarking::{account as benchmark_account, v2::*}; -use frame_support::{assert_ok, storage::unhashed::put_raw, traits::Currency}; +use frame_support::{assert_ok, traits::Currency}; /// Generate an unique smart contract using the provided index as a sort-of indetifier fn smart_contract(index: u8) -> T::SmartContract { @@ -107,20 +107,13 @@ mod benchmarks { #[benchmark] fn cleanup_old_storage_success() { - let hashed_prefix = twox_128(pallet_dapps_staking::Pallet::::name().as_bytes()); - let _ = clear_prefix(&hashed_prefix, None); - - put_raw(&hashed_prefix, &[0xFF; 128]); + initial_config::(); #[block] { - if cfg!(test) { - // TODO: for some reason, tests always fail here, nothing gets removed from storage. - // When tested against real runtime, it works just fine. - let _ = Migration::::cleanup_old_storage(1); - } else { - assert!(Migration::::cleanup_old_storage(1).is_ok()); - } + // TODO: for some reason, tests always fail here, nothing gets removed from storage. + // When tested against real runtime, it works just fine. + let _ = Migration::::cleanup_old_storage(1); } } diff --git a/pallets/dapp-staking-migration/src/lib.rs b/pallets/dapp-staking-migration/src/lib.rs index be26dedcd4..d6fdefe803 100644 --- a/pallets/dapp-staking-migration/src/lib.rs +++ b/pallets/dapp-staking-migration/src/lib.rs @@ -581,10 +581,26 @@ pub mod pallet { .collect(); // Get the stakers and their active locked (staked) amount. + + let min_lock_amount: Balance = + ::MinimumLockedAmount::get(); let stakers: Vec<_> = pallet_dapps_staking::Ledger::::iter() - .map(|(staker, ledger)| (staker, ledger.locked)) + .filter_map(|(staker, ledger)| { + if ledger.locked >= min_lock_amount { + Some((staker, ledger.locked)) + } else { + None + } + }) .collect(); + log::info!( + target: LOG_TARGET, + "Out of {} stakers, {} have sufficient amount to lock.", + pallet_dapps_staking::Ledger::::iter().count(), + stakers.len(), + ); + let helper = Helper:: { developers, stakers, @@ -651,6 +667,12 @@ pub mod pallet { total_locked ); + log::info!( + target: LOG_TARGET, + "Total locked amount in the new pallet: {:?}.", + total_locked, + ); + // 3. Check that rest of the storage has been cleaned up. assert!(!pallet_dapps_staking::PalletDisabled::::exists()); assert!(!pallet_dapps_staking::CurrentEra::::exists()); diff --git a/pallets/dapp-staking-migration/src/weights.rs b/pallets/dapp-staking-migration/src/weights.rs index 158adad022..313e4c7070 100644 --- a/pallets/dapp-staking-migration/src/weights.rs +++ b/pallets/dapp-staking-migration/src/weights.rs @@ -20,16 +20,16 @@ //! Autogenerated weights for pallet_dapp_staking_migration //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-13, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Dinos-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=dev +// --chain=shibuya-dev // --steps=50 // --repeat=20 // --pallet=pallet_dapp_staking_migration @@ -37,7 +37,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=weights.rs +// --output=./benchmark-results/shibuya-dev/dapp_staking_migration_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -72,10 +72,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking NextDAppId (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) fn migrate_dapps_success() -> Weight { // Proof Size summary in bytes: - // Measured: `147` + // Measured: `558` // Estimated: `6112` - // Minimum execution time: 43_000_000 picoseconds. - Weight::from_parts(45_000_000, 6112) + // Minimum execution time: 46_218_000 picoseconds. + Weight::from_parts(47_610_000, 6112) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -85,8 +85,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3551` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(4_000_000, 3551) + // Minimum execution time: 3_385_000 picoseconds. + Weight::from_parts(3_552_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: DappsStaking Ledger (r:2 w:1) @@ -95,18 +95,20 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: Balances Freezes (r:1 w:1) /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn migrate_ledger_success() -> Weight { // Proof Size summary in bytes: - // Measured: `136` + // Measured: `1748` // Estimated: `6472` - // Minimum execution time: 67_000_000 picoseconds. - Weight::from_parts(68_000_000, 6472) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 69_553_000 picoseconds. + Weight::from_parts(70_319_000, 6472) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: DappsStaking Ledger (r:1 w:0) /// Proof: DappsStaking Ledger (max_values: None, max_size: Some(266), added: 2741, mode: MaxEncodedLen) @@ -114,27 +116,27 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3731` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 3731) + // Minimum execution time: 2_918_000 picoseconds. + Weight::from_parts(3_022_000, 3731) .saturating_add(T::DbWeight::get().reads(1_u64)) } - /// Storage: unknown `0xc0d3d54ea9961b06a7139c5a75c15c4f` (r:1 w:1) - /// Proof Skipped: unknown `0xc0d3d54ea9961b06a7139c5a75c15c4f` (r:1 w:1) + /// Storage: DappsStaking Ledger (r:2 w:1) + /// Proof: DappsStaking Ledger (max_values: None, max_size: Some(266), added: 2741, mode: MaxEncodedLen) fn cleanup_old_storage_success() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `3465` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 3465) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Measured: `739` + // Estimated: `6472` + // Minimum execution time: 7_109_000 picoseconds. + Weight::from_parts(7_383_000, 6472) + .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } fn cleanup_old_storage_noop() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(2_000_000, 0) + // Minimum execution time: 2_095_000 picoseconds. + Weight::from_parts(2_213_000, 0) } } @@ -152,10 +154,10 @@ impl WeightInfo for () { /// Proof: DappStaking NextDAppId (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) fn migrate_dapps_success() -> Weight { // Proof Size summary in bytes: - // Measured: `147` + // Measured: `558` // Estimated: `6112` - // Minimum execution time: 43_000_000 picoseconds. - Weight::from_parts(45_000_000, 6112) + // Minimum execution time: 46_218_000 picoseconds. + Weight::from_parts(47_610_000, 6112) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -165,8 +167,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3551` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(4_000_000, 3551) + // Minimum execution time: 3_385_000 picoseconds. + Weight::from_parts(3_552_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: DappsStaking Ledger (r:2 w:1) @@ -175,18 +177,20 @@ impl WeightInfo for () { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: Balances Freezes (r:1 w:1) /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn migrate_ledger_success() -> Weight { // Proof Size summary in bytes: - // Measured: `136` + // Measured: `1748` // Estimated: `6472` - // Minimum execution time: 67_000_000 picoseconds. - Weight::from_parts(68_000_000, 6472) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(5_u64)) + // Minimum execution time: 69_553_000 picoseconds. + Weight::from_parts(70_319_000, 6472) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: DappsStaking Ledger (r:1 w:0) /// Proof: DappsStaking Ledger (max_values: None, max_size: Some(266), added: 2741, mode: MaxEncodedLen) @@ -194,26 +198,26 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3731` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 3731) + // Minimum execution time: 2_918_000 picoseconds. + Weight::from_parts(3_022_000, 3731) .saturating_add(RocksDbWeight::get().reads(1_u64)) } - /// Storage: unknown `0xc0d3d54ea9961b06a7139c5a75c15c4f` (r:1 w:1) - /// Proof Skipped: unknown `0xc0d3d54ea9961b06a7139c5a75c15c4f` (r:1 w:1) + /// Storage: DappsStaking Ledger (r:2 w:1) + /// Proof: DappsStaking Ledger (max_values: None, max_size: Some(266), added: 2741, mode: MaxEncodedLen) fn cleanup_old_storage_success() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `3465` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 3465) - .saturating_add(RocksDbWeight::get().reads(1_u64)) + // Measured: `739` + // Estimated: `6472` + // Minimum execution time: 7_109_000 picoseconds. + Weight::from_parts(7_383_000, 6472) + .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } fn cleanup_old_storage_noop() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(2_000_000, 0) + // Minimum execution time: 2_095_000 picoseconds. + Weight::from_parts(2_213_000, 0) } } diff --git a/pallets/dapp-staking-v3/src/benchmarking/mod.rs b/pallets/dapp-staking-v3/src/benchmarking/mod.rs index 3eab3c6f85..11663401d9 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/mod.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/mod.rs @@ -29,6 +29,11 @@ use ::assert_matches::assert_matches; mod utils; use utils::*; +// A lot of benchmarks which require many blocks, eras or periods to pass have been optimized to utilize +// `force` approach, which skips the required amount of blocks that need to be produced in order to advance. +// +// Without this optimization, benchmarks can take hours to execute for production runtimes. + #[benchmarks] mod benchmarks { use super::*; @@ -220,7 +225,7 @@ mod benchmarks { // Move over to the build&earn subperiod to ensure 'non-loyal' staking. // This is needed so we can achieve staker entry cleanup after claiming unlocked tokens. - advance_to_next_subperiod::(); + force_advance_to_next_subperiod::(); assert_eq!( ActiveProtocolState::::get().subperiod(), Subperiod::BuildAndEarn, @@ -261,8 +266,18 @@ mod benchmarks { ); let unlock_amount = unlock_amount * Into::::into(T::MaxUnlockingChunks::get()); + // Hack + // In order to speed up the benchmark, we reduce how long it takes to unlock the chunks + let mut counter = 1; + Ledger::::mutate(&staker, |ledger| { + ledger.unlocking.iter_mut().for_each(|unlocking| { + unlocking.unlock_block = System::::block_number() + counter; + }); + counter += 1; + }); + // Advance to next period to ensure the old stake entries are cleaned up. - advance_to_next_period::(); + force_advance_to_next_period::(); // Additionally, ensure enough blocks have passed so that the unlocking chunk can be claimed. let unlock_block = Ledger::::get(&staker) @@ -424,32 +439,50 @@ mod benchmarks { smart_contract.clone(), )); - // Lock some amount by the staker + // Lock & stake some amount by the staker let amount = T::MinimumLockedAmount::get(); T::BenchmarkHelper::set_balance(&staker, amount); assert_ok!(DappStaking::::lock( RawOrigin::Signed(staker.clone()).into(), amount, )); - - // Advance to the era just before a new span entry is created. - // This ensures that when rewards are claimed, we'll be claiming from the new span. - // - // This is convenient because it allows us to control how many rewards are claimed. - advance_to_era::(T::EraRewardSpanLength::get() - 1); - - // Now ensure the expected amount of rewards are claimable. - advance_to_era::( - ActiveProtocolState::::get().era + T::EraRewardSpanLength::get() - x, - ); assert_ok!(DappStaking::::stake( RawOrigin::Signed(staker.clone()).into(), smart_contract.clone(), amount )); + // Advance to era just after the last era covered by the first span + force_advance_to_era::(T::EraRewardSpanLength::get()); + + // Hack - modify staker's stake so it seems as if stake was valid from the 'first stake era'/ + // Also fill up the reward span. + // + // This allows us to easily control how many rewards are claimed, without having to advance large amount of blocks/eras/periods + // to find an appropriate scenario. + let first_stake_era = T::EraRewardSpanLength::get() - x; + Ledger::::mutate(&staker, |ledger| { + ledger.staked = ledger.staked_future.unwrap(); + ledger.staked_future = None; + ledger.staked.era = first_stake_era; + }); + + // Just fill them up, the ledger entry will control how much claims we can make + let mut reward_span = EraRewardSpan::<_>::new(); + for era in 0..(T::EraRewardSpanLength::get()) { + assert_ok!(reward_span.push( + era as EraNumber, + EraReward { + staker_reward_pool: 1_000_000_000_000, + staked: amount, + dapp_reward_pool: 1_000_000_000_000, + }, + )); + } + EraRewards::::insert(&0, reward_span); + // This ensures we claim from the past period. - advance_to_next_period::(); + force_advance_to_next_period::(); // For testing purposes System::::reset_events(); @@ -486,25 +519,41 @@ mod benchmarks { RawOrigin::Signed(staker.clone()).into(), amount, )); - - // Advance to the era just before a new span entry is created. - // This ensures that when rewards are claimed, we'll be claiming from the new span. - // - // This is convenient because it allows us to control how many rewards are claimed. - advance_to_era::(T::EraRewardSpanLength::get() - 1); - - // Now ensure the expected amount of rewards are claimable. - advance_to_era::( - ActiveProtocolState::::get().era + T::EraRewardSpanLength::get() - x, - ); assert_ok!(DappStaking::::stake( RawOrigin::Signed(staker.clone()).into(), smart_contract.clone(), amount )); - // This ensures we move over the entire span. - advance_to_era::(T::EraRewardSpanLength::get() * 2); + // Advance to era just after the last era covered by the first span + // This means we'll be able to claim all of the rewards from the previous span. + force_advance_to_era::(T::EraRewardSpanLength::get()); + + // Hack - modify staker's stake so it seems as if stake was valid from the 'first stake era'/ + // Also fill up the reward span. + // + // This allows us to easily control how many rewards are claimed, without having to advance large amount of blocks/eras/periods + // to find an appropriate scenario. + let first_stake_era = T::EraRewardSpanLength::get() - x; + Ledger::::mutate(&staker, |ledger| { + ledger.staked = ledger.staked_future.unwrap(); + ledger.staked_future = None; + ledger.staked.era = first_stake_era; + }); + + // Just fill them up, the ledger entry will control how much claims we can make + let mut reward_span = EraRewardSpan::<_>::new(); + for era in 0..(T::EraRewardSpanLength::get()) { + assert_ok!(reward_span.push( + era as EraNumber, + EraReward { + staker_reward_pool: 1_000_000_000_000, + staked: amount, + dapp_reward_pool: 1_000_000_000_000, + }, + )); + } + EraRewards::::insert(&0, reward_span); // For testing purposes System::::reset_events(); @@ -548,7 +597,7 @@ mod benchmarks { )); // Advance to the next period so we can claim the bonus reward. - advance_to_next_period::(); + force_advance_to_next_period::(); #[extrinsic_call] _(RawOrigin::Signed(staker.clone()), smart_contract.clone()); @@ -574,7 +623,7 @@ mod benchmarks { smart_contract.clone(), )); - let amount = T::MinimumLockedAmount::get() * 1000 * UNIT; + let amount = MIN_TIER_THRESHOLD * 1000; T::BenchmarkHelper::set_balance(&owner, amount); assert_ok!(DappStaking::::lock( RawOrigin::Signed(owner.clone()).into(), @@ -610,17 +659,18 @@ mod benchmarks { )); } + // Advance enough eras so dApp reward can be claimed. + force_advance_to_next_subperiod::(); + // This is a hacky part to ensure we accomodate max number of contracts. TierConfig::::mutate(|config| { let max_number_of_contracts: u16 = T::MaxNumberOfContracts::get().try_into().unwrap(); config.number_of_slots = max_number_of_contracts; config.slots_per_tier[0] = max_number_of_contracts; config.slots_per_tier[1..].iter_mut().for_each(|x| *x = 0); + config.tier_thresholds[0] = TierThreshold::FixedTvlAmount { amount: 1 }; }); - - // Advance enough eras so dApp reward can be claimed. - advance_to_next_subperiod::(); - advance_to_next_era::(); + force_advance_to_next_era::(); let claim_era = ActiveProtocolState::::get().era - 1; assert_eq!( @@ -695,7 +745,7 @@ mod benchmarks { initial_config::(); // Move over to the build&earn subperiod to ensure 'non-loyal' staking. - advance_to_next_subperiod::(); + force_advance_to_next_subperiod::(); // Prepare staker & lock some amount let staker: T::AccountId = whitelisted_caller(); @@ -725,7 +775,7 @@ mod benchmarks { } // Move over to the next period, marking the entries as expired since they don't have the loyalty flag. - advance_to_next_period::(); + force_advance_to_next_period::(); #[extrinsic_call] _(RawOrigin::Signed(staker.clone())); @@ -791,7 +841,7 @@ mod benchmarks { prepare_contracts_for_tier_assignment::(max_number_of_contracts::()); // Advance to build&earn subperiod - advance_to_next_subperiod::(); + force_advance_to_next_subperiod::(); let snapshot_state = ActiveProtocolState::::get(); // Advance over to the last era of the subperiod, and then again to the last block of that era. @@ -840,11 +890,11 @@ mod benchmarks { prepare_contracts_for_tier_assignment::(max_number_of_contracts::()); // Advance to build&earn subperiod - advance_to_next_subperiod::(); + force_advance_to_next_subperiod::(); let snapshot_state = ActiveProtocolState::::get(); // Advance over to the next era, and then again to the last block of that era. - advance_to_next_era::(); + force_advance_to_next_era::(); run_to_block::(ActiveProtocolState::::get().next_era_start - 1); // Some sanity checks, we should still be in the build&earn subperiod, and in the first period. @@ -888,7 +938,7 @@ mod benchmarks { // Register & stake contracts, to prepare for tier assignment. prepare_contracts_for_tier_assignment::(x); - advance_to_next_era::(); + force_advance_to_next_era::(); let reward_era = ActiveProtocolState::::get().era; let reward_period = ActiveProtocolState::::get().period_number(); @@ -907,9 +957,13 @@ mod benchmarks { // Prepare init config (protocol state, tier params & config, etc.) initial_config::(); - // Advance enough periods to trigger the cleanup + // Advance to era just after the last era covered by the first span. + // This is sufficient to completely fill up the first span with entries for the ongoing era. + force_advance_to_era::(T::EraRewardSpanLength::get()); + + // Advance enough periods to make cleanup feasible. let retention_period = T::RewardRetentionInPeriods::get(); - advance_to_period::( + force_advance_to_period::( ActiveProtocolState::::get().period_number() + retention_period + 2, ); diff --git a/pallets/dapp-staking-v3/src/benchmarking/utils.rs b/pallets/dapp-staking-v3/src/benchmarking/utils.rs index 688f964a76..28dde52267 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/utils.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/utils.rs @@ -49,34 +49,88 @@ pub(super) fn advance_to_era(era: EraNumber) { } } +/// Advance blocks until the specified era has been reached. +/// +/// Relies on the `force` approach to advance one era per block. +pub(super) fn force_advance_to_era(era: EraNumber) { + assert!(era >= ActiveProtocolState::::get().era); + while ActiveProtocolState::::get().era < era { + assert_ok!(DappStaking::::force( + RawOrigin::Root.into(), + ForcingType::Era + )); + run_for_blocks::(One::one()); + } +} + /// Advance blocks until next era has been reached. -pub(super) fn advance_to_next_era() { +pub(super) fn _advance_to_next_era() { advance_to_era::(ActiveProtocolState::::get().era + 1); } +/// Advance to next era, in the next block using the `force` approach. +pub(crate) fn force_advance_to_next_era() { + assert_ok!(DappStaking::::force( + RawOrigin::Root.into(), + ForcingType::Era + )); + run_for_blocks::(One::one()); +} + /// Advance blocks until the specified period has been reached. /// /// Function has no effect if period is already passed. -pub(super) fn advance_to_period(period: PeriodNumber) { +pub(super) fn _advance_to_period(period: PeriodNumber) { assert!(period >= ActiveProtocolState::::get().period_number()); while ActiveProtocolState::::get().period_number() < period { run_for_blocks::(One::one()); } } +/// Advance to the specified period, using the `force` approach. +pub(super) fn force_advance_to_period(period: PeriodNumber) { + assert!(period >= ActiveProtocolState::::get().period_number()); + while ActiveProtocolState::::get().period_number() < period { + force_advance_to_next_subperiod::(); + } +} + /// Advance blocks until next period has been reached. -pub(super) fn advance_to_next_period() { - advance_to_period::(ActiveProtocolState::::get().period_number() + 1); +pub(super) fn _advance_to_next_period() { + _advance_to_period::(ActiveProtocolState::::get().period_number() + 1); +} + +/// Advance blocks until next period has been reached. +/// +/// Relies on the `force` approach to advance one subperiod per block. +pub(super) fn force_advance_to_next_period() { + let init_period_number = ActiveProtocolState::::get().period_number(); + while ActiveProtocolState::::get().period_number() == init_period_number { + assert_ok!(DappStaking::::force( + RawOrigin::Root.into(), + ForcingType::Subperiod + )); + run_for_blocks::(One::one()); + } } /// Advance blocks until next period type has been reached. -pub(super) fn advance_to_next_subperiod() { +pub(super) fn _advance_to_next_subperiod() { let subperiod = ActiveProtocolState::::get().subperiod(); while ActiveProtocolState::::get().subperiod() == subperiod { run_for_blocks::(One::one()); } } +/// Use the `force` approach to advance to the next subperiod immediately in the next block. +pub(super) fn force_advance_to_next_subperiod() { + assert_ok!(DappStaking::::force( + RawOrigin::Root.into(), + ForcingType::Subperiod + )); + run_for_blocks::(One::one()); +} + /// All our networks use 18 decimals for native currency so this should be fine. pub(super) const UNIT: Balance = 1_000_000_000_000_000_000; @@ -172,7 +226,6 @@ pub(super) fn initial_config() { StaticTierParams::::put(tier_params); TierConfig::::put(init_tier_config.clone()); - NextTierConfig::::put(init_tier_config); } /// Maximum number of contracts that 'makes sense' - considers both contract number limit & number of slots. @@ -195,9 +248,14 @@ pub(super) fn prepare_contracts_for_tier_assignment(x: u32) { )); } - // TODO: try to make this more "shuffled" so the generated vector ends up being more random - let mut amount = 1000 * MIN_TIER_THRESHOLD; + let anchor_amount = 1000 * MIN_TIER_THRESHOLD; + let mut amounts: Vec<_> = (0..x) + .map(|i| anchor_amount - UNIT * i as Balance) + .collect(); + trivial_fisher_yates_shuffle(&mut amounts, SEED.into()); + for id in 0..x { + let amount = amounts[id as usize]; let staker = account("staker", id.into(), 1337); T::BenchmarkHelper::set_balance(&staker, amount); assert_ok!(DappStaking::::lock( @@ -211,8 +269,17 @@ pub(super) fn prepare_contracts_for_tier_assignment(x: u32) { smart_contract, amount, )); + } +} - // Slowly decrease the stake amount - amount.saturating_reduce(UNIT); +/// Reuse from `sassafras` pallet tests. +/// +/// Just a trivial, insecure shuffle for the benchmarks. +fn trivial_fisher_yates_shuffle(vector: &mut Vec, random_seed: u64) { + let mut rng = random_seed as usize; + for i in (1..vector.len()).rev() { + let j = rng % (i + 1); + vector.swap(i, j); + rng = (rng.wrapping_mul(8427637) + 1) as usize; // Some random number generation } } diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index a20c921dfc..f9a10da274 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -39,7 +39,7 @@ use frame_support::{ pallet_prelude::*, traits::{ fungible::{Inspect as FunInspect, MutateFreeze as FunMutateFreeze}, - StorageVersion, + OnRuntimeUpgrade, StorageVersion, }, weights::Weight, }; @@ -431,11 +431,6 @@ pub mod pallet { pub type StaticTierParams = StorageValue<_, TierParameters, ValueQuery>; - /// Tier configuration to be used during the newly started period - #[pallet::storage] - pub type NextTierConfig = - StorageValue<_, TiersConfiguration, ValueQuery>; - /// Tier configuration user for current & preceding eras. #[pallet::storage] pub type TierConfig = @@ -518,7 +513,6 @@ pub mod pallet { ActiveProtocolState::::put(protocol_state); StaticTierParams::::put(tier_params); TierConfig::::put(tier_config.clone()); - NextTierConfig::::put(tier_config); } } @@ -531,6 +525,27 @@ pub mod pallet { fn on_idle(_block: BlockNumberFor, remaining_weight: Weight) -> Weight { Self::expired_entry_cleanup(&remaining_weight) } + + fn integrity_test() { + // dApp staking params + // Sanity checks + assert!(T::EraRewardSpanLength::get() > 0); + assert!(T::RewardRetentionInPeriods::get() > 0); + assert!(T::MaxNumberOfContracts::get() > 0); + assert!(T::MaxUnlockingChunks::get() > 0); + assert!(T::UnlockingPeriod::get() > 0); + assert!(T::MaxNumberOfStakedContracts::get() > 0); + + assert!(T::MinimumLockedAmount::get() > 0); + assert!(T::MinimumStakeAmount::get() > 0); + assert!(T::MinimumLockedAmount::get() >= T::MinimumStakeAmount::get()); + + // Cycle config + assert!(T::CycleConfiguration::periods_per_cycle() > 0); + assert!(T::CycleConfiguration::eras_per_voting_subperiod() > 0); + assert!(T::CycleConfiguration::eras_per_build_and_earn_subperiod() > 0); + assert!(T::CycleConfiguration::blocks_per_era() > 0); + } } /// A reason for freezing funds. @@ -1739,10 +1754,6 @@ pub mod pallet { era_info.migrate_to_next_era(Some(protocol_state.subperiod())); - // Update tier configuration to be used when calculating rewards for the upcoming eras - let next_tier_config = NextTierConfig::::take(); - TierConfig::::put(next_tier_config); - consumed_weight .saturating_accrue(T::WeightInfo::on_initialize_voting_to_build_and_earn()); @@ -1813,7 +1824,7 @@ pub mod pallet { let average_price = T::NativePriceProvider::average_price(); let new_tier_config = TierConfig::::get().calculate_new(average_price, &tier_params); - NextTierConfig::::put(new_tier_config); + TierConfig::::put(new_tier_config); consumed_weight.saturating_accrue( T::WeightInfo::on_initialize_build_and_earn_to_voting(), @@ -1943,3 +1954,75 @@ pub mod pallet { } } } + +/// `OnRuntimeUpgrade` logic used to set & configure init dApp staking v3 storage items. +pub struct DAppStakingV3InitConfig(PhantomData<(T, G)>); +impl< + T: Config, + G: Get<( + EraNumber, + TierParameters, + TiersConfiguration, + )>, + > OnRuntimeUpgrade for DAppStakingV3InitConfig +{ + fn on_runtime_upgrade() -> Weight { + if Pallet::::on_chain_storage_version() >= STORAGE_VERSION { + return T::DbWeight::get().reads(1); + } + + // 0. Unwrap arguments + let (init_era, tier_params, init_tier_config) = G::get(); + + // 1. Prepare active protocol state + let now = frame_system::Pallet::::block_number(); + let voting_period_length = Pallet::::blocks_per_voting_period(); + + let protocol_state = ProtocolState { + era: init_era, + next_era_start: now.saturating_add(voting_period_length), + period_info: PeriodInfo { + number: 1, + subperiod: Subperiod::Voting, + next_subperiod_start_era: init_era.saturating_add(1), + }, + maintenance: true, + }; + + // 2. Write necessary items into storage + ActiveProtocolState::::put(protocol_state); + StaticTierParams::::put(tier_params); + TierConfig::::put(init_tier_config); + STORAGE_VERSION.put::>(); + + // 3. Emit events to make indexers happy + Pallet::::deposit_event(Event::::NewEra { era: init_era }); + Pallet::::deposit_event(Event::::NewSubperiod { + subperiod: Subperiod::Voting, + number: 1, + }); + + log::info!("dApp Staking v3 storage initialized."); + + T::DbWeight::get().reads_writes(1, 4) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + assert_eq!(Pallet::::on_chain_storage_version(), STORAGE_VERSION); + assert!(ActiveProtocolState::::get().maintenance); + + let number_of_tiers = T::NumberOfTiers::get(); + + let tier_params = StaticTierParams::::get(); + assert_eq!(tier_params.reward_portion.len(), number_of_tiers as usize); + assert!(tier_params.is_valid()); + + let tier_config = TierConfig::::get(); + assert_eq!(tier_config.reward_portion.len(), number_of_tiers as usize); + assert_eq!(tier_config.slots_per_tier.len(), number_of_tiers as usize); + assert_eq!(tier_config.tier_thresholds.len(), number_of_tiers as usize); + + Ok(()) + } +} diff --git a/pallets/dapp-staking-v3/src/test/mock.rs b/pallets/dapp-staking-v3/src/test/mock.rs index 3f116c6bbc..247605e456 100644 --- a/pallets/dapp-staking-v3/src/test/mock.rs +++ b/pallets/dapp-staking-v3/src/test/mock.rs @@ -24,10 +24,7 @@ use crate::{ use frame_support::{ construct_runtime, parameter_types, - traits::{ - fungible::{Mutate as FunMutate, Unbalanced as FunUnbalanced}, - ConstU128, ConstU32, - }, + traits::{fungible::Mutate as FunMutate, ConstU128, ConstU32}, weights::Weight, }; use sp_arithmetic::fixed_point::FixedU64; @@ -158,6 +155,7 @@ impl crate::BenchmarkHelper } fn set_balance(account: &AccountId, amount: Balance) { + use frame_support::traits::fungible::Unbalanced as FunUnbalanced; Balances::write_balance(account, amount) .expect("Must succeed in test/benchmark environment."); } @@ -305,7 +303,6 @@ impl ExtBuilder { pallet_dapp_staking::StaticTierParams::::put(tier_params); pallet_dapp_staking::TierConfig::::put(init_tier_config.clone()); - pallet_dapp_staking::NextTierConfig::::put(init_tier_config); DappStaking::on_initialize(System::block_number()); }); diff --git a/pallets/dapp-staking-v3/src/test/testing_utils.rs b/pallets/dapp-staking-v3/src/test/testing_utils.rs index 8f372a53ab..5e2e0af0d5 100644 --- a/pallets/dapp-staking-v3/src/test/testing_utils.rs +++ b/pallets/dapp-staking-v3/src/test/testing_utils.rs @@ -21,7 +21,7 @@ use crate::types::*; use crate::{ pallet::Config, ActiveProtocolState, ContractStake, CurrentEraInfo, DAppId, DAppTiers, EraRewards, Event, FreezeReason, HistoryCleanupMarker, IntegratedDApps, Ledger, NextDAppId, - NextTierConfig, PeriodEnd, PeriodEndInfo, StakerInfo, TierConfig, + PeriodEnd, PeriodEndInfo, StakerInfo, }; use frame_support::{ @@ -57,8 +57,6 @@ pub(crate) struct MemorySnapshot { era_rewards: HashMap::EraRewardSpanLength>>, period_end: HashMap, dapp_tiers: HashMap>, - tier_config: TiersConfiguration<::NumberOfTiers>, - next_tier_config: TiersConfiguration<::NumberOfTiers>, } impl MemorySnapshot { @@ -77,8 +75,6 @@ impl MemorySnapshot { era_rewards: EraRewards::::iter().collect(), period_end: PeriodEnd::::iter().collect(), dapp_tiers: DAppTiers::::iter().collect(), - tier_config: TierConfig::::get(), - next_tier_config: NextTierConfig::::get(), } } @@ -1273,22 +1269,7 @@ pub(crate) fn assert_block_bump(pre_snapshot: &MemorySnapshot) { ); } - // 3. Verify tier config - match pre_protoc_state.subperiod() { - Subperiod::Voting => { - assert!(!NextTierConfig::::exists()); - assert_eq!(post_snapshot.tier_config, pre_snapshot.next_tier_config); - } - Subperiod::BuildAndEarn if is_new_subperiod => { - assert!(NextTierConfig::::exists()); - assert_eq!(post_snapshot.tier_config, pre_snapshot.tier_config); - } - _ => { - assert_eq!(post_snapshot.tier_config, pre_snapshot.tier_config); - } - } - - // 4. Verify era reward + // 3. Verify era reward let era_span_index = DappStaking::era_reward_span_index(pre_protoc_state.era); let maybe_pre_era_reward_span = pre_snapshot.era_rewards.get(&era_span_index); let post_era_reward_span = post_snapshot @@ -1319,7 +1300,7 @@ pub(crate) fn assert_block_bump(pre_snapshot: &MemorySnapshot) { "Total staked amount must be equal to total amount staked at the end of the era." ); - // 5. Verify period end + // 4. Verify period end if is_new_subperiod && pre_protoc_state.subperiod() == Subperiod::BuildAndEarn { let period_end_info = post_snapshot.period_end[&pre_protoc_state.period_number()]; assert_eq!( @@ -1330,7 +1311,7 @@ pub(crate) fn assert_block_bump(pre_snapshot: &MemorySnapshot) { ); } - // 6. Verify event(s) + // 5. Verify event(s) if is_new_subperiod { let events = dapp_staking_events(); assert!( diff --git a/pallets/dapp-staking-v3/src/types.rs b/pallets/dapp-staking-v3/src/types.rs index 73c26974ee..cf70f0a6aa 100644 --- a/pallets/dapp-staking-v3/src/types.rs +++ b/pallets/dapp-staking-v3/src/types.rs @@ -396,7 +396,6 @@ pub struct AccountLedger> { /// Number of contract stake entries in storage. #[codec(compact)] pub contract_stake_count: u32, - // TODO: rename to staker_info_count? } impl Default for AccountLedger @@ -1525,6 +1524,11 @@ impl> Default for TiersConfiguration { } } +// Some TODOs: +// Some parts regarding tiers should be refactored. +// * There's no need to keep thresholds in two separate storage items since the calculation can always be done compared to the +// anchor value of 5 cents. This still needs to be checked & investigated, but it's worth a try. + impl> TiersConfiguration { /// Check if parameters are valid. pub fn is_valid(&self) -> bool { diff --git a/pallets/dapp-staking-v3/src/weights.rs b/pallets/dapp-staking-v3/src/weights.rs index 3b13aa4622..e98d798707 100644 --- a/pallets/dapp-staking-v3/src/weights.rs +++ b/pallets/dapp-staking-v3/src/weights.rs @@ -20,16 +20,16 @@ //! Autogenerated weights for pallet_dapp_staking_v3 //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Dinos-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=dev +// --chain=shibuya-dev // --steps=50 // --repeat=20 // --pallet=pallet_dapp_staking_v3 @@ -37,7 +37,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=weights.rs +// --output=./benchmark-results/shibuya-dev/dapp_staking_v3_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -81,11 +81,11 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) + // Minimum execution time: 8_474_000 picoseconds. + Weight::from_parts(8_711_000, 0) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking NextDAppId (r:1 w:1) @@ -93,201 +93,203 @@ impl WeightInfo for SubstrateWeight { fn register() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3093` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(18_000_000, 3093) + // Estimated: `3091` + // Minimum execution time: 16_360_000 picoseconds. + Weight::from_parts(16_697_000, 3091) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) fn set_dapp_reward_beneficiary() -> Weight { // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `3093` - // Minimum execution time: 13_000_000 picoseconds. - Weight::from_parts(13_000_000, 3093) + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 12_927_000 picoseconds. + Weight::from_parts(13_229_000, 3091) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) fn set_dapp_owner() -> Weight { // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `3093` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(14_000_000, 3093) + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 13_610_000 picoseconds. + Weight::from_parts(13_851_000, 3091) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:0 w:1) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) fn unregister() -> Weight { // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `3093` - // Minimum execution time: 17_000_000 picoseconds. - Weight::from_parts(19_000_000, 3093) + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 16_704_000 picoseconds. + Weight::from_parts(16_952_000, 3091) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn lock() -> Weight { // Proof Size summary in bytes: // Measured: `12` // Estimated: `4764` - // Minimum execution time: 40_000_000 picoseconds. - Weight::from_parts(43_000_000, 4764) + // Minimum execution time: 31_680_000 picoseconds. + Weight::from_parts(32_075_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn unlock() -> Weight { // Proof Size summary in bytes: - // Measured: `163` + // Measured: `156` // Estimated: `4764` - // Minimum execution time: 37_000_000 picoseconds. - Weight::from_parts(43_000_000, 4764) + // Minimum execution time: 34_576_000 picoseconds. + Weight::from_parts(34_777_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// The range of component `x` is `[0, 3]`. - fn claim_unlocked(_x: u32, ) -> Weight { + /// The range of component `x` is `[0, 8]`. + fn claim_unlocked(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `160 + x * (17 ±0)` + // Measured: `187` // Estimated: `4764` - // Minimum execution time: 34_000_000 picoseconds. - Weight::from_parts(40_955_543, 4764) + // Minimum execution time: 33_562_000 picoseconds. + Weight::from_parts(34_600_552, 4764) + // Standard Error: 5_079 + .saturating_add(Weight::from_parts(193_345, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn relock_unlocking() -> Weight { // Proof Size summary in bytes: - // Measured: `174` + // Measured: `182` // Estimated: `4764` - // Minimum execution time: 38_000_000 picoseconds. - Weight::from_parts(40_000_000, 4764) + // Minimum execution time: 36_436_000 picoseconds. + Weight::from_parts(37_262_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:1 w:1) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn stake() -> Weight { // Proof Size summary in bytes: - // Measured: `258` + // Measured: `250` // Estimated: `4764` - // Minimum execution time: 45_000_000 picoseconds. - Weight::from_parts(49_000_000, 4764) + // Minimum execution time: 43_866_000 picoseconds. + Weight::from_parts(44_468_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:1 w:1) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn unstake() -> Weight { // Proof Size summary in bytes: - // Measured: `437` + // Measured: `427` // Estimated: `4764` - // Minimum execution time: 48_000_000 picoseconds. - Weight::from_parts(54_000_000, 4764) + // Minimum execution time: 47_368_000 picoseconds. + Weight::from_parts(48_049_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:0) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) /// Storage: DappStaking PeriodEnd (r:1 w:0) /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 8]`. + /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_past_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `485 + x * (8 ±0)` + // Measured: `560` // Estimated: `4764` - // Minimum execution time: 50_000_000 picoseconds. - Weight::from_parts(51_664_058, 4764) - // Standard Error: 15_971 - .saturating_add(Weight::from_parts(4_243_613, 0).saturating_mul(x.into())) + // Minimum execution time: 51_230_000 picoseconds. + Weight::from_parts(48_696_805, 4764) + // Standard Error: 6_139 + .saturating_add(Weight::from_parts(3_374_191, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:0) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 8]`. + /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `438 + x * (8 ±0)` + // Measured: `501` // Estimated: `4764` - // Minimum execution time: 47_000_000 picoseconds. - Weight::from_parts(48_357_596, 4764) - // Standard Error: 16_408 - .saturating_add(Weight::from_parts(4_302_059, 0).saturating_mul(x.into())) + // Minimum execution time: 45_030_000 picoseconds. + Weight::from_parts(43_179_071, 4764) + // Standard Error: 5_547 + .saturating_add(Weight::from_parts(3_296_864, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -295,66 +297,68 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking PeriodEnd (r:1 w:0) /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) fn claim_bonus_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `158` - // Estimated: `3603` - // Minimum execution time: 34_000_000 picoseconds. - Weight::from_parts(36_000_000, 3603) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Measured: `267` + // Estimated: `3775` + // Minimum execution time: 42_248_000 picoseconds. + Weight::from_parts(42_687_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(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking DAppTiers (r:1 w:1) - /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(483), added: 2958, mode: MaxEncodedLen) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1086` - // Estimated: `3948` - // Minimum execution time: 37_000_000 picoseconds. - Weight::from_parts(41_000_000, 3948) + // Measured: `3021` + // Estimated: `5548` + // Minimum execution time: 50_968_000 picoseconds. + Weight::from_parts(51_778_000, 5548) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn unstake_from_unregistered() -> Weight { // Proof Size summary in bytes: - // Measured: `397` + // Measured: `389` // Estimated: `4764` - // Minimum execution time: 43_000_000 picoseconds. - Weight::from_parts(47_000_000, 4764) + // Minimum execution time: 42_329_000 picoseconds. + Weight::from_parts(42_737_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } - /// Storage: DappStaking StakerInfo (r:4 w:3) + /// Storage: DappStaking StakerInfo (r:9 w:8) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 3]`. + /// The range of component `x` is `[1, 8]`. fn cleanup_expired_entries(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `250 + x * (75 ±0)` + // Measured: `255 + x * (69 ±0)` // Estimated: `4764 + x * (2613 ±0)` - // Minimum execution time: 41_000_000 picoseconds. - Weight::from_parts(38_854_143, 4764) - // Standard Error: 54_134 - .saturating_add(Weight::from_parts(7_359_116, 0).saturating_mul(x.into())) + // Minimum execution time: 42_222_000 picoseconds. + Weight::from_parts(38_945_386, 4764) + // Standard Error: 14_325 + .saturating_add(Weight::from_parts(5_044_310, 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)) @@ -365,83 +369,91 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) + // Minimum execution time: 9_971_000 picoseconds. + Weight::from_parts(10_190_000, 0) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: DappStaking NextTierConfig (r:1 w:1) - /// Proof: DappStaking NextTierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:1) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) - /// Storage: DappStaking TierConfig (r:0 w:1) - /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) fn on_initialize_voting_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `151` - // Estimated: `3870` - // Minimum execution time: 22_000_000 picoseconds. - Weight::from_parts(24_000_000, 3870) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Measured: `16` + // Estimated: `4254` + // Minimum execution time: 17_308_000 picoseconds. + Weight::from_parts(17_774_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, 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: DappStaking TierConfig (r:1 w:0) + /// Storage: DappStaking TierConfig (r:1 w:1) /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:1) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) /// Storage: DappStaking PeriodEnd (r:0 w:1) /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) /// Storage: DappStaking DAppTiers (r:0 w:1) - /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(483), added: 2958, mode: MaxEncodedLen) - /// Storage: DappStaking NextTierConfig (r:0 w:1) - /// Proof: DappStaking NextTierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `685` - // Estimated: `3870` - // Minimum execution time: 34_000_000 picoseconds. - Weight::from_parts(37_000_000, 3870) + // Measured: `550` + // Estimated: `4254` + // Minimum execution time: 39_768_000 picoseconds. + Weight::from_parts(40_422_000, 4254) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:1) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) + /// 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(483), added: 2958, mode: MaxEncodedLen) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `73` - // Estimated: `3870` - // Minimum execution time: 17_000_000 picoseconds. - Weight::from_parts(18_000_000, 3870) + // Measured: `68` + // Estimated: `4254` + // Minimum execution time: 20_976_000 picoseconds. + Weight::from_parts(21_507_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking ContractStake (r:101 w:0) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) /// Storage: DappStaking TierConfig (r:1 w:0) /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) /// The range of component `x` is `[0, 100]`. fn dapp_tier_assignment(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `158 + x * (33 ±0)` - // Estimated: `3063 + x * (2073 ±0)` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(12_709_998, 3063) - // Standard Error: 8_047 - .saturating_add(Weight::from_parts(2_731_946, 0).saturating_mul(x.into())) + // Measured: `152 + x * (32 ±0)` + // Estimated: `3061 + x * (2071 ±0)` + // Minimum execution time: 7_374_000 picoseconds. + Weight::from_parts(10_826_637, 3061) + // Standard Error: 3_374 + .saturating_add(Weight::from_parts(2_291_643, 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, 2073).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) } + /// Storage: DappStaking HistoryCleanupMarker (r:1 w:1) + /// Proof: DappStaking HistoryCleanupMarker (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:1) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// 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(2083), added: 4558, mode: MaxEncodedLen) fn on_idle_cleanup() -> Weight { - T::DbWeight::get().reads_writes(3, 2) + // Proof Size summary in bytes: + // Measured: `473` + // Estimated: `4254` + // Minimum execution time: 14_500_000 picoseconds. + Weight::from_parts(14_969_000, 4254) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } } @@ -451,11 +463,11 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) + // Minimum execution time: 8_474_000 picoseconds. + Weight::from_parts(8_711_000, 0) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking NextDAppId (r:1 w:1) @@ -463,201 +475,203 @@ impl WeightInfo for () { fn register() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3093` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(18_000_000, 3093) + // Estimated: `3091` + // Minimum execution time: 16_360_000 picoseconds. + Weight::from_parts(16_697_000, 3091) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) fn set_dapp_reward_beneficiary() -> Weight { // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `3093` - // Minimum execution time: 13_000_000 picoseconds. - Weight::from_parts(13_000_000, 3093) + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 12_927_000 picoseconds. + Weight::from_parts(13_229_000, 3091) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) fn set_dapp_owner() -> Weight { // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `3093` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(14_000_000, 3093) + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 13_610_000 picoseconds. + Weight::from_parts(13_851_000, 3091) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:0 w:1) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) fn unregister() -> Weight { // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `3093` - // Minimum execution time: 17_000_000 picoseconds. - Weight::from_parts(19_000_000, 3093) + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 16_704_000 picoseconds. + Weight::from_parts(16_952_000, 3091) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn lock() -> Weight { // Proof Size summary in bytes: // Measured: `12` // Estimated: `4764` - // Minimum execution time: 40_000_000 picoseconds. - Weight::from_parts(43_000_000, 4764) + // Minimum execution time: 31_680_000 picoseconds. + Weight::from_parts(32_075_000, 4764) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn unlock() -> Weight { // Proof Size summary in bytes: - // Measured: `163` + // Measured: `156` // Estimated: `4764` - // Minimum execution time: 37_000_000 picoseconds. - Weight::from_parts(43_000_000, 4764) + // Minimum execution time: 34_576_000 picoseconds. + Weight::from_parts(34_777_000, 4764) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// The range of component `x` is `[0, 3]`. - fn claim_unlocked(_x: u32, ) -> Weight { + /// The range of component `x` is `[0, 8]`. + fn claim_unlocked(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `160 + x * (17 ±0)` + // Measured: `187` // Estimated: `4764` - // Minimum execution time: 34_000_000 picoseconds. - Weight::from_parts(40_955_543, 4764) + // Minimum execution time: 33_562_000 picoseconds. + Weight::from_parts(34_600_552, 4764) + // Standard Error: 5_079 + .saturating_add(Weight::from_parts(193_345, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn relock_unlocking() -> Weight { // Proof Size summary in bytes: - // Measured: `174` + // Measured: `182` // Estimated: `4764` - // Minimum execution time: 38_000_000 picoseconds. - Weight::from_parts(40_000_000, 4764) + // Minimum execution time: 36_436_000 picoseconds. + Weight::from_parts(37_262_000, 4764) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:1 w:1) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn stake() -> Weight { // Proof Size summary in bytes: - // Measured: `258` + // Measured: `250` // Estimated: `4764` - // Minimum execution time: 45_000_000 picoseconds. - Weight::from_parts(49_000_000, 4764) + // Minimum execution time: 43_866_000 picoseconds. + Weight::from_parts(44_468_000, 4764) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:1 w:1) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn unstake() -> Weight { // Proof Size summary in bytes: - // Measured: `437` + // Measured: `427` // Estimated: `4764` - // Minimum execution time: 48_000_000 picoseconds. - Weight::from_parts(54_000_000, 4764) + // Minimum execution time: 47_368_000 picoseconds. + Weight::from_parts(48_049_000, 4764) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:0) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) /// Storage: DappStaking PeriodEnd (r:1 w:0) /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 8]`. + /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_past_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `485 + x * (8 ±0)` + // Measured: `560` // Estimated: `4764` - // Minimum execution time: 50_000_000 picoseconds. - Weight::from_parts(51_664_058, 4764) - // Standard Error: 15_971 - .saturating_add(Weight::from_parts(4_243_613, 0).saturating_mul(x.into())) + // Minimum execution time: 51_230_000 picoseconds. + Weight::from_parts(48_696_805, 4764) + // Standard Error: 6_139 + .saturating_add(Weight::from_parts(3_374_191, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:0) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 8]`. + /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `438 + x * (8 ±0)` + // Measured: `501` // Estimated: `4764` - // Minimum execution time: 47_000_000 picoseconds. - Weight::from_parts(48_357_596, 4764) - // Standard Error: 16_408 - .saturating_add(Weight::from_parts(4_302_059, 0).saturating_mul(x.into())) + // Minimum execution time: 45_030_000 picoseconds. + Weight::from_parts(43_179_071, 4764) + // Standard Error: 5_547 + .saturating_add(Weight::from_parts(3_296_864, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -665,66 +679,68 @@ impl WeightInfo for () { /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking PeriodEnd (r:1 w:0) /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) fn claim_bonus_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `158` - // Estimated: `3603` - // Minimum execution time: 34_000_000 picoseconds. - Weight::from_parts(36_000_000, 3603) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Measured: `267` + // Estimated: `3775` + // Minimum execution time: 42_248_000 picoseconds. + Weight::from_parts(42_687_000, 3775) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking DAppTiers (r:1 w:1) - /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(483), added: 2958, mode: MaxEncodedLen) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1086` - // Estimated: `3948` - // Minimum execution time: 37_000_000 picoseconds. - Weight::from_parts(41_000_000, 3948) + // Measured: `3021` + // Estimated: `5548` + // Minimum execution time: 50_968_000 picoseconds. + Weight::from_parts(51_778_000, 5548) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(123), added: 2103, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn unstake_from_unregistered() -> Weight { // Proof Size summary in bytes: - // Measured: `397` + // Measured: `389` // Estimated: `4764` - // Minimum execution time: 43_000_000 picoseconds. - Weight::from_parts(47_000_000, 4764) + // Minimum execution time: 42_329_000 picoseconds. + Weight::from_parts(42_737_000, 4764) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } - /// Storage: DappStaking StakerInfo (r:4 w:3) + /// Storage: DappStaking StakerInfo (r:9 w:8) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) - /// Proof: DappStaking Ledger (max_values: None, max_size: Some(250), added: 2725, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 3]`. + /// The range of component `x` is `[1, 8]`. fn cleanup_expired_entries(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `250 + x * (75 ±0)` + // Measured: `255 + x * (69 ±0)` // Estimated: `4764 + x * (2613 ±0)` - // Minimum execution time: 41_000_000 picoseconds. - Weight::from_parts(38_854_143, 4764) - // Standard Error: 54_134 - .saturating_add(Weight::from_parts(7_359_116, 0).saturating_mul(x.into())) + // Minimum execution time: 42_222_000 picoseconds. + Weight::from_parts(38_945_386, 4764) + // Standard Error: 14_325 + .saturating_add(Weight::from_parts(5_044_310, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(RocksDbWeight::get().writes(2_u64)) @@ -735,82 +751,90 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) + // Minimum execution time: 9_971_000 picoseconds. + Weight::from_parts(10_190_000, 0) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// Storage: DappStaking NextTierConfig (r:1 w:1) - /// Proof: DappStaking NextTierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:1) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) - /// Storage: DappStaking TierConfig (r:0 w:1) - /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) fn on_initialize_voting_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `151` - // Estimated: `3870` - // Minimum execution time: 22_000_000 picoseconds. - Weight::from_parts(24_000_000, 3870) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) + // Measured: `16` + // Estimated: `4254` + // Minimum execution time: 17_308_000 picoseconds. + Weight::from_parts(17_774_000, 4254) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, 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: DappStaking TierConfig (r:1 w:0) + /// Storage: DappStaking TierConfig (r:1 w:1) /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:1) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) /// Storage: DappStaking PeriodEnd (r:0 w:1) /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) /// Storage: DappStaking DAppTiers (r:0 w:1) - /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(483), added: 2958, mode: MaxEncodedLen) - /// Storage: DappStaking NextTierConfig (r:0 w:1) - /// Proof: DappStaking NextTierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `685` - // Estimated: `3870` - // Minimum execution time: 34_000_000 picoseconds. - Weight::from_parts(37_000_000, 3870) + // Measured: `550` + // Estimated: `4254` + // Minimum execution time: 39_768_000 picoseconds. + Weight::from_parts(40_422_000, 4254) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) /// Storage: DappStaking EraRewards (r:1 w:1) - /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(405), added: 2880, mode: MaxEncodedLen) + /// 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(483), added: 2958, mode: MaxEncodedLen) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { // Proof Size summary in bytes: - // Measured: `73` - // Estimated: `3870` - // Minimum execution time: 17_000_000 picoseconds. - Weight::from_parts(18_000_000, 3870) + // Measured: `68` + // Estimated: `4254` + // Minimum execution time: 20_976_000 picoseconds. + Weight::from_parts(21_507_000, 4254) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking ContractStake (r:101 w:0) - /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(93), added: 2073, mode: MaxEncodedLen) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) /// Storage: DappStaking TierConfig (r:1 w:0) /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) /// The range of component `x` is `[0, 100]`. fn dapp_tier_assignment(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `158 + x * (33 ±0)` - // Estimated: `3063 + x * (2073 ±0)` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(12_709_998, 3063) - // Standard Error: 8_047 - .saturating_add(Weight::from_parts(2_731_946, 0).saturating_mul(x.into())) + // Measured: `152 + x * (32 ±0)` + // Estimated: `3061 + x * (2071 ±0)` + // Minimum execution time: 7_374_000 picoseconds. + Weight::from_parts(10_826_637, 3061) + // Standard Error: 3_374 + .saturating_add(Weight::from_parts(2_291_643, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into()))) - .saturating_add(Weight::from_parts(0, 2073).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) } + /// Storage: DappStaking HistoryCleanupMarker (r:1 w:1) + /// Proof: DappStaking HistoryCleanupMarker (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:1) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// 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(2083), added: 4558, mode: MaxEncodedLen) fn on_idle_cleanup() -> Weight { - RocksDbWeight::get().reads_writes(3, 2) + // Proof Size summary in bytes: + // Measured: `473` + // Estimated: `4254` + // Minimum execution time: 14_500_000 picoseconds. + Weight::from_parts(14_969_000, 4254) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } } diff --git a/pallets/dapps-staking/src/pallet/mod.rs b/pallets/dapps-staking/src/pallet/mod.rs index c7d46591c1..7b65ea2d0f 100644 --- a/pallets/dapps-staking/src/pallet/mod.rs +++ b/pallets/dapps-staking/src/pallet/mod.rs @@ -306,7 +306,7 @@ pub mod pallet { // Runtime upgrade should be timed so we ensure that we complete it before // a new era is triggered. This code is just a safety net to ensure nothing is broken // if we fail to do that. - if PalletDisabled::::get() { + if PalletDisabled::::get() || T::ForcePalletDisabled::get() { return T::DbWeight::get().reads(1); } diff --git a/pallets/inflation/Cargo.toml b/pallets/inflation/Cargo.toml index 6b1065d9bb..a82a1480ad 100644 --- a/pallets/inflation/Cargo.toml +++ b/pallets/inflation/Cargo.toml @@ -18,6 +18,7 @@ frame-support = { workspace = true } frame-system = { workspace = true } scale-info = { workspace = true } sp-runtime = { workspace = true } +sp-std = { workspace = true } frame-benchmarking = { workspace = true, optional = true } @@ -33,6 +34,7 @@ std = [ "sp-core/std", "scale-info/std", "serde/std", + "sp-std/std", "frame-support/std", "frame-system/std", "pallet-balances/std", diff --git a/pallets/inflation/src/lib.rs b/pallets/inflation/src/lib.rs index 717aa764f1..b643fe5e32 100644 --- a/pallets/inflation/src/lib.rs +++ b/pallets/inflation/src/lib.rs @@ -102,9 +102,13 @@ use astar_primitives::{ dapp_staking::{CycleConfiguration, StakingRewardHandler}, Balance, BlockNumber, }; -use frame_support::{pallet_prelude::*, traits::Currency}; +use frame_support::{ + pallet_prelude::*, + traits::{Currency, GetStorageVersion, OnRuntimeUpgrade}, +}; use frame_system::{ensure_root, pallet_prelude::*}; use sp_runtime::{traits::CheckedAdd, Perquintill}; +use sp_std::marker::PhantomData; pub mod weights; pub use weights::WeightInfo; @@ -122,7 +126,11 @@ pub mod pallet { use super::*; + /// The current storage version. + pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(PhantomData); // Negative imbalance type of this pallet. @@ -589,3 +597,42 @@ pub trait PayoutPerBlock { /// Payout reward to the collator responsible for producing the block. fn collators(reward: Imbalance); } + +/// `OnRuntimeUpgrade` logic for integrating this pallet into the live network. +#[cfg(feature = "try-runtime")] +use sp_std::vec::Vec; +pub struct PalletInflationInitConfig(PhantomData<(T, P)>); +impl> OnRuntimeUpgrade for PalletInflationInitConfig { + fn on_runtime_upgrade() -> Weight { + if Pallet::::on_chain_storage_version() >= STORAGE_VERSION { + return T::DbWeight::get().reads(1); + } + + // 1. Get & set inflation parameters + let inflation_params = P::get(); + InflationParams::::put(inflation_params.clone()); + + // 2. Calculation inflation config, set it & depossit event + let now = frame_system::Pallet::::block_number(); + let config = Pallet::::recalculate_inflation(now); + ActiveInflationConfig::::put(config.clone()); + + Pallet::::deposit_event(Event::::NewInflationConfiguration { config }); + + // 3. Set version + STORAGE_VERSION.put::>(); + + log::info!("Inflation pallet storage initialized."); + + T::WeightInfo::hook_with_recalculation() + .saturating_add(T::DbWeight::get().reads_writes(1, 2)) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + assert_eq!(Pallet::::on_chain_storage_version(), STORAGE_VERSION); + assert!(InflationParams::::get().is_valid()); + + Ok(()) + } +} diff --git a/pallets/inflation/src/weights.rs b/pallets/inflation/src/weights.rs index 1cee14c199..08a53283c4 100644 --- a/pallets/inflation/src/weights.rs +++ b/pallets/inflation/src/weights.rs @@ -20,16 +20,16 @@ //! Autogenerated weights for pallet_inflation //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Dinos-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=dev +// --chain=shibuya-dev // --steps=50 // --repeat=20 // --pallet=pallet_inflation @@ -37,7 +37,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=weights.rs +// --output=./benchmark-results/shibuya-dev/inflation_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -65,43 +65,50 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) + // Minimum execution time: 9_036_000 picoseconds. + Weight::from_parts(9_186_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } fn force_set_inflation_config() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) + // Minimum execution time: 9_073_000 picoseconds. + Weight::from_parts(9_411_000, 0) } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { // Proof Size summary in bytes: - // Measured: `59` + // Measured: `58` // Estimated: `1549` - // Minimum execution time: 15_000_000 picoseconds. - Weight::from_parts(16_000_000, 1549) + // Minimum execution time: 14_839_000 picoseconds. + Weight::from_parts(15_198_000, 1549) .saturating_add(T::DbWeight::get().reads(1_u64)) } + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn hook_with_recalculation() -> Weight { // Proof Size summary in bytes: - // Measured: `59` - // Estimated: `1549` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_000_000, 1549) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Measured: `232` + // Estimated: `6196` + // Minimum execution time: 31_965_000 picoseconds. + Weight::from_parts(32_498_000, 6196) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn hook_without_recalculation() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) + // Measured: `174` + // Estimated: `6196` + // Minimum execution time: 22_235_000 picoseconds. + Weight::from_parts(22_378_000, 6196) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } @@ -113,42 +120,49 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) + // Minimum execution time: 9_036_000 picoseconds. + Weight::from_parts(9_186_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } fn force_set_inflation_config() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) + // Minimum execution time: 9_073_000 picoseconds. + Weight::from_parts(9_411_000, 0) } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { // Proof Size summary in bytes: - // Measured: `59` + // Measured: `58` // Estimated: `1549` - // Minimum execution time: 15_000_000 picoseconds. - Weight::from_parts(16_000_000, 1549) + // Minimum execution time: 14_839_000 picoseconds. + Weight::from_parts(15_198_000, 1549) .saturating_add(RocksDbWeight::get().reads(1_u64)) } + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn hook_with_recalculation() -> Weight { // Proof Size summary in bytes: - // Measured: `59` - // Estimated: `1549` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_000_000, 1549) - .saturating_add(RocksDbWeight::get().reads(1_u64)) + // Measured: `232` + // Estimated: `6196` + // Minimum execution time: 31_965_000 picoseconds. + Weight::from_parts(32_498_000, 6196) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn hook_without_recalculation() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) + // Measured: `174` + // Estimated: `6196` + // Minimum execution time: 22_235_000 picoseconds. + Weight::from_parts(22_378_000, 6196) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index de1e2ac1a6..92740a2eae 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -68,7 +68,6 @@ pallet-transaction-payment-rpc-runtime-api = { workspace = true } # Astar pallets astar-primitives = { workspace = true } pallet-block-rewards-hybrid = { workspace = true } -pallet-chain-extension-dapps-staking = { workspace = true } pallet-chain-extension-unified-accounts = { workspace = true } pallet-chain-extension-xvm = { workspace = true } pallet-dapp-staking-migration = { workspace = true } @@ -124,7 +123,6 @@ std = [ "pallet-block-rewards-hybrid/std", "pallet-contracts/std", "pallet-contracts-primitives/std", - "pallet-chain-extension-dapps-staking/std", "pallet-chain-extension-xvm/std", "pallet-chain-extension-unified-accounts/std", "pallet-dapps-staking/std", diff --git a/runtime/local/src/chain_extensions.rs b/runtime/local/src/chain_extensions.rs index 87fc75da1a..a368fa8d18 100644 --- a/runtime/local/src/chain_extensions.rs +++ b/runtime/local/src/chain_extensions.rs @@ -22,7 +22,6 @@ use super::{Runtime, UnifiedAccounts, Xvm}; pub use pallet_chain_extension_assets::AssetsExtension; use pallet_contracts::chain_extension::RegisteredChainExtension; -pub use pallet_chain_extension_dapps_staking::DappsStakingExtension; pub use pallet_chain_extension_unified_accounts::UnifiedAccountsExtension; pub use pallet_chain_extension_xvm::XvmExtension; diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index c5d8abae9a..b1bec5ead9 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -61,12 +61,15 @@ use sp_runtime::{ }; use sp_std::prelude::*; -pub use astar_primitives::{ - dapp_staking::{CycleConfiguration, SmartContract, StakingRewardHandler}, +use astar_primitives::{ + dapp_staking::{CycleConfiguration, SmartContract}, evm::{EvmRevertCodeHandler, HashedDefaultMappings}, - AccountId, Address, AssetId, Balance, BlockNumber, Hash, Header, Index, Signature, + Address, AssetId, Balance, BlockNumber, Hash, Header, Index, }; + +pub use astar_primitives::{AccountId, Signature}; pub use pallet_block_rewards_hybrid::RewardDistributionConfig; +pub use pallet_dapp_staking_v3::TierThreshold; pub use crate::precompiles::WhitelistedCalls; #[cfg(feature = "std")] @@ -1156,8 +1159,7 @@ pub type Executive = frame_executive::Executive< Migrations, >; -// TODO: remove this prior to the PR merge -pub type Migrations = (pallet_dapp_staking_migration::DappStakingMigrationHandler,); +pub type Migrations = (); type EventRecord = frame_system::EventRecord< ::RuntimeEvent, diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 73c2b42296..bd50815120 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -20,6 +20,7 @@ smallvec = { workspace = true } fp-rpc = { workspace = true } fp-self-contained = { workspace = true } sp-api = { workspace = true } +sp-arithmetic = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } @@ -96,25 +97,29 @@ orml-xtokens = { workspace = true } # Astar pallets astar-primitives = { workspace = true } -pallet-block-rewards-hybrid = { workspace = true } pallet-chain-extension-unified-accounts = { workspace = true } pallet-chain-extension-xvm = { workspace = true } pallet-collator-selection = { workspace = true } +pallet-dapp-staking-migration = { workspace = true } +pallet-dapp-staking-v3 = { workspace = true } pallet-dapps-staking = { workspace = true } pallet-dynamic-evm-base-fee = { workspace = true } pallet-ethereum-checked = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } -pallet-evm-precompile-dapps-staking = { workspace = true } +pallet-evm-precompile-dapp-staking-v3 = { workspace = true } pallet-evm-precompile-sr25519 = { workspace = true } pallet-evm-precompile-substrate-ecdsa = { workspace = true } pallet-evm-precompile-unified-accounts = { workspace = true } pallet-evm-precompile-xcm = { workspace = true } pallet-evm-precompile-xvm = { workspace = true } +pallet-inflation = { workspace = true } pallet-unified-accounts = { workspace = true } pallet-xc-asset-config = { workspace = true } pallet-xcm = { workspace = true } pallet-xvm = { workspace = true } +dapp-staking-v3-runtime-api = { workspace = true } + precompile-utils = { workspace = true } # Moonbeam tracing @@ -153,6 +158,7 @@ std = [ "sp-block-builder/std", "sp-transaction-pool/std", "sp-inherents/std", + "sp-arithmetic/std", "frame-support/std", "frame-executive/std", "frame-system/std", @@ -161,7 +167,6 @@ std = [ "pallet-aura/std", "pallet-assets/std", "pallet-balances/std", - "pallet-block-rewards-hybrid/std", "pallet-contracts/std", "pallet-contracts-primitives/std", "pallet-chain-extension-xvm/std", @@ -178,7 +183,7 @@ std = [ "pallet-evm-precompile-ed25519/std", "pallet-evm-precompile-modexp/std", "pallet-evm-precompile-sha3fips/std", - "pallet-evm-precompile-dapps-staking/std", + "pallet-evm-precompile-dapp-staking-v3/std", "pallet-evm-precompile-sr25519/std", "pallet-evm-precompile-substrate-ecdsa/std", "pallet-evm-precompile-assets-erc20/std", @@ -186,6 +191,10 @@ std = [ "pallet-evm-precompile-xvm/std", "pallet-evm-precompile-unified-accounts/std", "pallet-dapps-staking/std", + "pallet-dapp-staking-v3/std", + "pallet-dapp-staking-migration/std", + "dapp-staking-v3-runtime-api/std", + "pallet-inflation/std", "pallet-identity/std", "pallet-multisig/std", "pallet-insecure-randomness-collective-flip/std", @@ -242,7 +251,9 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-dapps-staking/runtime-benchmarks", - "pallet-block-rewards-hybrid/runtime-benchmarks", + "pallet-dapp-staking-v3/runtime-benchmarks", + "pallet-dapp-staking-migration/runtime-benchmarks", + "pallet-inflation/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-collective/runtime-benchmarks", @@ -269,8 +280,10 @@ try-runtime = [ "frame-system/try-runtime", "pallet-aura/try-runtime", "pallet-balances/try-runtime", - "pallet-block-rewards-hybrid/try-runtime", "pallet-dapps-staking/try-runtime", + "pallet-dapp-staking-v3/try-runtime", + "pallet-dapp-staking-migration/try-runtime", + "pallet-inflation/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 3a4a0a3119..228718d421 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -22,7 +22,6 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -use astar_primitives::evm::HashedDefaultMappings; use cumulus_pallet_parachain_system::AnyRelayNumber; use frame_support::{ construct_runtime, @@ -54,6 +53,7 @@ use pallet_transaction_payment::{ use parity_scale_codec::{Compact, Decode, Encode, MaxEncodedLen}; use polkadot_runtime_common::BlockHashCount; use sp_api::impl_runtime_apis; +use sp_arithmetic::fixed_point::FixedU64; use sp_core::{ConstBool, OpaqueMetadata, H160, H256, U256}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_runtime::{ @@ -67,12 +67,16 @@ use sp_runtime::{ }; use sp_std::prelude::*; -pub use astar_primitives::{ - ethereum_checked::CheckedEthereumTransact, evm::EvmRevertCodeHandler, - xcm::AssetLocationIdConverter, AccountId, Address, AssetId, Balance, BlockNumber, Hash, Header, - Index, Signature, +use astar_primitives::{ + dapp_staking::{CycleConfiguration, SmartContract}, + evm::{EvmRevertCodeHandler, HashedDefaultMappings}, + xcm::AssetLocationIdConverter, + Address, AssetId, BlockNumber, Hash, Header, Index, }; -pub use pallet_block_rewards_hybrid::RewardDistributionConfig; + +pub use astar_primitives::{AccountId, Balance, Signature}; +pub use pallet_dapp_staking_v3::TierThreshold; +pub use pallet_inflation::InflationParameters; pub use crate::precompiles::WhitelistedCalls; @@ -297,7 +301,7 @@ parameter_types! { impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; - type OnTimestampSet = BlockReward; + type OnTimestampSet = (); type MinimumPeriod = MinimumPeriod; type WeightInfo = pallet_timestamp::weights::SubstrateWeight; } @@ -402,32 +406,109 @@ impl pallet_dapps_staking::Config for Runtime { type MinimumRemainingAmount = MinimumRemainingAmount; type MaxEraStakeValues = MaxEraStakeValues; type UnregisteredDappRewardRetention = ConstU32<10>; + // Needed so benchmark can use the pallets extrinsics + #[cfg(feature = "runtime-benchmarks")] type ForcePalletDisabled = ConstBool; + #[cfg(not(feature = "runtime-benchmarks"))] + type ForcePalletDisabled = ConstBool; } -/// Multi-VM pointer to smart contract instance. -#[derive( - PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, MaxEncodedLen, scale_info::TypeInfo, -)] -pub enum SmartContract { - /// EVM smart contract instance. - Evm(sp_core::H160), - /// Wasm smart contract instance. - Wasm(AccountId), +// Placeholder until we introduce a pallet for this. +// Real solution will be an oracle. +pub struct DummyPriceProvider; +impl pallet_dapp_staking_v3::PriceProvider for DummyPriceProvider { + fn average_price() -> FixedU64 { + FixedU64::from_rational(1, 10) + } } -impl Default for SmartContract { - fn default() -> Self { - SmartContract::Evm(H160::repeat_byte(0x00)) +#[cfg(feature = "runtime-benchmarks")] +pub struct BenchmarkHelper(sp_std::marker::PhantomData<(SC, ACC)>); +#[cfg(feature = "runtime-benchmarks")] +impl pallet_dapp_staking_v3::BenchmarkHelper, AccountId> + for BenchmarkHelper, AccountId> +{ + fn get_smart_contract(id: u32) -> SmartContract { + let id_bytes = id.to_le_bytes(); + let mut account = [0u8; 32]; + account[..id_bytes.len()].copy_from_slice(&id_bytes); + + SmartContract::Wasm(AccountId::from(account)) + } + + fn set_balance(account: &AccountId, amount: Balance) { + use frame_support::traits::fungible::Unbalanced as FunUnbalanced; + Balances::write_balance(account, amount) + .expect("Must succeed in test/benchmark environment."); + } +} + +impl pallet_dapp_staking_v3::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeFreezeReason = RuntimeFreezeReason; + type Currency = Balances; + type SmartContract = SmartContract; + type ManagerOrigin = frame_system::EnsureRoot; + type NativePriceProvider = DummyPriceProvider; + type StakingRewardHandler = Inflation; + type CycleConfiguration = InflationCycleConfig; + type EraRewardSpanLength = ConstU32<16>; + type RewardRetentionInPeriods = ConstU32<2>; // Low enough value so we can get some expired rewards during testing + type MaxNumberOfContracts = ConstU32<500>; + type MaxUnlockingChunks = ConstU32<8>; + type MinimumLockedAmount = MinimumStakingAmount; // Keep the same as the old pallet + type UnlockingPeriod = ConstU32<4>; // Keep it low so it's easier to test + type MaxNumberOfStakedContracts = ConstU32<8>; + type MinimumStakeAmount = MinimumStakingAmount; + type NumberOfTiers = ConstU32<4>; + type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper, AccountId>; +} + +pub struct InflationPayoutPerBlock; +impl pallet_inflation::PayoutPerBlock for InflationPayoutPerBlock { + fn treasury(reward: NegativeImbalance) { + Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward); + } + + fn collators(reward: NegativeImbalance) { + ToStakingPot::on_unbalanced(reward); } } -impl> From<[u8; 32]> for SmartContract { - fn from(input: [u8; 32]) -> Self { - SmartContract::Wasm(input.into()) +pub struct InflationCycleConfig; +impl CycleConfiguration for InflationCycleConfig { + fn periods_per_cycle() -> u32 { + 2 + } + + fn eras_per_voting_subperiod() -> u32 { + 8 + } + + fn eras_per_build_and_earn_subperiod() -> u32 { + 20 + } + + fn blocks_per_era() -> BlockNumber { + 6 * HOURS } } +impl pallet_inflation::Config for Runtime { + type Currency = Balances; + type PayoutPerBlock = InflationPayoutPerBlock; + type CycleConfiguration = InflationCycleConfig; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_inflation::weights::SubstrateWeight; +} + +impl pallet_dapp_staking_migration::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_dapp_staking_migration::weights::SubstrateWeight; +} + impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -531,41 +612,6 @@ impl OnUnbalanced for ToStakingPot { } } -pub struct DappsStakingTvlProvider(); -impl Get for DappsStakingTvlProvider { - fn get() -> Balance { - DappsStaking::tvl() - } -} - -pub struct BeneficiaryPayout(); -impl pallet_block_rewards_hybrid::BeneficiaryPayout for BeneficiaryPayout { - fn treasury(reward: NegativeImbalance) { - Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward); - } - - fn collators(reward: NegativeImbalance) { - ToStakingPot::on_unbalanced(reward); - } - - fn dapps_staking(stakers: NegativeImbalance, dapps: NegativeImbalance) { - DappsStaking::rewards(stakers, dapps) - } -} - -parameter_types! { - pub const MaxBlockRewardAmount: Balance = 230_718 * MILLISBY; -} - -impl pallet_block_rewards_hybrid::Config for Runtime { - type Currency = Balances; - type DappsStakingTvlProvider = DappsStakingTvlProvider; - type BeneficiaryPayout = BeneficiaryPayout; - type MaxBlockRewardAmount = MaxBlockRewardAmount; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_block_rewards_hybrid::weights::SubstrateWeight; -} - parameter_types! { pub const ExistentialDeposit: Balance = 1_000_000; pub const MaxLocks: u32 = 50; @@ -583,9 +629,9 @@ impl pallet_balances::Config for Runtime { type AccountStore = frame_system::Pallet; type WeightInfo = weights::pallet_balances::SubstrateWeight; type HoldIdentifier = (); - type FreezeIdentifier = (); + type FreezeIdentifier = RuntimeFreezeReason; type MaxHolds = ConstU32<0>; - type MaxFreezes = ConstU32<0>; + type MaxFreezes = ConstU32<1>; } parameter_types! { @@ -1080,7 +1126,7 @@ pub enum ProxyType { /// Only reject_announcement call from pallet proxy allowed for proxy account CancelProxy, /// All runtime calls from pallet DappStaking allowed for proxy account - DappsStaking, + DappStaking, /// Only claim_staker call from pallet DappStaking allowed for proxy account StakerRewardClaim, } @@ -1115,7 +1161,7 @@ impl InstanceFilter for ProxyType { | RuntimeCall::Vesting(pallet_vesting::Call::vest{..}) | RuntimeCall::Vesting(pallet_vesting::Call::vest_other{..}) // Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer` - | RuntimeCall::DappsStaking(..) + | RuntimeCall::DappStaking(..) // Skip entire Assets pallet | RuntimeCall::CollatorSelection(..) | RuntimeCall::Session(..) @@ -1166,13 +1212,15 @@ impl InstanceFilter for ProxyType { ) } // All runtime calls from pallet DappStaking allowed for proxy account - ProxyType::DappsStaking => { - matches!(c, RuntimeCall::DappsStaking(..)) + ProxyType::DappStaking => { + matches!(c, RuntimeCall::DappStaking(..)) } ProxyType::StakerRewardClaim => { matches!( c, - RuntimeCall::DappsStaking(pallet_dapps_staking::Call::claim_staker { .. }) + RuntimeCall::DappStaking( + pallet_dapp_staking_v3::Call::claim_staker_rewards { .. } + ) ) } } @@ -1184,7 +1232,7 @@ impl InstanceFilter for ProxyType { (ProxyType::Any, _) => true, (_, ProxyType::Any) => false, (ProxyType::NonTransfer, _) => true, - (ProxyType::DappsStaking, ProxyType::StakerRewardClaim) => true, + (ProxyType::DappStaking, ProxyType::StakerRewardClaim) => true, _ => false, } } @@ -1252,8 +1300,8 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment = 30, Balances: pallet_balances = 31, Vesting: pallet_vesting = 32, - DappsStaking: pallet_dapps_staking = 34, - BlockReward: pallet_block_rewards_hybrid = 35, + DappStaking: pallet_dapp_staking_v3 = 34, + Inflation: pallet_inflation = 35, Assets: pallet_assets = 36, Authorship: pallet_authorship = 40, @@ -1287,6 +1335,11 @@ construct_runtime!( Xvm: pallet_xvm = 90, Sudo: pallet_sudo = 99, + + // To be removed & cleaned up after migration has been finished + DappStakingMigration: pallet_dapp_staking_migration = 254, + // Legacy dApps staking v2, to be removed after migration has been finished + DappsStaking: pallet_dapps_staking = 255, } ); @@ -1324,10 +1377,118 @@ pub type Executive = frame_executive::Executive< Migrations, >; +parameter_types! { + pub const BlockRewardName: &'static str = "BlockReward"; +} /// 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_inflation::PalletInflationInitConfig, + pallet_dapp_staking_v3::DAppStakingV3InitConfig, + frame_support::migrations::RemovePallet< + BlockRewardName, + ::DbWeight, + >, + // This will handle new pallet storage version setting & it will put the new pallet into maintenance mode. + // But it's most important for testing with try-runtime. + pallet_dapp_staking_migration::DappStakingMigrationHandler, +); + +/// Used to initialize inflation parameters for the runtime. +pub struct InitInflationParams; +impl Get for InitInflationParams { + fn get() -> pallet_inflation::InflationParameters { + pallet_inflation::InflationParameters { + // Recalculation is done every two weeks, hence the small %. + max_inflation_rate: Perquintill::from_percent(1), + treasury_part: Perquintill::from_percent(5), + collators_part: Perquintill::from_percent(3), + dapps_part: Perquintill::from_percent(20), + base_stakers_part: Perquintill::from_percent(25), + adjustable_stakers_part: Perquintill::from_percent(35), + bonus_part: Perquintill::from_percent(12), + ideal_staking_rate: Perquintill::from_percent(20), + } + } +} + +use frame_support::BoundedVec; +use pallet_dapp_staking_v3::{EraNumber, TierParameters, TiersConfiguration}; +type NumberOfTiers = ::NumberOfTiers; +/// Used to initialize dApp staking parameters for the runtime. +pub struct InitDappStakingv3Params; +impl + Get<( + EraNumber, + TierParameters, + TiersConfiguration, + )> for InitDappStakingv3Params +{ + fn get() -> ( + EraNumber, + TierParameters, + TiersConfiguration, + ) { + // 1. Prepare init values + + // Init era of dApp staking v3 should be the next era after dApp staking v2 + let init_era = pallet_dapps_staking::CurrentEra::::get().saturating_add(1); + + // Reward portions according to the Tokenomics 2.0 report + let reward_portion = BoundedVec::try_from(vec![ + Permill::from_percent(40), + Permill::from_percent(30), + Permill::from_percent(20), + Permill::from_percent(10), + ]) + .unwrap_or_default(); + + // Tier thresholds adjusted according to numbers observed on Shibuya + let tier_thresholds = BoundedVec::try_from(vec![ + TierThreshold::DynamicTvlAmount { + amount: SBY.saturating_mul(1_000_000), + minimum_amount: SBY.saturating_mul(150_000), + }, + TierThreshold::DynamicTvlAmount { + amount: SBY.saturating_mul(100_000), + minimum_amount: SBY.saturating_mul(60_000), + }, + TierThreshold::DynamicTvlAmount { + amount: SBY.saturating_mul(50_000), + minimum_amount: SBY.saturating_mul(15_000), + }, + TierThreshold::FixedTvlAmount { + amount: SBY.saturating_mul(10_000), + }, + ]) + .unwrap_or_default(); + + // 2. Tier params + let tier_params = + TierParameters::<::NumberOfTiers> { + reward_portion: reward_portion.clone(), + slot_distribution: BoundedVec::try_from(vec![ + Permill::from_percent(10), + Permill::from_percent(20), + Permill::from_percent(30), + Permill::from_percent(40), + ]) + .unwrap_or_default(), + tier_thresholds: tier_thresholds.clone(), + }; + + // 3. Init tier config + let init_tier_config = TiersConfiguration { + number_of_slots: 100, + slots_per_tier: BoundedVec::try_from(vec![10, 20, 30, 40]).unwrap_or_default(), + reward_portion, + tier_thresholds, + }; + + (init_era, tier_params, init_tier_config) + } +} type EventRecord = frame_system::EventRecord< ::RuntimeEvent, @@ -1405,7 +1566,9 @@ mod benches { [pallet_balances, Balances] [pallet_timestamp, Timestamp] [pallet_dapps_staking, DappsStaking] - [block_rewards_hybrid, BlockReward] + [pallet_dapp_staking_v3, DappStaking] + [pallet_inflation, Inflation] + [pallet_dapp_staking_migration, DappStakingMigration] [pallet_xc_asset_config, XcAssetConfig] [pallet_collator_selection, CollatorSelection] [pallet_xcm, PolkadotXcm] @@ -1870,6 +2033,20 @@ impl_runtime_apis! { } } + impl dapp_staking_v3_runtime_api::DappStakingApi for Runtime { + fn eras_per_voting_subperiod() -> pallet_dapp_staking_v3::EraNumber { + InflationCycleConfig::eras_per_voting_subperiod() + } + + fn eras_per_build_and_earn_subperiod() -> pallet_dapp_staking_v3::EraNumber { + InflationCycleConfig::eras_per_build_and_earn_subperiod() + } + + fn blocks_per_era() -> BlockNumber { + InflationCycleConfig::blocks_per_era() + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( diff --git a/runtime/shibuya/src/precompiles.rs b/runtime/shibuya/src/precompiles.rs index 93f3e4ec16..c9f34a9a9d 100644 --- a/runtime/shibuya/src/precompiles.rs +++ b/runtime/shibuya/src/precompiles.rs @@ -24,7 +24,7 @@ use frame_support::{parameter_types, traits::Contains}; use pallet_evm_precompile_assets_erc20::Erc20AssetsPrecompileSet; use pallet_evm_precompile_blake2::Blake2F; use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; -use pallet_evm_precompile_dapps_staking::DappsStakingWrapper; +use pallet_evm_precompile_dapp_staking_v3::DappStakingV3Precompile; use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_ed25519::Ed25519Verify; use pallet_evm_precompile_modexp::Modexp; @@ -59,7 +59,7 @@ impl Contains for WhitelistedCalls { | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { calls.iter().all(|call| WhitelistedCalls::contains(call)) } - RuntimeCall::DappsStaking(_) => true, + RuntimeCall::DappStaking(_) => true, RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true, _ => false, } @@ -93,7 +93,7 @@ pub type ShibuyaPrecompilesSetAt = ( // Astar specific precompiles: PrecompileAt< AddressU64<20481>, - DappsStakingWrapper, + DappStakingV3Precompile, (CallableByContract, CallableByPrecompile), >, PrecompileAt< diff --git a/runtime/shibuya/src/weights/mod.rs b/runtime/shibuya/src/weights/mod.rs index f1df12d585..b49f1c1a29 100644 --- a/runtime/shibuya/src/weights/mod.rs +++ b/runtime/shibuya/src/weights/mod.rs @@ -18,4 +18,7 @@ pub mod pallet_assets; pub mod pallet_balances; +pub mod pallet_dapp_staking_migration; +pub mod pallet_dapp_staking_v3; +pub mod pallet_inflation; pub mod pallet_xcm; diff --git a/runtime/shibuya/src/weights/pallet_dapp_staking_migration.rs b/runtime/shibuya/src/weights/pallet_dapp_staking_migration.rs new file mode 100644 index 0000000000..cb43de8369 --- /dev/null +++ b/runtime/shibuya/src/weights/pallet_dapp_staking_migration.rs @@ -0,0 +1,133 @@ + +// This file is part of Astar. + +// Copyright (C) 2019-2023 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 . + +//! Autogenerated weights for pallet_dapp_staking_migration +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=shibuya-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_dapp_staking_migration +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/shibuya-dev/dapp_staking_migration_weights.rs +// --template=./scripts/templates/weight-template.hbs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; +use pallet_dapp_staking_migration::WeightInfo; + +/// Weights for pallet_dapp_staking_migration using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: DappsStaking RegisteredDapps (r:2 w:1) + /// Proof: DappsStaking RegisteredDapps (max_values: None, max_size: Some(86), added: 2561, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: DappStaking NextDAppId (r:1 w:1) + /// Proof: DappStaking NextDAppId (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + fn migrate_dapps_success() -> Weight { + // Proof Size summary in bytes: + // Measured: `558` + // Estimated: `6112` + // Minimum execution time: 46_218_000 picoseconds. + Weight::from_parts(47_610_000, 6112) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappsStaking RegisteredDapps (r:1 w:0) + /// Proof: DappsStaking RegisteredDapps (max_values: None, max_size: Some(86), added: 2561, mode: MaxEncodedLen) + fn migrate_dapps_noop() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3551` + // Minimum execution time: 3_385_000 picoseconds. + Weight::from_parts(3_552_000, 3551) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: DappsStaking Ledger (r:2 w:1) + /// Proof: DappsStaking Ledger (max_values: None, max_size: Some(266), added: 2741, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:1) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn migrate_ledger_success() -> Weight { + // Proof Size summary in bytes: + // Measured: `1748` + // Estimated: `6472` + // Minimum execution time: 69_553_000 picoseconds. + Weight::from_parts(70_319_000, 6472) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: DappsStaking Ledger (r:1 w:0) + /// Proof: DappsStaking Ledger (max_values: None, max_size: Some(266), added: 2741, mode: MaxEncodedLen) + fn migrate_ledger_noop() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3731` + // Minimum execution time: 2_918_000 picoseconds. + Weight::from_parts(3_022_000, 3731) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: DappsStaking Ledger (r:2 w:1) + /// Proof: DappsStaking Ledger (max_values: None, max_size: Some(266), added: 2741, mode: MaxEncodedLen) + fn cleanup_old_storage_success() -> Weight { + // Proof Size summary in bytes: + // Measured: `739` + // Estimated: `6472` + // Minimum execution time: 7_109_000 picoseconds. + Weight::from_parts(7_383_000, 6472) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn cleanup_old_storage_noop() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_095_000 picoseconds. + Weight::from_parts(2_213_000, 0) + } +} \ No newline at end of file diff --git a/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs b/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs new file mode 100644 index 0000000000..0bcfcee538 --- /dev/null +++ b/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs @@ -0,0 +1,432 @@ + +// This file is part of Astar. + +// Copyright (C) 2019-2023 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 . + +//! Autogenerated weights for pallet_dapp_staking_v3 +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=shibuya-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_dapp_staking_v3 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/shibuya-dev/dapp_staking_v3_weights.rs +// --template=./scripts/templates/weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; +use pallet_dapp_staking_v3::WeightInfo; + +/// Weights for pallet_dapp_staking_v3 using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + fn maintenance_mode() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_474_000 picoseconds. + Weight::from_parts(8_711_000, 0) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: DappStaking NextDAppId (r:1 w:1) + /// Proof: DappStaking NextDAppId (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + fn register() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3091` + // Minimum execution time: 16_360_000 picoseconds. + Weight::from_parts(16_697_000, 3091) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + fn set_dapp_reward_beneficiary() -> Weight { + // Proof Size summary in bytes: + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 12_927_000 picoseconds. + Weight::from_parts(13_229_000, 3091) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + fn set_dapp_owner() -> Weight { + // Proof Size summary in bytes: + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 13_610_000 picoseconds. + Weight::from_parts(13_851_000, 3091) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:0 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + fn unregister() -> Weight { + // Proof Size summary in bytes: + // Measured: `75` + // Estimated: `3091` + // Minimum execution time: 16_704_000 picoseconds. + Weight::from_parts(16_952_000, 3091) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock() -> Weight { + // Proof Size summary in bytes: + // Measured: `12` + // Estimated: `4764` + // Minimum execution time: 31_680_000 picoseconds. + Weight::from_parts(32_075_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn unlock() -> Weight { + // Proof Size summary in bytes: + // Measured: `156` + // Estimated: `4764` + // Minimum execution time: 34_576_000 picoseconds. + Weight::from_parts(34_777_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// The range of component `x` is `[0, 8]`. + fn claim_unlocked(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `187` + // Estimated: `4764` + // Minimum execution time: 33_562_000 picoseconds. + Weight::from_parts(34_600_552, 4764) + // Standard Error: 5_079 + .saturating_add(Weight::from_parts(193_345, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn relock_unlocking() -> Weight { + // Proof Size summary in bytes: + // Measured: `182` + // Estimated: `4764` + // Minimum execution time: 36_436_000 picoseconds. + Weight::from_parts(37_262_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:1 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn stake() -> Weight { + // Proof Size summary in bytes: + // Measured: `250` + // Estimated: `4764` + // Minimum execution time: 43_866_000 picoseconds. + Weight::from_parts(44_468_000, 4764) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:1 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn unstake() -> Weight { + // Proof Size summary in bytes: + // Measured: `427` + // Estimated: `4764` + // Minimum execution time: 47_368_000 picoseconds. + Weight::from_parts(48_049_000, 4764) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:0) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:0) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn claim_staker_rewards_past_period(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `560` + // Estimated: `4764` + // Minimum execution time: 51_230_000 picoseconds. + Weight::from_parts(48_696_805, 4764) + // Standard Error: 6_139 + .saturating_add(Weight::from_parts(3_374_191, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:0) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `501` + // Estimated: `4764` + // Minimum execution time: 45_030_000 picoseconds. + Weight::from_parts(43_179_071, 4764) + // Standard Error: 5_547 + .saturating_add(Weight::from_parts(3_296_864, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:0) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + fn claim_bonus_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `267` + // Estimated: `3775` + // Minimum execution time: 42_248_000 picoseconds. + Weight::from_parts(42_687_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(121), added: 2101, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:1 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) + fn claim_dapp_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `3021` + // Estimated: `5548` + // Minimum execution time: 50_968_000 picoseconds. + Weight::from_parts(51_778_000, 5548) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn unstake_from_unregistered() -> Weight { + // Proof Size summary in bytes: + // Measured: `389` + // Estimated: `4764` + // Minimum execution time: 42_329_000 picoseconds. + Weight::from_parts(42_737_000, 4764) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: DappStaking StakerInfo (r:9 w:8) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 8]`. + fn cleanup_expired_entries(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `255 + x * (69 ±0)` + // Estimated: `4764 + x * (2613 ±0)` + // Minimum execution time: 42_222_000 picoseconds. + Weight::from_parts(38_945_386, 4764) + // Standard Error: 14_325 + .saturating_add(Weight::from_parts(5_044_310, 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)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 2613).saturating_mul(x.into())) + } + fn force() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_971_000 picoseconds. + Weight::from_parts(10_190_000, 0) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + fn on_initialize_voting_to_build_and_earn() -> Weight { + // Proof Size summary in bytes: + // Measured: `16` + // Estimated: `4254` + // Minimum execution time: 17_308_000 picoseconds. + Weight::from_parts(17_774_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, 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: DappStaking TierConfig (r:1 w:1) + /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:0 w:1) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:0 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(2083), added: 4558, mode: MaxEncodedLen) + fn on_initialize_build_and_earn_to_voting() -> Weight { + // Proof Size summary in bytes: + // Measured: `550` + // Estimated: `4254` + // Minimum execution time: 39_768_000 picoseconds. + Weight::from_parts(40_422_000, 4254) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// 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(2083), added: 4558, mode: MaxEncodedLen) + fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { + // Proof Size summary in bytes: + // Measured: `68` + // Estimated: `4254` + // Minimum execution time: 20_976_000 picoseconds. + Weight::from_parts(21_507_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking ContractStake (r:101 w:0) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking TierConfig (r:1 w:0) + /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// The range of component `x` is `[0, 100]`. + fn dapp_tier_assignment(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `152 + x * (32 ±0)` + // Estimated: `3061 + x * (2071 ±0)` + // Minimum execution time: 7_374_000 picoseconds. + Weight::from_parts(10_826_637, 3061) + // Standard Error: 3_374 + .saturating_add(Weight::from_parts(2_291_643, 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())) + } + /// Storage: DappStaking HistoryCleanupMarker (r:1 w:1) + /// Proof: DappStaking HistoryCleanupMarker (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:1) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// 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(2083), added: 4558, mode: MaxEncodedLen) + fn on_idle_cleanup() -> Weight { + // Proof Size summary in bytes: + // Measured: `473` + // Estimated: `4254` + // Minimum execution time: 14_500_000 picoseconds. + Weight::from_parts(14_969_000, 4254) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } +} \ No newline at end of file diff --git a/runtime/shibuya/src/weights/pallet_inflation.rs b/runtime/shibuya/src/weights/pallet_inflation.rs new file mode 100644 index 0000000000..98616cb747 --- /dev/null +++ b/runtime/shibuya/src/weights/pallet_inflation.rs @@ -0,0 +1,105 @@ + +// This file is part of Astar. + +// Copyright (C) 2019-2023 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 . + +//! Autogenerated weights for pallet_inflation +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=shibuya-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_inflation +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/shibuya-dev/inflation_weights.rs +// --template=./scripts/templates/weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; +use pallet_inflation::WeightInfo; + +/// Weights for pallet_inflation using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: Inflation InflationParams (r:0 w:1) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn force_set_inflation_params() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_036_000 picoseconds. + Weight::from_parts(9_186_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn force_set_inflation_config() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_073_000 picoseconds. + Weight::from_parts(9_411_000, 0) + } + /// Storage: Inflation InflationParams (r:1 w:0) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn force_inflation_recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `58` + // Estimated: `1549` + // Minimum execution time: 14_839_000 picoseconds. + Weight::from_parts(15_198_000, 1549) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Inflation InflationParams (r:1 w:0) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn hook_with_recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `232` + // Estimated: `6196` + // Minimum execution time: 31_965_000 picoseconds. + Weight::from_parts(32_498_000, 6196) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn hook_without_recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `174` + // Estimated: `6196` + // Minimum execution time: 22_235_000 picoseconds. + Weight::from_parts(22_378_000, 6196) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} \ No newline at end of file diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index 2295c836a1..5bb0a19714 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -25,6 +25,7 @@ pallet-assets = { workspace = true } pallet-balances = { workspace = true } pallet-contracts = { workspace = true } pallet-contracts-primitives = { workspace = true } +pallet-dapp-staking-v3 = { workspace = true } pallet-dapps-staking = { workspace = true } pallet-proxy = { workspace = true } pallet-utility = { workspace = true } diff --git a/tests/integration/src/dispatch_precompile_filter_new.rs b/tests/integration/src/dispatch_precompile_filter_new.rs new file mode 100644 index 0000000000..b406b43d05 --- /dev/null +++ b/tests/integration/src/dispatch_precompile_filter_new.rs @@ -0,0 +1,207 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 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 . +#![cfg(test)] + +use crate::setup::*; +use astar_primitives::precompiles::DispatchFilterValidate; +use fp_evm::{ExitError, PrecompileFailure}; +use frame_support::{ + dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}, + traits::Contains, +}; +use pallet_evm_precompile_dispatch::DispatchValidateT; +use parity_scale_codec::Compact; + +/// Whitelisted Calls are defined in the runtime +#[test] +fn filter_accepts_batch_call_with_whitelisted_calls() { + ExtBuilder::default().build().execute_with(|| { + let inner_call = RuntimeCall::DappStaking(DappStakingCall::Call::claim_staker_rewards {}); + let call = RuntimeCall::Utility(UtilityCall::batch { + calls: vec![inner_call], + }); + assert!(WhitelistedCalls::contains(&call)); + }); +} + +#[test] +fn filter_rejects_non_whitelisted_batch_calls() { + ExtBuilder::default().build().execute_with(|| { + // CASE1 - only non whitelisted calls + let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { + dest: MultiAddress::Id(CAT), + value: 100_000_000_000, + }); + let transfer = Box::new(transfer_call); + let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { + calls: vec![*transfer.clone()], + })); + + // Utility call containing Balances Call + assert!(!WhitelistedCalls::contains(&call)); + + // CASE 2 - now whitelisted mixed with whitelisted calls + + let staking_call = RuntimeCall::DappStaking(DappStakingCall::Call::claim_staker_rewards {}); + let staking = Box::new(staking_call); + + let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { + calls: vec![*transfer, *staking.clone()], + })); + + // Utility call containing Balances Call and Dappsstaking Call Fails filter + assert!(!WhitelistedCalls::contains(&call)); + }); +} + +#[test] +fn filter_accepts_whitelisted_calls() { + ExtBuilder::default().build().execute_with(|| { + // Dappstaking call works + let stake_call = RuntimeCall::DappStaking(DappStakingCall::Call::claim_staker_rewards {}); + assert!(WhitelistedCalls::contains(&stake_call)); + + // Pallet::Assets transfer call works + let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { + id: Compact(0), + target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), + amount: 100, + }); + assert!(WhitelistedCalls::contains(&transfer_call)); + }); +} + +#[test] +fn filter_rejects_non_whitelisted_calls() { + ExtBuilder::default().build().execute_with(|| { + // Random call from non whitelisted pallet doesn't work + let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { + dest: MultiAddress::Id(CAT), + value: 100_000_000_000, + }); + assert!(!WhitelistedCalls::contains(&transfer_call)); + + // Only `transfer` call from pallet assets work + // Other random call from Pallet Assets doesn't work + let thaw_asset_call = + RuntimeCall::Assets(pallet_assets::Call::thaw_asset { id: Compact(0) }); + assert!(!WhitelistedCalls::contains(&thaw_asset_call)); + }) +} + +#[test] +fn filter_accepts_whitelisted_batch_all_calls() { + ExtBuilder::default().build().execute_with(|| { + let inner_call1 = RuntimeCall::DappStaking(DappStakingCall::Call::claim_staker_rewards {}); + let inner_call2 = RuntimeCall::DappStaking(DappStakingCall::Call::claim_staker_rewards {}); + let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { + id: Compact(0), + target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), + amount: 100, + }); + let call = RuntimeCall::Utility(UtilityCall::batch_all { + calls: vec![inner_call1, inner_call2, transfer_call], + }); + assert!(WhitelistedCalls::contains(&call)); + }); +} + +#[test] +fn test_correct_dispatch_info_works() { + ExtBuilder::default().build().execute_with(|| { + // Mock implementation + struct Filter; + struct AccountId; + enum RuntimeCall { + System, + DappStaking, + } + impl GetDispatchInfo for RuntimeCall { + fn get_dispatch_info(&self) -> DispatchInfo { + // Default is Pays::Yes and DispatchCall::Normal + DispatchInfo::default() + } + } + impl Contains for Filter { + fn contains(t: &RuntimeCall) -> bool { + match t { + RuntimeCall::DappStaking => true, + _ => false, + } + } + } + // Case 1: Whitelisted Call with correct Dispatch info + assert_eq!( + DispatchFilterValidate::::validate_before_dispatch( + &AccountId, + &RuntimeCall::DappStaking + ), + Option::None + ); + // Case 2: Non-Whitelisted Call with correct Dispatch Info + assert_eq!( + DispatchFilterValidate::::validate_before_dispatch( + &AccountId, + &RuntimeCall::System + ), + Option::Some(PrecompileFailure::Error { + exit_status: ExitError::Other("call filtered out".into()), + }) + ); + }); +} + +#[test] +fn test_incorrect_dispatch_info_fails() { + ExtBuilder::default().build().execute_with(|| { + // Mock implementation + struct Filter; + struct AccountId; + enum RuntimeCall { + DappStaking, + } + impl GetDispatchInfo for RuntimeCall { + fn get_dispatch_info(&self) -> DispatchInfo { + DispatchInfo { + weight: Weight::default(), + class: DispatchClass::Normal, + // Should have been Pays::Yes for call to pass + pays_fee: Pays::No, + } + } + } + impl Contains for Filter { + fn contains(t: &RuntimeCall) -> bool { + match t { + RuntimeCall::DappStaking => true, + } + } + } + + // WhiteListed Call fails because of incorrect DispatchInfo + assert_eq!( + DispatchFilterValidate::::validate_before_dispatch( + &AccountId, + &RuntimeCall::DappStaking + ), + Option::Some(PrecompileFailure::Error { + exit_status: ExitError::Other("invalid call".into()), + }) + ); + }) +} diff --git a/tests/integration/src/dispatch_precompile_filter.rs b/tests/integration/src/dispatch_precompile_filter_old.rs similarity index 95% rename from tests/integration/src/dispatch_precompile_filter.rs rename to tests/integration/src/dispatch_precompile_filter_old.rs index 7992b39c0a..95d04bcfba 100644 --- a/tests/integration/src/dispatch_precompile_filter.rs +++ b/tests/integration/src/dispatch_precompile_filter_old.rs @@ -32,7 +32,7 @@ use parity_scale_codec::Compact; fn filter_accepts_batch_call_with_whitelisted_calls() { ExtBuilder::default().build().execute_with(|| { let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let inner_call = RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { + let inner_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { contract_id: contract.clone(), }); let call = RuntimeCall::Utility(UtilityCall::batch { @@ -61,7 +61,7 @@ fn filter_rejects_non_whitelisted_batch_calls() { // CASE 2 - now whitelisted mixed with whitelisted calls let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let staking_call = RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { + let staking_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { contract_id: contract.clone(), }); let staking = Box::new(staking_call); @@ -80,7 +80,7 @@ fn filter_accepts_whitelisted_calls() { ExtBuilder::default().build().execute_with(|| { // Dappstaking call works let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let stake_call = RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { + let stake_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { contract_id: contract.clone(), }); assert!(WhitelistedCalls::contains(&stake_call)); @@ -117,10 +117,10 @@ fn filter_rejects_non_whitelisted_calls() { fn filter_accepts_whitelisted_batch_all_calls() { ExtBuilder::default().build().execute_with(|| { let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let inner_call1 = RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { + let inner_call1 = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { contract_id: contract.clone(), }); - let inner_call2 = RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { + let inner_call2 = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { contract_id: contract.clone(), }); let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index 012ee39d07..43b2d9843b 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -23,8 +23,12 @@ #[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod setup; -#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] -mod proxy; +#[cfg(any(feature = "shibuya"))] +mod proxy_new; + +// Remove this once dApp staking v3 is integrated into Shiden & Astar +#[cfg(any(feature = "shiden", feature = "astar"))] +mod proxy_old; #[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod assets; @@ -32,7 +36,12 @@ mod assets; #[cfg(feature = "shibuya")] mod xvm; -#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] -mod dispatch_precompile_filter; +#[cfg(any(feature = "shibuya"))] +mod dispatch_precompile_filter_new; + +// Remove this once dApp staking v3 is integrated into Shiden & Astar +#[cfg(any(feature = "shiden", feature = "astar"))] +mod dispatch_precompile_filter_old; + #[cfg(feature = "shibuya")] mod unified_accounts; diff --git a/tests/integration/src/proxy_new.rs b/tests/integration/src/proxy_new.rs new file mode 100644 index 0000000000..c54bc30ca8 --- /dev/null +++ b/tests/integration/src/proxy_new.rs @@ -0,0 +1,222 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 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 crate::setup::*; +use astar_primitives::dapp_staking::SmartContractHandle; +use pallet_dapp_staking_v3::ForcingType; + +#[test] +fn test_utility_call_pass_for_any() { + new_test_ext().execute_with(|| { + // Any proxy should be allowed to make balance transfer call + assert_ok!(Proxy::add_proxy( + RuntimeOrigin::signed(ALICE), + MultiAddress::Id(BOB), + ProxyType::Any, + 0 + )); + + // Preparing Utility call + let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { + dest: MultiAddress::Id(CAT), + value: 100_000_000_000, + }); + let inner = Box::new(transfer_call); + let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { + calls: vec![*inner], + })); + + // Utility call passed through filter + assert_ok!(Proxy::proxy( + RuntimeOrigin::signed(BOB), + MultiAddress::Id(ALICE), + None, + call.clone() + )); + expect_events(vec![ + UtilityEvent::BatchCompleted.into(), + ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), + ]); + }); +} + +#[test] +fn test_utility_call_pass_for_balances() { + new_test_ext().execute_with(|| { + // Balances proxy should be allowed to make balance transfer call + assert_ok!(Proxy::add_proxy( + RuntimeOrigin::signed(ALICE), + MultiAddress::Id(BOB), + ProxyType::Balances, + 0 + )); + + // Preparing Utility call + let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { + dest: MultiAddress::Id(CAT), + value: 100_000_000_000, + }); + let inner = Box::new(transfer_call); + let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { + calls: vec![*inner], + })); + + // Utility call passed through filter + assert_ok!(Proxy::proxy( + RuntimeOrigin::signed(BOB), + MultiAddress::Id(ALICE), + None, + call.clone() + )); + expect_events(vec![ + UtilityEvent::BatchCompleted.into(), + ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), + ]); + }); +} + +#[test] +fn test_utility_call_fail_non_transfer() { + new_test_ext().execute_with(|| { + // NonTransfer proxy shouldn't be allowed to make balance transfer call + assert_ok!(Proxy::add_proxy( + RuntimeOrigin::signed(ALICE), + MultiAddress::Id(BOB), + ProxyType::NonTransfer, + 0 + )); + + // Preparing Utility call + let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { + dest: MultiAddress::Id(CAT), + value: 100_000_000_000, + }); + let inner = Box::new(transfer_call); + let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { + calls: vec![*inner], + })); + + assert_ok!(Proxy::proxy( + RuntimeOrigin::signed(BOB), + MultiAddress::Id(ALICE), + None, + call.clone() + )); + + // Utility call filtered out + expect_events(vec![ + UtilityEvent::BatchInterrupted { + index: 0, + error: SystemError::CallFiltered.into(), + } + .into(), + ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), + ]); + }); +} + +#[test] +fn test_utility_call_fail_for_dappstaking() { + new_test_ext().execute_with(|| { + // Dappstaking proxy shouldn't be allowed to make balance transfer call + assert_ok!(Proxy::add_proxy( + RuntimeOrigin::signed(ALICE), + MultiAddress::Id(BOB), + ProxyType::DappStaking, + 0 + )); + + // Preparing Utility call + let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { + dest: MultiAddress::Id(CAT), + value: 100_000_000_000, + }); + let inner = Box::new(transfer_call); + let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { + calls: vec![*inner], + })); + + assert_ok!(Proxy::proxy( + RuntimeOrigin::signed(BOB), + MultiAddress::Id(ALICE), + None, + call.clone() + )); + // Utility call filtered out + expect_events(vec![ + UtilityEvent::BatchInterrupted { + index: 0, + error: SystemError::CallFiltered.into(), + } + .into(), + ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), + ]); + }); +} + +#[test] +fn test_staker_reward_claim_proxy_works() { + new_test_ext().execute_with(|| { + // Make CAT delegate for StakerRewardClaim proxy + assert_ok!(Proxy::add_proxy( + RuntimeOrigin::signed(BOB), + MultiAddress::Id(CAT), + ProxyType::StakerRewardClaim, + 0 + )); + + let contract = ::SmartContract::evm( + H160::repeat_byte(0x01), + ); + let staker_reward_claim_call = + RuntimeCall::DappStaking(DappStakingCall::Call::claim_staker_rewards {}); + let call = Box::new(staker_reward_claim_call); + + // contract must be registered + assert_ok!(DappStaking::register( + RuntimeOrigin::root(), + ALICE.clone(), + contract.clone() + )); + + // some amount must be locked&staked + let amount = 600 * UNIT; + assert_ok!(DappStaking::lock(RuntimeOrigin::signed(BOB), amount)); + assert_ok!(DappStaking::stake( + RuntimeOrigin::signed(BOB), + contract.clone(), + amount, + )); + + // Generate some rewards + assert_ok!(DappStaking::force(RuntimeOrigin::root(), ForcingType::Era)); + run_to_block(System::block_number() + 1); + assert_ok!(DappStaking::force(RuntimeOrigin::root(), ForcingType::Era)); + run_to_block(System::block_number() + 1); + + // CAT making proxy call on behalf of staker (BOB) + assert_ok!(Proxy::proxy( + RuntimeOrigin::signed(CAT), + MultiAddress::Id(BOB), + None, + call.clone() + )); + + expect_events(vec![ProxyEvent::ProxyExecuted { result: Ok(()) }.into()]); + }) +} diff --git a/tests/integration/src/proxy.rs b/tests/integration/src/proxy_old.rs similarity index 98% rename from tests/integration/src/proxy.rs rename to tests/integration/src/proxy_old.rs index 41fc247372..d6d9479a82 100644 --- a/tests/integration/src/proxy.rs +++ b/tests/integration/src/proxy_old.rs @@ -180,7 +180,7 @@ fn test_staker_reward_claim_proxy_works() { let contract = SmartContract::Evm(H160::repeat_byte(0x01)); let staker_reward_claim_call = - RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { + RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { contract_id: contract.clone(), }); let call = Box::new(staker_reward_claim_call); diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index bc7dddeaca..ba266bfe3e 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -159,7 +159,8 @@ pub const INITIAL_AMOUNT: u128 = 100_000 * UNIT; pub type SystemError = frame_system::Error; pub use pallet_balances::Call as BalancesCall; -pub use pallet_dapps_staking as DappStakingCall; +pub use pallet_dapp_staking_v3 as DappStakingCall; +pub use pallet_dapps_staking as DappsStakingCall; pub use pallet_proxy::Event as ProxyEvent; pub use pallet_utility::{Call as UtilityCall, Event as UtilityEvent}; @@ -212,32 +213,37 @@ pub const BLOCK_TIME: u64 = 12_000; pub fn run_to_block(n: u32) { while System::block_number() < n { let block_number = System::block_number(); - Timestamp::set_timestamp(block_number as u64 * BLOCK_TIME); TransactionPayment::on_finalize(block_number); + #[cfg(any(feature = "shibuya"))] + DappStaking::on_finalize(block_number); + #[cfg(any(feature = "astar", feature = "shiden"))] DappsStaking::on_finalize(block_number); Authorship::on_finalize(block_number); Session::on_finalize(block_number); AuraExt::on_finalize(block_number); PolkadotXcm::on_finalize(block_number); Ethereum::on_finalize(block_number); - #[cfg(any(features = "astar"))] - BaseFee::on_finalize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] DynamicEvmBaseFee::on_finalize(block_number); + #[cfg(any(feature = "shibuya"))] + Inflation::on_finalize(block_number); System::set_block_number(block_number + 1); + let block_number = System::block_number(); + #[cfg(any(feature = "shibuya"))] + Inflation::on_initialize(block_number); + Timestamp::set_timestamp(block_number as u64 * BLOCK_TIME); TransactionPayment::on_initialize(block_number); + #[cfg(any(feature = "shibuya"))] + DappStaking::on_initialize(block_number); + #[cfg(any(feature = "astar", feature = "shiden"))] DappsStaking::on_initialize(block_number); Authorship::on_initialize(block_number); Aura::on_initialize(block_number); AuraExt::on_initialize(block_number); Ethereum::on_initialize(block_number); - #[cfg(any(features = "astar"))] - BaseFee::on_initialize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] DynamicEvmBaseFee::on_initialize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden", features = "astar"))] + #[cfg(any(feature = "shibuya", feature = "shiden"))] RandomnessCollectiveFlip::on_initialize(block_number); XcmpQueue::on_idle(block_number, Weight::MAX);