-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Production / Non-Production Feature Flags for FRAME Pallets and Runtime #8965
Description
In FRAME we should try to satisfy these two, sometime conflicting requirements as best as possible:
- Make it dead simple easy to build new pallets with FRAME
- Allow developers to make completely safe, production ready pallets
The original SRML macros was really good at satisfying (1), where you could just start writing code and try it out right away.
However, over time, and as we transitioned to FRAME, we had to add more and more requirements to pallets in order to make it all production ready for Polkadot and Parachains.
Some example of "production features" that make the tinkerer experience worse:
- Weights
- MaxEncodedLen (PoV Size)
- Explicit Call / Pallet / Storage indexing (Use Mandatory Indices for FRAME Storage API (and others) #8964)
On the flip side, we also have introduced things within FRAME which should only be used in non-production environments:
- Transactional Extrinsics (is it production ready?)
()or test impl for many traits- Many pallets which are not fully audited or use real weights and stff
Using Rust's feature system, we should easily be able to enable / disable production and non-production features using feature flags.
For example, when building a pallet or working with substrate for fun, you can design a pallet without needing to define any weights, or maxencodedlen stuff.
However, when you are going to production, you can compile with --features=production, and these compiler errors will appear saying that you need to implement this stuff.
Then, at in the runtime definition, you can ensure that your runtime is always compiled with the production flag by using something like:
// instead of `construct_runtime!(...)
construct_production_runtime!(...)
This will only compile with the --features=production flag, ensuring that all pallets included in your runtime are ready to be used in production.