Skip to content

Commit

Permalink
not sure if we want this: separate init fn for integritee
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Nov 22, 2023
1 parent 2e39440 commit a28259e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct ParentchainSignedExtra {
}

pub type ParentchainAdditionalSigned = ((), u32, u32, Hash, Hash, (), (), ());

impl ExtrinsicParams<Index, Hash> for ParentchainExtrinsicParams {
type AdditionalParams = ParentchainAdditionalParams;
type SignedExtra = ParentchainSignedExtra;
Expand Down
51 changes: 46 additions & 5 deletions service/src/main_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
// 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(
Expand Down Expand Up @@ -662,7 +662,7 @@ fn init_target_parentchain<E, ApiFactory>(
) where
E: EnclaveBase + Sidechain,
ApiFactory: CreateNodeApi,
ApiFactory::Api: ChainApi
ApiFactory::Api: ChainApi<Hash = Hash>
+ AccountApi
+ GetTransactionPayment
+ GetBalance
Expand Down Expand Up @@ -733,7 +733,7 @@ fn init_parentchain<E, ParentchainApi>(
) -> (Arc<ParentchainHandler<ParentchainApi, E>>, Header)
where
E: EnclaveBase + Sidechain,
ParentchainApi: ChainApi
ParentchainApi: ChainApi<Hash = Hash>
+ AccountApi
+ GetTransactionPayment
+ GetBalance
Expand Down Expand Up @@ -772,6 +772,47 @@ where
(parentchain_handler, last_synced_header)
}

fn init_integritee_parentchain<E>(
enclave: &Arc<E>,
node_api: &IntegriteeParentchainApi,
tee_account_id: &AccountId32,
) -> (Arc<ParentchainHandler<IntegriteeParentchainApi, E>>, 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).
Expand Down Expand Up @@ -1050,7 +1091,7 @@ fn send_extrinsic<ParentchainApi>(
is_development_mode: bool,
) -> Option<Hash>
where
ParentchainApi: ChainApi
ParentchainApi: ChainApi<Hash = Hash>
+ SubmitAndWatch
+ BalancesExtrinsics
+ GetTransactionPayment
Expand Down Expand Up @@ -1091,7 +1132,7 @@ fn subscribe_to_parentchain_new_headers<E: EnclaveBase + Sidechain, ParentchainA
mut last_synced_header: Header,
) -> Result<(), Error>
where
ParentchainApi: ChainApi,
ParentchainApi: ChainApi<Hash = Hash>,
{
// TODO: this should be implemented by parentchain_handler directly, and not via
// exposed parentchain_api
Expand Down

0 comments on commit a28259e

Please sign in to comment.