Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixing startup panic. fast-sync disabled now
  • Loading branch information
brenzi committed Dec 7, 2023
commit 61cb3d58c7a97edf7dac0e352c683c52ca804e80
9 changes: 9 additions & 0 deletions core-primitives/enclave-api/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ extern "C" {
header_size: u32,
) -> sgx_status_t;

pub fn get_shard_birth_header(
eid: sgx_enclave_id_t,
retval: *mut sgx_status_t,
shard: *const u8,
shard_size: u32,
birth: *mut u8,
birth_size: u32,
) -> sgx_status_t;

pub fn execute_trusted_calls(eid: sgx_enclave_id_t, retval: *mut sgx_status_t) -> sgx_status_t;

pub fn sync_parentchain(
Expand Down
5 changes: 2 additions & 3 deletions core-primitives/enclave-api/src/enclave_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,11 @@ mod impl_ffi {
shard: &ShardIdentifier,
) -> EnclaveResult<(ParentchainId, Header)> {
let mut retval = sgx_status_t::SGX_SUCCESS;
let mut birth =
[0u8; std::mem::size_of::<Header>() + std::mem::size_of::<ParentchainId>()];
let mut birth = [0u8; HEADER_MAX_SIZE + std::mem::size_of::<ParentchainId>()];
let shard_bytes = shard.encode();

let result = unsafe {
ffi::get_ecc_vault_pubkey(
ffi::get_shard_birth_header(
self.eid,
&mut retval,
shard_bytes.as_ptr(),
Expand Down
4 changes: 2 additions & 2 deletions enclave-runtime/src/initialization/parentchain/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn create_integritee_parentchain_block_importer(
stf_executor: Arc<EnclaveStfExecutor>,
extrinsics_factory: Arc<EnclaveExtrinsicsFactory>,
node_metadata_repository: Arc<EnclaveNodeMetadataRepository>,
birth_header: Header,
maybe_birth_header: Option<Header>,
) -> Result<IntegriteeParentchainBlockImporter> {
let state_observer = GLOBAL_STATE_OBSERVER_COMPONENT.get()?;
let top_pool_author = GLOBAL_TOP_POOL_AUTHOR_COMPONENT.get()?;
Expand All @@ -80,7 +80,7 @@ pub(crate) fn create_integritee_parentchain_block_importer(
stf_executor,
extrinsics_factory,
indirect_calls_executor,
Some(birth_header),
maybe_birth_header,
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl IntegriteeParachainHandler {
pub fn init<WorkerModeProvider: ProvideWorkerMode>(
_base_path: PathBuf,
params: ParachainParams,
birth_header: Header,
maybe_birth_header: Option<Header>,
) -> Result<Self> {
let ocall_api = GLOBAL_OCALL_API_COMPONENT.get()?;
let state_handler = GLOBAL_STATE_HANDLER_COMPONENT.get()?;
Expand Down Expand Up @@ -92,7 +92,7 @@ impl IntegriteeParachainHandler {
stf_executor.clone(),
extrinsics_factory.clone(),
node_metadata_repository.clone(),
birth_header,
maybe_birth_header,
)?;

let import_dispatcher = match WorkerModeProvider::worker_mode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl IntegriteeSolochainHandler {
pub fn init<WorkerModeProvider: ProvideWorkerMode>(
_base_path: PathBuf,
params: SolochainParams,
birth_header: Header,
maybe_birth_header: Option<Header>,
) -> Result<Self> {
let ocall_api = GLOBAL_OCALL_API_COMPONENT.get()?;
let state_handler = GLOBAL_STATE_HANDLER_COMPONENT.get()?;
Expand Down Expand Up @@ -91,7 +91,7 @@ impl IntegriteeSolochainHandler {
stf_executor.clone(),
extrinsics_factory.clone(),
node_metadata_repository.clone(),
birth_header,
maybe_birth_header,
)?;

let import_dispatcher = match WorkerModeProvider::worker_mode() {
Expand Down
36 changes: 24 additions & 12 deletions enclave-runtime/src/initialization/parentchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use itc_parentchain::{
};
use itp_component_container::ComponentInitializer;
use itp_settings::worker_mode::ProvideWorkerMode;
use itp_types::parentchain::Header;
use std::{path::PathBuf, vec::Vec};

mod common;
Expand All @@ -60,18 +61,24 @@ pub(crate) fn init_parentchain_components<WorkerModeProvider: ProvideWorkerMode>
) -> Result<Vec<u8>> {
match ParentchainInitParams::decode(&mut encoded_params.as_slice())? {
ParentchainInitParams::Parachain { id, shard, params } => {
let (birth_parachain_id, birth_header) =
get_shard_birth_parentchain_header_internal(shard)?;
if birth_parachain_id != ParentchainId::Integritee {
unimplemented!("only Integritee parentchain is supported for shard birth");
}
let maybe_birth: Option<(ParentchainId, Header)> =
get_shard_birth_parentchain_header_internal(shard).ok();
let maybe_birth_header = if let Some((birth_parachain_id, birth_header)) = maybe_birth {
if birth_parachain_id != ParentchainId::Integritee {
unimplemented!("only Integritee parentchain is supported for shard birth");
}
Some(birth_header)
} else {
None
};

// todo: query timestamp of birth header to give a birth reference to target_a/b as well in order to fast-sync
match id {
ParentchainId::Integritee => {
let handler = IntegriteeParachainHandler::init::<WorkerModeProvider>(
base_path,
params,
birth_header,
maybe_birth_header,
)?;
let header = handler
.validator_accessor
Expand Down Expand Up @@ -100,18 +107,23 @@ pub(crate) fn init_parentchain_components<WorkerModeProvider: ProvideWorkerMode>
}
},
ParentchainInitParams::Solochain { id, shard, params } => {
let (birth_parachain_id, birth_header) =
get_shard_birth_parentchain_header_internal(shard)?;
if birth_parachain_id != ParentchainId::Integritee {
unimplemented!("only Integritee parentchain is supported for shard birth");
}
let maybe_birth: Option<(ParentchainId, Header)> =
get_shard_birth_parentchain_header_internal(shard).ok();
let maybe_birth_header = if let Some((birth_parachain_id, birth_header)) = maybe_birth {
if birth_parachain_id != ParentchainId::Integritee {
unimplemented!("only Integritee parentchain is supported for shard birth");
}
Some(birth_header)
} else {
None
};
// todo: query timestamp of birth header to give a birth reference to target_a/b as well in order to fast-sync
match id {
ParentchainId::Integritee => {
let handler = IntegriteeSolochainHandler::init::<WorkerModeProvider>(
base_path,
params,
birth_header,
maybe_birth_header,
)?;
let header = handler
.validator_accessor
Expand Down
9 changes: 6 additions & 3 deletions enclave-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,18 @@ pub unsafe extern "C" fn get_shard_birth_header(
let shard = ShardIdentifier::from_slice(slice::from_raw_parts(shard, shard_size as usize));

let shard_birth = match get_shard_birth_parentchain_header_internal(shard) {
Ok(account) => account,
Ok(birth) => birth,
Err(e) => {
warn!("Failed to fetch birth header: {:?}", e);
return sgx_status_t::SGX_ERROR_UNEXPECTED
},
};
trace!("fetched shard birth header from state: {:?}", shard_birth);
let birth_slice = slice::from_raw_parts_mut(birth, birth_size as usize);
birth_slice.clone_from_slice(shard_birth.encode().as_slice());

let mut birth_slice = slice::from_raw_parts_mut(birth, birth_size as usize);
if let Err(e) = write_slice_and_whitespace_pad(birth_slice, shard_birth.encode()) {
return Error::BufferError(e).into()
};
sgx_status_t::SGX_SUCCESS
}

Expand Down
20 changes: 11 additions & 9 deletions service/src/main_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
);
}

// ------------------------------------------------------------------------
// Init parentchain specific stuff. Needed early for parentchain communication.
let (integritee_parentchain_handler, integritee_last_synced_header_at_last_run) =
init_parentchain(
&enclave,
&integritee_rpc_api,
&tee_accountid,
ParentchainId::Integritee,
shard,
);

#[cfg(feature = "dcap")]
register_collateral(
&integritee_rpc_api,
Expand Down Expand Up @@ -532,15 +543,6 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
debug!("getting shard birth: {:?}", enclave.get_shard_birth_header(shard));
initialization_handler.registered_on_parentchain();

let (integritee_parentchain_handler, integritee_last_synced_header_at_last_run) =
init_parentchain(
&enclave,
&integritee_rpc_api,
&tee_accountid,
ParentchainId::Integritee,
shard,
);

match WorkerModeProvider::worker_mode() {
WorkerMode::Teeracle => {
// ------------------------------------------------------------------------
Expand Down