-
Notifications
You must be signed in to change notification settings - Fork 1k
add serialization support for dynamic_params macro and AggregateKey #9971
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
base: master
Are you sure you want to change the base?
add serialization support for dynamic_params macro and AggregateKey #9971
Conversation
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.
This really requires some test that ensures it is working :)
paste = { workspace = true } | ||
scale-info = { features = ["derive"], workspace = true } | ||
serde = { features = ["derive"], optional = true, workspace = true, default-features = true } | ||
serde = { optional = true, workspace = true } |
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.
We don't need this change or?
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.
Problem is one of the runtime has dynamic_params
with types that are not serializable. So, due to cargo's feature unification we will need to disable the support for dynamic_params
serialization everywhere.
Because if we enable this feature in one runtime, all runtime will have pallet_parameters
with serde
enabled which will result in substrate runtime not compiling.
#[pallet::genesis_config] | ||
pub struct GenesisConfig<T: Config> { | ||
/// Default runtime parameters | ||
#[cfg(feature = "serde")] |
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.
Right now all the other pallets also have serde
enabled all the time.
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.
Probably the best would be to disable GenesisConfig
at all when serde
is not enabled. But this needs to be done for every pallet.
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.
@bkchr We tried that unfortunately without changing the genesis config macro that is not possible. This is the least invasive way.
#[cfg(feature = "serde")] | ||
/// The overarching KV type of the parameters with serde serialization implemented | ||
/// | ||
/// Usually created by [`frame_support::dynamic_params`] or equivalent. | ||
type RuntimeParameters: AggregatedKeyValue + serde::Serialize + serde::de::DeserializeOwned; |
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.
#[cfg(feature = "serde")] | |
/// The overarching KV type of the parameters with serde serialization implemented | |
/// | |
/// Usually created by [`frame_support::dynamic_params`] or equivalent. | |
type RuntimeParameters: AggregatedKeyValue + serde::Serialize + serde::de::DeserializeOwned; |
/// | ||
/// Usually created by [`frame_support::dynamic_params`] or equivalent. | ||
#[pallet::no_default_bounds] | ||
type RuntimeParameters: AggregatedKeyValue; |
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.
type RuntimeParameters: AggregatedKeyValue; | |
type RuntimeParameters: AggregatedKeyValue + MaybeSerializeDeserialize; |
#[pallet::no_default_bounds] | ||
#[cfg(not(feature = "serde"))] | ||
/// The overarching KV type of the parameters. | ||
/// | ||
/// Usually created by [`frame_support::dynamic_params`] or equivalent. |
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.
#[pallet::no_default_bounds] | |
#[cfg(not(feature = "serde"))] | |
/// The overarching KV type of the parameters. | |
/// | |
/// Usually created by [`frame_support::dynamic_params`] or equivalent. | |
/// The overarching KV type of the parameters. | |
/// | |
/// Usually created by [`frame_support::dynamic_params`] or equivalent. | |
#[pallet::no_default_bounds] | |
#[cfg(not(feature = "serde"))] |
yes, planning to add test as soon as somebody from parity validates the approach. |
Description
This PR is attempt at #9714.
Review Notes
It adds conditional serialization support for
dynamic_params
macro by accepting a third argument as an expressionserializable = <bool>
. The parameter is made optional to ensure backward compatibility.Apart from that, I have modified
pallet-parameters
with following changes:RuntimeParameters
serializable are behindserde
feature.serde
feature inpallet-parameter
now is refactored as following:a)
serde
crate is still optional but without default features and derive feature.b) the default features (
std
) andderive
features are enabled ifstd
feature ofpallet-parameters
.I have not modified any runtime to enable
pallet-parameter
'sserde
feature. Since due to feature unification it will be applied for every runtime and the substrate runtime contains few parameters which does not implementSerialize
.TODO:
Checklist
T
required)