-
Notifications
You must be signed in to change notification settings - Fork 766
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
Migrating salary pallet to use umbrella crate #7048
Conversation
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.
A couple of things are imported manually that are likely in the prelude or else must be added, otherwise looks good!
@@ -46,8 +46,10 @@ | |||
#![allow(unused_imports)] | |||
#![allow(missing_docs)] | |||
|
|||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | |||
use crate::*; |
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 do you need this?
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.
Could you add some explanation as to why you think this is needed before resolving the thread again? You can add a commit link if you want or any explanation.
@@ -46,8 +46,10 @@ | |||
#![allow(unused_imports)] | |||
#![allow(missing_docs)] | |||
|
|||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | |||
use crate::*; | |||
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.
This again is not needed. All the imports are already in scope.
- 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.
Could you add some reasoning as to why you think this is needed before resolving the thread? I believe you shouldn't need this.
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.
Looks good to me, some comments about prelude.
substrate/frame/salary/src/lib.rs
Outdated
defensive, | ||
dispatch::DispatchResultWithPostInfo, | ||
ensure, | ||
|
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.
personal nits, separating imports in categories is a not needed overhead IMHO.
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.
Automatic change by fmt
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 trick is that if you don't have any extra newlines between use
statements, they will indeed be grouped together and rustfmt
will sort them for you. I think @gui1117 's comment is towards removing newlines in between use
statements.
pallet_prelude::Weight, | ||
parameter_types, | ||
traits::{ConstU64, EitherOf, MapSuccess, NoOpPoll}, | ||
|
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.
cargo fmt
will put crate above other import by default
@@ -20,20 +20,14 @@ | |||
use std::collections::BTreeMap; | |||
|
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.
substrate/frame/src/lib.rs
Outdated
defensive, defensive_assert, | ||
traits::{ | ||
tokens::ConvertRank, Contains, EitherOf, EstimateNextSessionRotation, IsSubType, | ||
MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, |
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 am not sure ConvertRank
is really prelude but it can be ok.
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.
Our rule here from other reviews was that if a trait is used in 3 or more pallets, it can be in prelude, if not directly imported in the migration.
substrate/frame/src/lib.rs
Outdated
@@ -505,7 +508,7 @@ pub mod runtime { | |||
#[cfg(feature = "std")] | |||
pub mod testing_prelude { | |||
pub use sp_core::storage::Storage; | |||
pub use sp_runtime::BuildStorage; | |||
pub use sp_runtime::{BuildStorage, DispatchError::Unavailable}; |
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 am not sure Unavailable
fits into prelude, DispatchError
should be enough I think.
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.
thanks for the comments @gui1117 I added a new commit for PRdoc, can you re review? additionally, for the current pallet only Unavailable was needed, I can have a separate PR for modifying this
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.
Yeah, I do think it is a bit too much to import enum variants
in any prelude -- the Enum itself makes a lot of sense. DispatchError
is super popular, and 100% should be in prelude.
If a code wants to use Unavailable
, they would just use DispatchError::Unavailable
and that is fine.
Please add this (among other guidelines) to substrate/frame/src/lib.rs
, in the top of the file, there is some high level doc, and a section exactly explaining the rules of the umbrella crate.
Review required! Latest push from author must always be reviewed |
substrate/frame/src/lib.rs
Outdated
@@ -319,7 +322,7 @@ pub mod testing_prelude { | |||
/// Other helper macros from `frame_support` that help with asserting in tests. | |||
pub use frame_support::{ | |||
assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok, | |||
assert_storage_noop, storage_alias, | |||
assert_storage_noop, construct_runtime, storage_alias, |
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.
Are you sure construct_runtime
is not already in runtime::prelude::*
? I would 99% be sure it already is.
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.
+1, it is also there in testing_prelude
.
@@ -66,15 +66,15 @@ impl<T: VariantCount> Get<u32> for VariantCountOf<T> { | |||
#[macro_export] | |||
macro_rules! defensive { | |||
() => { | |||
frame_support::__private::log::error!( | |||
$crate::__private::log::error!( |
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.
very good!
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.
LGTM after current comments are addressed.
parameter_types, | ||
traits::{ConstU64, EitherOf, MapSuccess, NoOpPoll}, | ||
use crate::{ | ||
tests::integration::sp_api_hidden_includes_construct_runtime::hidden_include::sp_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.
Why not import sp_runtime
from the umbrella
pallet directly?
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.
let me crosscheck this, this was not a conscious change for sure
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.
yes hidden_includes
are generated by the macro for the macro usage, it can break any time.
use crate as pallet_salary; | ||
use crate::*; | ||
use core::cell::RefCell; | ||
use frame::{deps::sp_runtime::traits::Identity, testing_prelude::*, traits::tokens::ConvertRank}; | ||
use std::collections::BTreeMap; |
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.
Removing the line space between two import blocks causes them to be sorted alphabetically by the fmt
. I don't have a strong preference but to be consistent, we should keep imports from the standard library in a separate block (having a line space at the end) at the top.
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 would prefer to not put in a separate block. If it is meant to be in a particular order then fmt
should do it, same as they put crate
and super
out of the alphabetic order.
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.
other comments addressed, leaving this as is
@@ -262,7 +265,7 @@ pub mod benchmarking { | |||
pub use frame_benchmarking::benchmarking::*; | |||
// The system origin, which is very often needed in benchmarking code. Might be tricky only |
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.
Please update the comments with descriptions when you add new re-exports to the umbrella
crate.
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.
Raworigin is still intacte
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 meant could you also add a description for frame_system::Pallet
like there exists for RawOrigin
.
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.
Pushing one last comment with a few fixes:
Identity
works fine if imported fromsp_runtime
RankedMembers, RankedMembersSwapHandler
are both used in 3 pallets, should go to prelude (as per the conventions of the migration)StateVersion
is used in the testing setup of the migration, same.
diff:
diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs
index 256d1ad0cd..6a843625f4 100644
--- a/substrate/frame/salary/src/lib.rs
+++ b/substrate/frame/salary/src/lib.rs
@@ -22,10 +22,7 @@
use core::marker::PhantomData;
use frame::{
prelude::*,
- traits::{
- tokens::{GetSalary, Pay, PaymentStatus},
- RankedMembers, RankedMembersSwapHandler,
- },
+ traits::tokens::{GetSalary, Pay, PaymentStatus},
};
#[cfg(test)]
diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs
index 6d38a1c9b0..e4e9c8f6a3 100644
--- a/substrate/frame/salary/src/tests/integration.rs
+++ b/substrate/frame/salary/src/tests/integration.rs
@@ -19,10 +19,7 @@
use crate as pallet_salary;
use crate::*;
-use frame::{
- deps::{sp_io, sp_runtime::StateVersion},
- testing_prelude::*,
-};
+use frame::{deps::sp_io, testing_prelude::*};
use pallet_ranked_collective::{EnsureRanked, Geometric};
type Rank = u16;
diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs
index 3bb7bc4adf..6bdd86ddef 100644
--- a/substrate/frame/salary/src/tests/unit.rs
+++ b/substrate/frame/salary/src/tests/unit.rs
@@ -20,7 +20,7 @@
use crate as pallet_salary;
use crate::*;
use core::cell::RefCell;
-use frame::{deps::sp_runtime::traits::Identity, testing_prelude::*, traits::tokens::ConvertRank};
+use frame::{testing_prelude::*, traits::tokens::ConvertRank};
use std::collections::BTreeMap;
type Block = MockBlock<Test>;
diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs
index dba039bee2..1795dfeb81 100644
--- a/substrate/frame/src/lib.rs
+++ b/substrate/frame/src/lib.rs
@@ -207,7 +207,7 @@ pub mod prelude {
defensive, defensive_assert,
traits::{
Contains, EitherOf, EstimateNextSessionRotation, IsSubType, MapSuccess, NoOpPoll,
- OnRuntimeUpgrade, OneSessionHandler,
+ OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler,
},
};
@@ -232,7 +232,7 @@ pub mod prelude {
/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
- BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy,
+ BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, Identity, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
};
/// Other error/result types for runtime
@@ -333,7 +333,7 @@ pub mod testing_prelude {
pub use sp_io::TestExternalities as TestState;
/// Commonly used runtime traits for testing.
- pub use sp_runtime::traits::BadOrigin;
+ pub use sp_runtime::{traits::BadOrigin, StateVersion};
}
/// All of the types and tools needed to build FRAME-based runtimes.
LGTM after applying the above patch
All GitHub workflows were cancelled due to failure one of the required jobs. |
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.
LGTM. 2 points:
-
25 CI workflows are failing. Could be a red-herring but the number is suspiciously large so we should check to ensure that the failures are unrelated and raise them in the CI help desk.
-
Add one small comment about adding description for new re-exports that are added to any of the
preludes
Description
Migrating salary pallet to use umbrella crate. It is a follow-up from #7025
Why did I create this new branch?
I did this, so that the unnecessary cargo fmt changes from the previous branch are discarded and hence opened this new PR.
Review Notes
This PR migrates pallet-salary to use the umbrella crate.
Added change: Explanation requested for why
TestExternalities
was replaced byTestState
as testing_prelude already includes itpub use sp_io::TestExternalities as TestState;
I have also modified the defensive! macro to be compatible with umbrella crate as it was being used in the salary pallet