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

Commit b597ed7

Browse files
authored
Merge pull request #213 from enigmampc/compute_update_state
updating state during computations
2 parents 4753833 + 63e095e commit b597ed7

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

.drone.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ steps:
1212
commands:
1313
- LD_LIBRARY_PATH=/opt/intel/libsgx-enclave-common/aesm /opt/intel/libsgx-enclave-common/aesm/aesm_service
1414
- . /opt/sgxsdk/environment && . /root/.cargo/env
15+
- cargo --version
1516
- cd enigma-core && RUSTFLAGS=-Awarnings make DEBUG=1
1617
- cd app && RUSTFLAGS=-Awarnings cargo test
1718
volumes:

enigma-core/app/src/db/dal.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub struct DB {
1515
// the DB needs to store the options for creating new
1616
// cf's that would be able to imitate the DB behaviour
1717
pub options: Options,
18+
// keeps track if the state needs to be rebuilt
19+
state_updated: bool,
1820
}
1921

2022
impl DB {
@@ -53,9 +55,23 @@ impl DB {
5355
let cf_list_burrowed = cf_list.iter().map(String::as_str).collect::<Vec<&str>>();
5456
let database = rocks_db::open_cf(&options, &location, &cf_list_burrowed[..])?;
5557
let location = location.as_ref().to_path_buf();
56-
let db_par = DB { location, database, options };
58+
// the state_updated is initialized to true since it won't be necessary to build
59+
// the state when the DB is empty.
60+
let db_par = DB { location, database, options, state_updated: true};
5761
Ok(db_par)
5862
}
63+
64+
/// updates the state_updated field according to the status of the state.
65+
/// every time the state is built (=true) and
66+
/// on the other hand when new deltas enter the DB (=false).
67+
pub fn update_state_status(&mut self, state: bool) {
68+
self.state_updated = state;
69+
}
70+
71+
/// get the current status of the state
72+
pub fn get_state_status(& mut self) -> bool {
73+
self.state_updated
74+
}
5975
}
6076

6177
pub trait CRUDInterface<E, K, T, V> {

enigma-core/app/src/networking/ipc_listener.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ pub(self) mod handling {
250250
if results.into_iter().any(| result | result.is_err()) {
251251
status = FAILED;
252252
}
253+
// since a new delta and bytecode were added, the state is no longer updated
254+
db.update_state_status(false);
253255
let result = IpcResults::Status(status);
254256
Ok(IpcResponse::UpdateNewContractOnDeployment { address, result })
255257
}
@@ -281,6 +283,8 @@ pub(self) mod handling {
281283
let delta = IpcStatusResult { address, key, status };
282284
errors.push(delta);
283285
}
286+
// since a new delta was added the state is no longer updated
287+
db.update_state_status(false);
284288
let result = IpcResults::UpdateDeltasResult { status: overall_status, errors };
285289
Ok(IpcResponse::UpdateDeltas {result})
286290
}
@@ -314,6 +318,7 @@ pub(self) mod handling {
314318
let msg = response.response.from_hex()?;
315319
km_u::ptt_res(eid, &msg)?;
316320
let res = km_u::ptt_build_state(db, eid)?;
321+
db.update_state_status(true);
317322
let result: Vec<_> = res
318323
.into_iter()
319324
.map(|a| IpcStatusResult{ address: a.to_hex(), status: FAILED, key: None })
@@ -366,6 +371,10 @@ pub(self) mod handling {
366371
let mut user_pubkey = [0u8; 64];
367372
user_pubkey.clone_from_slice(&input.user_dhkey.from_hex()?);
368373

374+
if !db.get_state_status() {
375+
let res = km_u::ptt_build_state(db, eid)?;
376+
db.update_state_status(true);
377+
}
369378
let bytecode = db.get_contract(address)?;
370379

371380

enigma-core/enclave/src/km_t/principal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn ecall_build_state_internal(db_ptr: *const RawPointer) -> Result<Ve
5858

5959
'contract: for (addrs, key) in guard.iter() {
6060
// Get the state and decrypt it.
61-
// if no state exist create new one and if failed decrypting push to failed_contracts and move on.
61+
// if no state exists create a new one and if failed decrypting, push to failed_contracts and move on.
6262
let (mut start, mut state ) = match runtime_ocalls_t::get_state(db_ptr, *addrs) {
6363
Ok(enc_state) => match ContractState::decrypt(enc_state, &key) {
6464
Ok(state) => (state.delta_index+1, state),

0 commit comments

Comments
 (0)