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-tx-pause to umbrella crate #6630

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
7 changes: 1 addition & 6 deletions Cargo.lock

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

14 changes: 14 additions & 0 deletions prdoc/pr_6630.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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: migrate pallet-tx-pause to umbrella crate

doc:
- audience: Runtime Dev
description: |
This pull request adapts the frame umbrella crate into pallet-tx-pause
by importing existing systems into the pallet.

crates:
- name: pallet-tx-pause
bump: minor
23 changes: 4 additions & 19 deletions substrate/frame/tx-pause/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { features = ["derive"], workspace = true }
docify = { workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
scale-info = { features = ["derive"], workspace = true }
sp-runtime = { workspace = true }
pallet-balances = { optional = true, workspace = true }
pallet-utility = { optional = true, workspace = true }
pallet-proxy = { optional = true, workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }
pallet-balances = { workspace = true, default-features = true }
pallet-utility = { workspace = true, default-features = true }
pallet-proxy = { workspace = true, default-features = true }
Expand All @@ -37,31 +32,21 @@ pallet-proxy = { workspace = true, default-features = true }
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"pallet-balances?/std",
"pallet-proxy?/std",
"pallet-utility?/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances?/try-runtime",
"pallet-proxy?/try-runtime",
"pallet-utility?/try-runtime",
"sp-runtime/try-runtime",
]
2 changes: 1 addition & 1 deletion substrate/frame/tx-pause/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use super::{Pallet as TxPause, *};
use alloc::vec;
use frame_benchmarking::v2::*;
use frame::benchmarking::prelude::*;

#[benchmarks]
mod benchmarks {
Expand Down
30 changes: 13 additions & 17 deletions substrate/frame/tx-pause/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ pub mod weights;
extern crate alloc;

use alloc::vec::Vec;
use frame_support::{
dispatch::GetDispatchInfo,
pallet_prelude::*,
traits::{CallMetadata, Contains, GetCallMetadata, IsSubType, IsType},
DefaultNoBound,
use frame::{
deps::frame_support::{dispatch::GetDispatchInfo, DefaultNoBound},
prelude::*,
traits::{
CallMetadata, Contains, Dispatchable, GetCallMetadata, IsSubType, IsType, TransactionPause,
TransactionPauseError,
},
};
use frame_system::pallet_prelude::*;
use sp_runtime::{traits::Dispatchable, DispatchResult};

pub use pallet::*;
pub use weights::*;

Expand All @@ -101,7 +100,8 @@ pub type PalletCallNameOf<T> = BoundedVec<u8, <T as Config>::MaxNameLen>;
/// to partially or fully specify an item a variant of a [`Config::RuntimeCall`].
pub type RuntimeCallNameOf<T> = (PalletNameOf<T>, PalletCallNameOf<T>);

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

Expand Down Expand Up @@ -294,7 +294,7 @@ where
}
}

impl<T: Config> frame_support::traits::TransactionPause for Pallet<T> {
impl<T: Config> TransactionPause for Pallet<T> {
type CallIdentifier = RuntimeCallNameOf<T>;

fn is_paused(full_name: Self::CallIdentifier) -> bool {
Expand All @@ -305,20 +305,16 @@ impl<T: Config> frame_support::traits::TransactionPause for Pallet<T> {
Self::ensure_can_pause(&full_name).is_ok()
}

fn pause(
full_name: Self::CallIdentifier,
) -> Result<(), frame_support::traits::TransactionPauseError> {
fn pause(full_name: Self::CallIdentifier) -> Result<(), TransactionPauseError> {
Self::do_pause(full_name).map_err(Into::into)
}

fn unpause(
full_name: Self::CallIdentifier,
) -> Result<(), frame_support::traits::TransactionPauseError> {
fn unpause(full_name: Self::CallIdentifier) -> Result<(), TransactionPauseError> {
Self::do_unpause(full_name).map_err(Into::into)
}
}

impl<T: Config> From<Error<T>> for frame_support::traits::TransactionPauseError {
impl<T: Config> From<Error<T>> for TransactionPauseError {
fn from(err: Error<T>) -> Self {
match err {
Error::<T>::NotFound => Self::NotFound,
Expand Down
24 changes: 14 additions & 10 deletions substrate/frame/tx-pause/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

use super::*;
use crate as pallet_tx_pause;

use frame_support::{
derive_impl, parameter_types,
traits::{ConstU64, Everything, InsideBoth, InstanceFilter},
use frame::{
prelude::frame_system,
runtime::{
prelude::{
Copy link
Contributor

Choose a reason for hiding this comment

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

preludes are meant to be imported as prelude::*.

Please read the instructions of the tracking issue as to how to do this migration more carefully.

Copy link
Author

Choose a reason for hiding this comment

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

@kianenigma There are cases where only one item is needed in the prelude

construct_runtime, derive_impl, ord_parameter_types, parameter_types, EnsureSignedBy,
},
testing_prelude::BuildStorage,
},
testing_prelude::TestExternalities,
traits::{BlakeTwo256, ConstU64, Everything, InsideBoth, InstanceFilter},
};
use frame_system::EnsureSignedBy;
use sp_runtime::{traits::BlakeTwo256, BuildStorage};

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
Expand Down Expand Up @@ -112,7 +116,7 @@ parameter_types! {
pub const MaxNameLen: u32 = 50;
}

frame_support::ord_parameter_types! {
ord_parameter_types! {
pub const PauseOrigin: u64 = 1;
pub const UnpauseOrigin: u64 = 2;
}
Expand Down Expand Up @@ -140,7 +144,7 @@ impl Config for Test {

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

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand All @@ -151,7 +155,7 @@ frame_support::construct_runtime!(
}
);

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Test> {
Expand All @@ -165,7 +169,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
let mut ext = TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
});
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/tx-pause/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

use super::*;
use crate::mock::{RuntimeCall, *};

use frame_support::{assert_err, assert_noop, assert_ok};
use sp_runtime::DispatchError;

use frame::{
deps::sp_runtime::DispatchError,
testing_prelude::{assert_err, assert_noop, assert_ok},
};
// GENERAL SUCCESS/POSITIVE TESTS ---------------------

#[docify::export]
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/tx-pause/src/weights.rs

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