diff --git a/service/src/main_impl.rs b/service/src/main_impl.rs index 17250584fc..2b8c8b2f7a 100644 --- a/service/src/main_impl.rs +++ b/service/src/main_impl.rs @@ -496,7 +496,12 @@ fn start_worker( let tee_accountid_clone = tee_accountid.clone(); let send_register_xt = move || { println!("[+] Send register enclave extrinsic"); - send_extrinsic(register_xt(), &node_api2, &tee_accountid_clone, is_development_mode) + send_integritee_extrinsic( + register_xt(), + &node_api2, + &tee_accountid_clone, + is_development_mode, + ) }; // Todo: Can't unwrap here because the extrinsic is for some reason not found in the block @@ -1054,7 +1059,7 @@ fn register_quotes_from_marblerun( for quote in quotes { match enclave.generate_dcap_ra_extrinsic_from_quote(url.clone(), "e) { Ok(xt) => { - send_extrinsic(xt, api, accountid, is_development_mode); + send_integritee_extrinsic(xt, api, accountid, is_development_mode); }, Err(e) => { error!("Extracting information from quote failed: {}", e) @@ -1076,28 +1081,20 @@ fn register_collateral( let (fmspc, _tcb_info) = extract_tcb_info_from_raw_dcap_quote(&dcap_quote).unwrap(); println!("[>] DCAP setup: register QE collateral"); let uxt = enclave.generate_register_quoting_enclave_extrinsic(fmspc).unwrap(); - send_extrinsic(uxt, api, accountid, is_development_mode); + send_integritee_extrinsic(uxt, api, accountid, is_development_mode); println!("[>] DCAP setup: register TCB info"); let uxt = enclave.generate_register_tcb_info_extrinsic(fmspc).unwrap(); - send_extrinsic(uxt, api, accountid, is_development_mode); + send_integritee_extrinsic(uxt, api, accountid, is_development_mode); } } -fn send_extrinsic( +fn send_integritee_extrinsic( extrinsic: Vec, - api: &ParentchainApi, + api: &IntegriteeParentchainApi, fee_payer: &AccountId32, is_development_mode: bool, -) -> Option -where - ParentchainApi: ChainApi - + SubmitAndWatch - + BalancesExtrinsics - + GetTransactionPayment - + GetBalance - + AccountApi, -{ +) -> Option { // ensure account funds if let Err(x) = setup_account_funding(api, fee_payer, extrinsic.clone(), is_development_mode) { error!("Ensure enclave funding failed: {:?}", x); diff --git a/service/src/parentchain_handler.rs b/service/src/parentchain_handler.rs index 087fd42cf3..9aba1968d9 100644 --- a/service/src/parentchain_handler.rs +++ b/service/src/parentchain_handler.rs @@ -16,7 +16,10 @@ */ -use crate::error::{Error, ServiceResult}; +use crate::{ + error::{Error, ServiceResult}, + parentchain_config::IntegriteeParentchainApi, +}; use codec::{Decode, Encode}; use itc_parentchain::{ light_client::light_client_init_params::{GrandpaParams, SimpleParams}, @@ -25,15 +28,12 @@ use itc_parentchain::{ use itp_enclave_api::{enclave_base::EnclaveBase, sidechain::Sidechain}; use itp_node_api::api_client::ChainApi; use itp_storage::StorageProof; -use itp_types::{ - parentchain::{BlockNumber, Hash, Header}, - Block, -}; use log::*; +use my_node_runtime::Header; use sp_consensus_grandpa::VersionedAuthorityList; -use sp_runtime::traits::{Block as BlockT, Header as HeaderTrait}; +use sp_runtime::traits::Header as HeaderTrait; use std::{cmp::min, sync::Arc}; -use substrate_api_client::ac_primitives::Header as HeaderT; +use substrate_api_client::ac_primitives::{Block, Header as HeaderT}; const BLOCK_SYNC_BATCH_SIZE: u32 = 1000; @@ -67,13 +67,12 @@ pub(crate) struct ParentchainHandler { // #TODO: #1451: Reintroduce `ParentchainApi: ChainApi` once there is no trait bound conflict // any more with the api-clients own trait definitions. -impl ParentchainHandler +impl ParentchainHandler where EnclaveApi: EnclaveBase, - ParentchainApi: ChainApi
, { pub fn new( - parentchain_api: ParentchainApi, + parentchain_api: IntegriteeParentchainApi, enclave_api: Arc, parentchain_init_params: ParentchainInitParams, ) -> Self { @@ -82,7 +81,7 @@ where // FIXME: Necessary in the future? Fix with #1080 pub fn new_with_automatic_light_client_allocation( - parentchain_api: ParentchainApi, + parentchain_api: IntegriteeParentchainApi, enclave_api: Arc, id: ParentchainId, ) -> ServiceResult { @@ -100,7 +99,16 @@ where let authority_list = VersionedAuthorityList::from(grandpas); - (id, GrandpaParams::new(genesis_header, authority_list.into(), grandpa_proof)).into() + ( + id, + GrandpaParams::new( + // #TODO: #1451: clean up type hacks + Header::decode(&mut genesis_header.encode().as_slice())?, + authority_list.into(), + grandpa_proof, + ), + ) + .into() } else { ( id, @@ -115,7 +123,7 @@ where Ok(Self::new(parentchain_api, enclave_api, parentchain_init_params)) } - pub fn parentchain_api(&self) -> &ParentchainApi { + pub fn parentchain_api(&self) -> &IntegriteeParentchainApi { &self.parentchain_api } @@ -124,12 +132,9 @@ where } } -impl HandleParentchain - for ParentchainHandler +impl HandleParentchain for ParentchainHandler where EnclaveApi: Sidechain + EnclaveBase, - ParentchainApi: - ChainApi
, { fn init_parentchain_components(&self) -> ServiceResult
{ Ok(self @@ -155,7 +160,7 @@ where loop { let block_chunk_to_sync = self.parentchain_api.get_blocks( until_synced_header.number + 1, - min(until_synced_header.number + BLOCK_SYNC_BATCH_SIZE, *curr_block_number), + min(until_synced_header.number + BLOCK_SYNC_BATCH_SIZE, curr_block_number), )?; println!("[+] [{:?}] Found {} block(s) to sync", id, block_chunk_to_sync.len()); if block_chunk_to_sync.is_empty() {