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

migrate pallet-node-authorization to use umbrella crate #7040

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions prdoc/pr_7040.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: '[pallet-node-authorization] Migrate to using frame umbrella crate'

doc:
- audience: Runtime Dev
description: This PR migrates the pallet-node-authorization to use the frame umbrella crate. This
Copy link
Contributor

Choose a reason for hiding this comment

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

The whole issue is marked as R0-silent, as well as this PR, so we don't need a PRdoc unless you do something more than just the migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be pedantic, we are only adding new types to frame, and adding things is still worthy of PRDoc and minor upgrade based on semver rules.

If we have merged some PRs already in this direction without PRDoc, it is okay since this crate is quite fresh, but going forward they should have PRDoc.

pallet-node-authorization should not be minor afaik, and since nothing is changing, it is a patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ggwpez can you please double check I am not wrong?

Copy link
Contributor Author

@UtkarshBhardwaj007 UtkarshBhardwaj007 Jan 6, 2025

Choose a reason for hiding this comment

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

I have been creating prdocs for the 2 PRs I have raised for this issue. My reasoning was that even though the changes in pallets could be argued to be none but adding new re-exports in the umbrella pallet must be a minor change.

pallet-node-authorization should not be minor afaik, and since nothing is changing, it is a patch.

I thought about this. I checked the SemVer documnetation and it seems like the recommedation for patch is specifically for bug fixes. Any changes to internal private functions could thus be categorised as minor. Since we are basically just changing imports and internal dependencies, I thought minor to be most accurate here. Curious to hear your thoughts @kianenigma @re-gius @ggwpez .

Copy link
Contributor

Choose a reason for hiding this comment

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

Your description sounds more educated than mine, and I trust it more here :) so minor for both sounds good to me.

is part of the ongoing effort to migrate all pallets to use the frame umbrella crate.
The effort is tracked [here](https://github.com/paritytech/polkadot-sdk/issues/6504).

crates:
- name: pallet-node-authorization
bump: minor
- name: polkadot-sdk-frame
bump: minor
16 changes: 3 additions & 13 deletions substrate/frame/node-authorization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,18 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
14 changes: 7 additions & 7 deletions substrate/frame/node-authorization/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ pub mod weights;
extern crate alloc;

use alloc::{collections::btree_set::BTreeSet, vec::Vec};
use frame::{
deps::{sp_core::OpaquePeerId as PeerId, sp_io},
prelude::*,
};
pub use pallet::*;
use sp_core::OpaquePeerId as PeerId;
use sp_runtime::traits::StaticLookup;
pub use weights::WeightInfo;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::pallet]
#[pallet::without_storage_info]
Expand Down Expand Up @@ -111,7 +111,7 @@ pub mod pallet {
StorageMap<_, Blake2_128Concat, PeerId, BTreeSet<PeerId>, ValueQuery>;

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub nodes: Vec<(PeerId, T::AccountId)>,
}
Expand Down Expand Up @@ -171,7 +171,7 @@ pub mod pallet {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// Set reserved node every block. It may not be enabled depends on the offchain
/// worker settings when starting the node.
fn offchain_worker(now: frame_system::pallet_prelude::BlockNumberFor<T>) {
fn offchain_worker(now: BlockNumberFor<T>) {
let network_state = sp_io::offchain::network_state();
match network_state {
Err(_) => log::error!(
Expand Down
8 changes: 3 additions & 5 deletions substrate/frame/node-authorization/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
use super::*;
use crate as pallet_node_authorization;

use frame_support::{derive_impl, ord_parameter_types, traits::ConstU32};
use frame_system::EnsureSignedBy;
use sp_runtime::BuildStorage;
use frame::testing_prelude::*;

type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -61,7 +59,7 @@ pub fn test_node(id: u8) -> PeerId {
PeerId(vec![id])
}

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestState {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_node_authorization::GenesisConfig::<Test> {
nodes: vec![(test_node(10), 10), (test_node(20), 20), (test_node(30), 30)],
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/node-authorization/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

use super::*;
use crate::mock::*;
use frame_support::{assert_noop, assert_ok};
use sp_runtime::traits::BadOrigin;
use frame::testing_prelude::*;

#[test]
fn add_well_known_node_works() {
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/node-authorization/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ pub mod testing_prelude {
pub use sp_io::TestExternalities;

pub use sp_io::TestExternalities as TestState;

/// Commonly used runtime traits for testing.
pub use sp_runtime::traits::BadOrigin;
}

/// All of the types and tools needed to build FRAME-based runtimes.
Expand Down
Loading