-
Notifications
You must be signed in to change notification settings - Fork 680
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
Parameters pallet #169
Comments
I am going to implement this in ORML |
don't have anything against a central pallet per se, but this could have also been something like
If named So all in all, something like: #[pallet::storage]
#[pallet::getter(fn foo)]
#[pallet::setter(T::FooOrigin)] // `T::FooOrigin::ensure_origin(o)?` is enough to set `Foo` via `set_foo`.
type Foo<T: Config> = StorageValue<Value = u32> UPDATE: call index of something like above would also be hard to manage 👎 |
Yes, unless we only have one |
A central pallet allows a single place for all the parameters. This is super useful for governance / audit / review. No need to check every single pallet for governance calls, which each of them may have different naming convention etc. |
One thing about variable |
how about having these features:
what you think? |
Every feature request must come with some use cases otherwise we will be wasting time implementing things no one is using, which we already have a few instances in Substrate. |
I believe we already have the use cases for those features,
|
You have access to the key and can do whatever logics you want to control the permission. this returns an option so user will just add unwrap_or_else to support default value
I don't 100% get what you mean but I will just say my implementation don't have this issue. |
true, solved with regarding the last point, let me give you an example.
now with this configuration and static value for
how clients will retrieve the budget? |
The key type defined by the macro contains all the keys and client can use them to query for parameters. Basically replace |
I like :) |
orml-parameters is ready open-web3-stack/open-runtime-module-library#927 |
Here's how I would think about this, in terms of the final API: // in some ./runtime/lib.rs
// A u32 parameter
pub struct Parameter1;
impl FRAMEParameter<u32> for Parameter1 {
// Something that has to implement `EnsureOrigin`
type AdminOrigin = ...
/// Something that is Get<u32> the default value for this parameter if not present in storage.
/// (if you update this after the parameter has already been set in storage, it would probably have no effect, but that's an implementation detail)
type Default = ...
}
// A Perbill parameter.
pub InflationRate;
impl FRAMEParameter<Perbill> for InflationRate {
type AdminOrigin = ...
type Default = ...
}
impl pallet_parameters::Config for Runtime {
type Parameters = (Parameter1, InflationRate);
} This will give you a custom origin per parameter. EDIT: the implementaiton by @xlc also supports this with |
@xlc nice |
I think we can start using this in Rococ/Westend to try it out (eg. pallet NIS). With Kusama/Polkadot it needs audit first. PS: It seems like the ORML repo is not exposing a Rust workspace, so we will have to copy&paste it. |
Closes #169 Fork of the `orml-parameters-pallet` as introduced by open-web3-stack/open-runtime-module-library#927 (cc @xlc) It greatly changes how the macros work, but keeps the pallet the same. The downside of my code is now that it does only support constant keys in the form of types, not value-bearing keys. I think this is an acceptable trade off, give that it can be used by *any* pallet without any changes. The pallet allows to dynamically set parameters that can be used in pallet configs while also restricting the updating on a per-key basis. The rust-docs contains a complete example. Changes: - Add `parameters-pallet` - Use in the kitchensink as demonstration - Add experimental attribute to define dynamic params in the runtime. - Adding a bunch of traits to `frame_support::traits::dynamic_params` that can be re-used by the ORML macros ## Example First to define the parameters in the runtime file. The syntax is very explicit about the codec index and errors if there is no. ```rust #[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); } } ``` Then the pallet is configured with the aggregate: ```rust impl pallet_parameters::Config for Runtime { type AggregratedKeyValue = RuntimeParameters; type AdminOrigin = EnsureRootWithSuccess<AccountId, ConstBool<true>>; ... } ``` And then the parameters can be used in a pallet config: ```rust impl pallet_preimage::Config for Runtime { type DepositBase = dynamic_params::storage::DepositBase; } ``` A custom origin an be defined like this: ```rust 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, ()> { Ok(RuntimeOrigin::Root) } } ``` --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Nikhil Gupta <[email protected]> Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: command-bot <>
Closes paritytech#169 Fork of the `orml-parameters-pallet` as introduced by open-web3-stack/open-runtime-module-library#927 (cc @xlc) It greatly changes how the macros work, but keeps the pallet the same. The downside of my code is now that it does only support constant keys in the form of types, not value-bearing keys. I think this is an acceptable trade off, give that it can be used by *any* pallet without any changes. The pallet allows to dynamically set parameters that can be used in pallet configs while also restricting the updating on a per-key basis. The rust-docs contains a complete example. Changes: - Add `parameters-pallet` - Use in the kitchensink as demonstration - Add experimental attribute to define dynamic params in the runtime. - Adding a bunch of traits to `frame_support::traits::dynamic_params` that can be re-used by the ORML macros ## Example First to define the parameters in the runtime file. The syntax is very explicit about the codec index and errors if there is no. ```rust #[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); } } ``` Then the pallet is configured with the aggregate: ```rust impl pallet_parameters::Config for Runtime { type AggregratedKeyValue = RuntimeParameters; type AdminOrigin = EnsureRootWithSuccess<AccountId, ConstBool<true>>; ... } ``` And then the parameters can be used in a pallet config: ```rust impl pallet_preimage::Config for Runtime { type DepositBase = dynamic_params::storage::DepositBase; } ``` A custom origin an be defined like this: ```rust 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, ()> { Ok(RuntimeOrigin::Root) } } ``` --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Nikhil Gupta <[email protected]> Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: command-bot <>
Originally posted by @gavofyork in paritytech/cumulus#2607 (comment)
A pallet that can implement dynamic
Get<…>
and have configurable origins for modifying those would be nice.Otherwise we are restricted to either use
pub storage
which can only be modified by root, or doing in the pallet itself.For naming: the word
Parameter
is currently used as trait for function params, so maybe not best.The text was updated successfully, but these errors were encountered: