From 08c5843f01de89fa227aeb20ca8c2d6771426d31 Mon Sep 17 00:00:00 2001 From: Dinonard <3002868+Dinonard@users.noreply.github.com> Date: Tue, 1 Feb 2022 11:09:33 +0100 Subject: [PATCH] Unbonding period for Shiden (#561) * Unbonding period for Shiden * Local runtime version bump --- Cargo.lock | 12 ++--- bin/collator/Cargo.toml | 2 +- runtime/astar/Cargo.toml | 2 +- runtime/local/Cargo.toml | 2 +- runtime/shibuya/Cargo.toml | 2 +- runtime/shiden/Cargo.toml | 4 +- runtime/shiden/src/lib.rs | 30 +++++++++++- .../src/weights/pallet_dapps_staking.rs | 46 +++++++++++-------- 8 files changed, 67 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c1838d2e6a..fc863d055f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,7 +162,7 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "astar-collator" -version = "3.5.0" +version = "3.6.0" dependencies = [ "astar-runtime", "async-trait", @@ -248,7 +248,7 @@ dependencies = [ [[package]] name = "astar-runtime" -version = "3.5.0" +version = "3.6.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -4262,7 +4262,7 @@ checksum = "687387ff42ec7ea4f2149035a5675fedb675d26f98db90a1846ac63d3addb5f5" [[package]] name = "local-runtime" -version = "3.5.0" +version = "3.6.0" dependencies = [ "evm", "fp-rpc", @@ -9305,7 +9305,7 @@ dependencies = [ [[package]] name = "shibuya-runtime" -version = "3.5.0" +version = "3.6.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -9373,7 +9373,7 @@ dependencies = [ [[package]] name = "shiden-runtime" -version = "3.5.0" +version = "3.6.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -9398,7 +9398,7 @@ dependencies = [ "pallet-collator-selection 3.0.0 (git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.13)", "pallet-collective", "pallet-custom-signatures", - "pallet-dapps-staking 1.1.2", + "pallet-dapps-staking 2.0.0", "pallet-ethereum", "pallet-evm", "pallet-evm-precompile-bn128", diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index e4c69ecc0b..3fb621af73 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-collator" -version = "3.5.0" +version = "3.6.0" authors = ["Stake Technologies "] description = "Astar collator implementation in Rust." build = "build.rs" diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 93e0be8147..1358295e82 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-runtime" -version = "3.5.0" +version = "3.6.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs" diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index 394e01ba9b..7a1dddcbba 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "local-runtime" -version = "3.5.0" +version = "3.6.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs" diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 9af6e9da92..be20acabd8 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shibuya-runtime" -version = "3.5.0" +version = "3.6.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs" diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index ad2e025ace..8fc456c5fd 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shiden-runtime" -version = "3.5.0" +version = "3.6.0" authors = ["Stake Technologies "] edition = "2018" build = "build.rs" @@ -82,7 +82,7 @@ try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "p pallet-block-reward = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-block-reward-3.0.0/polkadot-0.9.13", default-features = false } pallet-custom-signatures = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-custom-signatures-4.3.0/polkadot-0.9.13", default-features = false } pallet-precompile-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-precompile-staking-0.2.1/polkadot-0.9.13", default-features = false } -pallet-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-1.1.2/polkadot-0.9.13", default-features = false } +pallet-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-2.0.0/polkadot-0.9.13", default-features = false } [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index adddec4460..aa6e172f22 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/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, Imbalance, OnRuntimeUpgrade, OnUnbalanced}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND}, DispatchClass, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, @@ -86,7 +86,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("shiden"), impl_name: create_runtime_str!("shiden"), authoring_version: 1, - spec_version: 35, + spec_version: 36, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -274,6 +274,8 @@ parameter_types! { pub const MinimumRemainingAmount: Balance = 1 * SDN; pub const HistoryDepth: u32 = 14; pub const BonusEraDuration: u32 = 10; + pub const MaxUnlockingChunks: u32 = 5; + pub const UnbondingPeriod: u32 = 5; } impl pallet_dapps_staking::Config for Runtime { @@ -290,6 +292,8 @@ impl pallet_dapps_staking::Config for Runtime { type MinimumRemainingAmount = MinimumRemainingAmount; type HistoryDepth = HistoryDepth; type BonusEraDuration = BonusEraDuration; + type MaxUnlockingChunks = MaxUnlockingChunks; + type UnbondingPeriod = UnbondingPeriod; } /// Multi-VM pointer to smart contract instance. @@ -740,8 +744,30 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPallets, + (DappsStakingMigrationV2,), >; +// Migration for supporting unbonding period in dapps staking. +pub struct DappsStakingMigrationV2; + +impl OnRuntimeUpgrade for DappsStakingMigrationV2 { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + pallet_dapps_staking::migrations::v2::stateful_migrate::( + RuntimeBlockWeights::get().max_block / 5 * 3, + ) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + pallet_dapps_staking::migrations::v2::pre_migrate::() + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + pallet_dapps_staking::migrations::v2::post_migrate::() + } +} + impl fp_self_contained::SelfContainedCall for Call { type SignedInfo = H160; diff --git a/runtime/shiden/src/weights/pallet_dapps_staking.rs b/runtime/shiden/src/weights/pallet_dapps_staking.rs index 4076574eb6..293756a996 100644 --- a/runtime/shiden/src/weights/pallet_dapps_staking.rs +++ b/runtime/shiden/src/weights/pallet_dapps_staking.rs @@ -2,14 +2,14 @@ //! Autogenerated weights for `pallet_dapps_staking` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-25, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-testnet"), DB CACHE: 128 +//! DATE: 2021-11-30, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 128 // Executed Command: // ./target/release/astar-collator // benchmark // --chain -// shiden-testnet +// shiden-dev // --execution // wasm // --wasm-execution @@ -33,14 +33,14 @@ use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions for pallet_dapps_staking. +/// Weight functions for `pallet_dapps_staking`. pub struct WeightInfo(PhantomData); impl pallet_dapps_staking::WeightInfo for WeightInfo { // 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) + (39_297_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -52,9 +52,9 @@ impl pallet_dapps_staking::WeightInfo for WeightInfo // 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)) + (0 as Weight) + // Standard Error: 146_000 + .saturating_add((29_171_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)) @@ -62,12 +62,12 @@ impl pallet_dapps_staking::WeightInfo for WeightInfo } // Storage: DappsStaking PreApprovalIsEnabled (r:0 w:1) fn enable_developer_pre_approval() -> Weight { - (3_093_000 as Weight) + (1_694_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: DappsStaking PreApprovedDevelopers (r:1 w:1) fn developer_pre_approval() -> Weight { - (10_097_000 as Weight) + (5_210_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -79,37 +79,45 @@ impl pallet_dapps_staking::WeightInfo for WeightInfo // Storage: DappsStaking EraRewardsAndStakes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond_and_stake() -> Weight { - (351_300_000 as Weight) + (226_591_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: DappsStaking RegisteredDapps (r:1 w:0) // Storage: DappsStaking RegisteredDevelopers (r:1 w:0) // 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 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)) + fn unbond_and_unstake() -> Weight { + (221_721_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } + // Storage: DappsStaking Ledger (r:1 w:1) + // Storage: DappsStaking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + fn withdraw_unbonded() -> Weight { + (82_365_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } // 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)) + (70_778_000 as Weight) + // Standard Error: 15_000 + .saturating_add((5_258_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: DappsStaking ForceEra (r:0 w:1) fn force_new_era() -> Weight { - (3_082_000 as Weight) + (1_854_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } }