-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add base path to light-client initialization #1330
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f249daf
[itp-utils] create standalone buffer error
clangenb 895bece
add base-path to light-client initialization
clangenb 3f71e3d
fix clippy
clangenb b70863e
remove outdated documentation
clangenb ba7ccff
[enclave-runtime] cleanup imports
clangenb 9844f8f
minor optimizations
clangenb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ use crate::{ | |
get_triggered_dispatcher_from_solo_or_parachain, utf8_str_from_raw, DecodeRaw, | ||
}, | ||
}; | ||
use codec::{alloc::string::String, Decode}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to the rest in the std imports |
||
use codec::Decode; | ||
use itc_parentchain::block_import_dispatcher::{ | ||
triggered_dispatcher::TriggerParentchainBlockImport, DispatchBlockImport, | ||
}; | ||
|
@@ -59,7 +59,13 @@ use log::*; | |
use once_cell::sync::OnceCell; | ||
use sgx_types::sgx_status_t; | ||
use sp_runtime::traits::BlakeTwo256; | ||
use std::{boxed::Box, path::PathBuf, slice, vec::Vec}; | ||
use std::{ | ||
boxed::Box, | ||
path::PathBuf, | ||
slice, | ||
string::{String, ToString}, | ||
vec::Vec, | ||
}; | ||
|
||
mod attestation; | ||
mod empty_impls; | ||
|
@@ -85,6 +91,14 @@ pub type AuthorityPair = sp_core::ed25519::Pair; | |
|
||
static BASE_PATH: OnceCell<PathBuf> = OnceCell::new(); | ||
|
||
fn get_base_path() -> Result<PathBuf> { | ||
let base_path = BASE_PATH.get().ok_or_else(|| { | ||
Error::Other("BASE_PATH not initialized. Broken enclave init flow!".to_string().into()) | ||
})?; | ||
|
||
Ok(base_path.clone()) | ||
} | ||
|
||
/// Initialize the enclave. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn init( | ||
|
@@ -335,19 +349,22 @@ pub unsafe extern "C" fn init_parentchain_components( | |
let encoded_params = slice::from_raw_parts(params, params_size); | ||
let latest_header_slice = slice::from_raw_parts_mut(latest_header, latest_header_size); | ||
|
||
let encoded_latest_header = match initialization::parentchain::init_parentchain_components::< | ||
WorkerModeProvider, | ||
>(encoded_params.to_vec()) | ||
{ | ||
Ok(h) => h, | ||
Err(e) => return e.into(), | ||
}; | ||
match init_parentchain_params_internal(encoded_params.to_vec(), latest_header_slice) { | ||
Ok(()) => sgx_status_t::SGX_SUCCESS, | ||
Err(e) => e.into(), | ||
} | ||
} | ||
|
||
if let Err(e) = write_slice_and_whitespace_pad(latest_header_slice, encoded_latest_header) { | ||
return Error::Other(Box::new(e)).into() | ||
}; | ||
/// Initializes the parentchain components and writes the latest header into the `latest_header` slice. | ||
fn init_parentchain_params_internal(params: Vec<u8>, latest_header: &mut [u8]) -> Result<()> { | ||
use initialization::parentchain::init_parentchain_components; | ||
|
||
sgx_status_t::SGX_SUCCESS | ||
let encoded_latest_header = | ||
init_parentchain_components::<WorkerModeProvider>(get_base_path()?, params)?; | ||
|
||
write_slice_and_whitespace_pad(latest_header, encoded_latest_header)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[no_mangle] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This aggregated error does not make sense IMO because the enum variants do actually not really share anything. Regardless, I only extracted the error that we support now as an explicit variant in the enclave-runtime to not change too many unrelated things.