Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Oct 9, 2024

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:

  • fix frame benchmarking template. Can we detect the umbrella crate in there and have an if else? cc @ggwpez
  • Migrate benchmarking to v2 @re-gius a good candidate for you, you can open a PR against my branch.
  • tracking issue with follow-ups

@kianenigma kianenigma requested a review from a team as a code owner October 9, 2024 13:26
@kianenigma kianenigma added R0-silent Changes should not be mentioned in any release notes T1-FRAME This PR/Issue is related to core FRAME, the framework. and removed R0-silent Changes should not be mentioned in any release notes labels Oct 9, 2024
use core::marker::PhantomData;

// TODO update this in frame-weight-template.hbs
use frame::weights_prelude::*;
Copy link
Member

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.

Copy link
Contributor Author

@kianenigma kianenigma Oct 9, 2024

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?

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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:

  1. We currently use substrate/.maintain/frame-weight-template.hbs in most places. We create a new substrate/.maintain/frame-umbrella-weight-template.hbs. Users are free to choose. Our CI should also adapt, and based on the presence of frame-support in the deps, make a decision.
  2. 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 update substrate/.maintain/frame-weight-template.hbs to start with use 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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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:

2d8323f

substrate/frame/Cargo.toml Outdated Show resolved Hide resolved
frame-system = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
Copy link
Contributor

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

Copy link
Contributor Author

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> {
Copy link
Contributor

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/migrations.rs Outdated Show resolved Hide resolved
};
pub use weights::WeightInfo;
use weights::WeightInfo;
Copy link
Contributor

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"] }
Copy link
Contributor

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

//! pub mod runtime {
//! # use polkadot_sdk_frame as frame;
//! use frame::runtime::prelude::*;
//! }
//! ```
//!
//! See: [`prelude`], [`testing_prelude`] and [`runtime::prelude`].
//! See: .
Copy link
Contributor

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",
Copy link
Contributor

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.

Copy link
Member

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>
@paritytech-review-bot paritytech-review-bot bot requested a review from a team October 15, 2024 14:58
Comment on lines +8 to +9
#[allow(unused_imports)]
use frame::prelude::*;
Copy link
Member

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::*;
Copy link
Member

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.

Copy link
Member

@shawntabrizi shawntabrizi left a 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

re-gius and others added 3 commits October 15, 2024 17:32
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>
@kianenigma kianenigma requested review from a team as code owners October 15, 2024 17:13
@paritytech-review-bot paritytech-review-bot bot requested a review from a team October 16, 2024 13:35
//!
//! ```
//! # use polkadot_sdk_frame as frame;
//! use polkadot_sdk_frame as frame;
//! #[frame::pallet]
//! pub mod pallet {
//! # use polkadot_sdk_frame as frame;
Copy link

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::{
Copy link
Contributor Author

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.

Copy link
Contributor Author

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 and frame_system::pallet_prelude.

is not a good advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants