Skip to content

Commit

Permalink
feat: integrate extrinsic factory in VC handler (#3119)
Browse files Browse the repository at this point in the history
Replaced ParachainExtrinsicSender with itp-extrinsics-factory in VC
handler to send vc_issued extrinsics one by one.

Co-authored-by: Kai <[email protected]>
  • Loading branch information
2 people authored and BillyWooo committed Oct 8, 2024
1 parent a27f8bb commit 2346273
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tee-worker/Cargo.lock

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

2 changes: 1 addition & 1 deletion tee-worker/identity/enclave-runtime/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ fn run_vc_issuance() -> Result<(), Error> {
data_provider_config,
evm_assertion_repository,
);
let extrinsic_factory = get_extrinsic_factory_from_integritee_solo_or_parachain()?;
let node_metadata_repo = get_node_metadata_repository_from_integritee_solo_or_parachain()?;

run_vc_handler_runner(Arc::new(stf_task_context), node_metadata_repo);
run_vc_handler_runner(Arc::new(stf_task_context), extrinsic_factory, node_metadata_repo);

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sp-core = { workspace = true, features = ["full_crypto"] }
ita-sgx-runtime = { package = "id-ita-sgx-runtime", path = "../../../../app-libs/sgx-runtime", default-features = false }
ita-stf = { package = "id-ita-stf", path = "../../../../app-libs/stf", default-features = false }
itp-enclave-metrics = { workspace = true }
itp-extrinsics-factory = { workspace = true }
itp-node-api = { workspace = true }
itp-ocall-api = { workspace = true }
itp-sgx-crypto = { workspace = true }
Expand All @@ -29,7 +30,6 @@ itp-types = { workspace = true }
frame-support = { workspace = true }
lc-dynamic-assertion = { workspace = true }
lc-evm-dynamic-assertions = { workspace = true }
lc-parachain-extrinsic-task-sender = { workspace = true }
lc-stf-task-receiver = { workspace = true }
lc-stf-task-sender = { workspace = true }
lc-vc-task-sender = { workspace = true }
Expand All @@ -53,6 +53,7 @@ sgx = [
"lc-stf-task-sender/sgx",
"itp-node-api/sgx",
"itp-storage/sgx",
"itp-extrinsics-factory/sgx",
"lc-vc-task-sender/sgx",
"lc-dynamic-assertion/sgx",
"lc-evm-dynamic-assertions/sgx",
Expand All @@ -66,6 +67,7 @@ std = [
"itp-stf-executor/std",
"itp-stf-state-handler/std",
"itp-stf-primitives/std",
"itp-extrinsics-factory/std",
"sp-core/std",
"litentry-primitives/std",
"ita-sgx-runtime/std",
Expand Down
28 changes: 22 additions & 6 deletions tee-worker/identity/litentry/core/vc-task/receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use ita_stf::{
Getter, TrustedCall, TrustedCallSigned,
};
use itp_enclave_metrics::EnclaveMetric;
use itp_extrinsics_factory::CreateExtrinsics;
use itp_node_api::metadata::{
pallet_system::SystemConstants, pallet_vcmp::VCMPCallIndexes, provider::AccessNodeMetadata,
NodeMetadataTrait,
Expand All @@ -50,11 +51,11 @@ use itp_stf_state_handler::handle_state::HandleState;
use itp_storage::{storage_map_key, storage_value_key, StorageHasher};
use itp_top_pool_author::traits::AuthorApi;
use itp_types::{
AccountId, BlockNumber as SidechainBlockNumber, OpaqueCall, ShardIdentifier, H256,
parentchain::ParentchainId, AccountId, BlockNumber as SidechainBlockNumber, OpaqueCall,
ShardIdentifier, H256,
};
use lc_dynamic_assertion::AssertionLogicRepository;
use lc_evm_dynamic_assertions::AssertionRepositoryItem;
use lc_parachain_extrinsic_task_sender::{ParachainExtrinsicSender, SendParachainExtrinsic};
use lc_stf_task_receiver::{handler::assertion::create_credential_str, StfTaskContext};
use lc_vc_task_sender::init_vc_task_sender;
use litentry_macros::if_development_or;
Expand All @@ -78,8 +79,9 @@ use std::{
vec::Vec,
};

pub fn run_vc_handler_runner<ShieldingKeyRepository, A, S, H, O, N, AR>(
pub fn run_vc_handler_runner<ShieldingKeyRepository, A, S, H, O, Z, N, AR>(
context: Arc<StfTaskContext<ShieldingKeyRepository, A, S, H, O, AR>>,
extrinsic_factory: Arc<Z>,
node_metadata_repo: Arc<N>,
) where
ShieldingKeyRepository: AccessKey + Send + Sync + 'static,
Expand All @@ -90,6 +92,7 @@ pub fn run_vc_handler_runner<ShieldingKeyRepository, A, S, H, O, N, AR>(
H: HandleState + Send + Sync + 'static,
H::StateT: SgxExternalitiesTrait,
O: EnclaveOnChainOCallApi + EnclaveMetricsOCallApi + EnclaveAttestationOCallApi + 'static,
Z: CreateExtrinsics + Send + Sync + 'static,
N: AccessNodeMetadata + Send + Sync + 'static,
N::MetadataType: NodeMetadataTrait,
AR: AssertionLogicRepository<Id = H160, Item = AssertionRepositoryItem> + Send + Sync + 'static,
Expand Down Expand Up @@ -185,13 +188,15 @@ pub fn run_vc_handler_runner<ShieldingKeyRepository, A, S, H, O, N, AR>(

let shard_pool = request.shard;
let context_pool = context.clone();
let extrinsic_factory_pool = extrinsic_factory.clone();
let node_metadata_repo_pool = node_metadata_repo.clone();
let tc_sender_pool = tc_sender.clone();
let req_registry_pool = req_registry.clone();
pool.spawn_ok(async move {
let response = process_single_request(
shard_pool,
context_pool.clone(),
extrinsic_factory_pool,
node_metadata_repo_pool,
tc_sender_pool,
tcs.call.clone(),
Expand Down Expand Up @@ -249,6 +254,7 @@ pub fn run_vc_handler_runner<ShieldingKeyRepository, A, S, H, O, N, AR>(

let shard_pool = request.shard;
let context_pool = context.clone();
let extrinsic_factory_pool = extrinsic_factory.clone();
let node_metadata_repo_pool = node_metadata_repo.clone();
let tc_sender_pool = tc_sender.clone();
let req_registry_pool = req_registry.clone();
Expand All @@ -257,6 +263,7 @@ pub fn run_vc_handler_runner<ShieldingKeyRepository, A, S, H, O, N, AR>(
let response = process_single_request(
shard_pool,
context_pool.clone(),
extrinsic_factory_pool,
node_metadata_repo_pool,
tc_sender_pool,
new_call,
Expand Down Expand Up @@ -405,9 +412,10 @@ fn send_vc_response<ShieldingKeyRepository, A, S, H, O, AR>(
}
}

fn process_single_request<ShieldingKeyRepository, A, S, H, O, N, AR>(
fn process_single_request<ShieldingKeyRepository, A, S, H, O, Z, N, AR>(
shard: H256,
context: Arc<StfTaskContext<ShieldingKeyRepository, A, S, H, O, AR>>,
extrinsic_factory: Arc<Z>,
node_metadata_repo: Arc<N>,
tc_sender: Sender<(ShardIdentifier, TrustedCall)>,
call: TrustedCall,
Expand All @@ -421,6 +429,7 @@ where
H: HandleState + Send + Sync + 'static,
H::StateT: SgxExternalitiesTrait,
O: EnclaveOnChainOCallApi + EnclaveMetricsOCallApi + EnclaveAttestationOCallApi + 'static,
Z: CreateExtrinsics + Send + Sync + 'static,
N: AccessNodeMetadata + Send + Sync + 'static,
N::MetadataType: NodeMetadataTrait,
AR: AssertionLogicRepository<Id = H160, Item = AssertionRepositoryItem>,
Expand Down Expand Up @@ -599,8 +608,15 @@ where
.send((shard, c))
.map_err(|e| RequestVcErrorDetail::TrustedCallSendingFailed(e.to_string()))?;

let extrinsic_sender = ParachainExtrinsicSender::new();
extrinsic_sender.send(call).map_err(RequestVcErrorDetail::CallSendingFailed)?;
// this internally fetches nonce from a mutex and then updates it thereby ensuring ordering
let xt = extrinsic_factory
.create_extrinsics(&[call], None)
.map_err(|e| RequestVcErrorDetail::ExtrinsicConstructionFailed(e.to_string()))?;

context
.ocall_api
.send_to_parentchain(xt, &ParentchainId::Litentry, false)
.map_err(|e| RequestVcErrorDetail::ExtrinsicSendingFailed(e.to_string()))?;

if let Err(e) = context
.ocall_api
Expand Down

0 comments on commit 2346273

Please sign in to comment.