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-offences and pallet-offences-benchmarking to use umbrella crate #7213

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
15 changes: 2 additions & 13 deletions Cargo.lock

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

24 changes: 4 additions & 20 deletions substrate/frame/offences/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,28 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["runtime"]}
log = { workspace = true }
pallet-balances = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde = { optional = true, workspace = true, default-features = true }
sp-runtime = { workspace = true }
sp-staking = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"serde",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-staking/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
Nathy-bajo marked this conversation as resolved.
Show resolved Hide resolved
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"frame/runtime-benchmarks"
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
22 changes: 3 additions & 19 deletions substrate/frame/offences/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true }
frame-benchmarking = { workspace = true }
frame = { workspace = true, features = ["runtime"]}
frame-election-provider-support = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
pallet-babe = { workspace = true }
pallet-balances = { workspace = true }
Expand All @@ -30,23 +28,17 @@ pallet-offences = { workspace = true }
pallet-session = { workspace = true }
pallet-staking = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-runtime = { workspace = true }
sp-staking = { workspace = true }

[dev-dependencies]
pallet-staking-reward-curve = { workspace = true, default-features = true }
pallet-timestamp = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame/std",
"frame-election-provider-support/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-babe/std",
"pallet-balances/std",
Expand All @@ -57,24 +49,16 @@ std = [
"pallet-staking/std",
"pallet-timestamp/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-staking/std",
]

runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-offences/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
]
10 changes: 2 additions & 8 deletions substrate/frame/offences/benchmarking/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@

use alloc::{vec, vec::Vec};

use frame_benchmarking::v2::*;
use frame_support::traits::Get;
use frame_system::{Config as SystemConfig, Pallet as System, RawOrigin};
use frame::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.

Why the benchmarking prelude is not good enough here?


use sp_runtime::{
traits::{Convert, Saturating, StaticLookup},
Perbill,
};
use sp_staking::offence::ReportOffence;
use frame::deps::sp_staking::offence::ReportOffence;

use pallet_babe::EquivocationOffence as BabeEquivocationOffence;
use pallet_balances::Config as BalancesConfig;
Expand Down
21 changes: 7 additions & 14 deletions substrate/frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,9 @@ use frame_election_provider_support::{
bounds::{ElectionBounds, ElectionBoundsBuilder},
onchain, SequentialPhragmen,
};
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, ConstU64},
};
use frame_system as system;
use frame::testing_prelude::*;
use pallet_session::historical as pallet_session_historical;
use sp_runtime::{
testing::{Header, UintAuthorityId},
BuildStorage, KeyTypeId, Perbill,
};


type AccountId = u64;
type Balance = u64;
Expand Down Expand Up @@ -58,9 +51,9 @@ impl pallet_session::historical::Config for Test {
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
}

sp_runtime::impl_opaque_keys! {
impl_opaque_keys! {
pub struct SessionKeys {
pub foo: sp_runtime::testing::UintAuthorityId,
pub foo: UintAuthorityId,
}
}

Expand Down Expand Up @@ -179,7 +172,7 @@ impl crate::Config for Test {}
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, RuntimeCall, u64, ()>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: system::{Pallet, Call, Event<T>},
Expand All @@ -192,7 +185,7 @@ frame_support::construct_runtime!(
}
);

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestExternalities {
Nathy-bajo marked this conversation as resolved.
Show resolved Hide resolved
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
sp_io::TestExternalities::new(t)
TestExternalities::new(t)
Nathy-bajo marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 3 additions & 5 deletions substrate/frame/offences/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ extern crate alloc;
use alloc::vec::Vec;
use codec::Encode;
use core::marker::PhantomData;
use frame_support::weights::Weight;
use sp_runtime::{traits::Hash, Perbill};
use sp_staking::{
use frame::prelude::*;
use frame::deps::sp_staking::{
offence::{Kind, Offence, OffenceDetails, OffenceError, OnOffenceHandler, ReportOffence},
SessionIndex,
};
Expand All @@ -48,10 +47,9 @@ type ReportIdOf<T> = <T as frame_system::Config>::Hash;

const LOG_TARGET: &str = "runtime::offences";

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

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

Expand Down
19 changes: 5 additions & 14 deletions substrate/frame/offences/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@

use super::{Config, Kind, OffenceDetails, Pallet, Perbill, SessionIndex, LOG_TARGET};
use alloc::vec::Vec;
use frame_support::{
pallet_prelude::ValueQuery,
storage_alias,
traits::{Get, GetStorageVersion, OnRuntimeUpgrade},
weights::Weight,
Twox64Concat,
};
use sp_staking::offence::OnOffenceHandler;

use frame::deps::sp_staking::offence::OnOffenceHandler;

#[cfg(feature = "try-runtime")]
use frame_support::ensure;
#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;
use frame::try_runtime::TryRuntimeError;

mod v0 {
use super::*;
Expand All @@ -45,7 +37,7 @@ mod v0 {
}

pub mod v1 {
use frame_support::traits::StorageVersion;
use StorageVersion;

use super::*;

Expand Down Expand Up @@ -118,8 +110,7 @@ mod test {
use super::*;
use crate::mock::{new_test_ext, with_on_offence_fractions, Runtime as T, KIND};
use codec::Encode;
use sp_runtime::Perbill;
use sp_staking::offence::OffenceDetails;
use frame::testing_prelude::*;

#[test]
fn migration_to_v1_works() {
Expand Down
15 changes: 5 additions & 10 deletions substrate/frame/offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
use crate as offences;
use crate::Config;
use codec::Encode;
use frame_support::{
derive_impl, parameter_types,
traits::ConstU32,
weights::{constants::RocksDbWeight, Weight},
};
use sp_runtime::{traits::IdentityLookup, BuildStorage, Perbill};
use sp_staking::{
use frame::testing_prelude::*;
use frame::deps::sp_staking::{
offence::{self, Kind, OffenceDetails},
SessionIndex,
};
Expand Down Expand Up @@ -60,9 +55,9 @@ pub fn with_on_offence_fractions<R, F: FnOnce(&mut Vec<Perbill>) -> R>(f: F) ->
OnOffencePerbill::mutate(|fractions| f(fractions))
}

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

frame_support::construct_runtime!(
construct_runtime!(
pub enum Runtime {
System: frame_system,
Offences: offences,
Expand All @@ -85,7 +80,7 @@ impl Config for Runtime {
type OnOffenceHandler = OnOffenceHandler;
}

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestState {
let t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
Expand Down
5 changes: 2 additions & 3 deletions substrate/frame/offences/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ use crate::mock::{
new_test_ext, offence_reports, with_on_offence_fractions, Offence, Offences, Runtime,
RuntimeEvent, System, KIND,
};
use frame_system::{EventRecord, Phase};
use sp_core::H256;
use sp_runtime::Perbill;
use frame::testing_prelude::*;
use frame::deps::sp_core::H256;
Nathy-bajo marked this conversation as resolved.
Show resolved Hide resolved

#[test]
fn should_get_reports_with_storagemap_getter_and_function_getter() {
Expand Down
23 changes: 16 additions & 7 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@
/// Dispatch types from `frame-support`, other fundamental traits
#[doc(no_inline)]
pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo};
pub use frame_support::traits::{
Contains, EitherOf, EstimateNextSessionRotation, Everything, IsSubType, MapSuccess,
NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler,
VariantCount, VariantCountOf,
pub use frame_support::{
defensive, defensive_assert,
traits::{
Contains, EitherOf, EstimateNextSessionRotation, Get, GetStorageVersion, IsSubType,
MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers,
RankedMembersSwapHandler, StorageVersion,
},
Twox64Concat,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this stays better in the hashing module

};

/// Pallet prelude of `frame-system`.
Expand All @@ -231,9 +235,13 @@

/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
pub use sp_runtime::{
testing::{Header, UintAuthorityId},
Copy link
Contributor

Choose a reason for hiding this comment

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

testing-specific items should go to the testing prelude

traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, Hash, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, something like Hash should go into the hashing module

},
BuildStorage, KeyTypeId, Perbill,
};

/// Bounded storage related types.
Expand Down Expand Up @@ -583,6 +591,7 @@
pub use sp_core;
pub use sp_io;
pub use sp_runtime;
pub use sp_staking;

Check failure on line 594 in substrate/frame/src/lib.rs

View workflow job for this annotation

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

unresolved import `sp_staking`

pub use codec;
pub use scale_info;
Expand Down
Loading