From a28259ef7373657122f55acf67ead23761e5499c Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Wed, 22 Nov 2023 18:07:11 +0100 Subject: [PATCH] not sure if we want this: separate init fn for integritee --- .../src/integritee/extrinsic_parser.rs | 1 + service/src/main_impl.rs | 51 +++++++++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app-libs/parentchain-interface/src/integritee/extrinsic_parser.rs b/app-libs/parentchain-interface/src/integritee/extrinsic_parser.rs index 1437a4ec38..af205f6d13 100644 --- a/app-libs/parentchain-interface/src/integritee/extrinsic_parser.rs +++ b/app-libs/parentchain-interface/src/integritee/extrinsic_parser.rs @@ -59,6 +59,7 @@ pub struct ParentchainSignedExtra { } pub type ParentchainAdditionalSigned = ((), u32, u32, Hash, Hash, (), (), ()); + impl ExtrinsicParams for ParentchainExtrinsicParams { type AdditionalParams = ParentchainAdditionalParams; type SignedExtra = ParentchainSignedExtra; diff --git a/service/src/main_impl.rs b/service/src/main_impl.rs index 69ad98c919..17250584fc 100644 --- a/service/src/main_impl.rs +++ b/service/src/main_impl.rs @@ -448,7 +448,7 @@ fn start_worker( // Init parentchain specific stuff. Needed for parentchain communication. let (parentchain_handler, last_synced_header) = - init_parentchain(&enclave, &integritee_rpc_api, &tee_accountid, ParentchainId::Integritee); + init_integritee_parentchain(&enclave, &integritee_rpc_api, &tee_accountid); #[cfg(feature = "dcap")] register_collateral( @@ -662,7 +662,7 @@ fn init_target_parentchain( ) where E: EnclaveBase + Sidechain, ApiFactory: CreateNodeApi, - ApiFactory::Api: ChainApi + ApiFactory::Api: ChainApi + AccountApi + GetTransactionPayment + GetBalance @@ -733,7 +733,7 @@ fn init_parentchain( ) -> (Arc>, Header) where E: EnclaveBase + Sidechain, - ParentchainApi: ChainApi + ParentchainApi: ChainApi + AccountApi + GetTransactionPayment + GetBalance @@ -772,6 +772,47 @@ where (parentchain_handler, last_synced_header) } +fn init_integritee_parentchain( + enclave: &Arc, + node_api: &IntegriteeParentchainApi, + tee_account_id: &AccountId32, +) -> (Arc>, Header) +where + E: EnclaveBase + Sidechain, +{ + let parentchain_id = ParentchainId::Integritee; + let parentchain_handler = Arc::new( + ParentchainHandler::new_with_automatic_light_client_allocation( + node_api.clone(), + enclave.clone(), + parentchain_id, + ) + .unwrap(), + ); + let last_synced_header = parentchain_handler.init_parentchain_components().unwrap(); + println!("[{:?}] last synced parentchain block: {}", parentchain_id, last_synced_header.number); + + let nonce = node_api.get_nonce_of(tee_account_id).unwrap(); + info!("[{:?}] Enclave nonce = {:?}", parentchain_id, nonce); + enclave.set_nonce(nonce, parentchain_id).unwrap_or_else(|_| { + panic!("[{:?}] Could not set nonce of enclave. Returning here...", parentchain_id) + }); + + let metadata = node_api.metadata().clone(); + let runtime_spec_version = node_api.runtime_version().spec_version; + let runtime_transaction_version = node_api.runtime_version().transaction_version; + enclave + .set_node_metadata( + NodeMetadata::new(metadata, runtime_spec_version, runtime_transaction_version).encode(), + parentchain_id, + ) + .unwrap_or_else(|_| { + panic!("[{:?}] Could not set the node metadata in the enclave", parentchain_id) + }); + + (parentchain_handler, last_synced_header) +} + /// Start polling loop to wait until we have a worker for a shard registered on /// the parentchain (TEEREX WorkerForShard). This is the pre-requisite to be /// considered initialized and ready for the next worker to start (in sidechain mode only). @@ -1050,7 +1091,7 @@ fn send_extrinsic( is_development_mode: bool, ) -> Option where - ParentchainApi: ChainApi + ParentchainApi: ChainApi + SubmitAndWatch + BalancesExtrinsics + GetTransactionPayment @@ -1091,7 +1132,7 @@ fn subscribe_to_parentchain_new_headers Result<(), Error> where - ParentchainApi: ChainApi, + ParentchainApi: ChainApi, { // TODO: this should be implemented by parentchain_handler directly, and not via // exposed parentchain_api