Skip to content
This repository was archived by the owner on Jun 21, 2020. It is now read-only.

Commit bda56c3

Browse files
fredfortierelichai
authored andcommitted
FIX: Fixed PR requests - AtomicU64, TryInto, setWorkerParams, etc.
FIX: Replaced redundant AtomicU64 FIX: Removed duplicate entries FIX: Remove unnecessary log file FIX: Removing the priv key print FIX: Fixed the TryInto implementation FIX: Removed unnecessary code in the document storage unit test FIX: Housekeeping to improve the readibility of functions in the keys_keeper module FIX: Fixed the setWorkerParams message signature FIX: Housekeeping in the epoch keeper FIX: Fix rand byte array length and other fixes DEV: Moved the logging module to enigma_tools_u FIX: Removed redundant clone of a variable implementing Copy FIX: Removed the `connect_batch` fn which is no longer used FIX: Remove unnecessary config FIX: Removed unnecessary feature FIX: Housekeeping in the app file FIX: Removed redundant clone calls FIX: Improved error handling when fetching the current block number FIX: Removed explicit CORS domain validation config
1 parent a62ef36 commit bda56c3

File tree

26 files changed

+62
-173
lines changed

26 files changed

+62
-173
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,3 @@ dockerfile-elichai/
8989

9090
/target
9191
**/*.rs.bk
92-
93-
/target
94-
**/*.rs.bk

enigma-core/app/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enigma-core/app/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ lazy_static = "1.2.0"
2323
lru-cache = "0.1.1"
2424
log = "0.4.6"
2525
log-derive = "0.2"
26-
simplelog = "0.5.3"
2726
structopt = "0.2"
2827

2928

@@ -35,4 +34,4 @@ ethabi = "6.1.0"
3534
cross-test-utils = { path = "cross-test-utils" }
3635
regex = "1"
3736
rand = "0.6.5"
38-
tempfile = "3.0"
37+
tempfile = "3.0"

enigma-core/app/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern crate tokio_zmq;
1717
extern crate zmq;
1818
#[macro_use]
1919
extern crate failure;
20-
extern crate enigma_tools_u;
20+
pub extern crate enigma_tools_u;
2121
extern crate enigma_crypto;
2222
extern crate enigma_types;
2323
extern crate rustc_hex as hex;
@@ -29,7 +29,6 @@ pub extern crate log;
2929
#[macro_use]
3030
pub extern crate log_derive;
3131
pub extern crate structopt;
32-
pub extern crate simplelog;
3332

3433
pub mod common_u;
3534
pub mod db;
@@ -38,7 +37,6 @@ pub mod evm_u;
3837
pub mod km_u;
3938
pub mod networking;
4039
pub mod wasm_u;
41-
pub mod logging;
4240
pub mod cli;
4341

4442
#[cfg(feature = "cross-test-utils")]

enigma-core/app/src/logging.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

enigma-core/app/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use db::DB;
1111
use cli::Opt;
1212
use structopt::StructOpt;
1313
use futures::Future;
14-
use simplelog::CombinedLogger;
14+
use enigma_tools_u::common_u::logging::{self, CombinedLogger};
1515

1616
fn main() {
1717
let opt: Opt = Opt::from_args();
@@ -42,7 +42,7 @@ mod tests {
4242
use enigma_core_app::sgx_types::*;
4343
use enigma_core_app::db::DB;
4444
use self::enigma_types::RawPointer;
45-
use enigma_core_app::simplelog::TermLogger;
45+
use enigma_tools_u::common_u::logging::TermLogger;
4646
use enigma_core_app::log::LevelFilter;
4747
use self::tempfile::TempDir;
4848

enigma-principal/app/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enigma-principal/app/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ web3 = { git = "https://github.com/tomusdrw/rust-web3.git", default-features = f
3131
jsonrpc-http-server = "10.0"
3232
log = "0.4.6"
3333
log-derive = "0.2"
34-
simplelog = "0.5.3"
3534
unicase = "=2.2.0"
3635
rmp-serde = "0.13.7"
3736

enigma-principal/app/build-principal.log

Whitespace-only changes.

enigma-principal/app/src/boot_network/keys_provider_http.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ impl TryInto<[u8; 65]> for StringWrapper {
4545
}
4646
}
4747

48-
impl Into<Vec<u8>> for StringWrapper {
49-
fn into(self) -> Vec<u8> {
50-
self.try_into().expect("Unable to cast byte array attribute")
51-
}
52-
}
53-
54-
impl Into<[u8; 65]> for StringWrapper {
55-
fn into(self) -> [u8; 65] {
56-
self.try_into().expect("Unable to cast fixed 65-bytes array attribute")
57-
}
58-
}
59-
6048
#[derive(Deserialize, Debug, Clone)]
6149
pub struct StateKeyRequest {
6250
pub data: StringWrapper,
@@ -129,22 +117,20 @@ impl PrincipalHttpServer {
129117
/// Example:
130118
/// curl -X POST --data '{"jsonrpc": "2.0", "method": "get_state_keys", "params": ["84a46461746181a75265717565737493dc0020cca7cc937b64ccb8cccacca5cc8f03721bccb6ccbacccf5c78cccb235fccebcce0cce70b1bcc84cccdcc99541461cca0cc8edc002016367accacccb67a4a017ccc8dcca8ccabcc95682ccccb390863780f7114ccddcca0cca0cce0ccc55644ccc7ccc4dc0020ccb1cce9cc9324505bccd32dcca0cce1ccf85dcccf5e19cca0cc9dccb0481ecc8a15ccf62c41cceb320304cca8cce927a269649c1363ccb3301c101f33cce1cc9a0524a67072656669789e456e69676d61204d657373616765a67075626b6579dc0040cce5ccbe28cc9dcc9a2eccbd08ccc0457a5f16ccdfcc9fccdc256c5d5f6c3514cccdcc95ccb47c11ccc4cccd3e31ccf0cce4ccefccc83ccc80cce8121c3939ccbb2561cc80ccec48ccbecca8ccc569ccd2cca3ccda6bcce415ccfa20cc9bcc98ccda", "43f19586b0a0ae626b9418fe8355888013be1c9b4263a4b3a27953de641991e936ed6c4076a2a383b3b001936bf0eb6e23c78fbec1ee36f19c6a9d24d75e9e081c"]' -H "Content-Type: application/json" http://127.0.0.1:3040/
131119
///
132-
#[logfn(INFO)]
133120
pub fn start(&self) {
134121
let mut io = IoHandler::default();
135122
let epoch_provider = Arc::clone(&self.epoch_provider);
136123
io.add_method(METHOD_GET_STATE_KEYS, move |params: Params| {
137124
let epoch_provider = epoch_provider.clone();
138125
let request = params.parse::<StateKeyRequest>()?;
139-
let eid = epoch_provider.eid.load(Ordering::SeqCst);
140-
let body = match Self::get_state_keys_internal(epoch_provider, request, eid) {
126+
let eid = epoch_provider.eid.clone();
127+
let body = match Self::get_state_keys_internal(epoch_provider, request, *eid) {
141128
Ok(body) => body,
142129
Err(err) => return Err(ServerError { code: ErrorCode::InternalError, message: format!("Unable to get keys: {:?}", err), data: None }),
143130
};
144131
Ok(body)
145132
});
146133
let server = ServerBuilder::new(io)
147-
.cors(DomainsValidation::AllowOnly(vec![AccessControlAllowOrigin::Null]))
148134
.start_http(&format!("0.0.0.0:{}", self.port).parse().unwrap())
149135
.expect("Unable to start RPC server");
150136
println!("JSON-RPC HTTP server listening on port: {}", self.port);
@@ -181,7 +167,7 @@ mod test {
181167
let sig = Bytes::from(sig.to_vec());
182168
let nonce = U256::from(0);
183169
let epoch_state = EpochState { seed, sig, nonce, confirmed_state };
184-
let results = PrincipalHttpServer::find_epoch_contract_addresses(reader, request.sig.try_into(), epoch_state).unwrap();
170+
let results = PrincipalHttpServer::find_epoch_contract_addresses(reader, request.sig.try_into().unwrap(), epoch_state).unwrap();
185171
println!("Found contract addresses: {:?}", results);
186172
assert_eq!(results, vec![H256([0; 32])])
187173
}

enigma-principal/app/src/boot_network/principal_manager.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fs::File;
22
use std::io::prelude::*;
33
use std::str;
44
use std::sync::Arc;
5-
use std::sync::atomic::AtomicU64;
65
use std::thread;
76

87
use failure::Error;
@@ -149,20 +148,22 @@ impl Sampler for PrincipalManager {
149148

150149
fn get_contract_address(&self) -> Address { self.contract.address() }
151150

152-
fn get_account_address(&self) -> Address { self.contract.account.clone() }
151+
//noinspection RsBorrowChecker
152+
fn get_account_address(&self) -> Address { self.contract.account }
153153

154154
fn get_network_url(&self) -> String { self.config.url.clone() }
155155

156156
fn get_block_number(&self) -> Result<U256, Error> {
157-
let block_number = self.get_web3().eth().block_number().wait().unwrap();
157+
let block_number = match self.get_web3().eth().block_number().wait() {
158+
Ok(block_number) => block_number,
159+
Err(err) => bail!("Current block number not available: {:?}", err),
160+
};
158161
Ok(block_number)
159162
}
160163

161164
fn register<G: Into<U256>>(&self, signing_address: String, gas_limit: G) -> Result<H256, Error> {
162165
let registration_params = self.report_manager.get_registration_params()?;
163-
let report = registration_params.report.clone();
164-
let signature = registration_params.signature.clone();
165-
let receipt = self.contract.register(signing_address, report, signature, gas_limit, self.config.confirmations as usize)?;
166+
let receipt = self.contract.register(signing_address, registration_params.report, registration_params.signature, gas_limit, self.config.confirmations as usize)?;
166167
Ok(receipt.transaction_hash)
167168
}
168169

@@ -204,7 +205,7 @@ impl Sampler for PrincipalManager {
204205
// get enigma contract
205206
let enigma_contract = &self.contract;
206207
// Start the WorkerParameterized Web3 log filter
207-
let eid: Arc<AtomicU64> = Arc::new(AtomicU64::new(self.eid));
208+
let eid: Arc<sgx_enclave_id_t> = Arc::new(self.eid);
208209
let epoch_provider = Arc::new(EpochProvider::new(eid.clone(), self.contract.clone())?);
209210

210211
// Start the JSON-RPC Server
@@ -301,7 +302,7 @@ mod test {
301302
principal.verify_identity_or_register(gas_limit).unwrap();
302303

303304
let block_number = principal.get_web3().eth().block_number().wait().unwrap();
304-
let eid_safe = Arc::new(AtomicU64::new(eid));
305+
let eid_safe = Arc::new(eid);
305306
let epoch_provider = EpochProvider::new(eid_safe, principal.contract.clone()).unwrap();
306307
epoch_provider.reset_epoch_state().unwrap();
307308
epoch_provider.set_worker_params(block_number, gas_limit, 0).unwrap();

enigma-principal/app/src/cli/app.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fs::File;
22
use std::io::prelude::*;
33
use std::path::Path;
44
use std::sync::Arc;
5-
use std::sync::atomic::AtomicU64;
65

76
use failure::Error;
87
use sgx_types::sgx_enclave_id_t;
@@ -18,7 +17,6 @@ use esgx::general::{ENCLAVE_DIR, storage_dir};
1817
#[logfn(INFO)]
1918
pub fn start(eid: sgx_enclave_id_t) -> Result<(), Error> {
2019
let opt = cli::options::Opt::from_args();
21-
let _config = deploy_scripts::load_config(opt.deploy_config.as_str())?;
2220
let mut principal_config = PrincipalManager::load_config(opt.principal_config.as_str())?;
2321
let report_manager = ReportManager::new(principal_config.clone(), eid)?;
2422
let signing_address = report_manager.get_signing_address()?;
@@ -34,46 +32,8 @@ pub fn start(eid: sgx_enclave_id_t) -> Result<(), Error> {
3432
file.write_all(prefixed_signing_address.as_bytes())?;
3533
println!("Wrote signing address: {:?} in file: {:?}", prefixed_signing_address, path);
3634
} else {
37-
// cli::options::print_logo();
38-
39-
// deploy the contracts Enigma,EnigmaToken (not deployed yet)
4035
if opt.deploy {
41-
println!("[Mode:] deploying to default.");
42-
/* step1 : prepeare the contracts (deploy Enigma,EnigmaToken) */
43-
// load the config
44-
// deploy all contracts. (Enigma & EnigmaToken)
45-
// let enigma_contract = Arc::new(EnigmaContract::deploy_contract(Path::new(&config.enigma_token_contract_path),
46-
// Path::new(&config.enigma_contract_path),
47-
// &principal_config.url,
48-
// Some(&config.account_address), // This means that account no. 0 will be used, we should use the one from the JSON or add an `--account` cli option. or
49-
// &sign_key)?);
50-
//
51-
// /* step2 : build the config of the principal node */
52-
// // optional : set time limit for the principal node
53-
// let ttl = if opt.time_to_live > 0 { Some(opt.time_to_live) } else { None };
54-
//
55-
// let gas_limit = 5_999_999;
56-
// let contract_addr = enigma_contract.address();
57-
// principal_config.set_accounts_address(enigma_contract.account.to_hex());
58-
// principal_config.set_enigma_contract_address(contract_addr.to_hex());
59-
// principal_config.max_epochs = ttl;
60-
//
61-
// println!("Enigma contract deployed: {:?}", enigma_contract.address());
62-
// let principal: PrincipalManager = PrincipalManager::new_delegated(principal_config, enigma_contract, eid);
63-
// println!("Connected to the Enigma contract with account: {:?}", principal.get_account_address());
64-
//
65-
// /* step3 optional - run miner to simulate blocks */
66-
// let join_handle = if opt.mine > 0 {
67-
// Some(principal_manager::run_miner(principal.get_account_address(), principal.get_web3(), opt.mine as u64))
68-
// } else {
69-
// None
70-
// };
71-
//
72-
// /* step4 : run the principal manager */
73-
// principal.run(gas_limit).unwrap();
74-
// if let Some(t) = join_handle { t.join().unwrap(); }
75-
panic!("Self-deploy mode not yet implemented. Fix issues with linked libraries in the Enigma contract.");
76-
// contracts deployed, just run
36+
unimplemented!("Self-deploy mode not yet implemented. Fix issues with linked libraries in the Enigma contract.");
7737
} else {
7838
println!("[Mode:] run node NO DEPLOY.");
7939
/* step1 : build the config of the principal node */
@@ -112,7 +72,7 @@ pub fn start(eid: sgx_enclave_id_t) -> Result<(), Error> {
11272
};
11373
} else if opt.set_worker_params {
11474
let block_number = principal.get_block_number()?;
115-
let eid_safe = Arc::new(AtomicU64::new(eid));
75+
let eid_safe = Arc::new(eid);
11676
let epoch_provider = EpochProvider::new(eid_safe, principal.contract.clone())?;
11777
let tx = epoch_provider.set_worker_params(block_number, gas_limit, principal_config.confirmations as usize)?;
11878
println!("The setWorkersParams tx: {:?}", tx);

enigma-principal/app/src/epoch_u/epoch_provider.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ use epoch_u::epoch_types::{ConfirmedEpochState, EpochState, WorkersParameterized
2222
use esgx::epoch_keeper_u::set_worker_params;
2323
use esgx::general::{ENCLAVE_DIR, storage_dir};
2424
use keys_u::keeper_types_u::InputWorkerParams;
25+
use sgx_types::sgx_enclave_id_t;
2526

2627
pub struct EpochProvider {
2728
pub contract: Arc<EnigmaContract>,
2829
pub epoch_state: Arc<Mutex<Option<EpochState>>>,
29-
pub eid: Arc<AtomicU64>,
30+
pub eid: Arc<sgx_enclave_id_t>,
3031
}
3132

3233
impl EpochProvider {
33-
pub fn new(eid: Arc<AtomicU64>, contract: Arc<EnigmaContract>) -> Result<EpochProvider, Error> {
34+
pub fn new(eid: Arc<sgx_enclave_id_t>, contract: Arc<EnigmaContract>) -> Result<EpochProvider, Error> {
3435
let epoch_state_val = Self::read_epoch_state()?;
3536
// TODO: If the state is not empty, get the active workers and prove them to the enclave
3637
println!("Initializing EpochProvider with EpochState: {:?}", epoch_state_val);
@@ -179,10 +180,10 @@ impl EpochProvider {
179180
stakes: result.1,
180181
};
181182
println!("The active workers: {:?}", worker_params);
182-
let epoch_state = &mut set_worker_params(self.eid.load(Ordering::SeqCst), worker_params.clone())?;
183+
let epoch_state = &mut set_worker_params(*self.eid, worker_params.clone())?;
183184
println!("Waiting for setWorkerParams({:?}, {:?}, {:?})", block_number, epoch_state.seed, epoch_state.sig);
184185
// TODO: Consider a retry mechanism, either store the EpochSeed or add a getter ecall
185-
let receipt = self.contract.set_workers_params(block_number, epoch_state.seed.clone(), epoch_state.sig.clone(), gas_limit, confirmations)?;
186+
let receipt = self.contract.set_workers_params(block_number, epoch_state.seed, epoch_state.sig.clone(), gas_limit, confirmations)?;
186187
self.parse_worker_parameterized(&receipt)?;
187188
println!("Caching selected workers");
188189
self.confirm_epoch(epoch_state, worker_params)?;

enigma-principal/app/src/esgx/keys_keeper_u.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn get_enc_state_keys(eid: sgx_enclave_id_t, request: StateKeyRequest, epoch
5454
msg_bytes.len(),
5555
addrs_bytes.as_ptr() as *const u8,
5656
addrs_bytes.len(),
57-
&request.sig.into(),
57+
&request.sig.try_into()?,
5858
enc_response_slice.as_mut_ptr() as *mut u8,
5959
&mut enc_response_len_out,
6060
&mut sig_out,

0 commit comments

Comments
 (0)