Skip to content

Commit bf32fc9

Browse files
authored
[integritee-service] introduce getters for RunConfig and make fields private (#1349)
* [integritee-service] improve `RunConfig` handling * [integritee-service] fix attesteer flag * [integritee-service] fix teeracle build * [integritee-service] fix clippy * [integritee-service] add documentation about the default marblerun port.
1 parent bd5dfa6 commit bf32fc9

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

core-primitives/settings/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pub mod sidechain {
9898
pub mod enclave {}
9999

100100
/// Settings for the Teeracle
101-
#[cfg(feature = "teeracle")]
102101
pub mod teeracle {
103102
use core::time::Duration;
104103
// Send extrinsic to update market exchange rate on the parentchain once per day

service/src/config.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use clap::ArgMatches;
1919
use itc_rest_client::rest_client::Url;
20+
use itp_settings::teeracle::DEFAULT_MARKET_DATA_UPDATE_INTERVAL;
2021
use parse_duration::parse;
2122
use serde::{Deserialize, Serialize};
2223
use std::{
@@ -215,17 +216,46 @@ impl From<&ArgMatches<'_>> for Config {
215216
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
216217
pub struct RunConfig {
217218
/// Skip remote attestation. Set this flag if running enclave in SW mode
218-
pub skip_ra: bool,
219+
skip_ra: bool,
219220
/// Set this flag if running in development mode to bootstrap enclave account on parentchain via //Alice.
220-
pub dev: bool,
221+
dev: bool,
221222
/// Request key and state provisioning from a peer worker.
222-
pub request_state: bool,
223+
request_state: bool,
223224
/// Shard identifier base58 encoded. Defines the shard that this worker operates on. Default is mrenclave.
224-
pub shard: Option<String>,
225+
shard: Option<String>,
225226
/// Optional teeracle update interval
226-
pub teeracle_update_interval: Option<Duration>,
227+
teeracle_update_interval: Option<Duration>,
227228
/// Marblerun's Prometheus endpoint base URL
228-
pub marblerun_base_url: Option<String>,
229+
marblerun_base_url: Option<String>,
230+
}
231+
232+
impl RunConfig {
233+
pub fn skip_ra(&self) -> bool {
234+
self.skip_ra
235+
}
236+
237+
pub fn dev(&self) -> bool {
238+
self.dev
239+
}
240+
241+
pub fn request_state(&self) -> bool {
242+
self.request_state
243+
}
244+
245+
pub fn shard(&self) -> Option<&str> {
246+
self.shard.as_deref()
247+
}
248+
249+
pub fn teeracle_update_interval(&self) -> Duration {
250+
self.teeracle_update_interval.unwrap_or(DEFAULT_MARKET_DATA_UPDATE_INTERVAL)
251+
}
252+
253+
pub fn marblerun_base_url(&self) -> &str {
254+
// This conflicts with the default port of a substrate node, but it is indeed the
255+
// default port of marblerun too:
256+
// https://github.com/edgelesssys/marblerun/blob/master/docs/docs/workflows/monitoring.md?plain=1#L26
257+
self.marblerun_base_url.as_deref().unwrap_or("http://localhost:9944")
258+
}
229259
}
230260

231261
impl From<&ArgMatches<'_>> for RunConfig {

service/src/main.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn main() {
175175
)));
176176

177177
if let Some(run_config) = config.run_config() {
178-
let shard = extract_shard(&run_config.shard, enclave.as_ref());
178+
let shard = extract_shard(run_config.shard(), enclave.as_ref());
179179

180180
println!("Worker Config: {:?}", config);
181181

@@ -186,12 +186,12 @@ fn main() {
186186
let node_api =
187187
node_api_factory.create_api().expect("Failed to create parentchain node API");
188188

189-
if run_config.request_state {
189+
if run_config.request_state() {
190190
sync_state::sync_state::<_, _, WorkerModeProvider>(
191191
&node_api,
192192
&shard,
193193
enclave.as_ref(),
194-
run_config.skip_ra,
194+
run_config.skip_ra(),
195195
);
196196
}
197197

@@ -210,7 +210,7 @@ fn main() {
210210
node_api_factory.create_api().expect("Failed to create parentchain node API");
211211
sync_state::sync_state::<_, _, WorkerModeProvider>(
212212
&node_api,
213-
&extract_shard(&smatches.value_of("shard").map(|s| s.to_string()), enclave.as_ref()),
213+
&extract_shard(smatches.value_of("shard"), enclave.as_ref()),
214214
enclave.as_ref(),
215215
smatches.is_present("skip-ra"),
216216
);
@@ -235,7 +235,7 @@ fn main() {
235235
} else if let Some(sub_matches) = matches.subcommand_matches("init-shard") {
236236
setup::init_shard(
237237
enclave.as_ref(),
238-
&extract_shard(&sub_matches.value_of("shard").map(|s| s.to_string()), enclave.as_ref()),
238+
&extract_shard(sub_matches.value_of("shard"), enclave.as_ref()),
239239
);
240240
} else if let Some(sub_matches) = matches.subcommand_matches("test") {
241241
if sub_matches.is_present("provisioning-server") {
@@ -249,10 +249,7 @@ fn main() {
249249
println!("[+] Done!");
250250
} else if sub_matches.is_present("provisioning-client") {
251251
println!("*** Running Enclave MU-RA TLS client\n");
252-
let shard = extract_shard(
253-
&sub_matches.value_of("shard").map(|s| s.to_string()),
254-
enclave.as_ref(),
255-
);
252+
let shard = extract_shard(sub_matches.value_of("shard"), enclave.as_ref());
256253
enclave_request_state_provisioning(
257254
enclave.as_ref(),
258255
sgx_quote_sign_type_t::SGX_UNLINKABLE_SIGNATURE,
@@ -294,7 +291,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
294291
WorkerModeProvider: ProvideWorkerMode,
295292
{
296293
let run_config = config.run_config().clone().expect("Run config missing");
297-
let skip_ra = run_config.skip_ra;
294+
let skip_ra = run_config.skip_ra();
298295

299296
println!("Integritee Worker v{}", VERSION);
300297
info!("starting worker on shard {}", shard.encode().to_base58());
@@ -313,7 +310,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
313310
// ------------------------------------------------------------------------
314311
// let new workers call us for key provisioning
315312
println!("MU-RA server listening on {}", config.mu_ra_url());
316-
let is_development_mode = run_config.dev;
313+
let is_development_mode = run_config.dev();
317314
let ra_url = config.mu_ra_url();
318315
let enclave_api_key_prov = enclave.clone();
319316
thread::spawn(move || {
@@ -427,9 +424,6 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
427424
register_collateral(&node_api, &*enclave, &tee_accountid, is_development_mode, skip_ra);
428425

429426
let trusted_url = config.trusted_worker_url_external();
430-
#[cfg(feature = "attesteer")]
431-
let marblerun_base_url =
432-
run_config.marblerun_base_url.unwrap_or("http://localhost:9944".to_owned());
433427

434428
#[cfg(feature = "attesteer")]
435429
fetch_marblerun_events_every_hour(
@@ -438,7 +432,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
438432
tee_accountid.clone(),
439433
is_development_mode,
440434
trusted_url.clone(),
441-
marblerun_base_url.clone(),
435+
run_config.marblerun_base_url().to_string(),
442436
);
443437

444438
// ------------------------------------------------------------------------
@@ -478,7 +472,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
478472
if WorkerModeProvider::worker_mode() == WorkerMode::Teeracle {
479473
start_interval_market_update(
480474
&node_api,
481-
run_config.teeracle_update_interval,
475+
run_config.teeracle_update_interval(),
482476
enclave.as_ref(),
483477
&teeracle_tokio_handle,
484478
);
@@ -712,7 +706,7 @@ fn fetch_marblerun_events_every_hour<E>(
712706
&accountid,
713707
is_development_mode,
714708
url.clone(),
715-
marblerun_base_url.clone(),
709+
&marblerun_base_url,
716710
);
717711

718712
thread::sleep(Duration::from_secs(POLL_INTERVAL_5_MINUTES_IN_SECS));
@@ -728,10 +722,10 @@ fn register_quotes_from_marblerun(
728722
accountid: &AccountId32,
729723
is_development_mode: bool,
730724
url: String,
731-
marblerun_base_url: String,
725+
marblerun_base_url: &str,
732726
) {
733727
let enclave = enclave.as_ref();
734-
let events = prometheus_metrics::fetch_marblerun_events(&marblerun_base_url)
728+
let events = prometheus_metrics::fetch_marblerun_events(marblerun_base_url)
735729
.map_err(|e| {
736730
info!("Fetching events from Marblerun failed with: {:?}, continuing with 0 events.", e);
737731
})

service/src/teeracle/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::teeracle::interval_scheduling::schedule_on_repeating_intervals;
1919
use codec::{Decode, Encode};
2020
use itp_enclave_api::teeracle_api::TeeracleApi;
2121
use itp_node_api::api_client::ParentchainApi;
22-
use itp_settings::teeracle::DEFAULT_MARKET_DATA_UPDATE_INTERVAL;
2322
use itp_utils::hex::hex_encode;
2423
use log::*;
2524
use sp_runtime::OpaqueExtrinsic;
@@ -35,7 +34,7 @@ pub(crate) mod teeracle_metrics;
3534
/// with the current market data (for now only exchange rate).
3635
pub(crate) fn start_interval_market_update<E: TeeracleApi>(
3736
api: &ParentchainApi,
38-
maybe_interval: Option<Duration>,
37+
interval: Duration,
3938
enclave_api: &E,
4039
tokio_handle: &Handle,
4140
) {
@@ -47,7 +46,6 @@ pub(crate) fn start_interval_market_update<E: TeeracleApi>(
4746
info!("Teeracle will update now");
4847
updates_to_run();
4948

50-
let interval = maybe_interval.unwrap_or(DEFAULT_MARKET_DATA_UPDATE_INTERVAL);
5149
info!("Starting teeracle interval for oracle update, interval of {:?}", interval);
5250
schedule_on_repeating_intervals(updates_to_run, interval);
5351
}

service/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use itp_types::ShardIdentifier;
2222
use log::info;
2323

2424
pub fn extract_shard<E: EnclaveBase>(
25-
maybe_shard_str: &Option<String>,
25+
maybe_shard_str: Option<&str>,
2626
enclave_api: &E,
2727
) -> ShardIdentifier {
2828
match maybe_shard_str {

0 commit comments

Comments
 (0)