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

Deploy pallet-parameters to rococo and fix dynamic_params name expand #4006

Merged
merged 11 commits into from
Apr 13, 2024
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions polkadot/runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pallet-mmr = { path = "../../../substrate/frame/merkle-mountain-range", default-
pallet-multisig = { path = "../../../substrate/frame/multisig", default-features = false }
pallet-nis = { path = "../../../substrate/frame/nis", default-features = false }
pallet-offences = { path = "../../../substrate/frame/offences", default-features = false }
pallet-parameters = { path = "../../../substrate/frame/parameters", default-features = false }
pallet-preimage = { path = "../../../substrate/frame/preimage", default-features = false }
pallet-proxy = { path = "../../../substrate/frame/proxy", default-features = false }
pallet-ranked-collective = { path = "../../../substrate/frame/ranked-collective", default-features = false }
Expand Down Expand Up @@ -164,6 +165,7 @@ std = [
"pallet-multisig/std",
"pallet-nis/std",
"pallet-offences/std",
"pallet-parameters/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-ranked-collective/std",
Expand Down Expand Up @@ -239,6 +241,7 @@ runtime-benchmarks = [
"pallet-multisig/runtime-benchmarks",
"pallet-nis/runtime-benchmarks",
"pallet-offences/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
Expand Down Expand Up @@ -294,6 +297,7 @@ try-runtime = [
"pallet-multisig/try-runtime",
"pallet-nis/try-runtime",
"pallet-offences/try-runtime",
"pallet-parameters/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-ranked-collective/try-runtime",
Expand Down
39 changes: 37 additions & 2 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use beefy_primitives::{
ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature},
mmr::{BeefyDataProvider, MmrLeafVersion},
};
use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params};
use pallet_nis::WithMaximumOf;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::{
Expand Down Expand Up @@ -234,6 +235,32 @@ impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
}
}

/// Dynamic params that can be adjusted at runtime.
#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
pub mod dynamic_params {
use super::*;

#[dynamic_pallet_params]
#[codec(index = 0)]
pub mod nis {
use super::*;

/// The target of active total issuance fot the non-interactive-staking pallet.
#[codec(index = 0)]
pub static Target: Perquintill = Perquintill::zero();
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[cfg(feature = "runtime-benchmarks")]
impl Default for RuntimeParameters {
fn default() -> Self {
RuntimeParameters::Nis(dynamic_params::nis::Parameters::Target(
dynamic_params::nis::Target,
Some(Perquintill::from_percent(10)),
))
}
}

impl pallet_scheduler::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -1128,7 +1155,6 @@ parameter_types! {
pub const IntakePeriod: BlockNumber = 5 * MINUTES;
pub MaxIntakeWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 10;
pub const ThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
pub storage NisTarget: Perquintill = Perquintill::zero();
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
}

Expand All @@ -1142,7 +1168,7 @@ impl pallet_nis::Config for Runtime {
type CounterpartAmount = WithMaximumOf<ConstU128<21_000_000_000_000_000_000u128>>;
type Deficit = (); // Mint
type IgnoredIssuance = ();
type Target = NisTarget;
type Target = dynamic_params::nis::Target;
type PalletId = NisPalletId;
type QueueCount = ConstU32<300>;
type MaxQueueLen = ConstU32<1000>;
Expand All @@ -1156,6 +1182,13 @@ impl pallet_nis::Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
}

impl pallet_parameters::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeParameters = RuntimeParameters;
type AdminOrigin = EnsureRoot<AccountId>;
type WeightInfo = weights::pallet_parameters::WeightInfo<Runtime>;
}

parameter_types! {
pub BeefySetIdSessionEntries: u32 = BondingDuration::get() * SessionsPerEra::get();
}
Expand Down Expand Up @@ -1281,6 +1314,7 @@ construct_runtime! {
Timestamp: pallet_timestamp = 2,
Indices: pallet_indices = 3,
Balances: pallet_balances = 4,
Parameters: pallet_parameters = 6,
TransactionPayment: pallet_transaction_payment = 33,

// Consensus support.
Expand Down Expand Up @@ -1621,6 +1655,7 @@ mod benches {
[pallet_indices, Indices]
[pallet_message_queue, MessageQueue]
[pallet_multisig, Multisig]
[pallet_parameters, Parameters]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_ranked_collective, FellowshipCollective]
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/rococo/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod pallet_indices;
pub mod pallet_message_queue;
pub mod pallet_multisig;
pub mod pallet_nis;
pub mod pallet_parameters;
pub mod pallet_preimage;
pub mod pallet_proxy;
pub mod pallet_ranked_collective;
Expand Down
63 changes: 63 additions & 0 deletions polkadot/runtime/rococo/src/weights/pallet_parameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot 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.

// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Autogenerated weights for `pallet_parameters`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-04-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-anb7yjbi-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024

// Executed Command:
// target/production/polkadot
// benchmark
// pallet
// --steps=50
// --repeat=20
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
// --pallet=pallet_parameters
// --chain=rococo-dev
// --header=./polkadot/file_header.txt
// --output=./polkadot/runtime/rococo/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;

/// Weight functions for `pallet_parameters`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_parameters::WeightInfo for WeightInfo<T> {
/// Storage: `Parameters::Parameters` (r:1 w:1)
/// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`)
fn set_parameter() -> Weight {
// Proof Size summary in bytes:
// Measured: `4`
// Estimated: `3493`
// Minimum execution time: 6_937_000 picoseconds.
Weight::from_parts(7_242_000, 0)
.saturating_add(Weight::from_parts(0, 3493))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}
19 changes: 19 additions & 0 deletions prdoc/pr_4006.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "Deploy pallet-parameters to rococo and fix dynamic_params name expand"

doc:
- audience: Runtime Dev
description: |
Fix the expanded names of `dynamic_params` to not remove suffix "s".

Also deploy the parameters pallet to the rococo-runtime.

crates:
- name: frame-support-procedural
bump: major
- name: rococo-runtime
bump: major
- name: pallet-parameters
bump: patch
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for DynamicParamet
frame_system::ensure_root(origin.clone()).map_err(|_| origin)?;
return Ok(())
},
RuntimeParametersKey::Contract(_) => {
RuntimeParametersKey::Contracts(_) => {
frame_system::ensure_root(origin.clone()).map_err(|_| origin)?;
return Ok(())
},
Expand Down
17 changes: 17 additions & 0 deletions substrate/frame/parameters/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

#![cfg(any(test, feature = "runtime-benchmarks"))]
#![allow(non_snake_case)]

//! Mock runtime that configures the `pallet_example_basic` to use dynamic params for testing.

Expand Down Expand Up @@ -66,6 +67,20 @@ pub mod dynamic_params {
#[codec(index = 0)]
pub static Key3: u128 = 4;
}

#[dynamic_pallet_params]
#[codec(index = 2)]
pub mod nis {
#[codec(index = 0)]
pub static Target: u64 = 0;
}

#[dynamic_pallet_params]
#[codec(index = 3)]
pub mod somE_weird_SPElLInG_s {
#[codec(index = 0)]
pub static V: u64 = 0;
}
}

#[docify::export(benchmarking_default)]
Expand Down Expand Up @@ -98,6 +113,8 @@ mod custom_origin {
}

match key {
RuntimeParametersKey::SomEWeirdSPElLInGS(_) |
RuntimeParametersKey::Nis(_) |
RuntimeParametersKey::Pallet1(_) => ensure_root(origin.clone()),
RuntimeParametersKey::Pallet2(_) => ensure_signed(origin.clone()).map(|_| ()),
}
Expand Down
8 changes: 5 additions & 3 deletions substrate/frame/support/procedural/src/dynamic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl ToTokens for DynamicParamModAttr {
let mut quoted_enum = quote! {};
for m in self.inner_mods() {
let aggregate_name =
syn::Ident::new(&m.ident.to_string().to_class_case(), m.ident.span());
syn::Ident::new(&m.ident.to_string().to_pascal_case(), m.ident.span());
let mod_name = &m.ident;

let mut attrs = m.attrs.clone();
Expand Down Expand Up @@ -222,8 +222,10 @@ impl ToTokens for DynamicPalletParamAttr {
let (params_mod, parameter_pallet, runtime_params) =
(&self.inner_mod, &self.meta.parameter_pallet, &self.meta.runtime_params);

let aggregate_name =
syn::Ident::new(&params_mod.ident.to_string().to_class_case(), params_mod.ident.span());
let aggregate_name = syn::Ident::new(
&params_mod.ident.to_string().to_pascal_case(),
params_mod.ident.span(),
);
let (mod_name, vis) = (&params_mod.ident, &params_mod.vis);
let statics = self.statics();

Expand Down
Loading