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-identity to umbrella crate #6731

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
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.

23 changes: 4 additions & 19 deletions substrate/frame/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@ codec = { features = ["derive", "max-encoded-len"], workspace = true }
enumflags2 = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-keystore = { workspace = true, default-features = true }

[features]
Expand All @@ -37,27 +32,17 @@ default = ["std"]
std = [
"codec/std",
"enumflags2/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-keystore/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",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
23 changes: 16 additions & 7 deletions substrate/frame/identity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ use super::*;

use crate::{migration::v2::LazyMigrationV1ToV2, Pallet as Identity};
use alloc::{vec, vec::Vec};
use frame::{
benchmarking::prelude::*,
deps::RawOrigin,
runtime::types_common::Signature,
traits::{Bounded, EnsureOrigin, Get, IdentifyAccount, OnFinalize, OnInitialize, One},
};
/*
use frame_benchmarking::{account, v2::*, whitelisted_caller, BenchmarkError};
use frame_support::{
assert_ok, ensure,
traits::{EnsureOrigin, Get, OnFinalize, OnInitialize},
};
use frame_system::RawOrigin;
*/
use sp_io::crypto::{sr25519_generate, sr25519_sign};
/*
use sp_runtime::{
traits::{Bounded, IdentifyAccount, One},
MultiSignature, MultiSigner,
};

*/
const SEED: u32 = 0;

fn assert_has_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
Expand Down Expand Up @@ -134,7 +143,7 @@ fn bounded_username<T: Config>(username: Vec<u8>, suffix: Vec<u8>) -> Username<T
#[benchmarks(
where
<T as frame_system::Config>::AccountId: From<sp_runtime::AccountId32>,
T::OffchainSignature: From<MultiSignature>,
T::OffchainSignature: From<Signature>,
)]
mod benchmarks {
use super::*;
Expand Down Expand Up @@ -590,7 +599,7 @@ mod benchmarks {
let suffix = bench_suffix();
let allocation = 10;

assert_ok!(Identity::<T>::add_username_authority(
frame::testing_prelude::assert_ok!(Identity::<T>::add_username_authority(
origin.clone(),
authority_lookup.clone(),
suffix.clone(),
Expand Down Expand Up @@ -626,12 +635,12 @@ mod benchmarks {
let bounded_username = bounded_username::<T>(username.clone(), suffix.clone());

let public = sr25519_generate(0.into(), None);
let who_account: T::AccountId = MultiSigner::Sr25519(public).into_account().into();
let who_account: T::AccountId =
frame::deps::sp_runtime::MultiSigner::Sr25519(public).into_account().into();
let who_lookup = T::Lookup::unlookup(who_account.clone());

let signature = MultiSignature::Sr25519(
sr25519_sign(0.into(), &public, &bounded_username[..]).unwrap(),
);
let signature =
Signature::Sr25519(sr25519_sign(0.into(), &public, &bounded_username[..]).unwrap());

// Verify signature here to avoid surprise errors at runtime
assert!(signature.verify(&bounded_username[..], &public.into()));
Expand Down
9 changes: 7 additions & 2 deletions substrate/frame/identity/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ use codec::{Decode, Encode, MaxEncodedLen};
#[cfg(feature = "runtime-benchmarks")]
use enumflags2::BitFlag;
use enumflags2::{bitflags, BitFlags};
use frame_support::{traits::Get, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound};
use frame::{
derive::{CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebug, RuntimeDebugNoBound},
runtime::prelude::BoundedVec,
traits::Get,
};
// use frame_support::{traits::Get, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound};
use scale_info::{build::Variants, Path, Type, TypeInfo};
use sp_runtime::{BoundedVec, RuntimeDebug};
// use sp_runtime::{BoundedVec, RuntimeDebug};

use crate::types::{Data, IdentityInformationProvider};

Expand Down
17 changes: 14 additions & 3 deletions substrate/frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ extern crate alloc;
use crate::types::{AuthorityProperties, Provider, Suffix, Username, UsernameInformation};
use alloc::{boxed::Box, vec::Vec};
use codec::Encode;
use frame::{
prelude::*,
traits::{
AppendZerosInput, BalanceStatus, Currency, Defensive, Hash, IdentifyAccount,
OnUnbalanced, ReservableCurrency, StorageVersion, Verify, Zero,
},
};
pub use pallet::*;
/*
use frame_support::{
ensure,
pallet_prelude::{DispatchError, DispatchResult},
Expand All @@ -128,10 +137,11 @@ use frame_support::{
BoundedVec,
};
use frame_system::pallet_prelude::*;
pub use pallet::*;

use sp_runtime::traits::{
AppendZerosInput, Hash, IdentifyAccount, Saturating, StaticLookup, Verify, Zero,
};
*/
pub use types::{
Data, IdentityInformationProvider, Judgement, RegistrarIndex, RegistrarInfo, Registration,
};
Expand All @@ -145,10 +155,11 @@ type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
type ProviderOf<T> = Provider<BalanceOf<T>>;

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

#[pallet::config]
pub trait Config: frame_system::Config {
Expand Down
29 changes: 21 additions & 8 deletions substrate/frame/identity/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@
extern crate alloc;

use super::*;
use frame::deps::frame_support::{
migrations::{MigrationId, SteppedMigration, SteppedMigrationError, VersionedMigration},
pallet_prelude::*,
storage_alias,
traits::UncheckedOnRuntimeUpgrade,
weights::WeightMeter,
Hashable, IterableStorageMap,
migration,
};
/*
use frame_support::{
migrations::VersionedMigration, pallet_prelude::*, storage_alias,
traits::UncheckedOnRuntimeUpgrade, IterableStorageMap,
};
*/

#[cfg(feature = "try-runtime")]
use alloc::collections::BTreeMap;
#[cfg(feature = "try-runtime")]
use codec::{Decode, Encode};
#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;
use frame::deps::sp_runtime::TryRuntimeError;

pub const PALLET_MIGRATIONS_ID: &[u8; 15] = b"pallet-identity";

Expand Down Expand Up @@ -181,10 +192,12 @@ pub mod v1 {

pub mod v2 {
use super::*;
/*
use frame_support::{
migrations::{MigrationId, SteppedMigration, SteppedMigrationError},
weights::WeightMeter,
};
*/

type HashedKey = BoundedVec<u8, ConstU32<256>>;
// The resulting state of the step and the actual weight consumed.
Expand Down Expand Up @@ -603,15 +616,15 @@ pub mod v2 {
<T as Config>::MaxRegistrars,
<T as Config>::IdentityInformation,
> = Registration { judgements: Default::default(), deposit: 10u32.into(), info };
frame_support::migration::put_storage_value(
migration::put_storage_value(
b"Identity",
b"IdentityOf",
&account_id.twox_64_concat(),
(&registration, Some(username.clone())),
);
types_v1::AccountOfUsername::<T>::insert(&username, &account_id);
let since: BlockNumberFor<T> = 0u32.into();
frame_support::migration::put_storage_value(
migration::put_storage_value(
b"Identity",
b"PendingUsernames",
&username.blake2_128_concat(),
Expand Down Expand Up @@ -671,7 +684,7 @@ pub mod v2 {

#[cfg(test)]
mod tests {
use frame_support::Hashable;
// use frame_support::Hashable;

use super::*;
use crate::tests::{new_test_ext, Test};
Expand Down Expand Up @@ -724,7 +737,7 @@ pub mod v2 {
if i % 2 == 0 {
let has_identity = i % 4 == 0;
let reg = registration(has_identity);
frame_support::migration::put_storage_value(
migration::put_storage_value(
b"Identity",
b"IdentityOf",
&account_id.twox_64_concat(),
Expand All @@ -738,7 +751,7 @@ pub mod v2 {
let username_2: Username<Test> = username_2.try_into().unwrap();
types_v1::AccountOfUsername::<Test>::insert(&username_2, &account_id);
let reg = registration(has_identity);
frame_support::migration::put_storage_value(
migration::put_storage_value(
b"Identity",
b"IdentityOf",
&account_id.twox_64_concat(),
Expand All @@ -756,7 +769,7 @@ pub mod v2 {
bare_username.extend(suffix_1.iter());
let username: Username<Test> = bare_username.try_into().unwrap();
let since: BlockNumberFor<Test> = i.into();
frame_support::migration::put_storage_value(
migration::put_storage_value(
b"Identity",
b"PendingUsernames",
&username.blake2_128_concat(),
Expand All @@ -769,7 +782,7 @@ pub mod v2 {
for i in 120u8..130u8 {
let account_id = account_from_u8(i);
let reg = registration(true);
frame_support::migration::put_storage_value(
migration::put_storage_value(
b"Identity",
b"IdentityOf",
&account_id.twox_64_concat(),
Expand Down
26 changes: 22 additions & 4 deletions substrate/frame/identity/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,45 @@ use crate::{
};

use codec::{Decode, Encode};
use frame::{
deps::sp_io::crypto::{sr25519_generate, sr25519_sign},
hashing::H256,
runtime::{
prelude::{derive_impl, parameter_types, BoundedVec, EnsureRoot},
testing_prelude::BuildStorage,
types_common::{Signature as MultiSignature, MultiSigner},
},
testing_prelude::{assert_err, assert_noop, assert_ok, construct_runtime, TestExternalities},
traits::{
BadOrigin, BlakeTwo256, ConstU32, ConstU64, IdentifyAccount, IdentityLookup,
/*OnFinalize, OnInitialize,*/ Verify,
},
};
/*
use frame_support::{
assert_err, assert_noop, assert_ok, derive_impl, parameter_types,
traits::{ConstU32, ConstU64, Get, OnFinalize, OnInitialize},
BoundedVec,
};

use frame_system::EnsureRoot;
use sp_core::H256;
use sp_io::crypto::{sr25519_generate, sr25519_sign};
*/
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
/*
use sp_runtime::{
traits::{BadOrigin, BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
BuildStorage, MultiSignature, MultiSigner,
};

*/
type AccountIdOf<Test> = <Test as frame_system::Config>::AccountId;
pub type AccountPublic = <MultiSignature as Verify>::Signer;
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;

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

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -94,7 +112,7 @@ impl pallet_identity::Config for Test {
type WeightInfo = ();
}

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> {
balances: vec![
Expand All @@ -108,7 +126,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.register_extension(KeystoreExt::new(MemoryKeystore::new()));
ext.execute_with(|| System::set_block_number(1));
ext
Expand Down
10 changes: 9 additions & 1 deletion substrate/frame/identity/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,27 @@ use super::*;
use alloc::{vec, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use core::{fmt::Debug, iter::once, ops::Add};
use frame::{
derive::{CloneNoBound, PartialEqNoBound, RuntimeDebug, RuntimeDebugNoBound},
runtime::prelude::BoundedVec,
traits::{ConstU32, Get, Member, Zero},
};
/*
use frame_support::{
traits::{ConstU32, Get},
BoundedVec, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound,
};
*/
use scale_info::{
build::{Fields, Variants},
Path, Type, TypeInfo,
};
/*
use sp_runtime::{
traits::{Member, Zero},
RuntimeDebug,
};

*/
/// An identifier for a single name registrar/identity verification service.
pub type RegistrarIndex = u32;

Expand Down
Loading