Skip to content
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c0dccbe
[service] better logging
clangenb Oct 9, 2023
09ba3d1
[service] probably fix OOM
clangenb Oct 9, 2023
7fb40ee
[service/parentchain_handler] rename `last_synced_header` to `sync_un…
clangenb Oct 12, 2023
30d99cb
[service/parentchain_handler] extract internal `sync_blocks` method
clangenb Oct 12, 2023
c608731
[service/parentchain_handler] some renaming
clangenb Oct 12, 2023
325303c
[service/parentchain_handler] some renaming
clangenb Oct 12, 2023
083ce2e
[service/parentchain_handler] fix break statement
clangenb Oct 12, 2023
960cc4d
[service/parentchain_handler] move check if up to date to the end of …
clangenb Oct 12, 2023
856a09e
[service/parentchain_handler] uplift total sync info from trace to pr…
clangenb Oct 12, 2023
dbb7474
[service/parentchain_handler] move check for monotonically rising blo…
clangenb Oct 12, 2023
cc8f3b7
[service/parentchain_handler] fix check for sleeping in sync process
clangenb Oct 12, 2023
58e14bc
[service/parentchain_handler] rename `until_header` to `sync_target`
clangenb Oct 12, 2023
a8b1928
[service/parentchain_handler] change for loop into while and better n…
clangenb Oct 12, 2023
42a2645
[service/parentchain_handler] add comment
clangenb Oct 12, 2023
43cac9e
[service/parentchain_handler] better logs
clangenb Oct 12, 2023
b749381
[service/parentchain_handler] better logs
clangenb Oct 12, 2023
89de215
[service/parentchain_handler] fix import condition in while loop
clangenb Oct 13, 2023
c2ba744
[service/parentchain_handler] introduce block sync error
clangenb Oct 13, 2023
4271c42
Merge branch 'master' into cl/fix-sidechain-light-client
clangenb Oct 13, 2023
600a983
Merge branch 'master' into cl/fix-sidechain-light-client
clangenb Oct 13, 2023
ec0a750
[service/main] improve log levels
clangenb Oct 14, 2023
3f8b757
[service] `sidechain_start_untrusted_rpc_server`downgrade tokyo handl…
clangenb Oct 14, 2023
14fbc5a
[service/main] distinguish better between different setups
clangenb Oct 14, 2023
f84e5ed
[service/main] extract duplicate code
clangenb Oct 14, 2023
0cbd95b
[service/main] fix clippy
clangenb Oct 14, 2023
e7d15e6
[service/main] fix clippy with teeracle feature
clangenb Oct 14, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ where
&self,
predicate: impl Fn(&BlockImporter::SignedBlockType) -> bool,
) -> Result<Option<BlockImporter::SignedBlockType>> {
trace!("Import of parentchain blocks and events has been triggered");
let blocks_to_import =
self.import_queue.pop_until(predicate).map_err(Error::ImportQueue)?;

Expand All @@ -174,7 +175,7 @@ where
let latest_imported_block = blocks_to_import.last().map(|b| (*b).clone());

trace!(
"Import of parentchain blocks and events has been triggered, importing {} blocks and {} events from queue",
"Importing {} blocks and {} events from queue",
blocks_to_import.len(),
events_to_import.len(),
);
Expand Down
2 changes: 1 addition & 1 deletion service/src/account_funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn bootstrap_funds_from_alice(
"funding amount is too high: please change EXISTENTIAL_DEPOSIT_FACTOR_FOR_INIT_FUNDS ({:?})",
funding_amount
);
return Err(Error::ApplicationSetup)
return Err(Error::ApplicationSetup("Alice funds too low".into()))
}

let mut alice_signer_api = api.clone();
Expand Down
6 changes: 4 additions & 2 deletions service/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub enum Error {
Serialization(#[from] serde_json::Error),
#[error("{0}")]
FromUtf8(#[from] std::string::FromUtf8Error),
#[error("Application setup error!")]
ApplicationSetup,
#[error("Application setup error: {0}")]
ApplicationSetup(String),
#[error("Failed to find any peer worker")]
NoPeerWorkerFound,
#[error("No worker for shard {0} found on parentchain")]
Expand All @@ -50,6 +50,8 @@ pub enum Error {
MissingGenesisHeader,
#[error("Could not find last finalized block of the parentchain")]
MissingLastFinalizedBlock,
#[error("Error during the block sync process: {0}")]
BlockSync(String),
#[error("{0}")]
Custom(Box<dyn std::error::Error + Sync + Send + 'static>),
}
Expand Down
119 changes: 59 additions & 60 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Comment on lines -390 to -391
Copy link
Contributor Author

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.


// ------------------------------------------------------------------------
// Get the public key of our TEE.
let tee_accountid = enclave_account(enclave.as_ref());
Expand Down Expand Up @@ -455,7 +452,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
&config,
enclave.clone(),
sidechain_storage.clone(),
tokio_handle,
&tokio_handle,
);
}

Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TEEracle code is not a lot, I am actually considering removing the feature gate in most places because it won't really affect the binary size, but I haven't thought much about it, this could be a preparation for #1418 or #1195.

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(),
&register_enclave_xt_header,
we_are_primary_validateer,
Expand All @@ -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() {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>(
Expand Down
Loading