Skip to content

Commit

Permalink
Using events instead of extrinsics as indirect call triggers (#2625)
Browse files Browse the repository at this point in the history
  • Loading branch information
silva-fj committed Apr 17, 2024
1 parent 315e701 commit f53fb13
Show file tree
Hide file tree
Showing 38 changed files with 982 additions and 1,556 deletions.
26 changes: 20 additions & 6 deletions pallets/identity-management/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ benchmarks! {
let encrypted_did = vec![1u8; 2048];
let encrypted_validation_data = vec![1u8; 2048];
let encrypted_web3networks = vec![1u8; 2048];
}: _(RawOrigin::Signed(caller.clone()), shard, caller.clone(), encrypted_did, encrypted_validation_data, encrypted_web3networks)
}: _(RawOrigin::Signed(caller.clone()), shard, caller.clone(), encrypted_did.clone(), encrypted_validation_data.clone(), encrypted_web3networks.clone())
verify {
assert_last_event::<T>(Event::LinkIdentityRequested{ shard }.into());
assert_last_event::<T>(Event::LinkIdentityRequested{
shard,
account: caller,
encrypted_identity: encrypted_did,
encrypted_validation_data,
encrypted_web3networks,
}.into());
}

// Benchmark `deactivate_identity`. There are no worst conditions. The benchmark showed that
Expand All @@ -74,9 +80,13 @@ benchmarks! {
let encrypted_validation_data = vec![1u8; 2048];
let encrypted_web3networks = vec![1u8; 2048];
IdentityManagement::<T>::link_identity(RawOrigin::Signed(caller.clone()).into(), shard, caller.clone(), encrypted_did.clone(), encrypted_validation_data, encrypted_web3networks)?;
}: _(RawOrigin::Signed(caller), shard, encrypted_did)
}: _(RawOrigin::Signed(caller.clone()), shard, encrypted_did.clone())
verify {
assert_last_event::<T>(Event::DeactivateIdentityRequested{ shard }.into());
assert_last_event::<T>(Event::DeactivateIdentityRequested{
shard,
account: caller,
encrypted_identity: encrypted_did,
}.into());
}

// Benchmark `activate_identity`. There are no worst conditions. The benchmark showed that
Expand All @@ -88,9 +98,13 @@ benchmarks! {
let encrypted_validation_data = vec![1u8; 2048];
let encrypted_web3networks = vec![1u8; 2048];
IdentityManagement::<T>::link_identity(RawOrigin::Signed(caller.clone()).into(), shard, caller.clone(), encrypted_did.clone(), encrypted_validation_data, encrypted_web3networks)?;
}: _(RawOrigin::Signed(caller), shard, encrypted_did)
}: _(RawOrigin::Signed(caller.clone()), shard, encrypted_did.clone())
verify {
assert_last_event::<T>(Event::ActivateIdentityRequested{ shard }.into());
assert_last_event::<T>(Event::ActivateIdentityRequested{
shard,
account: caller,
encrypted_identity: encrypted_did,
}.into());
}

// Benchmark `identity_linked`. There are no worst conditions. The benchmark showed that
Expand Down
32 changes: 27 additions & 5 deletions pallets/identity-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,20 @@ pub mod pallet {
// TODO: do we need account as event parameter? This needs to be decided by F/E
LinkIdentityRequested {
shard: ShardIdentifier,
account: T::AccountId,
encrypted_identity: Vec<u8>,
encrypted_validation_data: Vec<u8>,
encrypted_web3networks: Vec<u8>,
},
DeactivateIdentityRequested {
shard: ShardIdentifier,
account: T::AccountId,
encrypted_identity: Vec<u8>,
},
ActivateIdentityRequested {
shard: ShardIdentifier,
account: T::AccountId,
encrypted_identity: Vec<u8>,
},
// event that should be triggered by TEECallOrigin
// we return the request-extrinsic-hash for better tracking
Expand Down Expand Up @@ -210,7 +218,13 @@ pub mod pallet {
who == user || Delegatee::<T>::contains_key(&who),
Error::<T>::UnauthorizedUser
);
Self::deposit_event(Event::LinkIdentityRequested { shard });
Self::deposit_event(Event::LinkIdentityRequested {
shard,
account: user,
encrypted_identity,
encrypted_validation_data,
encrypted_web3networks,
});
Ok(().into())
}

Expand All @@ -222,8 +236,12 @@ pub mod pallet {
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
) -> DispatchResultWithPostInfo {
let _ = T::ExtrinsicWhitelistOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::DeactivateIdentityRequested { shard });
let who = T::ExtrinsicWhitelistOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::DeactivateIdentityRequested {
shard,
account: who,
encrypted_identity,
});
Ok(().into())
}

Expand All @@ -235,8 +253,12 @@ pub mod pallet {
shard: ShardIdentifier,
encrypted_identity: Vec<u8>,
) -> DispatchResultWithPostInfo {
let _ = T::ExtrinsicWhitelistOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::ActivateIdentityRequested { shard });
let who = T::ExtrinsicWhitelistOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::ActivateIdentityRequested {
shard,
account: who,
encrypted_identity,
});
Ok(().into())
}

Expand Down
46 changes: 36 additions & 10 deletions pallets/identity-management/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ fn link_identity_without_delegatee_works() {
assert_ok!(IdentityManagement::link_identity(
RuntimeOrigin::signed(alice.clone()),
shard,
alice,
alice.clone(),
vec![1u8; 2048],
vec![1u8; 2048],
vec![1u8; 2048],
));
System::assert_last_event(RuntimeEvent::IdentityManagement(
crate::Event::LinkIdentityRequested { shard },
crate::Event::LinkIdentityRequested {
shard,
account: alice,
encrypted_identity: vec![1u8; 2048],
encrypted_validation_data: vec![1u8; 2048],
encrypted_web3networks: vec![1u8; 2048],
},
));
});
}
Expand All @@ -53,13 +59,19 @@ fn link_identity_with_authorized_delegatee_works() {
assert_ok!(IdentityManagement::link_identity(
RuntimeOrigin::signed(eddie), // authorized delegatee set in initialisation
shard,
alice,
alice.clone(),
vec![1u8; 2048],
vec![1u8; 2048],
vec![1u8; 2048],
));
System::assert_last_event(RuntimeEvent::IdentityManagement(
crate::Event::LinkIdentityRequested { shard },
crate::Event::LinkIdentityRequested {
shard,
account: alice,
encrypted_identity: vec![1u8; 2048],
encrypted_validation_data: vec![1u8; 2048],
encrypted_web3networks: vec![1u8; 2048],
},
));
});
}
Expand Down Expand Up @@ -90,12 +102,16 @@ fn deactivate_identity_works() {
let alice: SystemAccountId = get_signer(ALICE_PUBKEY);
let shard: ShardIdentifier = H256::from_slice(&TEST8_MRENCLAVE);
assert_ok!(IdentityManagement::deactivate_identity(
RuntimeOrigin::signed(alice),
RuntimeOrigin::signed(alice.clone()),
shard,
vec![1u8; 2048]
));
System::assert_last_event(RuntimeEvent::IdentityManagement(
crate::Event::DeactivateIdentityRequested { shard },
crate::Event::DeactivateIdentityRequested {
shard,
account: alice,
encrypted_identity: vec![1u8; 2048],
},
));
});
}
Expand All @@ -106,12 +122,16 @@ fn activate_identity_works() {
let alice: SystemAccountId = get_signer(ALICE_PUBKEY);
let shard: ShardIdentifier = H256::from_slice(&TEST8_MRENCLAVE);
assert_ok!(IdentityManagement::activate_identity(
RuntimeOrigin::signed(alice),
RuntimeOrigin::signed(alice.clone()),
shard,
vec![1u8; 2048]
));
System::assert_last_event(RuntimeEvent::IdentityManagement(
crate::Event::ActivateIdentityRequested { shard },
crate::Event::ActivateIdentityRequested {
shard,
account: alice,
encrypted_identity: vec![1u8; 2048],
},
));
});
}
Expand Down Expand Up @@ -156,13 +176,19 @@ fn extrinsic_whitelist_origin_works() {
assert_ok!(IdentityManagement::link_identity(
RuntimeOrigin::signed(alice.clone()),
shard,
alice,
alice.clone(),
vec![1u8; 2048],
vec![1u8; 2048],
vec![1u8; 2048],
));
System::assert_last_event(RuntimeEvent::IdentityManagement(
crate::Event::LinkIdentityRequested { shard },
crate::Event::LinkIdentityRequested {
shard,
account: alice,
encrypted_identity: vec![1u8; 2048],
encrypted_validation_data: vec![1u8; 2048],
encrypted_web3networks: vec![1u8; 2048],
},
));
});
}
4 changes: 2 additions & 2 deletions pallets/teebag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub mod pallet {
who: T::AccountId,
},
OpaqueTaskPosted {
shard: ShardIdentifier,
request: RsaRequest,
},
ParentchainBlockProcessed {
who: T::AccountId,
Expand Down Expand Up @@ -527,7 +527,7 @@ pub mod pallet {
#[pallet::weight((195_000_000, DispatchClass::Normal))]
pub fn post_opaque_task(origin: OriginFor<T>, request: RsaRequest) -> DispatchResult {
let _ = ensure_signed(origin)?;
Self::deposit_event(Event::OpaqueTaskPosted { shard: request.shard });
Self::deposit_event(Event::OpaqueTaskPosted { request });
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

use itp_api_client_types::ParentchainApi;
use itp_types::parentchain::{BalanceTransfer, ParentchainId};
use itp_types::parentchain::{events::BalanceTransfer, ParentchainId};
use substrate_api_client::SubscribeEvents;

pub fn subscribe_to_parentchain_events(api: &ParentchainApi, parentchain_id: ParentchainId) {
Expand Down
80 changes: 0 additions & 80 deletions tee-worker/app-libs/parentchain-interface/src/extrinsic_parser.rs

This file was deleted.

This file was deleted.

0 comments on commit f53fb13

Please sign in to comment.