Skip to content

Commit

Permalink
revert changes to parentchain_handler due to earlier remark about con…
Browse files Browse the repository at this point in the history
…flicts
  • Loading branch information
brenzi committed Nov 22, 2023
1 parent a28259e commit c093289
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
27 changes: 12 additions & 15 deletions service/src/main_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,12 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
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
Expand Down Expand Up @@ -1054,7 +1059,7 @@ fn register_quotes_from_marblerun(
for quote in quotes {
match enclave.generate_dcap_ra_extrinsic_from_quote(url.clone(), &quote) {
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)
Expand All @@ -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<ParentchainApi>(
fn send_integritee_extrinsic(
extrinsic: Vec<u8>,
api: &ParentchainApi,
api: &IntegriteeParentchainApi,
fee_payer: &AccountId32,
is_development_mode: bool,
) -> Option<Hash>
where
ParentchainApi: ChainApi<Hash = Hash>
+ SubmitAndWatch
+ BalancesExtrinsics
+ GetTransactionPayment
+ GetBalance
+ AccountApi,
{
) -> Option<Hash> {
// ensure account funds
if let Err(x) = setup_account_funding(api, fee_payer, extrinsic.clone(), is_development_mode) {
error!("Ensure enclave funding failed: {:?}", x);
Expand Down
41 changes: 23 additions & 18 deletions service/src/parentchain_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;

Expand Down Expand Up @@ -67,13 +67,12 @@ pub(crate) struct ParentchainHandler<ParentchainApi, EnclaveApi> {

// #TODO: #1451: Reintroduce `ParentchainApi: ChainApi` once there is no trait bound conflict
// any more with the api-clients own trait definitions.
impl<ParentchainApi, EnclaveApi> ParentchainHandler<ParentchainApi, EnclaveApi>
impl<EnclaveApi> ParentchainHandler<IntegriteeParentchainApi, EnclaveApi>
where
EnclaveApi: EnclaveBase,
ParentchainApi: ChainApi<Header = Header>,
{
pub fn new(
parentchain_api: ParentchainApi,
parentchain_api: IntegriteeParentchainApi,
enclave_api: Arc<EnclaveApi>,
parentchain_init_params: ParentchainInitParams,
) -> Self {
Expand All @@ -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<EnclaveApi>,
id: ParentchainId,
) -> ServiceResult<Self> {
Expand All @@ -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,
Expand All @@ -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
}

Expand All @@ -124,12 +132,9 @@ where
}
}

impl<ParentchainApi, EnclaveApi> HandleParentchain
for ParentchainHandler<ParentchainApi, EnclaveApi>
impl<EnclaveApi> HandleParentchain for ParentchainHandler<IntegriteeParentchainApi, EnclaveApi>
where
EnclaveApi: Sidechain + EnclaveBase,
ParentchainApi:
ChainApi<Header = Header, Block = Block, BlockNumber = BlockNumber, Hash = Hash>,
{
fn init_parentchain_components(&self) -> ServiceResult<Header> {
Ok(self
Expand All @@ -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() {
Expand Down

0 comments on commit c093289

Please sign in to comment.