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

[FRAME] Parameters pallet #2061

Merged
merged 62 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
8bdbbec
Import pallet from ORML
ggwpez Oct 26, 2023
2381a0b
Change everything
ggwpez Oct 27, 2023
c0a7538
Deploy to rococo
ggwpez Oct 27, 2023
ec974c6
Adds proc macros for dynamic params
gupnik Nov 6, 2023
f5fa37a
Adds attr support
gupnik Nov 6, 2023
b8099db
Merge branch 'master' of github.com:paritytech/polkadot-sdk into oty-…
gupnik Nov 10, 2023
5dad373
Try in kitchensink example pallet
ggwpez Nov 24, 2023
2c3043c
Fix macro
ggwpez Nov 24, 2023
b2cb9ff
fmt
ggwpez Nov 24, 2023
cc4dec1
Fixes parser
gupnik Nov 27, 2023
28d3f18
Cleanup and fixes
ggwpez Dec 4, 2023
188e393
Fixes
ggwpez Dec 5, 2023
2deb2ab
Remove old stuff
ggwpez Dec 5, 2023
04bde56
Merge remote-tracking branch 'origin/master' into oty-parameters-pallet
ggwpez Jan 8, 2024
811b023
fmt
ggwpez Jan 8, 2024
e48118b
Add ORML compatibility tests
ggwpez Jan 8, 2024
27c741c
Fork ORML traits
ggwpez Jan 8, 2024
777f4bc
Fix
ggwpez Jan 8, 2024
ad573f7
Merge remote-tracking branch 'origin/master' into oty-parameters-pallet
ggwpez Jan 25, 2024
4bdf258
fmt
ggwpez Jan 25, 2024
46230b1
Rename ORML traits
ggwpez Jan 25, 2024
65eb8c7
Remove ORML macros
ggwpez Jan 25, 2024
1a3c615
Add docs and remove old tests
ggwpez Jan 25, 2024
cabaed4
Add tests
ggwpez Jan 25, 2024
64146c3
Use explicit type
ggwpez Jan 25, 2024
db90aa5
Clippy
ggwpez Jan 25, 2024
436cf13
Add PrDoc
ggwpez Jan 25, 2024
d977599
Revert Rococo deployment - can be done later
ggwpez Jan 25, 2024
fae55cc
Update
ggwpez Jan 29, 2024
bb08742
Cleanup macros
ggwpez Jan 30, 2024
877ba5c
Fix features
ggwpez Jan 30, 2024
9a79aed
Merge remote-tracking branch 'origin/master' into oty-parameters-pallet
ggwpez Jan 30, 2024
c11a3db
No duplicate bench
ggwpez Jan 30, 2024
66ebbe3
Fixup
ggwpez Jan 31, 2024
f31cd80
Add benchmark
ggwpez Jan 31, 2024
d42412b
Fix kitchensink
ggwpez Feb 1, 2024
9968cdf
Clippy
ggwpez Feb 1, 2024
64e6d12
Merge remote-tracking branch 'origin/master' into oty-parameters-pallet
ggwpez Feb 1, 2024
4ce3862
Add error when index is missing
ggwpez Feb 1, 2024
15a1e28
Fix test
ggwpez Feb 1, 2024
fd69b6d
Update substrate/frame/parameters/src/lib.rs
ggwpez Feb 5, 2024
9832196
Fix prdoc
ggwpez Feb 5, 2024
5a3b67f
Rename to RuntimeParameters
ggwpez Feb 5, 2024
4fe37b6
Introduce default config
ggwpez Feb 5, 2024
19cee20
Deploy benchmarks for kitchensink
ggwpez Feb 5, 2024
f980bef
toml format
ggwpez Feb 5, 2024
9b5b4d2
Fix doc links
ggwpez Feb 5, 2024
b518928
Fix UI tests
ggwpez Feb 5, 2024
38aea42
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Feb 5, 2024
39fd233
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Feb 5, 2024
6096f08
Review fixes
ggwpez Feb 7, 2024
2ad0f6e
Rename AggregatedKey -> Key and Value
ggwpez Feb 7, 2024
e6d02b0
Review fixes
ggwpez Feb 7, 2024
2d68aba
Require RuntimeParameters: Default for benchmarks
ggwpez Feb 7, 2024
bbd2504
Linters
ggwpez Feb 7, 2024
095d245
Make compile
ggwpez Feb 7, 2024
b40bc32
Merge branch 'master' into oty-parameters-pallet
ggwpez Feb 7, 2024
aeb3ab6
Remove unused dep
ggwpez Feb 7, 2024
1669a7c
Merge remote-tracking branch 'origin/oty-parameters-pallet' into oty-…
ggwpez Feb 7, 2024
0d0ebb9
Merge branch 'master' into oty-parameters-pallet
ggwpez Feb 8, 2024
a696893
Fix and test renaming
ggwpez Feb 8, 2024
d63d07c
Merge remote-tracking branch 'origin/master' into oty-parameters-pallet
ggwpez Feb 8, 2024
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
21 changes: 21 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 @@ -366,6 +366,7 @@ members = [
"substrate/frame/offences/benchmarking",
"substrate/frame/paged-list",
"substrate/frame/paged-list/fuzzer",
"substrate/frame/parameters",
"substrate/frame/preimage",
"substrate/frame/proxy",
"substrate/frame/ranked-collective",
Expand Down
14 changes: 14 additions & 0 deletions prdoc/pr_2061.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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: Add Parameters Pallet

doc:
- audience: Runtime Dev
description: |
Adds `pallet-parameters` that allows to have parameters for pallet configs that dynamically change at runtime. Allows to be permissioned on a per-key basis and is compatible with ORML macros.

crates:
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
- name: "pallet-parameters"
- name: "frame-support"
- name: "frame-support-procedural"
4 changes: 4 additions & 0 deletions substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pallet-vesting = { path = "../../../frame/vesting", default-features = false }
pallet-whitelist = { path = "../../../frame/whitelist", default-features = false }
pallet-tx-pause = { path = "../../../frame/tx-pause", default-features = false }
pallet-safe-mode = { path = "../../../frame/safe-mode", default-features = false }
pallet-parameters = { path = "../../../frame/parameters", default-features = false }

[build-dependencies]
substrate-wasm-builder = { path = "../../../utils/wasm-builder", optional = true }
Expand Down Expand Up @@ -209,6 +210,7 @@ std = [
"pallet-nomination-pools/std",
"pallet-offences-benchmarking?/std",
"pallet-offences/std",
"pallet-parameters/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-ranked-collective/std",
Expand Down Expand Up @@ -310,6 +312,7 @@ runtime-benchmarks = [
"pallet-nomination-pools/runtime-benchmarks",
"pallet-offences-benchmarking/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 @@ -386,6 +389,7 @@ try-runtime = [
"pallet-nis/try-runtime",
"pallet-nomination-pools/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: 84 additions & 13 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use frame_election_provider_support::{
use frame_support::{
construct_runtime, derive_impl,
dispatch::DispatchClass,
dynamic_params::{dynamic_pallet_params, dynamic_params},
genesis_builder_helper::{build_config, create_default_config},
instances::{Instance1, Instance2},
ord_parameter_types,
Expand All @@ -44,9 +45,9 @@ use frame_support::{
GetSalary, PayFromAccount,
},
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Contains, Currency,
EitherOfDiverse, EqualPrivilegeOnly, Imbalance, InsideBoth, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, LockIdentifier, Nothing, OnUnbalanced,
WithdrawReasons,
EitherOfDiverse, EnsureOriginWithArg, EqualPrivilegeOnly, Imbalance, InsideBoth,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, LockIdentifier, Nothing,
OnUnbalanced, WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -457,9 +458,6 @@ impl pallet_glutton::Config for Runtime {
}

parameter_types! {
pub const PreimageBaseDeposit: Balance = 1 * DOLLARS;
// One cent: $10,000 / MB
pub const PreimageByteDeposit: Balance = 1 * CENTS;
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
}

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

Expand Down Expand Up @@ -1324,9 +1326,6 @@ impl pallet_tips::Config for Runtime {
}

parameter_types! {
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerByte: Balance = deposit(0, 1);
pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
}
Expand All @@ -1344,9 +1343,9 @@ impl pallet_contracts::Config for Runtime {
/// change because that would break already deployed contracts. The `Call` structure itself
/// is not allowed to change the indices of existing pallets, too.
type CallFilter = Nothing;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type DefaultDepositLimit = DefaultDepositLimit;
type DepositPerItem = dynamic_params::contracts::DepositPerItem;
type DepositPerByte = dynamic_params::contracts::DepositPerByte;
type DefaultDepositLimit = dynamic_params::contracts::DefaultDepositLimit;
type CallStack = [pallet_contracts::Frame<Self>; 5];
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
Expand Down Expand Up @@ -2086,6 +2085,76 @@ impl pallet_mixnet::Config for Runtime {
type MinMixnodes = ConstU32<7>; // Low to allow small testing networks
}

/// Dynamic parameters that can be changed at runtime through the `pallet_parametes::set_parameter`.
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
pub mod dynamic_params {
use super::*;

#[dynamic_pallet_params]
#[codec(index = 0)]
pub mod storage {
/// Configures the base deposit of storing some data.
#[codec(index = 0)]
pub static BaseDeposit: Balance = 1 * DOLLARS;

/// Configures the per-byte deposit of storing some data.
#[codec(index = 1)]
pub static ByteDeposit: Balance = 1 * CENTS;
}

#[dynamic_pallet_params]
#[codec(index = 1)]
pub mod contracts {
#[codec(index = 0)]
pub static DepositPerItem: Balance = deposit(1, 0);

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

#[codec(index = 2)]
pub static DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
}
}

parameter_types! {
pub BenchmarkingDefault: RuntimeParameters = RuntimeParameters::Storage(dynamic_params::storage::Parameters::BaseDeposit(dynamic_params::storage::BaseDeposit, Some(1 * DOLLARS)));
}

pub struct DynamicParametersManagerOrigin;
impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for DynamicParametersManagerOrigin {
type Success = ();

fn try_origin(
origin: RuntimeOrigin,
key: &RuntimeParametersKey,
) -> Result<Self::Success, RuntimeOrigin> {
match key {
RuntimeParametersKey::Storage(_) => {
frame_system::ensure_root(origin.clone()).map_err(|_| origin)?;
return Ok(())
},
RuntimeParametersKey::Contract(_) => {
frame_system::ensure_root(origin.clone()).map_err(|_| origin)?;
return Ok(())
},
}
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_key: &RuntimeParametersKey) -> Result<RuntimeOrigin, ()> {
Err(())
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl pallet_parameters::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AdminOrigin = DynamicParametersManagerOrigin;
type WeightInfo = ();
type RuntimeParameters = RuntimeParameters;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkingDefault = BenchmarkingDefault;
}

construct_runtime!(
pub enum Runtime {
System: frame_system,
Expand Down Expand Up @@ -2167,6 +2236,7 @@ construct_runtime!(
Broker: pallet_broker,
TasksExample: pallet_example_tasks,
Mixnet: pallet_mixnet,
Parameters: pallet_parameters,
SkipFeelessPayment: pallet_skip_feeless_payment,
}
);
Expand Down Expand Up @@ -2286,6 +2356,7 @@ mod benches {
[pallet_elections_phragmen, Elections]
[pallet_fast_unstake, FastUnstake]
[pallet_nis, Nis]
[pallet_parameters, Parameters]
[pallet_grandpa, Grandpa]
[pallet_identity, Identity]
[pallet_im_online, ImOnline]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/examples/kitchensink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features =
log = { version = "0.4.17", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }

frame-support = { path = "../../support", default-features = false }
frame-support = { path = "../../support", default-features = false, features = ["experimental"] }
frame-system = { path = "../../system", default-features = false }

sp-io = { path = "../../../primitives/io", default-features = false }
Expand Down
58 changes: 58 additions & 0 deletions substrate/frame/parameters/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[package]
name = "pallet-parameters"
description = "Pallet to store and configure parameters."
repository.workspace = true
license = "Apache-2.0"
version = "0.0.1"
authors = ["Acala Developers", "Parity Technologies <[email protected]>"]
edition.workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
paste = { version = "1.0.14", default-features = false }
serde = { version = "1.0.188", features = ["derive"], optional = true }

frame-support = { path = "../support", default-features = false, features = ["experimental"] }
frame-system = { path = "../system", default-features = false }
sp-core = { path = "../../primitives/core", default-features = false }
sp-runtime = { path = "../../primitives/runtime", default-features = false }
sp-std = { path = "../../primitives/std", default-features = false }
docify = "0.2.5"
frame-benchmarking = { path = "../benchmarking", default-features = false, optional = true }

[dev-dependencies]
sp-core = { path = "../../primitives/core", features = ["std"] }
sp-io = { path = "../../primitives/io", features = ["std"] }
pallet-example-basic = { path = "../examples/basic", features = ["std"] }
pallet-balances = { path = "../balances", features = ["std"] }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"serde",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
#"orml-traits/std",
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-example-basic/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"pallet-example-basic/try-runtime",
"sp-runtime/try-runtime",
]
52 changes: 52 additions & 0 deletions substrate/frame/parameters/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// This file is part of Substrate.

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

//! Parameters pallet benchmarking.

#![cfg(feature = "runtime-benchmarks")]

use super::*;
#[cfg(test)]
use crate::Pallet as Parameters;

use frame_benchmarking::v2::*;
use sp_core::Get;

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn set_parameter() -> Result<(), BenchmarkError> {
let kv = T::BenchmarkingDefault::get();
let k = kv.clone().into_parts().0;

let origin =
T::AdminOrigin::try_successful_origin(&k).map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, kv);

Ok(())
}

impl_benchmark_test_suite! {
Parameters,
crate::tests::mock::new_test_ext(),
crate::tests::mock::Runtime,
}
}
Loading
Loading