Skip to content

Commit

Permalink
read threads count from cli (#2912)
Browse files Browse the repository at this point in the history
  • Loading branch information
kziemianek authored Jul 22, 2024
1 parent b94879e commit 0fe7e73
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bitacross-worker/core-primitives/enclave-api/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extern "C" {
untrusted_worker_addr_size: u32,
encoded_base_dir_str: *const u8,
encoded_base_dir_size: u32,
ceremony_commands_thread_count: u8,
ceremony_events_thread_count: u8,
) -> sgx_status_t;

pub fn init_direct_invocation_server(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub trait EnclaveBase: Send + Sync + 'static {
mu_ra_addr: &str,
untrusted_worker_addr: &str,
base_dir: &str,
ceremony_commands_thread_count: u8,
ceremony_events_thread_count: u8,
) -> EnclaveResult<()>;
/// Initialize the direct invocation RPC server.
fn init_direct_invocation_server(&self, rpc_server_addr: String) -> EnclaveResult<()>;
Expand Down Expand Up @@ -118,6 +120,8 @@ mod impl_ffi {
mu_ra_addr: &str,
untrusted_worker_addr: &str,
base_dir: &str,
ceremony_commands_thread_count: u8,
ceremony_events_thread_count: u8,
) -> EnclaveResult<()> {
let mut retval = sgx_status_t::SGX_SUCCESS;

Expand All @@ -135,6 +139,8 @@ mod impl_ffi {
encoded_untrusted_worker_addr.len() as u32,
encoded_base_dir.as_ptr(),
encoded_base_dir.len() as u32,
ceremony_commands_thread_count,
ceremony_events_thread_count,
)
};

Expand Down
3 changes: 2 additions & 1 deletion bitacross-worker/enclave-runtime/Enclave.edl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ enclave {
public sgx_status_t init(
[in, size=mu_ra_addr_size] uint8_t* mu_ra_addr, uint32_t mu_ra_addr_size,
[in, size=untrusted_worker_addr_size] uint8_t* untrusted_worker_addr, uint32_t untrusted_worker_addr_size,
[in, size=encoded_base_dir_size] uint8_t* encoded_base_dir_str, uint32_t encoded_base_dir_size
[in, size=encoded_base_dir_size] uint8_t* encoded_base_dir_str, uint32_t encoded_base_dir_size,
uint8_t ceremony_commands_thread_count, uint8_t ceremony_events_thread_count
);

public sgx_status_t publish_wallets();
Expand Down
5 changes: 5 additions & 0 deletions bitacross-worker/enclave-runtime/src/initialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ pub(crate) fn init_enclave(
mu_ra_url: String,
untrusted_worker_url: String,
base_dir: PathBuf,
ceremony_commands_thread_count: u8,
ceremony_events_thread_count: u8,
) -> EnclaveResult<()> {
info!("Ceremony commands thread count: {}", ceremony_commands_thread_count);
info!("Ceremony events thread count: {}", ceremony_events_thread_count);

let signing_key_repository = Arc::new(get_ed25519_repository(base_dir.clone())?);

GLOBAL_SIGNING_KEY_REPOSITORY_COMPONENT.initialize(signing_key_repository.clone());
Expand Down
10 changes: 9 additions & 1 deletion bitacross-worker/enclave-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub unsafe extern "C" fn init(
untrusted_worker_addr_size: u32,
encoded_base_dir_str: *const u8,
encoded_base_dir_size: u32,
ceremony_commands_thread_count: u8,
ceremony_events_thread_count: u8,
) -> sgx_status_t {
// Initialize the logging environment in the enclave.
if_development_or!(
Expand Down Expand Up @@ -184,7 +186,13 @@ pub unsafe extern "C" fn init(
// Litentry: the default value here is only for clippy checking
BASE_PATH.set(path.clone()).unwrap_or(());

match initialization::init_enclave(mu_ra_url, untrusted_worker_url, path) {
match initialization::init_enclave(
mu_ra_url,
untrusted_worker_url,
path,
ceremony_commands_thread_count,
ceremony_events_thread_count,
) {
Err(e) => e.into(),
Ok(()) => sgx_status_t::SGX_SUCCESS,
}
Expand Down
12 changes: 12 additions & 0 deletions bitacross-worker/service/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ args:
takes_value: true
required: false
default_value: "0"
- ceremony-commands-thread-count:
long: ceremony-commands-thread-count
help: Number of threads to spawn for ceremony commands handling
takes_value: true
default_value: "4"
required: false
- ceremony-events-thread-count:
long: ceremony-events-thread-count
help: Number of threads to spawn for ceremony events handling
takes_value: true
default_value: "20"
required: false

subcommands:
- run:
Expand Down
18 changes: 18 additions & 0 deletions bitacross-worker/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ pub struct Config {

/// the parentchain block number to start syncing with
pub parentchain_start_block: String,

/// Number of threads to spawn for ceremony commands handling
pub ceremony_commands_thread_count: u8,

/// Number of threads to spawn for ceremony events handling
pub ceremony_events_thread_count: u8,
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -93,6 +99,8 @@ impl Config {
data_dir: PathBuf,
run_config: Option<RunConfig>,
parentchain_start_block: String,
ceremony_commands_thread_count: u8,
ceremony_events_thread_count: u8,
) -> Self {
Self {
litentry_rpc_url,
Expand All @@ -114,6 +122,8 @@ impl Config {
data_dir,
run_config,
parentchain_start_block,
ceremony_commands_thread_count,
ceremony_events_thread_count,
}
}

Expand Down Expand Up @@ -249,6 +259,12 @@ impl From<&ArgMatches<'_>> for Config {

let parentchain_start_block =
m.value_of("parentchain-start-block").unwrap_or(DEFAULT_PARENTCHAIN_START_BLOCK);

let ceremony_commands_thread_count =
m.value_of("ceremony-commands-thread-count").unwrap_or("4").parse().unwrap();
let ceremony_events_thread_count =
m.value_of("ceremony-events-thread-count").unwrap_or("20").parse().unwrap();

Self::new(
m.value_of("node-url").unwrap_or(DEFAULT_NODE_URL).into(),
m.value_of("node-port").unwrap_or(DEFAULT_NODE_PORT).into(),
Expand All @@ -272,6 +288,8 @@ impl From<&ArgMatches<'_>> for Config {
data_dir,
run_config,
parentchain_start_block.to_string(),
ceremony_commands_thread_count,
ceremony_events_thread_count,
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions bitacross-worker/service/src/enclave/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ pub fn enclave_init(config: &Config) -> EnclaveResult<Enclave> {
&config.mu_ra_url_external(),
&config.untrusted_worker_url_external(),
&config.data_dir().display().to_string(),
config.ceremony_commands_thread_count,
config.ceremony_events_thread_count,
)?;

Ok(enclave_api)
Expand Down
2 changes: 2 additions & 0 deletions bitacross-worker/service/src/tests/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ pub fn local_worker_config(
crate::config::pwd(),
None,
"0".to_string(),
5,
10,
)
}
9 changes: 8 additions & 1 deletion bitacross-worker/service/src/tests/mocks/enclave_api_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ use sp_core::ed25519;
pub struct EnclaveMock;

impl EnclaveBase for EnclaveMock {
fn init(&self, _mu_ra_url: &str, _untrusted_url: &str, _base_dir: &str) -> EnclaveResult<()> {
fn init(
&self,
_mu_ra_url: &str,
_untrusted_url: &str,
_base_dir: &str,
_ceremony_commands_thread_count: u8,
_ceremony_events_thread_count: u8,
) -> EnclaveResult<()> {
Ok(())
}

Expand Down

0 comments on commit 0fe7e73

Please sign in to comment.