-
Notifications
You must be signed in to change notification settings - Fork 742
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
Conversation
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
I may have asked this before, but don't recall the answer? can we define one |
Yes. I will extend docs for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be done under the experimental
flag?
The downside of my cod is now that it does only support constant keys in the form of types, not value-bearing keys.
Could you add a UI Test to demonstrate the current behaviour in this case?
With my original code, it is simple to implement a |
I am not sure if i get what you mean. The approach in the MR is compatible with old pallets, since the |
What I am trying to say is you don’t need to rewrite orml-parameters to be compatible with existing pallets. I want to avoid two similar but incompatible pallet which will create a lot of maintenance overhead for no good reasons. |
I looked at this and saw the change to the It got a new config param |
I will suggest updating pallets to fully utilize the features of parameters pallet such as parametrized keys but that's not necessary for simple use cases. I already described how to do it in my previous comment. But let me elaborate it further using my PR as an example
struct GetInstantUnstakeFee;
impl Get<Option<Permill>> for GetInstantUnstakeFee {
fn get() -> Option<Permill> {
ParameterStoreAdapter<Parameters, EarningParameters>::get(InstantUnstakeFee)
}
}
It is easy to write a macro to generate the struct |
A piece of good code are like onions. They have many layers and we build new abstractions on top of each layer. If the most top layer is not suitable, we pick the lower layer instead. We identify the right level of abstraction for our use cases and reuse the code. But please don't just throw it into a blender, and some spices that you want and give me a mash. It may work for you but unlikely for everyone. |
Here is my diff that adds support for the following syntax: #[dynamic_params(RuntimeParameters)]
pub mod dynamic_params {
use super::*;
#[dynamic_pallet_params(crate::Parameters::<Runtime>, Parameters)]
pub mod pallet1 {
#[codec(index = 0)]
pub static Key1: u64 = 0;
#[codec(index = 1)]
pub static Key2: u32 = 1;
#[codec(index = 2)]
pub static Key3: u128 = 2;
}
#[dynamic_pallet_params(crate::Parameters::<Runtime>, Parameters)]
pub mod pallet2 {
#[codec(index = 0)]
pub static Key1: u64 = 0;
#[codec(index = 1)]
pub static Key2: u32 = 2;
#[codec(index = 2)]
pub static Key3: u128 = 4;
}
}
pub use dynamic_params::*; |
…parameters-pallet
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
I figured that you guys have decided to ignore my suggestions and just going to do whatever you want? |
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Pretty much. Your ideas and our need for a simple pallet seemed to not be compatible. |
I already told you it is compatible 💁♂️ #2061 (comment) |
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> Co-authored-by: muharem <ismailov.m.h@gmail.com> Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
The CI pipeline was cancelled due to failure one of the required jobs. |
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
…parameters-pallet
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
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 <oliver.tale-yazdi@parity.io> Co-authored-by: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: command-bot <>
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:
parameters-pallet
frame_support::traits::dynamic_params
that can be re-used by the ORML macrosExample
First to define the parameters in the runtime file. The syntax is very explicit about the codec index and errors if there is no.
Then the pallet is configured with the aggregate:
And then the parameters can be used in a pallet config:
A custom origin an be defined like this: