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-alliance to umbrella crate #6541

Open
wants to merge 9 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
8 changes: 2 additions & 6 deletions Cargo.lock

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

17 changes: 17 additions & 0 deletions prdoc/pr_6541.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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-alliance to umbrella crate.

doc:
- audience: Runtime Dev
description: |
Imports frame umbrella crate systems into pallet-alliance and
exports BoundedVec as part of runtime::prelude of the
polkadot-sdk-frame crate.

crates:
- name: pallet-alliance
bump: minor
- name: polkadot-sdk-frame
bump: minor
28 changes: 5 additions & 23 deletions substrate/frame/alliance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
array-bytes = { optional = true, workspace = true, default-features = true }
log = { workspace = true }

codec = { features = ["derive"], workspace = true }
scale-info = { features = ["derive"], workspace = true }

sp-core = { workspace = true }
sp-crypto-hashing = { optional = true, workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }

frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-identity = { workspace = true }
pallet-collective = { optional = true, workspace = true }

Expand All @@ -39,40 +30,31 @@ array-bytes = { workspace = true, default-features = true }
sp-crypto-hashing = { workspace = true }
pallet-balances = { workspace = true, default-features = true }
pallet-collective = { workspace = true, default-features = true }
pretty_assertions = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"pallet-collective?/std",
"pallet-identity/std",
"scale-info/std",
"sp-core/std",
"sp-crypto-hashing?/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"array-bytes",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"sp-crypto-hashing",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"pallet-collective?/try-runtime",
"pallet-identity/try-runtime",
"sp-runtime/try-runtime",
]
19 changes: 10 additions & 9 deletions substrate/frame/alliance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

#![cfg(feature = "runtime-benchmarks")]

use core::{cmp, mem::size_of};
use sp_runtime::traits::{Bounded, Hash, StaticLookup};

use frame_benchmarking::{account, v2::*, BenchmarkError};
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin as SystemOrigin};

use super::{Call as AllianceCall, Pallet as Alliance, *};
use core::{cmp, mem::size_of};
use frame::{
benchmarking::prelude::*,
deps::{
frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable},
frame_system::{Pallet as System, RawOrigin as SystemOrigin},
},
};

const SEED: u32 = 0;

Expand Down Expand Up @@ -193,7 +194,7 @@ mod benchmarks {

// Whitelist voter account from further DB operations.
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
add_to_whitelist(voter_key.into());

#[extrinsic_call]
_(SystemOrigin::Signed(voter), last_hash, index, approve);
Expand Down Expand Up @@ -264,7 +265,7 @@ mod benchmarks {

// Whitelist voter account from further DB operations.
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
add_to_whitelist(voter_key.into());

#[extrinsic_call]
close(SystemOrigin::Signed(voter), last_hash, index, Weight::MAX, bytes_in_storage);
Expand Down
22 changes: 7 additions & 15 deletions substrate/frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,13 @@ extern crate alloc;

use alloc::{boxed::Box, vec, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_runtime::{
traits::{Dispatchable, Saturating, StaticLookup, Zero},
DispatchError, RuntimeDebug,
};

use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, PostDispatchInfo},
ensure,
use frame::{
deps::sp_runtime::DispatchError,
prelude::*,
traits::{
ChangeMembers, Currency, Get, InitializeMembers, IsSubType, OnUnbalanced,
ReservableCurrency,
ChangeMembers, Currency, Dispatchable, InitializeMembers, OnUnbalanced, ReservableCurrency,
Saturating, StaticLookup, Zero,
},
weights::Weight,
};
use scale_info::TypeInfo;

Expand Down Expand Up @@ -215,7 +207,7 @@ type UnscrupulousItemOf<T, I> =

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

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

Expand Down Expand Up @@ -399,7 +391,7 @@ pub mod pallet {
}

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(frame::derive::DefaultNoBound)]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
pub fellows: Vec<T::AccountId>,
pub allies: Vec<T::AccountId>,
Expand Down
7 changes: 6 additions & 1 deletion substrate/frame/alliance/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
// limitations under the License.

use crate::{Config, Pallet, Weight, LOG_TARGET};
use frame_support::{pallet_prelude::*, storage::migration, traits::OnRuntimeUpgrade};
use frame::{
deps::frame_support::{pallet_prelude::*, storage::migration},
traits::OnRuntimeUpgrade,
};
use log;

/// The in-code storage version.
Expand Down Expand Up @@ -163,6 +166,8 @@ pub(crate) mod v1_to_v2 {
mod test {
use super::*;
use crate::{mock::*, MemberRole, Members};
use frame::testing_prelude::assert_ok;
use pretty_assertions::assert_eq;

#[test]
fn migration_v1_to_v2_works() {
Expand Down
33 changes: 16 additions & 17 deletions substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
// limitations under the License.

//! Test utilities

pub use sp_core::H256;
use sp_runtime::traits::Hash;
pub use sp_runtime::{
traits::{BlakeTwo256, IdentifyAccount, Lazy, Verify},
BuildStorage,
};

pub use frame_support::{
assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types,
traits::EitherOfDiverse, BoundedVec,
use frame::{
arithmetic::Perbill,
runtime::{
prelude::{
construct_runtime, derive_impl, ord_parameter_types, parameter_types, BoundedVec,
EnsureRoot, EnsureSignedBy,
},
testing_prelude::BuildStorage,
},
testing_prelude::{assert_noop, assert_ok, TestExternalities},
traits::{EitherOfDiverse, IdentifyAccount, Lazy, Verify},
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use pallet_identity::{
legacy::{IdentityField, IdentityInfo},
Data, IdentityOf, Judgement, SuperOf,
Expand Down Expand Up @@ -63,7 +62,7 @@ parameter_types! {
pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS;
pub const MaxProposals: u32 = 100;
pub const MaxMembers: u32 = 100;
pub MaxProposalWeight: Weight = sp_runtime::Perbill::from_percent(50) * BlockWeights::get().max_block;
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * BlockWeights::get().max_block;
}
type AllianceCollective = pallet_collective::Instance1;
impl pallet_collective::Config<AllianceCollective> for Test {
Expand Down Expand Up @@ -237,7 +236,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 Down Expand Up @@ -268,7 +267,7 @@ pub(super) fn test_identity_info_deposit() -> <Test as pallet_balances::Config>:
byte_deposit * test_identity_info().encoded_size() as u64 + basic_deposit
}

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 @@ -295,7 +294,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(|| {
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1));

Expand Down Expand Up @@ -372,7 +371,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
}

#[cfg(feature = "runtime-benchmarks")]
pub fn new_bench_ext() -> sp_io::TestExternalities {
pub fn new_bench_ext() -> TestExternalities {
RuntimeGenesisConfig::default().build_storage().unwrap().into()
}

Expand Down
11 changes: 7 additions & 4 deletions substrate/frame/alliance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

//! Tests for the alliance pallet.

use frame_support::{assert_noop, assert_ok};
use frame_system::{EventRecord, Phase};
use sp_runtime::traits::BadOrigin;

use super::*;
use crate::{self as alliance, mock::*};
use frame::{
deps::{
frame_system::{EventRecord, Phase},
sp_runtime::DispatchError::BadOrigin,
},
testing_prelude::{assert_noop, assert_ok},
};

type AllianceMotionEvent = pallet_collective::Event<Test, pallet_collective::Instance1>;

Expand Down
6 changes: 4 additions & 2 deletions substrate/frame/alliance/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

use alloc::vec::Vec;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{traits::ConstU32, BoundedVec};
use frame::{
derive::RuntimeDebug,
runtime::prelude::{BoundedVec, ConstU32},
};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

/// A Multihash instance that only supports the basic functionality and no hashing.
#[derive(
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/alliance/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 @@ -342,6 +342,9 @@ pub mod runtime {
/// Consider using the new version of this [`frame_construct_runtime`].
pub use frame_support::construct_runtime;

/// Related to runtime contruction.
pub use frame_support::BoundedVec;

/// Macro to amalgamate the runtime into `struct Runtime`.
///
/// This is the newer version of [`construct_runtime`].
Expand Down