-
Notifications
You must be signed in to change notification settings - Fork 46
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
Refactor global components and initialization process #677
Conversation
let authority = Ed25519Seal::unseal()?; | ||
let state_key = AesSeal::unseal()?; | ||
|
||
let state_handler = Arc::new(GlobalFileStateHandler); | ||
let stf_executor = Arc::new(StfExecutor::new(Arc::new(OcallApi), state_handler.clone())); | ||
let extrinsics_factory = | ||
ExtrinsicsFactory::new(genesis_hash, authority.clone(), GLOBAL_NONCE_CACHE.clone()); | ||
let stf_executor = GLOBAL_STF_EXECUTOR_COMPONENT.get().ok_or_else(|| { | ||
error!("Failed to retrieve stf executor component. Maybe it's not initialized?"); | ||
Error::ComponentNotInitialized | ||
})?; |
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.
Get the STF executor from the global instance instead of creating another instance here.
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 is certainly an improvement. However, I'm questioning the introduction of two separate E-Calls that need to be called in a specific order. Should this really be two separate E-calls, or rather one E-call that calls internal functions in a specific order?
I'm wondering what's the end goal here:
We now have several init E-calls, ranging from plain init
worker/enclave-runtime/src/lib.rs
Line 129 in 73c8ddb
pub unsafe extern "C" fn init( |
to new
components
inits and individual inits, such as the rpc-direct server worker/enclave-runtime/src/lib.rs
Line 525 in 73c8ddb
pub unsafe extern "C" fn init_direct_invocation_server( |
Do you have a roadmap in mind, or did you need to introduce this change to resolve something? If so, could you link this PR to a corresponding issue?
We already have multiple We're experiencing some issues, where the order of starting up the direct invocation server and registering ourselves to the parentchain results in errors because of the initialization ordering. This PR is a step towards solving that (#600). To answer your question: This is just a further refactoring step, but not the end goal. We would still need to think more about our bootstrapping process and when we do what. |
a7ebe9e
to
c2a8482
Compare
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.
Nice, looks like yet another cleanup. Only Some minor comments.
Co-authored-by: haerdib <[email protected]>
also removed the 'init_enclave_base_components', merged it into the existing 'init' function
c3214ab
to
c643ca5
Compare
parentchain block is already imported and thus cannot be peeked anymore
I now moved all the component initialization into a separate module, In order to fix #600, I had to move the RPC server starting before the parentchain registering. Doing that revealed another issue, #684 - which I also fixed now in this PR. |
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.
LGTM, Massive clean up, thanks! Only one minor comment
(import queue is ready and filled earlier)
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.
It looks like a very nice clean up! I have only two comments.
let stf_executor = GLOBAL_STF_EXECUTOR_COMPONENT.get().ok_or_else(|| { | ||
error!("Failed to retrieve global STF executor component (maybe it is not initialized?)"); | ||
Error::ComponentNotInitialized | ||
})?; |
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 seems to be a very repeating pattern. Why not introduce: Error::ComponentNotInitialize(Component)
? Then we can simply call:
GLOBAL_STF_EXECUTOR_COMPONENT.get().ok_or_else(|| Error::ComponentNotInitialized(Component)?
Then we can remove the redundant logging here, as the caller of this does print the error anyhow. (Which is not so expressive currently).
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.
Yes, agreed, this can be simplified and the amount of logging reduced 👍 thanks for pointing that out. Now I wish I had a nameof()
function in Rust too, so I wouldn't need to type all the variable names as string for the errors 🙈
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.
I agree to that. We could introduce an enum for the components and implement toString
for that, but there might be a better way.
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.
I think refactoring the get
method of ComponentContainer
might be sensible, to return an error that already contains all the information. And a container can also have a name that it puts into the error itself, so the caller does not have to care about the error contents.
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.
The component container now knows its own name, and the getter returns a proper Result
with an error that includes its name. That allowed me to reduce a lot of the getter calls to just .get()?;
, which is certainly a lot cleaner. Thanks for insisting 😉
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.
Coolio! Thanks for the extra effort. I think this was worth it!
… of option the result includes the information about the component name and it not being initialized
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.
Looks good to me now! Thanks for the cleanup
* Add a local-setup config to the tutorial (integritee book) (integritee-network#666) * Update call status to `InSidechainBlock` only after block import (integritee-network#676) * rename on_block_created to on_block_imported * update tx status only after block import * fix clippy * fix cargo test * remove waiting time from demos * readd removed comments * udpate comments * extract call removal logic from on_block_imported * Bump substrate to commit f5f286db0da9... (integritee-network#669) * Bump substrate Bump substrate to commit 8df8d908c4d77a8dd19751784b6aca62159ddda8 Remove dependencies of scale-info 1.0.0 and parity-scale-codec 2.3.1 Upgrade substrate to commit f5f286d... substrate fix for : sp-core's full_crypto feature flag breaks no_std builds * frame-metadata from crates.io * Update CI to use updated node Co-authored-by: echevrier <[email protected]> * Dockerize (integritee-network#668) * Dockerize the binaries integritee-network#579 * Add tags to run as well integritee-network#579 * Fix running binary in docker integritee-network#579 * Add more files to docker integritee-network#579 * Add conditional runs * Add +x earlier * Rename docker-service to integritee-demo-validateer. Fixes integritee-network#579 * Lift clap to version 3.16 and move stf cli to cli crate. (integritee-network#679) * Lift clap to version 3.16 and move stf cli to cli crate. * Adapt demo script parameters * Add cli examples to README.md * update comment descriptions Co-authored-by: Gaudenz Kessler <[email protected]> * Refactor global components and initialization process (integritee-network#677) * Consistently (re-)use the component container * RPC server is initialized before registering on the parentchain * Fix issue with sidechain block import when latest parentchain block is already too new Closes integritee-network#545 integritee-network#600 integritee-network#684 integritee-network#683 * create alive service to deterine that the service is up, running and registered (integritee-network#697) * create alive service * replace alive with initialized Co-authored-by: Gaudenz Kessler <[email protected]> * Add port config for the untrusted http server for `is_initialized` (integritee-network#700) * rename wrong `signing_key` function name to `state_key` (integritee-network#704) * Move top pool and top pool author crates to core primitives (integritee-network#705) * Introduce state snapshot history (integritee-network#698) Closes integritee-network#688 * Add header to sidechain block (integritee-network#699) Closes integritee-network#686 Co-authored-by: Gaudenz Kessler <[email protected]> * introduce layer for indirection for sidechainblock (integritee-network#716) Closes integritee-network#710 Co-authored-by: Gaudenz Kessler <[email protected]> Co-authored-by: Felix Müller <[email protected]> * Persist web-socket connections (integritee-network#718) Complete overhaul of the trusted web-socket server: * using MIO to serve concurrent connections * Server keeps connections open until a client requests a close * Changed our clients to match this pattern * Upgrade to polkadot v0.9.19 (integritee-network#720) * Bump substrate to polkadot-v0.9.19 Bump RUNTIME_SPEC_VERSION to 9 Set substrate-api-client to polkadot-v0.9.19 Set integritee-node to polkadot-v0.9.19 Set integritee-node to master * Cargo update + reabse * Update github actions Co-authored-by: echevrier <[email protected]> * fix some cargo.tomls * fix cargo.lock * remove game engine * update teerex module * fix itp-registry-storage * cargo update * resinsert game engine * some further clean up * update teaclave * add ajuna commands * cargo update * carog update * update ajuna cli * fix some thins * Signed sidechain block * fix shard_id getter * fix load_initialized * fix sgx externalities import * fix compilation issues * remove patches and cargo update * update demo docu * add bin folder to docu * remove hard coded ports. Not necesasry * add ./ * update pallet verions * make tests compile again * fix import in sgx mode * merge from upstream number two.. remove itp storage verifier * cargo fmt * fix tests * update doc once again * fix script and queue game * cargo update + some code clean up Co-authored-by: Felix Müller <[email protected]> Co-authored-by: echevrier <[email protected]> Co-authored-by: echevrier <[email protected]> Co-authored-by: mosonyi <[email protected]> Co-authored-by: gaudenzkessler <[email protected]> Co-authored-by: Gaudenz Kessler <[email protected]> Co-authored-by: Felix Müller <[email protected]>
Further refactoring for the initialization of components in the enclave-runtime. More re-use of existing/instantiated components instead of creating new instances.
The main idea was to extract the component initialization happens explicitly, in functions that have corresponding names, not implicitly.
Explicit component initialization e-calls were added:
Base components are initialized with the
init()
function. This includes all the components necessary for running the trusted and untrusted RPC servers in order to fix #600. In the course of doing that, I encountered another issue, #684, which I also had to fix in this PR.Linked issues: #545 #600 #684
Closes #600 #684