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 safe mode to umbrella crate #6905

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 1 addition & 4 deletions Cargo.lock

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

23 changes: 4 additions & 19 deletions substrate/frame/safe-mode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ 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-arithmetic = { workspace = true }
sp-runtime = { workspace = true }
pallet-balances = { optional = true, workspace = true }
pallet-utility = { optional = true, workspace = true }
pallet-proxy = { optional = true, workspace = true }
Expand All @@ -39,32 +35,21 @@ frame-support = { features = ["experimental"], workspace = true, default-feature
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-arithmetic/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",
]
6 changes: 2 additions & 4 deletions substrate/frame/safe-mode/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@

use super::{Pallet as SafeMode, *};

use frame_benchmarking::v2::*;
use frame_support::traits::{fungible, UnfilteredDispatchable};
use frame_system::{Pallet as System, RawOrigin};
use sp_runtime::traits::{Bounded, One, Zero};
use frame::{benchmarking::prelude::*, traits::UnfilteredDispatchable};
use frame::deps::frame_system::{Pallet as System, RawOrigin};

#[benchmarks(where T::Currency: fungible::Mutate<T::AccountId>)]
mod benchmarks {
Expand Down
22 changes: 8 additions & 14 deletions substrate/frame/safe-mode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@
mod tests;
pub mod weights;

use frame_support::{
defensive_assert,
pallet_prelude::*,
use frame::{
prelude::*,
traits::{
fungible::{
self,
Expand All @@ -86,20 +85,15 @@
tokens::{Fortitude, Precision},
CallMetadata, Contains, Defensive, GetCallMetadata, PalletInfoAccess, SafeModeNotify,
},
weights::Weight,
DefaultNoBound,
};
use frame_system::pallet_prelude::*;
use sp_arithmetic::traits::Zero;
use sp_runtime::traits::Saturating;

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

type BalanceOf<T> =
<<T as Config>::Currency as fungible::Inspect<<T as frame_system::Config>::AccountId>>::Balance;

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

Expand Down Expand Up @@ -553,7 +547,7 @@
Fortitude::Force,
)
.map_err(|_| Error::<T>::CurrencyError)?;
defensive_assert!(burned == amount, "Could not burn the full held amount");

Check failure on line 550 in substrate/frame/safe-mode/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

failed to resolve: use of undeclared crate or module `frame_support`
Self::deposit_event(Event::<T>::DepositSlashed { account, amount });
Ok(())
}
Expand Down Expand Up @@ -609,7 +603,7 @@
}
}

impl<T: Config> frame_support::traits::SafeMode for Pallet<T> {
impl<T: Config> frame::traits::SafeMode for Pallet<T> {
type BlockNumber = BlockNumberFor<T>;

fn is_entered() -> bool {
Expand All @@ -623,20 +617,20 @@
})
}

fn enter(duration: BlockNumberFor<T>) -> Result<(), frame_support::traits::SafeModeError> {
fn enter(duration: BlockNumberFor<T>) -> Result<(), frame::traits::SafeModeError> {
Self::do_enter(None, duration).map_err(Into::into)
}

fn extend(duration: BlockNumberFor<T>) -> Result<(), frame_support::traits::SafeModeError> {
fn extend(duration: BlockNumberFor<T>) -> Result<(), frame::traits::SafeModeError> {
Self::do_extend(None, duration).map_err(Into::into)
}

fn exit() -> Result<(), frame_support::traits::SafeModeError> {
fn exit() -> Result<(), frame::traits::SafeModeError> {
Self::do_exit(ExitReason::Force).map_err(Into::into)
}
}

impl<T: Config> From<Error<T>> for frame_support::traits::SafeModeError {
impl<T: Config> From<Error<T>> for frame::traits::SafeModeError {
fn from(err: Error<T>) -> Self {
match err {
Error::<T>::Entered => Self::AlreadyEntered,
Expand Down
22 changes: 12 additions & 10 deletions substrate/frame/safe-mode/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
use super::*;
use crate as pallet_safe_mode;

use frame_support::{
derive_impl, parameter_types,
traits::{ConstU64, Everything, InsideBoth, InstanceFilter, IsInVec, SafeModeNotify},
};
use frame_system::EnsureSignedBy;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use frame::{deps::sp_io, testing_prelude::*};
use frame::traits::{BlakeTwo256, IdentityLookup, ConstU64, Everything, InsideBoth, InstanceFilter, IsInVec, SafeModeNotify};
// use frame_support::{
// derive_impl, parameter_types,
// traits::{ConstU64, Everything, InsideBoth, InstanceFilter, IsInVec, SafeModeNotify},
// };
// use frame_system::EnsureSignedBy;
// use sp_core::H256;
// use sp_runtime::{
// traits::{BlakeTwo256, IdentityLookup},
// BuildStorage,
// };

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/safe-mode/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
use super::*;
use crate::mock::{RuntimeCall, *};

use frame_support::{assert_err, assert_noop, assert_ok, hypothetically_ok, traits::Currency};
use sp_runtime::traits::Dispatchable;
use frame::{deps::frame_support::hypothetically_ok, testing_prelude::*, traits::Currency};

#[test]
fn fails_to_filter_calls_to_safe_mode_pallet() {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/safe-mode/src/weights.rs

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

Loading