-
Notifications
You must be signed in to change notification settings - Fork 46
Fix OOM error in large parentchain syncs #1468
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
Changes from 24 commits
c0dccbe
09ba3d1
7fb40ee
30d99cb
c608731
325303c
083ce2e
960cc4d
856a09e
dbb7474
cc8f3b7
58e14bc
a8b1928
42a2645
43cac9e
b749381
89de215
c2ba744
4271c42
600a983
ec0a750
3f8b757
14fbc5a
f84e5ed
0cbd95b
e7d15e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -387,9 +387,6 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>( | |
|
|
||
| let tokio_handle = tokio_handle_getter.get_handle(); | ||
|
|
||
| #[cfg(feature = "teeracle")] | ||
| let teeracle_tokio_handle = tokio_handle.clone(); | ||
|
|
||
| // ------------------------------------------------------------------------ | ||
| // Get the public key of our TEE. | ||
| let tee_accountid = enclave_account(enclave.as_ref()); | ||
|
|
@@ -455,7 +452,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>( | |
| &config, | ||
| enclave.clone(), | ||
| sidechain_storage.clone(), | ||
| tokio_handle, | ||
| &tokio_handle, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -542,34 +539,39 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>( | |
|
|
||
| initialization_handler.registered_on_parentchain(); | ||
|
|
||
| // ------------------------------------------------------------------------ | ||
| // initialize teeracle interval | ||
| #[cfg(feature = "teeracle")] | ||
| if WorkerModeProvider::worker_mode() == WorkerMode::Teeracle { | ||
|
Comment on lines
-546
to
-548
Contributor
Author
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. The flow of the following section was a bit hard to understand because there were non-exclusive if statements (which is why I didn't notice that it doesn't work yet). Now we have three exclusive paths in the match statement, which make it easier to understand. The code redundancy is reduced to some function calls by extracting some code into functions. |
||
| schedule_periodic_reregistration_thread( | ||
| send_register_xt, | ||
| run_config.reregister_teeracle_interval(), | ||
| ); | ||
| match WorkerModeProvider::worker_mode() { | ||
| WorkerMode::Teeracle => { | ||
| // ------------------------------------------------------------------------ | ||
| // initialize teeracle interval | ||
| #[cfg(feature = "teeracle")] | ||
|
Contributor
Author
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. |
||
| schedule_periodic_reregistration_thread( | ||
| send_register_xt, | ||
| run_config.reregister_teeracle_interval(), | ||
| ); | ||
|
|
||
| start_periodic_market_update( | ||
| &integritee_rpc_api, | ||
| run_config.teeracle_update_interval(), | ||
| enclave.as_ref(), | ||
| &teeracle_tokio_handle, | ||
| ); | ||
| } | ||
| #[cfg(feature = "teeracle")] | ||
| start_periodic_market_update( | ||
| &integritee_rpc_api, | ||
| run_config.teeracle_update_interval(), | ||
| enclave.as_ref(), | ||
| &tokio_handle.clone(), | ||
| ); | ||
| }, | ||
| WorkerMode::OffChainWorker => { | ||
| println!("*** [+] Finished initializing light client, syncing parentchain..."); | ||
|
|
||
| if WorkerModeProvider::worker_mode() != WorkerMode::Teeracle { | ||
| println!("*** [+] Finished initializing light client, syncing parentchain..."); | ||
| // Syncing all parentchain blocks, this might take a while.. | ||
| let last_synced_header = | ||
| parentchain_handler.sync_parentchain(last_synced_header).unwrap(); | ||
|
|
||
| // Syncing all parentchain blocks, this might take a while.. | ||
| let mut last_synced_header = | ||
| parentchain_handler.sync_parentchain(last_synced_header).unwrap(); | ||
| start_parentchain_header_subscription_thread(parentchain_handler, last_synced_header); | ||
| }, | ||
| WorkerMode::Sidechain => { | ||
| println!("*** [+] Finished initializing light client, syncing parentchain..."); | ||
|
|
||
| // ------------------------------------------------------------------------ | ||
| // Initialize the sidechain | ||
| if WorkerModeProvider::worker_mode() == WorkerMode::Sidechain { | ||
| last_synced_header = sidechain_init_block_production( | ||
| // ------------------------------------------------------------------------ | ||
| // Initialize the sidechain | ||
| let last_synced_header = sidechain_init_block_production( | ||
| enclave.clone(), | ||
| ®ister_enclave_xt_header, | ||
| we_are_primary_validateer, | ||
|
|
@@ -578,26 +580,15 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>( | |
| &last_synced_header, | ||
| ) | ||
| .unwrap(); | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------ | ||
| // start parentchain syncing loop (subscribe to header updates) | ||
| thread::Builder::new() | ||
| .name("parentchain_sync_loop".to_owned()) | ||
| .spawn(move || { | ||
| if let Err(e) = | ||
| subscribe_to_parentchain_new_headers(parentchain_handler, last_synced_header) | ||
| { | ||
| error!("Parentchain block syncing terminated with a failure: {:?}", e); | ||
| } | ||
| println!("[!] Parentchain block syncing has terminated"); | ||
| }) | ||
| .unwrap(); | ||
| } | ||
| start_parentchain_header_subscription_thread(parentchain_handler, last_synced_header); | ||
|
|
||
| // ------------------------------------------------------------------------ | ||
| if WorkerModeProvider::worker_mode() == WorkerMode::Sidechain { | ||
| spawn_worker_for_shard_polling(shard, integritee_rpc_api.clone(), initialization_handler); | ||
| spawn_worker_for_shard_polling( | ||
| shard, | ||
| integritee_rpc_api.clone(), | ||
| initialization_handler, | ||
| ); | ||
| }, | ||
| } | ||
|
|
||
| if let Some(url) = config.target_a_parentchain_rpc_endpoint() { | ||
|
|
@@ -666,20 +657,7 @@ fn init_target_parentchain<E>( | |
| parentchain_handler.sync_parentchain(last_synched_header).unwrap(); | ||
|
|
||
| // start parentchain syncing loop (subscribe to header updates) | ||
| thread::Builder::new() | ||
| .name(format!("{:?}_parentchain_sync_loop", parentchain_id)) | ||
| .spawn(move || { | ||
| if let Err(e) = | ||
| subscribe_to_parentchain_new_headers(parentchain_handler, last_synched_header) | ||
| { | ||
| error!( | ||
| "[{:?}] parentchain block syncing terminated with a failure: {:?}", | ||
| parentchain_id, e | ||
| ); | ||
| } | ||
| println!("[!] [{:?}] parentchain block syncing has terminated", parentchain_id); | ||
| }) | ||
| .unwrap(); | ||
| start_parentchain_header_subscription_thread(parentchain_handler, last_synched_header) | ||
| } | ||
|
|
||
| // Subscribe to events and print them. | ||
|
|
@@ -1042,6 +1020,27 @@ fn send_extrinsic( | |
| } | ||
| } | ||
|
|
||
| fn start_parentchain_header_subscription_thread<E: EnclaveBase + Sidechain>( | ||
| parentchain_handler: Arc<ParentchainHandler<ParentchainApi, E>>, | ||
| last_synced_header: Header, | ||
| ) { | ||
| let parentchain_id = parentchain_handler.parentchain_id().clone(); | ||
| thread::Builder::new() | ||
| .name(format!("{:?}_parentchain_sync_loop", parentchain_id)) | ||
| .spawn(move || { | ||
| if let Err(e) = | ||
| subscribe_to_parentchain_new_headers(parentchain_handler, last_synced_header) | ||
| { | ||
| error!( | ||
| "[{:?}] parentchain block syncing terminated with a failure: {:?}", | ||
| parentchain_id, e | ||
| ); | ||
| } | ||
| println!("[!] [{:?}] parentchain block syncing has terminated", parentchain_id); | ||
| }) | ||
| .unwrap(); | ||
| } | ||
|
|
||
| /// Subscribe to the node API finalized heads stream and trigger a parent chain sync | ||
| /// upon receiving a new header. | ||
| fn subscribe_to_parentchain_new_headers<E: EnclaveBase + Sidechain>( | ||
|
|
||
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.
No longer needed as another function needs a borrow now instead of an owned handle.