Skip to content

Commit

Permalink
Deploy pallet-parameters to rococo and fix dynamic_params name expa…
Browse files Browse the repository at this point in the history
…nd (paritytech#4006)

Changes:
- Add pallet-parameters to Rococo to configure the NIS and preimage
pallet.
- Fix names of expanded dynamic params. Apparently, `to_class_case`
removes suffix `s`, and `Nis` becomes `Ni` 😑. Now using
`to_pascal_case`.

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: Alessandro Siniscalchi <[email protected]>
Co-authored-by: Kian Paimani <[email protected]>
Co-authored-by: command-bot <>
  • Loading branch information
3 people authored Apr 13, 2024
1 parent 1bca825 commit 30c58fa
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 14 deletions.
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
97 changes: 87 additions & 10 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 @@ -73,9 +74,10 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, Contains, EitherOf, EitherOfDiverse, EverythingBut,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage,
ProcessMessageError, StorageMapShim, WithdrawReasons,
fungible::HoldConsideration, Contains, EitherOf, EitherOfDiverse, EnsureOrigin,
EnsureOriginWithArg, EverythingBut, InstanceFilter, KeyOwnerProofSystem,
LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim,
WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -234,6 +236,72 @@ 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::*;

#[codec(index = 0)]
pub static Target: Perquintill = Perquintill::zero();

#[codec(index = 1)]
pub static MinBid: Balance = 100 * UNITS;
}

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

#[codec(index = 0)]
pub static BaseDeposit: Balance = deposit(2, 64);

#[codec(index = 1)]
pub static ByteDeposit: Balance = deposit(0, 1);
}
}

#[cfg(feature = "runtime-benchmarks")]
impl Default for RuntimeParameters {
fn default() -> Self {
RuntimeParameters::Preimage(dynamic_params::preimage::Parameters::BaseDeposit(
dynamic_params::preimage::BaseDeposit,
Some(1u32.into()),
))
}
}

/// Defines what origin can modify which dynamic parameters.
pub struct DynamicParameterOrigin;
impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for DynamicParameterOrigin {
type Success = ();

fn try_origin(
origin: RuntimeOrigin,
key: &RuntimeParametersKey,
) -> Result<Self::Success, RuntimeOrigin> {
use crate::{dynamic_params::*, governance::*, RuntimeParametersKey::*};

match key {
Nis(nis::ParametersKey::MinBid(_)) => StakingAdmin::ensure_origin(origin.clone()),
Nis(nis::ParametersKey::Target(_)) => GeneralAdmin::ensure_origin(origin.clone()),
Preimage(_) => frame_system::ensure_root(origin.clone()),
}
.map_err(|_| origin)
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_key: &RuntimeParametersKey) -> Result<RuntimeOrigin, ()> {
// Provide the origin for the parameter returned by `Default`:
Ok(RuntimeOrigin::root())
}
}

impl pallet_scheduler::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
Expand All @@ -250,8 +318,6 @@ impl pallet_scheduler::Config for Runtime {
}

parameter_types! {
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
pub const PreimageByteDeposit: Balance = deposit(0, 1);
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
}

Expand All @@ -264,7 +330,11 @@ impl pallet_preimage::Config for Runtime {
AccountId,
Balances,
PreimageHoldReason,
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
LinearStoragePrice<
dynamic_params::preimage::BaseDeposit,
dynamic_params::preimage::ByteDeposit,
Balance,
>,
>;
}

Expand Down Expand Up @@ -1128,12 +1198,10 @@ impl pallet_balances::Config<NisCounterpartInstance> for Runtime {

parameter_types! {
pub const NisBasePeriod: BlockNumber = 30 * DAYS;
pub const MinBid: Balance = 100 * UNITS;
pub MinReceipt: Perquintill = Perquintill::from_rational(1u64, 10_000_000u64);
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 @@ -1147,13 +1215,13 @@ 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>;
type FifoQueueLen = ConstU32<250>;
type BasePeriod = NisBasePeriod;
type MinBid = MinBid;
type MinBid = dynamic_params::nis::MinBid;
type MinReceipt = MinReceipt;
type IntakePeriod = IntakePeriod;
type MaxIntakeWeight = MaxIntakeWeight;
Expand All @@ -1163,6 +1231,13 @@ impl pallet_nis::Config for Runtime {
type BenchmarkSetup = ();
}

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

parameter_types! {
pub BeefySetIdSessionEntries: u32 = BondingDuration::get() * SessionsPerEra::get();
}
Expand Down Expand Up @@ -1291,6 +1366,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 @@ -1631,6 +1707,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 @@ -2198,7 +2198,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

0 comments on commit 30c58fa

Please sign in to comment.