paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.9k stars 697 forks source link

[FRAME Core] tracking issue for full unleash of `DefaultConfig` for FRAME #171

Open kianenigma opened 1 year ago

kianenigma commented 1 year ago

https://github.com/paritytech/substrate/pull/13454 will bring in the basic functionality needed to start using this feature. See this example to learn more.

This will mark the first version of this work complete, but a lot has to be done in order for it to be fully complete.

Improve Error Handling, Bugs

Full usage in Substrate Pallets

Full Usage in node-template-runtime and parachain-template-runtime

Full usage in westend -> kusama -> polkadot runtimes.

For security reasons we should be super caution here. Adding #[derive_impl] will open the door for upstream changes manipulating the configurations used in the Polkadot runtime. Perhaps we should only ever do this once we have more tooling that could notify us of unexpected upstream changes to config_preludes.

I would personally find it reasonable to never use this feature in production runtimes for this reason.

V2

At the moment, the system that is introduced is has some limitations. Most notably:

I believe this is father easy to fix, by standardizing frame_system::DefaultConfig and making trait DefaultConfig: frame_system::DefaultConfig.

Other approaches could be explored for the last step, as I am not quite sure what is the best way forward.

Improvements

bkchr commented 1 year ago
  • it cannot provide default for types that are reliant on types that are themselves reliant on frame_system::Config. For example, a type Admin: Get<Self::AccountId> cannot have a default. Is is mainly because trait DefaultConfig is not in itself trait DefaultConfig: frame_system::DefaultConfig. Moreover, sadly, because the definition of BalanceOf<T> (somewhat needlessly) also relies on frame_system::Config::AccountId, anything akin to Get<BalanceOf<Self>> can also not have a sensible default.

Personally I would say that we do this before we do all the other things, otherwise you will start changing all this code twice. I already left a comment here on how it could work: https://github.com/paritytech/substrate/pull/13454#issuecomment-1495855632

In general to this feature, I had some idea recently which could improve the versioning around our crates. Currently when we are adding a new type to a Config trait it requires that we bump the major version of the crate. If we have the system outlined here working and it is being used everywhere. (I would even go that far and say it is fine to use it in production runtimes, at least having the attribute above each Config implementation) Then we could introduce some kind of "versioning" of these Config traits. Then every time you would add a new config type, you would bump this version in your pallet. We would then only require to bump the minor version. Downstream users would then at some point bump the pallet minor version. It would still compile, because the attribute above the impl Config would put there some safe/secure default value. But it would also generate a warning that tells the user that it put there some new type. It could even show some more context to the new type added. The user can accept the new safe default value by bumping the "trait version to use" or they just add the type on their own and bump the trait version in use. Not sure if this idea is something we should really do, but I wanted to leave it here :P

sam0x17 commented 1 year ago

is the parse issue still present with #[pallet::whatever]?

Checked off some other things in here that are now fixed as of the recent macro_magic overhaul

sam0x17 commented 1 year ago

potential vast improvement: https://github.com/paritytech/substrate/pull/14437#discussion_r1251861668

ggwpez commented 9 months ago

The easiest way to participate here is to update mock.rs files to use the derive_impl configs.

Polkadot-Forum commented 6 months ago

This issue has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/seeking-feedback-on-derive-impl-for-default-configurations-in-pallet-templates/7584/1