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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Deploy to rococo
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
ggwpez committed Oct 27, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
commit c0a7538e0d99923ac55966b5c2acdbe5c797966e
1 change: 1 addition & 0 deletions polkadot/runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ frame-support = { path = "../../../substrate/frame/support", default-features =
pallet-staking = { path = "../../../substrate/frame/staking", default-features = false }
frame-system = { path = "../../../substrate/frame/system", default-features = false }
frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false }
pallet-parameters = { path = "../../../substrate/frame/parameters", default-features = false }
pallet-timestamp = { path = "../../../substrate/frame/timestamp", default-features = false }
pallet-tips = { path = "../../../substrate/frame/tips", default-features = false }
pallet-treasury = { path = "../../../substrate/frame/treasury", default-features = false }
99 changes: 83 additions & 16 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ use frame_system::EnsureRoot;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_identity::simple::IdentityInfo;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_parameters::define_aggregrated_parameters;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo};
use sp_core::{ConstU128, OpaqueMetadata, H256};
@@ -137,7 +138,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("rococo"),
impl_name: create_runtime_str!("parity-rococo-v2.0"),
authoring_version: 0,
spec_version: 10020,
spec_version: 8888,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 22,
@@ -229,8 +230,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);
}

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

@@ -1095,12 +1098,11 @@ 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 NisMinBid: Balance = 100 * UNITS;
pub NisMinReceipt: Perquintill = Perquintill::from_rational(1u64, 10_000_000u64);
pub const NisIntakePeriod: BlockNumber = 5 * MINUTES;
pub NisMaxIntakeWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 10;
pub const NisThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
}

@@ -1114,17 +1116,17 @@ 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::NisTarget;
type PalletId = NisPalletId;
type QueueCount = ConstU32<300>;
type MaxQueueLen = ConstU32<1000>;
type FifoQueueLen = ConstU32<250>;
type BasePeriod = NisBasePeriod;
type MinBid = MinBid;
type MinReceipt = MinReceipt;
type IntakePeriod = IntakePeriod;
type MaxIntakeWeight = MaxIntakeWeight;
type ThawThrottle = ThawThrottle;
type MinBid = NisMinBid;
type MinReceipt = NisMinReceipt;
type IntakePeriod = NisIntakePeriod;
type MaxIntakeWeight = NisMaxIntakeWeight;
type ThawThrottle = NisThawThrottle;
type RuntimeHoldReason = RuntimeHoldReason;
}

@@ -1242,6 +1244,68 @@ impl pallet_asset_rate::Config for Runtime {
type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments;
}

use frame_system::EnsureRootWithSuccess;
use pallet_parameters::define_parameters;
use sp_runtime::traits::ConstBool;

/// Dynamic parameters that can be set by Root without a runtime upgrade.
///
/// All parameters expose metadata and docs.
pub mod dynamic_params {
use super::*;

/// Dynamic params for [`pallet_nis`].
pub mod nis {
use super::*;

define_parameters! {
pub NisParams = {
/// Configures [`pallet_nis::Config::Target`].
#[codec(index = 0)]
NisTarget: Perquintill = Perquintill::zero(),
},
Pallet = pallet_parameters::Parameters::<Runtime>,
Aggregation = RuntimeParameters::Nis
}
}

/// Dynamic params for [`pallet_preimage`].
pub mod preimage {
use super::*;

define_parameters! {
pub PreimageParams = {
/// Configures the base deposit of noting a preimage.
#[codec(index = 0)]
BaseDeposit: Balance = deposit(2, 64),

/// Configures the per-byte deposit of noting a preimage.
#[codec(index = 1)]
ByteDeposit: Balance = deposit(0, 1),
},
Pallet = pallet_parameters::Parameters::<Runtime>,
Aggregation = RuntimeParameters::Preimage
}
}

define_aggregrated_parameters! {
pub RuntimeParameters = {
#[codec(index = 0)]
Nis: nis::NisParams,

#[codec(index = 1)]
Preimage: preimage::PreimageParams,
}
}
}

impl pallet_parameters::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AggregratedKeyValue = dynamic_params::RuntimeParameters;
type AdminOrigin = EnsureRootWithSuccess<AccountId, ConstBool<true>>;
type WeightInfo = ();
}

construct_runtime! {
pub enum Runtime
{
@@ -1365,11 +1429,14 @@ construct_runtime! {
// Validator Manager pallet.
ValidatorManager: validator_manager::{Pallet, Call, Storage, Event<T>} = 252,

Parameters: pallet_parameters::{Pallet, Call, Storage, Event<T>} = 253,

// State trie migration pallet, only temporary.
StateTrieMigration: pallet_state_trie_migration = 254,

// Sudo.
Sudo: pallet_sudo::{Pallet, Call, Storage, Event<T>, Config<T>} = 255,

}
}

46 changes: 30 additions & 16 deletions substrate/frame/parameters/src/lib.rs
Original file line number Diff line number Diff line change
@@ -29,27 +29,34 @@
//!
//! ## Pallet API
//!
//! This pallet exposes two APIs; one *inbound* side to update parameters, and one *outbound* side to access said parameters.
//!
//! ### Inbound
//! This pallet exposes two APIs; one *inbound* side to update parameters, and one *outbound* side
//! to access said parameters.
//!
//! ### Inbound
//!
//! This solely consists of the `set_parameter` extrinsic, which allows to update a parameter. Each
//! parameter can have their own admin.
//!
//! This solely consists of the `set_parameter` extrinsic, which allows to update a parameter. Each parameter can have their own admin.
//!
//! ### Outbound
//!
//! The outbound side is runtime facing for the most part. More general, it provides a `Get` implementation and can be used in every spot where that is accepted. Two macros are in place: `define_parameters` and `define_aggregrated_parameters` to define and expose parameters in a typed manner.
//! The outbound side is runtime facing for the most part. More general, it provides a `Get`
//! implementation and can be used in every spot where that is accepted. Two macros are in place:
//! `define_parameters` and `define_aggregrated_parameters` to define and expose parameters in a
//! typed manner.
//!
//! See the [`pallet`] module for more information about the interfaces this pallet exposes, including its
//! configuration trait, dispatchables, storage items, events and errors.
//! See the [`pallet`] module for more information about the interfaces this pallet exposes,
//! including its configuration trait, dispatchables, storage items, events and errors.
//!
//! ## Overview
//!
//! This pallet is a good fit for updating parameters without a runtime upgrade. It allows for fine-grained control over who can update what. The only down-side is that it trades off performance with convenience and should therefore only be used in places where that is proven to be uncritical.
//! This pallet is a good fit for updating parameters without a runtime upgrade. It allows for
//! fine-grained control over who can update what. The only down-side is that it trades off
//! performance with convenience and should therefore only be used in places where that is proven to
//! be uncritical.
//!
//! ### Example
//!
//! Here is an example of how to define some parameters, including their default values:
//!
#![doc = docify::embed!("src/mock.rs", dynamic_params)]
//!
//! Now the aggregated parameter needs to be injected into the pallet config:
@@ -63,10 +70,14 @@
//!
//! ## Low Level / Implementation Details
//!
//! The pallet stores the parameters in a storage map and implements the matching `Get<Value>` for each `Key` type. The `Get` then accesses the `Parameters` map to retrieve the value.
//! An event is emitted every time that a value was updated. It is even emitted when the value is changed to the same.
//! The pallet stores the parameters in a storage map and implements the matching `Get<Value>` for
//! each `Key` type. The `Get` then accesses the `Parameters` map to retrieve the value. An event is
//! emitted every time that a value was updated. It is even emitted when the value is changed to the
//! same.
//!
//! The key and value types themselves are defined by macros and aggregated into a runtime wide enum. This enum is then injected into the pallet. This allows it to be used without any changed to the pallet that the parameter will be utilized by.
//! The key and value types themselves are defined by macros and aggregated into a runtime wide
//! enum. This enum is then injected into the pallet. This allows it to be used without any changed
//! to the pallet that the parameter will be utilized by.
//!
//! ### Design Goals (optional)
//!
@@ -76,9 +87,12 @@
//!
//! ### Design
//!
//! 1. Everything is done at runtime without the need for `const` values. `Get` allows for this - which is coincidentally an upside and a downside.
//! 2. The types are defined through macros, which allows to expose metadata and docs.
//! 3. Access control is done through the `EnsureOriginWithArg` trait, that allows to pass data along to the origin check. It gets passed in the key. The implementor can then match on the key and the origin to decide whether the origin is permissioned to set the value.
//! 1. Everything is done at runtime without the need for `const` values. `Get` allows for this -
//! which is coincidentally an upside and a downside. 2. The types are defined through macros, which
//! allows to expose metadata and docs. 3. Access control is done through the `EnsureOriginWithArg`
//! trait, that allows to pass data along to the origin check. It gets passed in the key. The
//! implementor can then match on the key and the origin to decide whether the origin is
//! permissioned to set the value.

use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
1 change: 0 additions & 1 deletion substrate/frame/parameters/src/mock.rs
Original file line number Diff line number Diff line change
@@ -106,7 +106,6 @@ pub mod dynamic_params {
}
pub use dynamic_params::*;


#[docify::export(impl_config)]
impl Config for Runtime {
// Inject the aggregated parameters into the runtime:
13 changes: 8 additions & 5 deletions substrate/frame/parameters/src/tests.rs
Original file line number Diff line number Diff line change
@@ -11,15 +11,18 @@ use RuntimeOrigin as Origin;
#[test]
fn set_parameters_example() {
use RuntimeParameters::*;

ExtBuilder::new().execute_with(|| {
assert_eq!(pallet1::Key3::get(), 2, "Default works");

// This gets rejected since the origin is not root.
assert_noop!(ModuleParameters::set_parameter(
Origin::signed(1),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
), DispatchError::BadOrigin);
assert_noop!(
ModuleParameters::set_parameter(
Origin::signed(1),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
),
DispatchError::BadOrigin
);

assert_ok!(ModuleParameters::set_parameter(
Origin::root(),