Skip to content

Commit

Permalink
rename get_node_metadata_repository_from_solo_or_parachain to `get_…
Browse files Browse the repository at this point in the history
…node_metadata_repository_from_teerex_solo_or_parachain` and add `get_node_metadata_repository_from_secondary_solo_or_parachain`
  • Loading branch information
clangenb committed Aug 26, 2023
1 parent cd5ed0a commit 5c5912f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
12 changes: 6 additions & 6 deletions enclave-runtime/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
initialization::global_components::GLOBAL_ATTESTATION_HANDLER_COMPONENT,
utils::{
get_extrinsic_factory_from_solo_or_parachain,
get_node_metadata_repository_from_solo_or_parachain,
get_node_metadata_repository_from_teerex_solo_or_parachain,
},
Error as EnclaveError, Result as EnclaveResult,
};
Expand Down Expand Up @@ -289,7 +289,7 @@ pub fn generate_dcap_ra_extrinsic_from_quote_internal(
url: String,
quote: &[u8],
) -> EnclaveResult<OpaqueExtrinsic> {
let node_metadata_repo = get_node_metadata_repository_from_solo_or_parachain()?;
let node_metadata_repo = get_node_metadata_repository_from_teerex_solo_or_parachain()?;
info!(" [Enclave] Compose register enclave getting callIDs:");

let call_ids = node_metadata_repo
Expand All @@ -311,7 +311,7 @@ pub fn generate_dcap_skip_ra_extrinsic_from_mr_enclave(
url: String,
quote: &[u8],
) -> EnclaveResult<OpaqueExtrinsic> {
let node_metadata_repo = get_node_metadata_repository_from_solo_or_parachain()?;
let node_metadata_repo = get_node_metadata_repository_from_teerex_solo_or_parachain()?;
info!(" [Enclave] Compose register enclave (skip-ra) getting callIDs:");

let call_ids = node_metadata_repo
Expand Down Expand Up @@ -347,7 +347,7 @@ pub fn generate_ias_ra_extrinsic_from_der_cert_internal(
url: String,
cert_der: &[u8],
) -> EnclaveResult<OpaqueExtrinsic> {
let node_metadata_repo = get_node_metadata_repository_from_solo_or_parachain()?;
let node_metadata_repo = get_node_metadata_repository_from_teerex_solo_or_parachain()?;

info!(" [Enclave] Compose register enclave call");
let call_ids = node_metadata_repo
Expand All @@ -363,7 +363,7 @@ pub fn generate_ias_skip_ra_extrinsic_from_der_cert_internal(
url: String,
cert_der: &[u8],
) -> EnclaveResult<OpaqueExtrinsic> {
let node_metadata_repo = get_node_metadata_repository_from_solo_or_parachain()?;
let node_metadata_repo = get_node_metadata_repository_from_teerex_solo_or_parachain()?;

info!(" [Enclave] Compose register ias enclave (skip-ra) call");
let call_ids = node_metadata_repo
Expand Down Expand Up @@ -461,7 +461,7 @@ where
{
let extrinsics_factory = get_extrinsic_factory_from_solo_or_parachain()?;

let node_metadata_repo = get_node_metadata_repository_from_solo_or_parachain()?;
let node_metadata_repo = get_node_metadata_repository_from_teerex_solo_or_parachain()?;
let call_ids = node_metadata_repo
.get_from_metadata(getter)?
.map_err(MetadataProviderError::MetadataError)?;
Expand Down
3 changes: 2 additions & 1 deletion enclave-runtime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub enum Error {
ParentchainBlockImportDispatch(itc_parentchain::block_import_dispatcher::error::Error),
ExpectedTriggeredImportDispatcher,
CouldNotDispatchBlockImport,
NoParentchainAssigned,
NoTeerexParentchainAssigned,
NoSecondaryParentchainAssigned,
ParentChainValidation(itp_storage::error::Error),
ParentChainSync,
PrimitivesAccess(itp_primitives_cache::error::Error),
Expand Down
4 changes: 2 additions & 2 deletions enclave-runtime/src/initialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
rpc::{rpc_response_channel::RpcResponseChannel, worker_api_direct::public_api_rpc_handler},
utils::{
get_extrinsic_factory_from_solo_or_parachain,
get_node_metadata_repository_from_solo_or_parachain,
get_node_metadata_repository_from_teerex_solo_or_parachain,
get_triggered_dispatcher_from_solo_or_parachain,
get_validator_accessor_from_solo_or_parachain,
},
Expand Down Expand Up @@ -212,7 +212,7 @@ pub(crate) fn init_enclave_sidechain_components() -> EnclaveResult<()> {
));

let sidechain_block_import_queue = GLOBAL_SIDECHAIN_IMPORT_QUEUE_COMPONENT.get()?;
let metadata_repository = get_node_metadata_repository_from_solo_or_parachain()?;
let metadata_repository = get_node_metadata_repository_from_teerex_solo_or_parachain()?;
let extrinsics_factory = get_extrinsic_factory_from_solo_or_parachain()?;
let validator_accessor = get_validator_accessor_from_solo_or_parachain()?;

Expand Down
17 changes: 11 additions & 6 deletions enclave-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use crate::{
},
rpc::worker_api_direct::sidechain_io_handler,
utils::{
get_node_metadata_repository_from_solo_or_parachain,
get_node_metadata_repository_from_secondary_solo_or_parachain,
get_node_metadata_repository_from_teerex_solo_or_parachain,
get_triggered_dispatcher_from_solo_or_parachain, utf8_str_from_raw, DecodeRaw,
},
};
Expand Down Expand Up @@ -267,15 +268,19 @@ pub unsafe extern "C" fn set_node_metadata(

info!("Setting node meta data for parentchain: {:?}", id);

let node_metadata_repository = match get_node_metadata_repository_from_solo_or_parachain() {
Ok(r) => r,
let node_metadata_repository = match id {
ParentchainId::Teerex => get_node_metadata_repository_from_teerex_solo_or_parachain(),
ParentchainId::Secondary => get_node_metadata_repository_from_secondary_solo_or_parachain(),
};

match node_metadata_repository {
Ok(repo) => repo.set_metadata(metadata),
Err(e) => {
error!("Component get failure: {:?}", e);
error!("Could not get {:?} parentchain component: {:?}", id, e);
return sgx_status_t::SGX_ERROR_UNEXPECTED
},
};

node_metadata_repository.set_metadata(metadata);
info!("Successfully set the node meta data");

sgx_status_t::SGX_SUCCESS
Expand Down Expand Up @@ -478,7 +483,7 @@ fn dispatch_parentchain_blocks_for_import<WorkerModeProvider: ProvideWorkerMode>
} else if let Ok(parachain_handler) = GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT.get() {
parachain_handler.import_dispatcher.clone()
} else {
return Err(Error::NoParentchainAssigned)
return Err(Error::NoTeerexParentchainAssigned)
};

import_dispatcher.dispatch_import(blocks_to_sync, events_to_sync)?;
Expand Down
6 changes: 3 additions & 3 deletions enclave-runtime/src/teeracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
initialization::global_components::GLOBAL_OCALL_API_COMPONENT,
utils::{
get_extrinsic_factory_from_solo_or_parachain,
get_node_metadata_repository_from_solo_or_parachain,
get_node_metadata_repository_from_teerex_solo_or_parachain,
},
};
use codec::{Decode, Encode};
Expand Down Expand Up @@ -82,7 +82,7 @@ where

println!("Update the longitude: {}, for source {}", longitude, source_base_url);

let node_metadata_repository = get_node_metadata_repository_from_solo_or_parachain()?;
let node_metadata_repository = get_node_metadata_repository_from_teerex_solo_or_parachain()?;

let call_ids = node_metadata_repository
.get_from_metadata(|m| m.update_oracle_call_indexes())
Expand Down Expand Up @@ -247,7 +247,7 @@ where
source_base_url,
);

let node_metadata_repository = get_node_metadata_repository_from_solo_or_parachain()?;
let node_metadata_repository = get_node_metadata_repository_from_teerex_solo_or_parachain()?;

let call_ids = node_metadata_repository
.get_from_metadata(|m| m.update_exchange_rate_call_indexes())
Expand Down
28 changes: 21 additions & 7 deletions enclave-runtime/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::{
initialization::global_components::{
EnclaveExtrinsicsFactory, EnclaveNodeMetadataRepository, EnclaveStfExecutor,
EnclaveValidatorAccessor, TeerexParentchainBlockImportDispatcher,
TeerexParentchainTriggeredBlockImportDispatcher, GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT,
TeerexParentchainTriggeredBlockImportDispatcher, GLOBAL_FULL_PARACHAIN2_HANDLER_COMPONENT,
GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT, GLOBAL_FULL_SOLOCHAIN2_HANDLER_COMPONENT,
GLOBAL_FULL_SOLOCHAIN_HANDLER_COMPONENT,
},
};
Expand Down Expand Up @@ -77,7 +78,7 @@ pub(crate) fn get_triggered_dispatcher_from_solo_or_parachain(
} else if let Ok(parachain_handler) = GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT.get() {
get_triggered_dispatcher(parachain_handler.import_dispatcher.clone())?
} else {
return Err(Error::NoParentchainAssigned)
return Err(Error::NoTeerexParentchainAssigned)
};
Ok(dispatcher)
}
Expand All @@ -99,20 +100,33 @@ pub(crate) fn get_validator_accessor_from_solo_or_parachain(
} else if let Ok(parachain_handler) = GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT.get() {
parachain_handler.validator_accessor.clone()
} else {
return Err(Error::NoParentchainAssigned)
return Err(Error::NoTeerexParentchainAssigned)
};
Ok(validator_accessor)
}

pub(crate) fn get_node_metadata_repository_from_solo_or_parachain(
pub(crate) fn get_node_metadata_repository_from_teerex_solo_or_parachain(
) -> Result<Arc<EnclaveNodeMetadataRepository>> {
let metadata_repository =
if let Ok(solochain_handler) = GLOBAL_FULL_SOLOCHAIN_HANDLER_COMPONENT.get() {
solochain_handler.node_metadata_repository.clone()
} else if let Ok(parachain_handler) = GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT.get() {
parachain_handler.node_metadata_repository.clone()
} else {
return Err(Error::NoParentchainAssigned)
return Err(Error::NoTeerexParentchainAssigned)
};
Ok(metadata_repository)
}

pub(crate) fn get_node_metadata_repository_from_secondary_solo_or_parachain(
) -> Result<Arc<EnclaveNodeMetadataRepository>> {
let metadata_repository =
if let Ok(solochain_handler) = GLOBAL_FULL_SOLOCHAIN2_HANDLER_COMPONENT.get() {
solochain_handler.node_metadata_repository.clone()
} else if let Ok(parachain_handler) = GLOBAL_FULL_PARACHAIN2_HANDLER_COMPONENT.get() {
parachain_handler.node_metadata_repository.clone()
} else {
return Err(Error::NoSecondaryParentchainAssigned)
};
Ok(metadata_repository)
}
Expand All @@ -125,7 +139,7 @@ pub(crate) fn get_extrinsic_factory_from_solo_or_parachain() -> Result<Arc<Encla
} else if let Ok(parachain_handler) = GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT.get() {
parachain_handler.extrinsics_factory.clone()
} else {
return Err(Error::NoParentchainAssigned)
return Err(Error::NoTeerexParentchainAssigned)
};
Ok(extrinsics_factory)
}
Expand All @@ -137,7 +151,7 @@ pub(crate) fn get_stf_executor_from_solo_or_parachain() -> Result<Arc<EnclaveStf
} else if let Ok(parachain_handler) = GLOBAL_FULL_PARACHAIN_HANDLER_COMPONENT.get() {
parachain_handler.stf_executor.clone()
} else {
return Err(Error::NoParentchainAssigned)
return Err(Error::NoTeerexParentchainAssigned)
};
Ok(stf_executor)
}

0 comments on commit 5c5912f

Please sign in to comment.