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

salary pallet migration to umbrella crate #7025

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

Conversation

seemantaggarwal
Copy link

βœ„ -----------------------------------------------------------------------------

Thank you for your Pull Request! πŸ™ Please make sure it follows the contribution guidelines outlined in this
document
and fill out the
sections below. Once you're ready to submit your PR for review, please delete this section and leave only the text under
the "Description" heading.

Description

Migrating salary pallet to use umbrella crates

Review Notes

This PR migrates pallet-salary to use the umbrella crate.

βœ„ -----------------------------------------------------------------------------

@seemantaggarwal seemantaggarwal requested a review from a team as a code owner January 2, 2025 08:09
@seemantaggarwal seemantaggarwal added R0-silent Changes should not be mentioned in any release notes T2-pallets This PR/Issue is related to a particular pallet. labels Jan 2, 2025
use sp_core::Get;

#[allow(deprecated)]
use frame::benchmarking::v1::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use frame::benchmarking::v1::*;
use frame::benchmarking::prelude::*;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, notice that here we have the v2 benchmarking syntax, not the v1 (see here for more details)


};
use frame::{
hashing::blake2_256,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hashing module is already imported in the main prelude, so you don't need this

substrate/frame/salary/src/lib.rs Show resolved Hide resolved
assert_noop, assert_ok, derive_impl,
pallet_prelude::Weight,
parameter_types,
use frame::{prelude::*, runtime::prelude::*, testing_prelude::*,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you need them all? Ideally, we would like to have only the testing prelude here because it's a test file and the testing prelude should already contain the other two

};

use frame::{prelude::*, runtime::prelude::*, testing_prelude::*,
traits::{ConstU64, EitherOf, MapSuccess, NoOpPoll,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConstU64 is already in the runtime::prelude::*, which is in the testing_prelude::*, so it's not needed. Try to double check the other traits and imports, they may already be imported through a prelude.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, to add to that - you might not need all these preludes. Try checking for each import and minimising the number of imports required.

@@ -17,43 +17,29 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
pallet-ranked-collective = { optional = true, workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp-core should be imported from the deps module to further reduce dependencies outside the umbrella.

Suggested change
sp-core = { workspace = true }

@@ -17,43 +17,29 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
pallet-ranked-collective = { optional = true, workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-arithmetic = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp-arithmetic is present in the main prelude and should be used directly from there instead of adding a dependency to this pallet.

Suggested change
sp-arithmetic = { workspace = true }

@@ -22,10 +22,9 @@
use super::*;
use crate::Pallet as Salary;

use frame_benchmarking::v2::*;
use frame_system::{Pallet as System, RawOrigin};
use sp_core::Get;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use sp_core::Get;
use frame::deps::sp_core::Get;

"frame-benchmarking?/std",
"frame-support/experimental",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-ranked-collective/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-core/std",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"sp-core/std",

"frame-benchmarking?/std",
"frame-support/experimental",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-ranked-collective/std",
"scale-info/std",
"sp-arithmetic/std",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"sp-arithmetic/std",

};

use frame::{prelude::*, runtime::prelude::*, testing_prelude::*,
traits::{ConstU64, EitherOf, MapSuccess, NoOpPoll,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, to add to that - you might not need all these preludes. Try checking for each import and minimising the number of imports required.

traits::{Convert, ReduceBy, ReplaceWithDefault},
BuildStorage,
};
use crate::tests::integration::sp_api_hidden_includes_construct_runtime::hidden_include::hypothetically;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import was originally from frame_support. Why not -

Suggested change
use crate::tests::integration::sp_api_hidden_includes_construct_runtime::hidden_include::hypothetically;
use frame::deps::frame_support::hypothetically;

or add it to one of the preludes where it makes sense?

frame_support::construct_runtime!(
pub enum Test
construct_runtime!(
pub struct Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain a bit as to why did we have to change this from an enum to a struct?

@@ -145,9 +144,9 @@ impl pallet_ranked_collective::Config for Test {
type BenchmarkSetup = Salary;
}

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestState{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add some explanation here as well?

@@ -194,7 +193,7 @@ fn swap_exhaustive_works() {

// The events mess up the storage root:
System::reset_events();
sp_io::storage::root(sp_runtime::StateVersion::V1)
sp_io::storage::root( frame::deps::sp_runtime::StateVersion::V1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the whole path here, let's import this at the top and then use it.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 2, 2025 18:32
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/12587029273
Failed job name: fmt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants