-
Notifications
You must be signed in to change notification settings - Fork 668
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
Use frame umbrella crate in pallet-proxy
and pallet-multisig
#5995
base: master
Are you sure you want to change the base?
Conversation
…frame-umbrella-in-pallets
use core::marker::PhantomData; | ||
|
||
// TODO update this in frame-weight-template.hbs | ||
use frame::weights_prelude::*; |
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.
Huh honestly not sure what to best do here. The long-term solution is to have a project config file for the benchmarker, like for Zepter, so that it gets all the flags from there.
Then we could add an argument to use the frame
crate instead.
Until then we either have to add a --use-frame-crate
flag manually, or cheat by re-exporting the weight type from the crate and use that.
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 would break both for frame
and polkadot-sdk
, basically meaning pallet development always needs frame_support
directly in Cargo.toml
? unfortunate.
How about providing two frame-weight-template.hbs
? One for old school, one for new school?
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.
Discussed about moving all our pallets to include frame
as dependency and moving the template to assume that exists.
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.
maybe we could also assume that the pallet weight is a direct module inside the module with pallet definition.
So we can use super::pallet::reexport_of_frame
?
But assuming frame
as a dependency sounds better, people can always modify the .hbs
to their flavor.
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.
the handlebar templates should be able to allow whatever decision you all pick, but the change needs to happen at that level, not here.
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.
I see two ways forward with this:
- We currently use
substrate/.maintain/frame-weight-template.hbs
in most places. We create a newsubstrate/.maintain/frame-umbrella-weight-template.hbs
. Users are free to choose. Our CI should also adapt, and based on the presence offrame-support
in the deps, make a decision. - We make a mega PR that will move all pallets to have a
#[doc(hidden)] pub(crate) mod __private_weights { /* re export all the stuff that might be needed in the weight.rs file */ }
. We also updatesubstrate/.maintain/frame-weight-template.hbs
to start withuse crate::__private_weights::*
. Our CI should pass once we merge this. Then, we resume this PR.
Solution 1 is clearly better, and more extensible. Solution 2 is only a reasonable hack if 1 is too hard to pull off.
@mordamax this is mainly a question from you; how hard will it be to have our weight generation CI (the fellowship's) be able to handle two templates? or perhaps we already support it?
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.
I talked to @mordamax and we should explore option, it should not have any major blockers and just needs more updates to our CI.
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.
It is not the cleanest thing in the world, but this is how it would look like:
frame-system = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
frame = { workspace = true, features = ["experimental", "runtime"] } |
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.
do we actually need experimental? I don't see it used in the past AFAICT
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.
I will remove it as soon as I am a bit more confident in the readiness of the frame
crate 🙈
@@ -42,15 +36,14 @@ pub mod v1 { | |||
pub struct MigrateToV1<T>(core::marker::PhantomData<T>); | |||
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> { | |||
#[cfg(feature = "try-runtime")] | |||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> { | |||
fn pre_upgrade() -> Result<Vec<u8>, frame::deps::sp_runtime::TryRuntimeError> { |
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.
Not related to the PR, but maybe we could introduce: TryRuntimeResult<T> = Result<T, TryRuntimeError>
substrate/frame/multisig/src/lib.rs
Outdated
}; | ||
pub use weights::WeightInfo; | ||
use weights::WeightInfo; |
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.
Note that it can be used by the weights templates like this line:
impl<T: frame_system::Config> {{pallet}}::WeightInfo for WeightInfo<T> {
frame-system = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
frame = { workspace = true, features = ["experimental", "runtime"] } |
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.
note experimental
wasn't used before
substrate/frame/src/lib.rs
Outdated
//! pub mod runtime { | ||
//! # use polkadot_sdk_frame as frame; | ||
//! use frame::runtime::prelude::*; | ||
//! } | ||
//! ``` | ||
//! | ||
//! See: [`prelude`], [`testing_prelude`] and [`runtime::prelude`]. | ||
//! See: . |
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.
what is this line?
"scale-info/std", | ||
"serde_json/std", | ||
|
||
"pallet-minimal-template/std", | ||
"polkadot-sdk/std", |
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.
personally I find keeping it in one block better.
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.
then it can also be sorted by toml linters
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
#[allow(unused_imports)] | ||
use frame::prelude::*; |
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.
why though? just for the template to be extended? perhaps you are better to find some way to just use it?
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | ||
use core::marker::PhantomData; | ||
use frame::weights_prelude::*; |
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 change doesn't make sense. it needs to be done at the template level, or handled later.
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.
went through all the files, and changes look good except the benchmarks which need template level changes
Sub-task of PR #5995 ## Integration These changes should **not** require any integration effort. --------- Co-authored-by: Dónal Murray <donal.murray@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
//! | ||
//! ``` | ||
//! # use polkadot_sdk_frame as frame; | ||
//! use polkadot_sdk_frame as frame; | ||
//! #[frame::pallet] | ||
//! pub mod pallet { | ||
//! # use polkadot_sdk_frame as frame; |
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 can remove this line since it's a duplicate
@@ -886,7 +886,10 @@ pub mod testing_prelude { | |||
pub mod pallet_prelude { | |||
pub use crate::{ | |||
defensive, defensive_assert, | |||
dispatch::{DispatchClass, DispatchResult, DispatchResultWithPostInfo, Parameter, Pays}, | |||
dispatch::{ |
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.
I now realize that it is actually best if we don't alter re-exports that are made here, and instead bring more and more things into frame::prelude
. So I would resume by reverting all changes here, add the items added to frame::prelude
manually as new pub use frame_support::{this, that}
.
This is because adding dependencies here would also mean that we will need to cause a breaking change in frame_support, as we are altering the public API.
Also, in action we are seeing that it in this PR, adding items in this prelude is causing random other pallets to break, because of ambiguous imports.
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.
So, the guideline that I have written so far:
- When doing so, prefer adding the relevant item to
frame_support::pallet_prelude
andframe_system::pallet_prelude
.
is not a good advice.
A step towards #4782
In order to nail down the right preludes in
polkadot-sdk-frame
, we need to migrate a number of pallets to be written with it. Moreover, migrating our pallets to this simpler patter will encourage the ecosystem to also follow along.If this PR is approved and has no unwanted negative consequences, I will make a tracking issue to migrate all pallets to this umbrella crate.
TODO:
if else
? cc @ggwpez