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-society to use umbrella crate #7258

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 2 additions & 8 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sp-session = { optional = true, workspace = true }
sp-storage = { optional = true, workspace = true }
sp-transaction-pool = { optional = true, workspace = true }
sp-version = { optional = true, workspace = true }
sp-crypto-hashing = { optional = true, workspace = true }

frame-executive = { optional = true, workspace = true }
frame-system-rpc-runtime-api = { optional = true, workspace = true }
Expand Down Expand Up @@ -111,6 +112,7 @@ std = [
"sp-storage/std",
"sp-transaction-pool?/std",
"sp-version?/std",
"sp-crypto-hashing/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
29 changes: 4 additions & 25 deletions substrate/frame/society/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,32 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame = { workspace = true, features = ["runtime"] }
log = { workspace = true }
rand_chacha = { workspace = true }
scale-info = { features = ["derive"], workspace = true }

frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-arithmetic = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
frame-support-test = { workspace = true }
pallet-balances = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-crypto-hashing = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support-test/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"rand_chacha/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support-test/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
14 changes: 7 additions & 7 deletions substrate/frame/society/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

use super::*;

use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use frame::benchmarking::prelude::{RawOrigin, *};

use alloc::vec;
use sp_runtime::traits::Bounded;

use crate::Pallet as Society;

Expand Down Expand Up @@ -510,10 +508,12 @@ mod benchmarks {

impl_benchmark_test_suite!(
Society,
sp_io::TestExternalities::from(
<frame_system::GenesisConfig::<crate::mock::Test> as sp_runtime::BuildStorage>::build_storage(
&frame_system::GenesisConfig::default()).unwrap()
),
TestState::from(
<frame_system::GenesisConfig::<crate::mock::Test> as BuildStorage>::build_storage(
&frame_system::GenesisConfig::default()
)
.unwrap()
),
crate::mock::Test
);
}
26 changes: 4 additions & 22 deletions substrate/frame/society/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,31 +260,13 @@ pub mod migrations;
extern crate alloc;

use alloc::vec::Vec;
use frame_support::{
impl_ensure_origin_with_arg_ignoring_arg,
pallet_prelude::*,
storage::KeyLenOf,
traits::{
BalanceStatus, Currency, EnsureOrigin, EnsureOriginWithArg,
ExistenceRequirement::AllowDeath, Imbalance, OnUnbalanced, Randomness, ReservableCurrency,
StorageVersion,
},
PalletId,
};
use frame_system::pallet_prelude::*;

use frame::prelude::*;
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{
AccountIdConversion, CheckedAdd, CheckedSub, Hash, Saturating, StaticLookup,
TrailingZeroInput, Zero,
},
ArithmeticError::Overflow,
Percent, RuntimeDebug,
};

pub use weights::WeightInfo;

Expand Down Expand Up @@ -469,7 +451,7 @@ pub type GroupParamsFor<T, I> = GroupParams<BalanceOf<T, I>>;

pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

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

Expand Down Expand Up @@ -792,7 +774,7 @@ pub mod pallet {
}

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
pub pot: BalanceOf<T, I>,
}
Expand Down
16 changes: 7 additions & 9 deletions substrate/frame/society/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
use super::*;
use alloc::{vec, vec::Vec};
use codec::{Decode, Encode};
use frame_support::traits::{Defensive, DefensiveOption, Instance, UncheckedOnRuntimeUpgrade};

#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;
use frame::try_runtime::TryRuntimeError;
use frame::testing_prelude::*;
use frame::runtime::prelude::storage::unhashed;

/// The log target.
const TARGET: &'static str = "runtime::society::migration";
Expand Down Expand Up @@ -96,7 +95,7 @@ impl<

/// [`VersionUncheckedMigrateToV2`] wrapped in a [`frame_support::migrations::VersionedMigration`],
/// ensuring the migration is only performed when on-chain version is 0.
pub type MigrateToV2<T, I, PastPayouts> = frame_support::migrations::VersionedMigration<
pub type MigrateToV2<T, I, PastPayouts> = VersionedMigration<
0,
2,
VersionUncheckedMigrateToV2<T, I, PastPayouts>,
Expand All @@ -106,7 +105,6 @@ pub type MigrateToV2<T, I, PastPayouts> = frame_support::migrations::VersionedMi

pub(crate) mod v0 {
use super::*;
use frame_support::storage_alias;

/// A vote by a member on a candidate application.
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
Expand Down Expand Up @@ -226,7 +224,7 @@ pub fn assert_internal_consistency<T: Config<I>, I: Instance + 'static>() {
// Check all payouts are valid data.
for p in Payouts::<T, I>::iter_keys() {
let k = Payouts::<T, I>::hashed_key_for(&p);
let v = frame_support::storage::unhashed::get_raw(&k[..]).expect("value is in map");
let v = unhashed::get_raw(&k[..]).expect("value is in map");
assert!(PayoutRecordFor::<T, I>::decode(&mut &v[..]).is_ok());
}

Expand Down Expand Up @@ -293,7 +291,7 @@ pub fn from_original<T: Config<I>, I: Instance + 'static>(
if let Some(member) = m {
member.index = 0;
} else {
frame_support::defensive!(
defensive!(
"Member somehow disappeared from storage after it was inserted"
);
}
Expand All @@ -302,7 +300,7 @@ pub fn from_original<T: Config<I>, I: Instance + 'static>(
if let Some(member) = m {
member.index = member_count;
} else {
frame_support::defensive!(
defensive!(
"Member somehow disappeared from storage after it was queried"
);
}
Expand Down
11 changes: 3 additions & 8 deletions substrate/frame/society/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@
use super::*;
use crate as pallet_society;

use frame_support::{
assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types,
traits::{ConstU32, ConstU64},
};
use frame::testing_prelude::*;
use frame_support_test::TestRandomness;
use frame_system::EnsureSignedBy;
use sp_runtime::{traits::IdentityLookup, BuildStorage};

use RuntimeOrigin as Origin;

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

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down
5 changes: 2 additions & 3 deletions substrate/frame/society/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ use super::*;
use migrations::v0;
use mock::*;

use frame_support::{assert_noop, assert_ok};
use sp_crypto_hashing::blake2_256;
use sp_runtime::traits::BadOrigin;
use frame::testing_prelude::*;
use frame::deps::sp_crypto_hashing::blake2_256;
use BidKind::*;
use VouchingStatus::*;

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/society/src/weights.rs

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

27 changes: 20 additions & 7 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,17 @@ pub mod prelude {
/// 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, impl_ensure_origin_with_arg_ignoring_arg,
storage::KeyLenOf,
traits::{
BalanceStatus, Contains, Currency, Defensive, DefensiveOption, EitherOf, EnsureOrigin,
EnsureOriginWithArg, EstimateNextSessionRotation, ExistenceRequirement::AllowDeath,
Imbalance, Instance, IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OnUnbalanced,
OneSessionHandler, Randomness, RankedMembers, RankedMembersSwapHandler,
ReservableCurrency, StorageVersion, UncheckedOnRuntimeUpgrade,
},
PalletId, migrations::VersionedMigration,
};

/// Pallet prelude of `frame-system`.
Expand All @@ -231,9 +238,14 @@ pub mod prelude {

/// 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::{
traits::{
AccountIdConversion, BlockNumberProvider, Bounded, CheckedAdd, CheckedSub, Convert,
DispatchInfoOf, Dispatchable, Hash, ReduceBy, ReplaceWithDefault, SaturatedConversion,
Saturating, StaticLookup, TrailingZeroInput, Zero,
},
ArithmeticError::Overflow,
BuildStorage, Percent, RuntimeDebug,
};

/// Bounded storage related types.
Expand Down Expand Up @@ -583,6 +595,7 @@ pub mod deps {
pub use sp_core;
pub use sp_io;
pub use sp_runtime;
pub use sp_crypto_hashing;

pub use codec;
pub use scale_info;
Expand Down
Loading