Skip to content

Commit

Permalink
remove redundant imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Kailai-Wang committed Apr 28, 2023
1 parent 237d582 commit 24be83b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 92 deletions.
2 changes: 1 addition & 1 deletion tee-worker/app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ where
match node_metadata_repo.get_from_metadata(|m| m.vc_issued_call_indexes()) {
Ok(Ok(c)) => calls.push(OpaqueCall::from_tuple(&(
c,
SgxParentchainTypeConverter::convert(who.clone()),
SgxParentchainTypeConverter::convert(who),
assertion,
vc_index,
vc_hash,
Expand Down
21 changes: 3 additions & 18 deletions tee-worker/enclave-runtime/src/stf_task_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ use crate::{
GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT, GLOBAL_STATE_OBSERVER_COMPONENT,
GLOBAL_TOP_POOL_AUTHOR_COMPONENT,
},
utils::{
get_extrinsic_factory_from_solo_or_parachain,
get_node_metadata_repository_from_solo_or_parachain,
},
GLOBAL_STATE_HANDLER_COMPONENT,
};

Expand Down Expand Up @@ -82,26 +78,15 @@ fn run_stf_task_handler_internal() -> Result<()> {
let shielding_key = Rsa3072Seal::unseal_from_static_file().unwrap();

let ocall_api = GLOBAL_OCALL_API_COMPONENT.get()?;

let node_metadata = get_node_metadata_repository_from_solo_or_parachain()?;
let extrinsic_factory = get_extrinsic_factory_from_solo_or_parachain()?;

let stf_enclave_signer = Arc::new(EnclaveStfEnclaveSigner::new(
state_observer,
ocall_api.clone(),
ocall_api,
shielding_key_repository,
author_api.clone(),
));

let stf_task_context = StfTaskContext::new(
shielding_key,
ocall_api,
extrinsic_factory,
node_metadata,
author_api,
stf_enclave_signer,
state_handler,
);
let stf_task_context =
StfTaskContext::new(shielding_key, author_api, stf_enclave_signer, state_handler);

run_stf_task_receiver(Arc::new(stf_task_context)).map_err(Error::StfTaskReceiver)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

use crate::{handler::TaskHandler, StfTaskContext, TrustedCall};
use ita_sgx_runtime::Hash;
use itp_extrinsics_factory::CreateExtrinsics;
use itp_node_api::metadata::{
pallet_imp::IMPCallIndexes, pallet_vcmp::VCMPCallIndexes, provider::AccessNodeMetadata,
};
use itp_ocall_api::EnclaveOnChainOCallApi;
use itp_sgx_crypto::{ShieldingCryptoDecrypt, ShieldingCryptoEncrypt};
use itp_sgx_externalities::SgxExternalitiesTrait;
use itp_stf_executor::traits::StfEnclaveSigning;
Expand All @@ -38,24 +33,17 @@ use std::{format, sync::Arc};

pub(crate) struct AssertionHandler<
K: ShieldingCryptoDecrypt + ShieldingCryptoEncrypt + Clone,
O: EnclaveOnChainOCallApi,
C: CreateExtrinsics,
M: AccessNodeMetadata,
A: AuthorApi<Hash, Hash>,
S: StfEnclaveSigning,
H: HandleState,
> {
pub(crate) req: AssertionBuildRequest,
pub(crate) context: Arc<StfTaskContext<K, O, C, M, A, S, H>>,
pub(crate) context: Arc<StfTaskContext<K, A, S, H>>,
}

impl<K, O, C, M, A, S, H> TaskHandler for AssertionHandler<K, O, C, M, A, S, H>
impl<K, A, S, H> TaskHandler for AssertionHandler<K, A, S, H>
where
K: ShieldingCryptoDecrypt + ShieldingCryptoEncrypt + Clone,
O: EnclaveOnChainOCallApi,
C: CreateExtrinsics,
M: AccessNodeMetadata,
M::MetadataType: IMPCallIndexes + VCMPCallIndexes,
A: AuthorApi<Hash, Hash>,
S: StfEnclaveSigning,
H: HandleState,
Expand Down Expand Up @@ -204,15 +192,17 @@ where

fn on_success(&self, result: Self::Result) {
debug!("Assertion build OK");
let (vc_index, vc_hash, output) = result;
// we shouldn't have the maximum text length limit in normal RSA3072 encryption, as the payload
// using enclave's shielding key is encrypted in chunks
let (vc_index, vc_hash, vc_payload) = result;
if let Ok(enclave_signer) = self.context.enclave_signer.get_enclave_account() {
let c = TrustedCall::handle_vc_issued(
enclave_signer,
self.req.who.clone(),
self.req.assertion.clone(),
vc_index,
vc_hash,
output,
vc_payload,
self.req.hash,
);
let _ = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

use crate::{handler::TaskHandler, StfTaskContext, TrustedCall};
use ita_sgx_runtime::Hash;
use itp_extrinsics_factory::CreateExtrinsics;
use itp_node_api::metadata::{
pallet_imp::IMPCallIndexes, pallet_vcmp::VCMPCallIndexes, provider::AccessNodeMetadata,
};
use itp_ocall_api::EnclaveOnChainOCallApi;
use itp_sgx_crypto::{ShieldingCryptoDecrypt, ShieldingCryptoEncrypt};
use itp_sgx_externalities::SgxExternalitiesTrait;
use itp_stf_executor::traits::StfEnclaveSigning;
Expand All @@ -33,24 +28,17 @@ use std::sync::Arc;

pub(crate) struct IdentityVerificationHandler<
K: ShieldingCryptoDecrypt + ShieldingCryptoEncrypt + Clone,
O: EnclaveOnChainOCallApi,
C: CreateExtrinsics,
M: AccessNodeMetadata,
A: AuthorApi<Hash, Hash>,
S: StfEnclaveSigning,
H: HandleState,
> {
pub(crate) req: IdentityVerificationRequest,
pub(crate) context: Arc<StfTaskContext<K, O, C, M, A, S, H>>,
pub(crate) context: Arc<StfTaskContext<K, A, S, H>>,
}

impl<K, O, C, M, A, S, H> TaskHandler for IdentityVerificationHandler<K, O, C, M, A, S, H>
impl<K, A, S, H> TaskHandler for IdentityVerificationHandler<K, A, S, H>
where
K: ShieldingCryptoDecrypt + ShieldingCryptoEncrypt + Clone,
O: EnclaveOnChainOCallApi,
C: CreateExtrinsics,
M: AccessNodeMetadata,
M::MetadataType: IMPCallIndexes + VCMPCallIndexes,
A: AuthorApi<Hash, Hash>,
S: StfEnclaveSigning,
H: HandleState,
Expand Down
56 changes: 14 additions & 42 deletions tee-worker/litentry/core/stf-task/receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ use handler::{
};
use ita_sgx_runtime::{Hash, IdentityManagement};
use ita_stf::{hash::Hash as TopHash, TrustedCall, TrustedOperation};
use itp_extrinsics_factory::CreateExtrinsics;
use itp_node_api::metadata::{
pallet_imp::IMPCallIndexes, pallet_vcmp::VCMPCallIndexes, provider::AccessNodeMetadata,
};
use itp_ocall_api::EnclaveOnChainOCallApi;
use itp_sgx_crypto::{ShieldingCryptoDecrypt, ShieldingCryptoEncrypt};
use itp_sgx_externalities::SgxExternalitiesTrait;
use itp_stf_executor::traits::StfEnclaveSigning;
Expand All @@ -57,7 +52,7 @@ use itp_top_pool_author::traits::AuthorApi;
use itp_types::ShardIdentifier;
use lc_stf_task_sender::{stf_task_sender, RequestType};
use log::{debug, error};
use std::{format, string::String, sync::Arc, vec::Vec};
use std::{format, string::String, sync::Arc};

#[derive(Debug, thiserror::Error, Clone)]
pub enum Error {
Expand All @@ -74,53 +69,32 @@ pub enum Error {
#[allow(dead_code)]
pub struct StfTaskContext<
K: ShieldingCryptoDecrypt + ShieldingCryptoEncrypt + Clone,
O: EnclaveOnChainOCallApi,
C: CreateExtrinsics,
M: AccessNodeMetadata,
A: AuthorApi<Hash, Hash>,
S: StfEnclaveSigning,
H: HandleState,
> {
shielding_key: K,
ocall_api: Arc<O>,
create_extrinsics: Arc<C>,
node_metadata: Arc<M>,
author_api: Arc<A>,
enclave_signer: Arc<S>,
pub state_handler: Arc<H>,
}

impl<
K: ShieldingCryptoDecrypt + ShieldingCryptoEncrypt + Clone,
O: EnclaveOnChainOCallApi,
C: CreateExtrinsics,
M: AccessNodeMetadata,
A: AuthorApi<Hash, Hash>,
S: StfEnclaveSigning,
H: HandleState,
> StfTaskContext<K, O, C, M, A, S, H>
> StfTaskContext<K, A, S, H>
where
H::StateT: SgxExternalitiesTrait,
M::MetadataType: IMPCallIndexes + VCMPCallIndexes,
{
pub fn new(
shielding_key: K,
ocall_api: Arc<O>,
create_extrinsics: Arc<C>,
node_metadata: Arc<M>,
author_api: Arc<A>,
enclave_signer: Arc<S>,
state_handler: Arc<H>,
) -> Self {
Self {
shielding_key,
ocall_api,
create_extrinsics,
node_metadata,
author_api,
enclave_signer,
state_handler,
}
Self { shielding_key, author_api, enclave_signer, state_handler }
}

fn submit_trusted_call(
Expand All @@ -138,15 +112,13 @@ where
// find out if we have any trusted operation which has the same hash in the pool already.
// The hash can be used to de-duplicate a trusted operation for a certain request, as the
// `trusted_call` in this fn always contains the req_ext_hash, which is unique for each request.
let filtered_top: Vec<TrustedOperation> = self
if self
.author_api
.get_pending_trusted_calls_for(*shard, trusted_call.sender_account())
.into_iter()
.filter(|t| t.hash() == top.hash())
.collect();

// skip the submission if filtered_top is non empty, return Ok(())
if !filtered_top.is_empty() {
.any(|t| t.hash() == top.hash())
{
// skip the submission if some top with the same hash already exists, return Ok(())
warn!("Skip submit_trusted_call because top with the same hash exists");
return Ok(())
}
Expand All @@ -156,7 +128,11 @@ where
.encrypt(&top.encode())
.map_err(|e| Error::OtherError(format!("{:?}", e)))?;

debug!("submit encrypted trusted call: {} bytes", encrypted_trusted_call.len());
debug!(
"submit encrypted trusted call: {} bytes, original encoded top: {} bytes",
encrypted_trusted_call.len(),
top.encode().len()
);
executor::block_on(self.author_api.submit_top(encrypted_trusted_call, *shard)).map_err(
|e| Error::OtherError(format!("error submitting trusted call to top pool: {:?}", e)),
)?;
Expand All @@ -166,15 +142,11 @@ where
}

// lifetime elision: StfTaskContext is guaranteed to outlive the fn
pub fn run_stf_task_receiver<K, O, C, M, A, S, H>(
context: Arc<StfTaskContext<K, O, C, M, A, S, H>>,
pub fn run_stf_task_receiver<K, A, S, H>(
context: Arc<StfTaskContext<K, A, S, H>>,
) -> Result<(), Error>
where
K: ShieldingCryptoDecrypt + ShieldingCryptoEncrypt + Clone,
O: EnclaveOnChainOCallApi,
C: CreateExtrinsics,
M: AccessNodeMetadata,
M::MetadataType: IMPCallIndexes + VCMPCallIndexes,
A: AuthorApi<Hash, Hash>,
S: StfEnclaveSigning,
H: HandleState,
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/vc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describeLitentry('VC test', 0, async (context) => {
for (let k = 0; k < res.length; k++) {
const vcString = res[k].vc.replace('0x', '');
const vcObj = JSON.parse(vcString);
console.log('---------VC json----------', vcObj);
console.log('---------VC json----------\n', vcObj);

const vcProof = vcObj.proof;

Expand Down

0 comments on commit 24be83b

Please sign in to comment.