From 9f204f178b3a7f76122526d7dbf5d51929969f51 Mon Sep 17 00:00:00 2001 From: Dinonard <3002868+Dinonard@users.noreply.github.com> Date: Tue, 12 Apr 2022 15:11:56 +0200 Subject: [PATCH] Astar upgrade for ds re-launch (#608) Rebase & update astar params Add precompiles, version bump, unbonding-period change Use git branch for dep Update deps Expose try-runtime access Spec version uplift Fix benchmark issues tag-usage for dapps-staking pallets Adjust params as agreed on Slack Fix int type --- Cargo.lock | 104 ++++++++++----- bin/collator/Cargo.toml | 2 +- .../src/parachain/chain_spec/astar.rs | 20 ++- runtime/astar/Cargo.toml | 33 ++++- runtime/astar/src/lib.rs | 120 ++++++++++++++---- runtime/astar/src/precompiles.rs | 18 ++- .../astar/src/weights/pallet_dapps_staking.rs | 115 +++++++++++------ runtime/local/Cargo.toml | 2 +- runtime/shibuya/Cargo.toml | 2 +- runtime/shiden/Cargo.toml | 2 +- 10 files changed, 309 insertions(+), 109 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1c2ced993..84e58bd9a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,7 +153,7 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "astar-collator" -version = "3.18.0" +version = "3.19.0" dependencies = [ "astar-runtime", "async-trait", @@ -185,7 +185,7 @@ dependencies = [ "jsonrpc-pubsub", "local-runtime", "log", - "pallet-block-reward 2.0.0", + "pallet-block-reward", "pallet-contracts-rpc", "pallet-ethereum", "pallet-evm", @@ -240,7 +240,7 @@ dependencies = [ [[package]] name = "astar-runtime" -version = "3.18.0" +version = "3.19.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -255,16 +255,17 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal", "pallet-aura", "pallet-authorship", "pallet-balances", "pallet-base-fee", - "pallet-block-reward 0.2.0", + "pallet-block-reward", "pallet-collator-selection 3.0.0 (git+https://github.com/AstarNetwork/astar-frame?branch=polkadot-v0.9.17)", "pallet-collective", "pallet-custom-signatures", - "pallet-dapps-staking 1.1.2", + "pallet-dapps-staking 3.2.1", "pallet-ethereum", "pallet-evm", "pallet-evm-precompile-blake2", @@ -274,8 +275,10 @@ dependencies = [ "pallet-evm-precompile-modexp", "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", + "pallet-evm-precompile-sr25519", "pallet-identity", "pallet-multisig", + "pallet-precompile-dapps-staking 3.2.1", "pallet-session", "pallet-sudo", "pallet-timestamp", @@ -303,6 +306,7 @@ dependencies = [ "sp-transaction-pool", "sp-version", "substrate-wasm-builder", + "try-runtime-cli", ] [[package]] @@ -4661,7 +4665,7 @@ checksum = "a261afc61b7a5e323933b402ca6a1765183687c614789b1e4db7762ed4230bca" [[package]] name = "local-runtime" -version = "3.18.0" +version = "3.19.0" dependencies = [ "fp-rpc", "fp-self-contained", @@ -4676,7 +4680,7 @@ dependencies = [ "pallet-aura", "pallet-balances", "pallet-base-fee", - "pallet-block-reward 2.0.0", + "pallet-block-reward", "pallet-contracts", "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", @@ -4694,7 +4698,7 @@ dependencies = [ "pallet-evm-precompile-sr25519", "pallet-evm-precompile-substrate-ecdsa", "pallet-grandpa", - "pallet-precompile-dapps-staking", + "pallet-precompile-dapps-staking 3.2.0", "pallet-randomness-collective-flip", "pallet-sudo", "pallet-timestamp", @@ -5606,17 +5610,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-block-reward" -version = "0.2.0" -source = "git+https://github.com/AstarNetwork/astar-frame?tag=pallet-block-reward-0.2.0/polkadot-v0.9.17#162d8fcde709d0140bc8da9f7df5ac165c0c43a7" -dependencies = [ - "frame-support", - "frame-system", - "parity-scale-codec", - "scale-info", -] - [[package]] name = "pallet-block-reward" version = "2.0.0" @@ -5873,9 +5866,10 @@ dependencies = [ [[package]] name = "pallet-dapps-staking" -version = "1.1.2" -source = "git+https://github.com/AstarNetwork/astar-frame?branch=pallet-dapps-staking-1.1.2/polkadot-v0.9.17#ee2f6a6913a61d7e21144415dac0da0e8fa59375" +version = "3.2.0" +source = "git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.0/polkadot-v0.9.17#33e48c2e54109bb5980f8117336c9489f9c20d06" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "num-traits", @@ -5895,8 +5889,8 @@ dependencies = [ [[package]] name = "pallet-dapps-staking" -version = "3.2.0" -source = "git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.0/polkadot-v0.9.17#33e48c2e54109bb5980f8117336c9489f9c20d06" +version = "3.2.1" +source = "git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.1/polkadot-v0.9.17#dc36c421ac6d12e1a340d10b384a306144fc7a95" dependencies = [ "frame-benchmarking", "frame-support", @@ -6395,6 +6389,26 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-precompile-dapps-staking" +version = "3.2.1" +source = "git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.1/polkadot-v0.9.17#dc36c421ac6d12e1a340d10b384a306144fc7a95" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum", + "pallet-dapps-staking 3.2.1", + "pallet-evm", + "parity-scale-codec", + "precompile-utils 0.1.0 (git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.1/polkadot-v0.9.17)", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-preimage" version = "4.0.0-dev" @@ -8302,6 +8316,26 @@ dependencies = [ "xcm", ] +[[package]] +name = "precompile-utils" +version = "0.1.0" +source = "git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.1/polkadot-v0.9.17#dc36c421ac6d12e1a340d10b384a306144fc7a95" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum", + "pallet-evm", + "parity-scale-codec", + "precompile-utils-macro 0.1.0 (git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.1/polkadot-v0.9.17)", + "sha3 0.9.1", + "sp-core", + "sp-io", + "sp-std", + "xcm", +] + [[package]] name = "precompile-utils" version = "0.1.0" @@ -8374,6 +8408,18 @@ dependencies = [ "syn", ] +[[package]] +name = "precompile-utils-macro" +version = "0.1.0" +source = "git+https://github.com/AstarNetwork/astar-frame?tag=pallet-dapps-staking-3.2.1/polkadot-v0.9.17#dc36c421ac6d12e1a340d10b384a306144fc7a95" +dependencies = [ + "num_enum", + "proc-macro2", + "quote", + "sha3 0.8.2", + "syn", +] + [[package]] name = "precompile-utils-macro" version = "0.1.0" @@ -10427,7 +10473,7 @@ dependencies = [ [[package]] name = "shibuya-runtime" -version = "3.18.0" +version = "3.19.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -10452,7 +10498,7 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-base-fee", - "pallet-block-reward 2.0.0", + "pallet-block-reward", "pallet-collator-selection 3.0.0 (git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.17)", "pallet-collective", "pallet-contracts", @@ -10474,7 +10520,7 @@ dependencies = [ "pallet-evm-precompile-substrate-ecdsa", "pallet-identity", "pallet-multisig", - "pallet-precompile-dapps-staking", + "pallet-precompile-dapps-staking 3.2.0", "pallet-randomness-collective-flip", "pallet-session", "pallet-sudo", @@ -10513,7 +10559,7 @@ dependencies = [ [[package]] name = "shiden-runtime" -version = "3.18.0" +version = "3.19.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -10534,7 +10580,7 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-base-fee", - "pallet-block-reward 2.0.0", + "pallet-block-reward", "pallet-collator-selection 3.0.0 (git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.17)", "pallet-collective", "pallet-custom-signatures", @@ -10551,7 +10597,7 @@ dependencies = [ "pallet-evm-precompile-sr25519", "pallet-identity", "pallet-multisig", - "pallet-precompile-dapps-staking", + "pallet-precompile-dapps-staking 3.2.0", "pallet-session", "pallet-sudo", "pallet-timestamp", diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index 9e0de573bc..cb522c1559 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-collator" -version = "3.18.0" +version = "3.19.0" authors = ["Stake Technologies "] description = "Astar collator implementation in Rust." build = "build.rs" diff --git a/bin/collator/src/parachain/chain_spec/astar.rs b/bin/collator/src/parachain/chain_spec/astar.rs index 47e1aaab0b..96136e8663 100644 --- a/bin/collator/src/parachain/chain_spec/astar.rs +++ b/bin/collator/src/parachain/chain_spec/astar.rs @@ -1,13 +1,16 @@ //! Astar chain specifications. use astar_runtime::{ - wasm_binary_unwrap, AccountId, AuraId, Balance, BaseFeeConfig, EVMConfig, ParachainInfoConfig, - Precompiles, Signature, SystemConfig, ASTR, + wasm_binary_unwrap, AccountId, AuraId, Balance, BaseFeeConfig, BlockRewardConfig, EVMConfig, + ParachainInfoConfig, Precompiles, Signature, SystemConfig, ASTR, }; use cumulus_primitives_core::ParaId; use sc_service::ChainType; use sp_core::{crypto::Ss58Codec, sr25519, Pair, Public}; -use sp_runtime::traits::{IdentifyAccount, Verify}; +use sp_runtime::{ + traits::{IdentifyAccount, Verify}, + Perbill, +}; use super::{get_from_seed, Extensions}; @@ -126,6 +129,17 @@ fn make_genesis( }, parachain_info: ParachainInfoConfig { parachain_id }, balances: astar_runtime::BalancesConfig { balances }, + block_reward: BlockRewardConfig { + // Make sure sum is 100 + reward_config: pallet_block_reward::RewardDistributionConfig { + base_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: astar_runtime::VestingConfig { vesting: vec![] }, session: astar_runtime::SessionConfig { keys: authorities diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 3d7b544d4b..2071d6468d 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-runtime" -version = "3.18.0" +version = "3.19.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs" @@ -73,12 +73,18 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false, optional = true } pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false, optional = true } +# try-runtime +frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false, optional = true } +try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false, optional = true } + # Astar pallets -pallet-block-reward = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-block-reward-0.2.0/polkadot-v0.9.17", default-features = false } +pallet-block-reward = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-block-reward-2.0.0/polkadot-v0.9.17", default-features = false } pallet-collator-selection = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.17", default-features = false } pallet-custom-signatures = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.17", default-features = false } -pallet-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", branch = "pallet-dapps-staking-1.1.2/polkadot-v0.9.17", default-features = false } pallet-vesting = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.17", default-features = false } +pallet-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-3.2.1/polkadot-v0.9.17", default-features = false } +pallet-precompile-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-3.2.1/polkadot-v0.9.17", default-features = false } +pallet-evm-precompile-sr25519 = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-evm-precompile-sr25519-1.0.0/polkadot-v0.9.17", default-features = false } [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17" } @@ -110,6 +116,8 @@ std = [ "pallet-block-reward/std", "pallet-custom-signatures/std", "pallet-dapps-staking/std", + "pallet-precompile-dapps-staking/std", + "pallet-evm-precompile-sr25519/std", "pallet-base-fee/std", "pallet-ethereum/std", "pallet-evm/std", @@ -153,4 +161,23 @@ runtime-benchmarks = [ 'pallet-timestamp/runtime-benchmarks', 'pallet-collective/runtime-benchmarks', "pallet-ethereum/runtime-benchmarks", + "pallet-dapps-staking/runtime-benchmarks", + "pallet-block-reward/runtime-benchmarks", +] +try-runtime = [ + "frame-try-runtime", + "frame-executive/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-aura/try-runtime", + "pallet-balances/try-runtime", + "pallet-block-reward/try-runtime", + "pallet-custom-signatures/try-runtime", + "pallet-dapps-staking/try-runtime", + "pallet-block-reward/try-runtime", + "pallet-sudo/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", ] diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index 292c930012..872c3dc6aa 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -7,7 +7,7 @@ use codec::{Decode, Encode}; use frame_support::{ construct_runtime, parameter_types, - traits::{Contains, Currency, FindAuthor, Imbalance, OnUnbalanced}, + traits::{Contains, Currency, FindAuthor, Get, Imbalance, OnRuntimeUpgrade, OnUnbalanced}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND}, DispatchClass, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, @@ -87,7 +87,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("astar"), impl_name: create_runtime_str!("astar"), authoring_version: 1, - spec_version: 11, + spec_version: 12, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -270,13 +270,13 @@ impl pallet_custom_signatures::Config for Runtime { parameter_types! { pub const BlockPerEra: BlockNumber = 1 * DAYS; - pub const RegisterDeposit: Balance = 100 * ASTR; - pub const DeveloperRewardPercentage: Perbill = Perbill::from_percent(1); - pub const MaxNumberOfStakersPerContract: u32 = 512; + pub const RegisterDeposit: Balance = 1000 * ASTR; + pub const MaxNumberOfStakersPerContract: u32 = 16384; pub const MinimumStakingAmount: Balance = 500 * ASTR; pub const MinimumRemainingAmount: Balance = 1 * ASTR; - pub const HistoryDepth: u32 = 14; - pub const BonusEraDuration: u32 = 0; + pub const MaxEraStakeValues: u32 = 5; + pub const MaxUnlockingChunks: u32 = 4; + pub const UnbondingPeriod: u32 = 10; } impl pallet_dapps_staking::Config for Runtime { @@ -284,15 +284,15 @@ impl pallet_dapps_staking::Config for Runtime { type BlockPerEra = BlockPerEra; type SmartContract = SmartContract; type RegisterDeposit = RegisterDeposit; - type DeveloperRewardPercentage = DeveloperRewardPercentage; type Event = Event; type WeightInfo = weights::pallet_dapps_staking::WeightInfo; type MaxNumberOfStakersPerContract = MaxNumberOfStakersPerContract; type MinimumStakingAmount = MinimumStakingAmount; type PalletId = DappsStakingPalletId; + type MaxUnlockingChunks = MaxUnlockingChunks; + type UnbondingPeriod = UnbondingPeriod; type MinimumRemainingAmount = MinimumRemainingAmount; - type HistoryDepth = HistoryDepth; - type BonusEraDuration = BonusEraDuration; + type MaxEraStakeValues = MaxEraStakeValues; } /// Multi-VM pointer to smart contract instance. @@ -433,18 +433,25 @@ impl OnUnbalanced for ToStakingPot { } } -pub struct OnBlockReward; -impl OnUnbalanced for OnBlockReward { - fn on_nonzero_unbalanced(amount: NegativeImbalance) { - let (dapps, maintain) = amount.ration(50, 50); - // dapp staking block reward - DappsStaking::on_unbalanced(dapps); - - let (treasury, collators) = maintain.ration(40, 10); - // treasury slice of block reward - Balances::resolve_creating(&TreasuryPalletId::get().into_account(), treasury); - // collators block reward - ToStakingPot::on_unbalanced(collators); +pub struct DappsStakingTvlProvider(); +impl Get for DappsStakingTvlProvider { + fn get() -> Balance { + DappsStaking::tvl() + } +} + +pub struct BeneficiaryPayout(); +impl pallet_block_reward::BeneficiaryPayout for BeneficiaryPayout { + fn treasury(reward: NegativeImbalance) { + Balances::resolve_creating(&TreasuryPalletId::get().into_account(), reward); + } + + fn collators(reward: NegativeImbalance) { + ToStakingPot::on_unbalanced(reward); + } + + fn dapps_staking(stakers: NegativeImbalance, dapps: NegativeImbalance) { + DappsStaking::rewards(stakers, dapps) } } @@ -454,8 +461,11 @@ parameter_types! { impl pallet_block_reward::Config for Runtime { type Currency = Balances; - type OnBlockReward = OnBlockReward; + type DappsStakingTvlProvider = DappsStakingTvlProvider; + type BeneficiaryPayout = BeneficiaryPayout; type RewardAmount = RewardAmount; + type Event = Event; + type WeightInfo = pallet_block_reward::weights::SubstrateWeight; } parameter_types! { @@ -676,8 +686,8 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 30, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 31, Vesting: pallet_vesting::{Pallet, Call, Storage, Config, Event} = 32, - BlockReward: pallet_block_reward::{Pallet} = 33, DappsStaking: pallet_dapps_staking::{Pallet, Call, Storage, Event} = 34, + BlockReward: pallet_block_reward::{Pallet, Call, Storage, Config, Event} = 35, Authorship: pallet_authorship::{Pallet, Call, Storage, Inherent} = 40, CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event, Config} = 41, @@ -741,8 +751,47 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, + (FestivalReset,), >; +pub struct FestivalReset; +impl OnRuntimeUpgrade for FestivalReset { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + pallet_dapps_staking::migrations::festival_end::pre_migrate::() + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + // TODO: discuss these params on sync & with community + let mut reward_config = pallet_block_reward::RewardDistributionConfig { + base_treasury_percent: Perbill::from_percent(40), + base_staker_percent: Perbill::from_rational(495u32, 1000u32), + dapps_percent: Perbill::from_rational(5u32, 1000u32), + collators_percent: Perbill::from_percent(10), + adjustable_percent: Perbill::from_percent(0), + ideal_dapps_staking_tvl: Perbill::from_percent(0), + }; + // This HAS to be tested prior to update - we need to ensure that config is consistent + #[cfg(feature = "try-runtime")] + assert!(reward_config.is_consistent()); + + // This should never execute but we need to have code in place that ensures config is consistent + if !reward_config.is_consistent() { + reward_config = Default::default(); + } + pallet_block_reward::RewardDistributionConfigStorage::::put(reward_config); + + pallet_dapps_staking::migrations::festival_end::on_runtime_upgrade::( + MAXIMUM_BLOCK_WEIGHT / 5, + ) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + pallet_dapps_staking::migrations::festival_end::post_migrate::() + } +} + impl fp_self_contained::SelfContainedCall for Call { type SignedInfo = H160; @@ -1041,14 +1090,17 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(_extra: bool) -> ( + fn benchmark_metadata(extra: bool) -> ( Vec, Vec, ) { - use frame_benchmarking::BenchmarkList; + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; - let list = Vec::::new(); + let mut list = Vec::::new(); + + list_benchmark!(list, extra, pallet_dapps_staking, DappsStaking); + list_benchmark!(list, extra, pallet_block_reward, BlockReward); let storage_info = AllPalletsWithSystem::storage_info(); @@ -1080,11 +1132,25 @@ impl_runtime_apis! { add_benchmark!(params, batches, frame_system, SystemBench::); add_benchmark!(params, batches, pallet_balances, Balances); add_benchmark!(params, batches, pallet_timestamp, Timestamp); + add_benchmark!(params, batches, pallet_dapps_staking, DappsStaking); + add_benchmark!(params, batches, pallet_block_reward, BlockReward); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) } } + + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> (Weight, Weight) { + let weight = Executive::try_runtime_upgrade().unwrap(); + (weight, RuntimeBlockWeights::get().max_block) + } + + fn execute_block_no_check(block: Block) -> Weight { + Executive::execute_block_no_check(block) + } + } } struct CheckInherents; diff --git a/runtime/astar/src/precompiles.rs b/runtime/astar/src/precompiles.rs index 26180544cf..fa9d2dc301 100644 --- a/runtime/astar/src/precompiles.rs +++ b/runtime/astar/src/precompiles.rs @@ -2,8 +2,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -use codec::Decode; -use frame_support::dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo}; use pallet_evm::{Context, Precompile, PrecompileResult, PrecompileSet}; use pallet_evm_precompile_blake2::Blake2F; use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; @@ -12,6 +10,8 @@ use pallet_evm_precompile_ed25519::Ed25519Verify; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_sha3fips::Sha3FIPS256; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; +use pallet_evm_precompile_sr25519::Sr25519Precompile; +use pallet_precompile_dapps_staking::DappsStakingWrapper; use sp_core::H160; use sp_std::fmt::Debug; use sp_std::marker::PhantomData; @@ -28,7 +28,7 @@ impl AstarNetworkPrecompiles { /// Return all addresses that contain precompiles. This can be used to populate dummy code /// under the precompile. pub fn used_addresses() -> impl Iterator { - sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 1024, 1025, 1026, 1027, 20480] + sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 1024, 1025, 1026, 1027, 20481, 20482] .into_iter() .map(|x| hash(x)) } @@ -40,8 +40,8 @@ impl AstarNetworkPrecompiles { impl PrecompileSet for AstarNetworkPrecompiles where R: pallet_evm::Config, - ::Origin: From>, - R::Call: Dispatchable + GetDispatchInfo + Decode, + Dispatch: Precompile, + DappsStakingWrapper: Precompile, { fn execute( &self, @@ -76,6 +76,14 @@ where input, target_gas, context, is_static, )), // Astar precompiles (starts from 0x5000): + // DappStaking 0x5001 + a if a == hash(20481) => Some(DappsStakingWrapper::::execute( + input, target_gas, context, is_static, + )), + // Sr25519 0x5002 + a if a == hash(20482) => Some(Sr25519Precompile::::execute( + input, target_gas, context, is_static, + )), // Default _ => None, } diff --git a/runtime/astar/src/weights/pallet_dapps_staking.rs b/runtime/astar/src/weights/pallet_dapps_staking.rs index 4076574eb6..a1a5962e2e 100644 --- a/runtime/astar/src/weights/pallet_dapps_staking.rs +++ b/runtime/astar/src/weights/pallet_dapps_staking.rs @@ -36,80 +36,119 @@ use sp_std::marker::PhantomData; /// Weight functions for pallet_dapps_staking. pub struct WeightInfo(PhantomData); impl pallet_dapps_staking::WeightInfo for WeightInfo { + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking RegisteredDevelopers (r:1 w:1) // Storage: DappsStaking RegisteredDapps (r:1 w:1) // Storage: DappsStaking PreApprovalIsEnabled (r:1 w:0) fn register() -> Weight { - (68_206_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) + (32_139_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: DappsStaking RegisteredDevelopers (r:1 w:1) + // Storage: DappsStaking PalletDisabled (r:1 w:0) + // Storage: DappsStaking RegisteredDapps (r:1 w:1) // Storage: DappsStaking CurrentEra (r:1 w:0) - // Storage: DappsStaking ContractEraStake (r:3 w:1) - // Storage: DappsStaking EraRewardsAndStakes (r:1 w:1) // Storage: System Account (r:1 w:1) - // Storage: DappsStaking Ledger (r:25 w:25) - // Storage: Balances Locks (r:25 w:25) - fn unregister(n: u32, ) -> Weight { - (417_315_000 as Weight) - // Standard Error: 370_000 - .saturating_add((43_644_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) + fn unregister() -> Weight { + (31_929_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: DappsStaking PalletDisabled (r:1 w:0) + // Storage: DappsStaking RegisteredDapps (r:1 w:0) + // Storage: DappsStaking StakersInfo (r:1 w:1) + // Storage: DappsStaking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: DappsStaking CurrentEra (r:1 w:0) + // Storage: DappsStaking GeneralEraInfo (r:1 w:1) + fn withdraw_from_unregistered() -> Weight { + (46_667_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) } + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking PreApprovalIsEnabled (r:0 w:1) fn enable_developer_pre_approval() -> Weight { - (3_093_000 as Weight) + (2_745_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking PreApprovedDevelopers (r:1 w:1) fn developer_pre_approval() -> Weight { - (10_097_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + (5_320_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking RegisteredDapps (r:1 w:0) - // Storage: DappsStaking RegisteredDevelopers (r:1 w:0) // Storage: DappsStaking Ledger (r:1 w:1) // Storage: DappsStaking CurrentEra (r:1 w:0) // Storage: DappsStaking ContractEraStake (r:1 w:1) - // Storage: DappsStaking EraRewardsAndStakes (r:1 w:1) + // Storage: DappsStaking StakersInfo (r:1 w:1) + // Storage: DappsStaking GeneralEraInfo (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond_and_stake() -> Weight { - (351_300_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + (133_638_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) } + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking RegisteredDapps (r:1 w:0) - // Storage: DappsStaking RegisteredDevelopers (r:1 w:0) + // Storage: DappsStaking StakersInfo (r:1 w:1) // Storage: DappsStaking CurrentEra (r:1 w:0) - // Storage: DappsStaking ContractEraStake (r:3 w:1) + // Storage: DappsStaking ContractEraStake (r:1 w:1) + // Storage: DappsStaking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: DappsStaking GeneralEraInfo (r:1 w:1) + fn unbond_and_unstake() -> Weight { + (134_480_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking Ledger (r:1 w:1) + // Storage: DappsStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) - // Storage: DappsStaking EraRewardsAndStakes (r:1 w:1) - fn unbond_unstake_and_withdraw() -> Weight { - (379_690_000 as Weight) - .saturating_add(T::DbWeight::get().reads(9 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + // Storage: DappsStaking GeneralEraInfo (r:1 w:1) + fn withdraw_unbonded() -> Weight { + (114_252_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: DappsStaking PalletDisabled (r:1 w:0) + // Storage: DappsStaking StakersInfo (r:1 w:1) + // Storage: DappsStaking RegisteredDapps (r:1 w:0) + // Storage: DappsStaking CurrentEra (r:1 w:0) + // Storage: DappsStaking ContractEraStake (r:1 w:0) + // Storage: DappsStaking GeneralEraInfo (r:1 w:0) + fn claim_staker() -> Weight { + (36_748_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking RegisteredDapps (r:1 w:0) // Storage: DappsStaking CurrentEra (r:1 w:0) // Storage: DappsStaking ContractEraStake (r:1 w:1) - // Storage: DappsStaking EraRewardsAndStakes (r:1 w:0) - // Storage: Balances TotalIssuance (r:1 w:1) - fn claim(n: u32, ) -> Weight { - (80_743_000 as Weight) - // Standard Error: 30_000 - .saturating_add((9_858_000 as Weight).saturating_mul(n as Weight)) + // Storage: DappsStaking GeneralEraInfo (r:1 w:0) + fn claim_dapp() -> Weight { + (31_619_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + // Storage: DappsStaking PalletDisabled (r:1 w:0) // Storage: DappsStaking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (3_082_000 as Weight) + (2_815_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: DappsStaking PalletDisabled (r:1 w:1) + fn maintenance_mode() -> Weight { + (10_970_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index 4fd068f4d5..6cf13bdd66 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "local-runtime" -version = "3.18.0" +version = "3.19.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs" diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 56fe8ecb98..93be529ffe 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shibuya-runtime" -version = "3.18.0" +version = "3.19.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs" diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index d6a1e81d34..54970e2ecc 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shiden-runtime" -version = "3.18.0" +version = "3.19.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs"