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

982 renaming issue #1052

Merged
merged 9 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 6 additions & 6 deletions pallets/identity-management-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
// Events from this pallet
LinkIdentityRequested {
CreateIdentityRequested {
shard: ShardIdentifier,
},
UnlinkIdentityRequested {
RemoveIdentityRequested {
shard: ShardIdentifier,
},
VerifyIdentityRequested {
Expand Down Expand Up @@ -285,15 +285,15 @@ pub mod pallet {

/// Link an identity
Kailai-Wang marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::weight(195_000_000)]
pub fn link_identity(
pub fn create_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
encrypted_metadata: Option<Vec<u8>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
Self::deposit_event(Event::LinkIdentityRequested { shard });
Self::deposit_event(Event::CreateIdentityRequested { shard });

let decrypted_identitty = Self::decrypt_with_tee_shielding_key(&encrypted_identity)?;
let identity = Identity::decode(&mut decrypted_identitty.as_slice())
Expand Down Expand Up @@ -351,14 +351,14 @@ pub mod pallet {

/// Unlink an identity
#[pallet::weight(195_000_000)]
pub fn unlink_identity(
pub fn remove_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
Self::deposit_event(Event::UnlinkIdentityRequested { shard });
Self::deposit_event(Event::RemoveIdentityRequested { shard });

let decrypted_identitty = Self::decrypt_with_tee_shielding_key(&encrypted_identity)?;
let identity = Identity::decode(&mut decrypted_identitty.as_slice())
Expand Down
10 changes: 5 additions & 5 deletions pallets/identity-management-mock/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ pub fn setup_user_shieding_key(
key
}

pub fn setup_link_identity(
pub fn setup_create_identity(
who: <Test as frame_system::Config>::AccountId,
identity: Identity,
bn: <Test as frame_system::Config>::BlockNumber,
) {
let key = setup_user_shieding_key(who);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
assert_ok!(IdentityManagementMock::link_identity(
assert_ok!(IdentityManagementMock::create_identity(
Origin::signed(who),
H256::random(),
encrypted_identity.to_vec(),
Expand Down Expand Up @@ -274,7 +274,7 @@ pub fn setup_verify_twitter_identity(
identity: Identity,
bn: <Test as frame_system::Config>::BlockNumber,
) {
setup_link_identity(who, identity.clone(), bn);
setup_create_identity(who, identity.clone(), bn);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
let validation_data = match &identity.web_type {
IdentityWebType::Web2(Web2Network::Twitter) => create_mock_twitter_validation_data(),
Expand All @@ -294,7 +294,7 @@ pub fn setup_verify_polkadot_identity(
bn: <Test as frame_system::Config>::BlockNumber,
) {
let identity = create_mock_polkadot_identity(p.public().0);
setup_link_identity(who, identity.clone(), bn);
setup_create_identity(who, identity.clone(), bn);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
let code = IdentityManagementMock::challenge_codes(&who, &identity).unwrap();
let validation_data = match &identity.web_type {
Expand All @@ -321,7 +321,7 @@ pub fn setup_verify_eth_identity(
bn: <Test as frame_system::Config>::BlockNumber,
) {
let identity = create_mock_eth_identity(p.address().0);
setup_link_identity(who, identity.clone(), bn);
setup_create_identity(who, identity.clone(), bn);
let encrypted_identity = tee_encrypt(identity.encode().as_slice());
let code = IdentityManagementMock::challenge_codes(&who, &identity).unwrap();
let validation_data = match &identity.web_type {
Expand Down
6 changes: 3 additions & 3 deletions pallets/identity-management-mock/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn set_user_shielding_key_works() {
fn link_twitter_identity_works() {
new_test_ext().execute_with(|| {
System::set_block_number(5);
setup_link_identity(2, create_mock_twitter_identity(), 5);
setup_create_identity(2, create_mock_twitter_identity(), 5);
});
}

Expand All @@ -59,7 +59,7 @@ fn link_polkadot_identity_works() {
new_test_ext().execute_with(|| {
System::set_block_number(3);
let p = sp_core::sr25519::Pair::from_string("//Alice", None).unwrap();
setup_link_identity(2, create_mock_polkadot_identity(p.public().0), 3);
setup_create_identity(2, create_mock_polkadot_identity(p.public().0), 3);
});
}

Expand All @@ -68,7 +68,7 @@ fn link_eth_identity_works() {
new_test_ext().execute_with(|| {
System::set_block_number(3);
let p = Random.generate();
setup_link_identity(2, create_mock_eth_identity(p.address().0), 3);
setup_create_identity(2, create_mock_eth_identity(p.address().0), 3);
});
}

Expand Down
12 changes: 6 additions & 6 deletions pallets/identity-management/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {

benchmarks! {

// Benchmark `link_identity`. There are no worst conditions. The benchmark showed that
// Benchmark `create_identity`. There are no worst conditions. The benchmark showed that
// execution time is constant irrespective of encrypted_data size.
link_identity {
create_identity {
let caller = whitelisted_caller();
let shard = H256::from_slice(&TEST_MRENCLAVE);
let encrypted_did = vec![1u8; 2048];
let encrypted_metadata = Some(vec![1u8; 2048]);
}: _(RawOrigin::Signed(caller), shard, encrypted_did, encrypted_metadata)
verify {
assert_last_event::<T>(Event::LinkIdentityRequested{ shard }.into());
assert_last_event::<T>(Event::CreateIdentityRequested{ shard }.into());
}

// Benchmark `unlink_identity`. There are no worst conditions. The benchmark showed that
// Benchmark `remove_identity`. There are no worst conditions. The benchmark showed that
// execution time is constant irrespective of encrypted_data size.
unlink_identity {
remove_identity {
let caller = whitelisted_caller();
let shard = H256::from_slice(&TEST_MRENCLAVE);
let encrypted_did = vec![1u8; 2048];
}: _(RawOrigin::Signed(caller), shard, encrypted_did )
verify {
assert_last_event::<T>(Event::UnlinkIdentityRequested{ shard }.into());
assert_last_event::<T>(Event::RemoveIdentityRequested{ shard }.into());
}

// Benchmark `verify_identity`. There are no worst conditions. The benchmark showed that
Expand Down
20 changes: 10 additions & 10 deletions pallets/identity-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ use sp_std::vec::Vec;

// fn types for handling inside tee-worker
pub type SetUserShieldingKeyFn = ([u8; 2], ShardIdentifier, Vec<u8>);
pub type LinkIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>, Option<Vec<u8>>);
pub type UnlinkIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>);
pub type CreateIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>, Option<Vec<u8>>);
pub type RemoveIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>);
pub type VerifyIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>, Vec<u8>);

#[frame_support::pallet]
Expand All @@ -75,8 +75,8 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
// TODO: do we need account as event parameter? This needs to be decided by F/E
LinkIdentityRequested { shard: ShardIdentifier },
UnlinkIdentityRequested { shard: ShardIdentifier },
CreateIdentityRequested { shard: ShardIdentifier },
RemoveIdentityRequested { shard: ShardIdentifier },
VerifyIdentityRequested { shard: ShardIdentifier },
SetUserShieldingKeyRequested { shard: ShardIdentifier },
// event that should be triggered by TEECallOrigin
Expand Down Expand Up @@ -110,27 +110,27 @@ pub mod pallet {
}

/// Link an identity
#[pallet::weight(<T as Config>::WeightInfo::link_identity())]
pub fn link_identity(
#[pallet::weight(<T as Config>::WeightInfo::create_identity())]
pub fn create_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
encrypted_metadata: Option<Vec<u8>>,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
Self::deposit_event(Event::LinkIdentityRequested { shard });
Self::deposit_event(Event::CreateIdentityRequested { shard });
Ok(().into())
}

/// Unlink an identity
#[pallet::weight(<T as Config>::WeightInfo::unlink_identity())]
pub fn unlink_identity(
#[pallet::weight(<T as Config>::WeightInfo::remove_identity())]
pub fn remove_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
Self::deposit_event(Event::UnlinkIdentityRequested { shard });
Self::deposit_event(Event::RemoveIdentityRequested { shard });
Ok(().into())
}

Expand Down
16 changes: 8 additions & 8 deletions pallets/identity-management/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ fn set_user_shielding_key_works() {
}

#[test]
fn link_identity_works() {
fn create_identity_works() {
new_test_ext().execute_with(|| {
let shard: ShardIdentifier = H256::from_slice(&TEST_MRENCLAVE);
assert_ok!(IdentityManagement::link_identity(
assert_ok!(IdentityManagement::create_identity(
Origin::signed(1),
shard,
vec![1u8; 2048],
Some(vec![1u8; 2048])
));
System::assert_last_event(Event::IdentityManagement(crate::Event::LinkIdentityRequested {
shard,
}));
System::assert_last_event(Event::IdentityManagement(
crate::Event::CreateIdentityRequested { shard },
));
});
}

#[test]
fn unlink_identity_works() {
fn remove_identity_works() {
new_test_ext().execute_with(|| {
let shard: ShardIdentifier = H256::from_slice(&TEST_MRENCLAVE);
assert_ok!(IdentityManagement::unlink_identity(Origin::signed(1), shard, vec![1u8; 2048]));
assert_ok!(IdentityManagement::remove_identity(Origin::signed(1), shard, vec![1u8; 2048]));
System::assert_last_event(Event::IdentityManagement(
crate::Event::UnlinkIdentityRequested { shard },
crate::Event::RemoveIdentityRequested { shard },
));
});
}
Expand Down
12 changes: 6 additions & 6 deletions pallets/identity-management/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ use sp_std::marker::PhantomData;

/// Weight functions needed for pallet_identity_management.
pub trait WeightInfo {
fn link_identity() -> Weight;
fn unlink_identity() -> Weight;
fn create_identity() -> Weight;
fn remove_identity() -> Weight;
fn verify_identity() -> Weight;
fn set_user_shielding_key() -> Weight;
}

/// Weights for pallet_identity_management using the Litentry node and recommended hardware.
pub struct LitentryWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for LitentryWeight<T> {
fn link_identity() -> Weight {
fn create_identity() -> Weight {
Weight::from_ref_time(17_000_000 as u64)
}
fn unlink_identity() -> Weight {
fn remove_identity() -> Weight {
Weight::from_ref_time(17_000_000 as u64)
}
fn verify_identity() -> Weight {
Expand All @@ -72,10 +72,10 @@ impl<T: frame_system::Config> WeightInfo for LitentryWeight<T> {

// For backwards compatibility and tests
impl WeightInfo for () {
fn link_identity() -> Weight {
fn create_identity() -> Weight {
Weight::from_ref_time(17_000_000 as u64)
}
fn unlink_identity() -> Weight {
fn remove_identity() -> Weight {
Weight::from_ref_time(17_000_000 as u64)
}
fn verify_identity() -> Weight {
Expand Down
4 changes: 2 additions & 2 deletions runtime/litmus/src/weights/pallet_identity_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ use sp_std::marker::PhantomData;
/// Weight functions for `pallet_identity_management`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_identity_management::WeightInfo for WeightInfo<T> {
fn link_identity() -> Weight {
fn create_identity() -> Weight {
Weight::from_ref_time(15_164_000 as u64)
}
fn unlink_identity() -> Weight {
fn remove_identity() -> Weight {
Weight::from_ref_time(14_108_000 as u64)
}
fn verify_identity() -> Weight {
Expand Down
4 changes: 2 additions & 2 deletions runtime/rococo/src/weights/pallet_identity_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ use sp_std::marker::PhantomData;
/// Weight functions for `pallet_identity_management`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_identity_management::WeightInfo for WeightInfo<T> {
fn link_identity() -> Weight {
fn create_identity() -> Weight {
Weight::from_ref_time(16_109_000 as u64)
}
fn unlink_identity() -> Weight {
fn remove_identity() -> Weight {
Weight::from_ref_time(14_568_000 as u64)
}
fn verify_identity() -> Weight {
Expand Down
Loading