Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds staking-rococo cumulus runtime #2673

Merged
merged 5 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ members = [
"cumulus/parachains/runtimes/collectives/collectives-westend",
"cumulus/parachains/runtimes/contracts/contracts-rococo",
"cumulus/parachains/runtimes/glutton/glutton-westend",
"cumulus/parachains/runtimes/staking/staking-rococo",
"cumulus/parachains/runtimes/starters/seedling",
"cumulus/parachains/runtimes/starters/shell",
"cumulus/parachains/runtimes/test-utils",
Expand Down
77 changes: 77 additions & 0 deletions cumulus/parachains/chain-specs/staking-rococo.json

Large diffs are not rendered by default.

Empty file.
71 changes: 71 additions & 0 deletions cumulus/parachains/runtimes/staking/common/CARGO.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[package]
name = "staking-common"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
description = "Staking common utilities"
license = "Apache-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
log = { version = "0.4.20", default-features = false }
impl-trait-for-tuples = "0.2.2"

# Substrate
frame-support = { path = "../../../../../substrate/frame/support", default-features = false}
sp-api = { path = "../../../../../substrate/primitives/api", default-features = false}
sp-std = { path = "../../../../../substrate/primitives/std", default-features = false}
sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false}
sp-core = { path = "../../../../../substrate/primitives/core", default-features = false }
sp-staking = { path = "../../../../../substrate/primitives/staking", default-features = false, features=["serde"] }
pallet-staking = { path = "../../../../../substrate/frame/staking", default-features = false }
pallet-election-provider-multi-phase = { path = "../../../../../substrate/frame/election-provider-multi-phase", default-features = false }

# Polkadot
pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false}
xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false}
xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false}

# Cumulus
parachains-common = { path = "../../../common", default-features = false }
cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false }

[build-dependencies]
substrate-wasm-builder = { path = "../../../../../substrate/utils/wasm-builder" }

[features]
default = [ "std" ]
std = [
"codec/std",
"cumulus-primitives-core/std",
"frame-support/std",
"log/std",
"pallet-xcm/std",
"parachains-common/std",
"scale-info/std",
"sp-api/std",
"sp-runtime/std",
"sp-core/std",
"sp-std/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"sp-staking/std",
"pallet-staking/std",
"pallet-election-provider-multi-phase/std",
]

runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
]
64 changes: 64 additions & 0 deletions cumulus/parachains/runtimes/staking/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::traits::ConstU32;
use parachains_common::Balance;

/// The type used for currency conversion.
///
/// This must only be used as long as the balance type is `u128`.
pub type CurrencyToVote = sp_staking::currency_to_vote::U128CurrencyToVote;

/// Convert a balance to an unsigned 256-bit number, use in nomination pools.
pub struct BalanceToU256;
impl sp_runtime::traits::Convert<Balance, sp_core::U256> for BalanceToU256 {
fn convert(n: Balance) -> sp_core::U256 {
n.into()
}
}

/// Convert an unsigned 256-bit number to balance, use in nomination pools.
pub struct U256ToBalance;
impl sp_runtime::traits::Convert<sp_core::U256, Balance> for U256ToBalance {
fn convert(n: sp_core::U256) -> Balance {
use frame_support::traits::Defensive;
n.try_into().defensive_unwrap_or(Balance::MAX)
}
}

/// A reasonable benchmarking config for staking pallet.
pub struct StakingBenchmarkingConfig;
impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig {
type MaxValidators = ConstU32<1000>;
type MaxNominators = ConstU32<1000>;
}

/// The numbers configured here could always be more than the the maximum limits of staking pallet
/// to ensure election snapshot will not run out of memory. For now, we set them to smaller values
/// since the staking is bounded and the weight pipeline takes hours for this single pallet.
pub struct BenchmarkConfig;
impl pallet_election_provider_multi_phase::BenchmarkingConfig for BenchmarkConfig {
const VOTERS: [u32; 2] = [1000, 2000];
const TARGETS: [u32; 2] = [500, 1000];
const ACTIVE_VOTERS: [u32; 2] = [500, 800];
const DESIRED_TARGETS: [u32; 2] = [200, 400];
const SNAPSHOT_MAXIMUM_VOTERS: u32 = 1000;
const MINER_MAXIMUM_VOTERS: u32 = 1000;
const MAXIMUM_TARGETS: u32 = 300;
}

pub type OnChainAccuracy = sp_runtime::Perbill;
Loading