Skip to content

Conversation

ParthDesai
Copy link
Contributor

@ParthDesai ParthDesai commented Oct 8, 2025

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 expression serializable = <bool>. The parameter is made optional to ensure backward compatibility.

Apart from that, I have modified pallet-parameters with following changes:

  1. Changes related to make RuntimeParameters serializable are behind serde feature.
  2. The existing serde feature in pallet-parameter now is refactored as following:
    a) serde crate is still optional but without default features and derive feature.
    b) the default features (std) and derive features are enabled if std feature of pallet-parameters.

I have not modified any runtime to enable pallet-parameter's serde feature. Since due to feature unification it will be applied for every runtime and the substrate runtime contains few parameters which does not implement Serialize.

TODO:

  • Tests

Checklist

  • My PR includes a detailed description as outlined in the "Description" and its two subsections above.
  • My PR follows the labeling requirements of this project (at minimum one label for T required)
    • External contributors: ask maintainers to put the right label on your PR.
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@ParthDesai ParthDesai requested a review from a team as a code owner October 8, 2025 20:15
Copy link
Member

@bkchr bkchr left a 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 }
Copy link
Member

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?

Copy link
Contributor Author

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")]
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Comment on lines +165 to +169
#[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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type RuntimeParameters: AggregatedKeyValue;
type RuntimeParameters: AggregatedKeyValue + MaybeSerializeDeserialize;

Comment on lines +159 to 163
#[pallet::no_default_bounds]
#[cfg(not(feature = "serde"))]
/// The overarching KV type of the parameters.
///
/// Usually created by [`frame_support::dynamic_params`] or equivalent.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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"))]

@ParthDesai
Copy link
Contributor Author

This really requires some test that ensures it is working :)

yes, planning to add test as soon as somebody from parity validates the approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants