Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
42898bb
move content to book
brenzi May 26, 2020
fff3ee5
badge
brenzi May 26, 2020
bfd2516
Cl fixme todos (#138)
clangenb May 27, 2020
ba232e2
update deps (#143)
clangenb May 27, 2020
cc77d37
Jenkinsfile: Archive binaries
electronix May 28, 2020
2448db9
Jenkinsfile: Archive binary after build
electronix May 28, 2020
76be1ff
* bump node: v0.6.6-sub2.0.0-alpha.7 (#147)
clangenb May 29, 2020
ca3ef97
fix running multiple workers (#149)
clangenb May 29, 2020
4a38417
! fix: indexing in get_first_worker_that_is_not_equal_to_self (#150)
clangenb May 30, 2020
24ef5b3
on block storage updates for every shard (#155)
clangenb Jun 3, 2020
c68084b
allow on chain read in get state (#156)
clangenb Jun 3, 2020
f2e67e6
back up chain relay db before update in case of file corruption
Jun 21, 2020
ca9622d
Ws server refactor (#13)
clangenb Jun 23, 2020
c2af738
update Block number in state and apply demurrage in client (#17)
brenzi Jun 24, 2020
8a05115
[enclave/chain_relay] store only hashes of the headers instead of the…
Aug 20, 2020
3977104
enclave: patch log and env_logger to mesalock
Aug 30, 2020
d185559
worker should panic if it can't write to shard
Jun 23, 2020
f815fcd
add public getters for unpermissioned statistics (#16)
brenzi Jun 23, 2020
23b8485
manual fixes to remove encointer-specifics. bump version to 0.6.11 li…
Sep 8, 2020
f4c93e0
Merge branch 'master' into enhancements-upstreaming
brenzi Sep 8, 2020
e13c5d9
fixed stf cli. client and worker build successfully
Sep 8, 2020
daa30b9
some worker fixes
Sep 8, 2020
a0da29c
building works
Sep 9, 2020
15fc7cd
don't request key provisioning form other worker
Sep 9, 2020
e9efdc4
fix
Sep 9, 2020
e4b9bc5
more stf debug output
Sep 9, 2020
68d6679
fix demo shielding example
Sep 9, 2020
01e437c
fmt
Sep 9, 2020
506e844
fmt - also enclave
Sep 9, 2020
8a16eae
fix clippy. fmt
Sep 9, 2020
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
Prev Previous commit
Next Next commit
back up chain relay db before update in case of file corruption
clean up chain relay sync logging
  • Loading branch information
Alain Brenzikofer committed Sep 8, 2020
commit f2e67e60cf099be9b7cc8a10fee05a9c7342d32e
13 changes: 9 additions & 4 deletions enclave/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.

*/
use std::fs::File;
use std::fs;
use std::io::{Read, Write};
use std::sgxfs::SgxFile;
use std::string::String;
Expand All @@ -31,7 +31,7 @@ pub fn unseal(filepath: &str) -> SgxResult<Vec<u8>> {
}

pub fn read(filepath: &str) -> SgxResult<Vec<u8>> {
File::open(filepath)
fs::File::open(filepath)
.map(_read)
.sgx_error_with_log(&format!("[Enclave] File '{}' not found!", filepath))?
}
Expand All @@ -46,7 +46,7 @@ fn _read<F: Read>(mut file: F) -> SgxResult<Vec<u8>> {

pub fn read_to_string(filepath: &str) -> SgxResult<String> {
let mut contents = String::new();
File::open(filepath)
fs::File::open(filepath)
.map(|mut f| f.read_to_string(&mut contents))
.sgx_error_with_log(&format!("[Enclave] Could not read '{}'", filepath))?
.sgx_error_with_log(&format!("[Enclave] File '{}' not found!", filepath))?;
Expand All @@ -61,7 +61,7 @@ pub fn seal(bytes: &[u8], filepath: &str) -> SgxResult<sgx_status_t> {
}

pub fn write(bytes: &[u8], filepath: &str) -> SgxResult<sgx_status_t> {
File::create(filepath)
fs::File::create(filepath)
.map(|f| _write(bytes, f))
.sgx_error_with_log(&format!("[Enclave] Creating '{}' failed", filepath))?
}
Expand All @@ -83,13 +83,18 @@ pub mod light_validation {
use sgx_types::{sgx_status_t, SgxResult};
use sp_finality_grandpa::VersionedAuthorityList;
use std::sgxfs::SgxFile;
use std::fs;

pub fn unseal() -> SgxResult<LightValidation> {
let vec = super::unseal(CHAIN_RELAY_DB)?;
LightValidation::decode(&mut vec.as_slice()).map_err(|_| sgx_status_t::SGX_ERROR_UNEXPECTED)
}

pub fn seal(validator: LightValidation) -> SgxResult<sgx_status_t> {
debug!("backup chain relay state");
if fs::copy(CHAIN_RELAY_DB, format!("{}.1", CHAIN_RELAY_DB)).is_err() {
warn!("could not backup previous chain relay state");
};
debug!("Seal Chain Relay State. Current state: {:?}", validator);
super::seal(validator.encode().as_slice(), CHAIN_RELAY_DB)
}
Expand Down
2 changes: 1 addition & 1 deletion enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ pub fn update_states(header: Header) -> SgxResult<()> {

/// Scans blocks for extrinsics that ask the enclave to execute some actions.
pub fn scan_block_for_relevant_xt(block: &Block) -> SgxResult<Vec<OpaqueCall>> {
debug!("Scanning blocks for relevant xt");
debug!("Scanning block {} for relevant xt", block.header.number());
let mut calls = Vec::<OpaqueCall>::new();
for xt_opaque in block.extrinsics.iter() {
if let Ok(xt) =
Expand Down
14 changes: 7 additions & 7 deletions enclave/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ pub fn load(shard: &ShardIdentifier) -> SgxResult<StfState> {
shard.encode().to_base58(),
ENCRYPTED_STATE_FILE
);
debug!("loading state from: {}", state_path);
trace!("loading state from: {}", state_path);
let state_vec = read(&state_path)?;

// state is now decrypted!
let state: StfState = match state_vec.len() {
0 => {
debug!("state is empty. will initialize it.");
debug!("state at {} is empty. will initialize it.", state_path);
Stf::init_state()
}
n => {
debug!("State loaded with size {}B, deserializing...", n);
debug!("State loaded from {} with size {}B, deserializing...", state_path, n);
StfState::decode(state_vec)
}
};
debug!("state decoded successfully");
trace!("state decoded successfully");
Ok(state)
}

Expand All @@ -67,7 +67,7 @@ pub fn write(state: StfState, shard: &ShardIdentifier) -> SgxResult<H256> {
shard.encode().to_base58(),
ENCRYPTED_STATE_FILE
);
debug!("writing state to: {}", state_path);
trace!("writing state to: {}", state_path);

let cyphertext = encrypt(state.encode())?;

Expand All @@ -76,7 +76,7 @@ pub fn write(state: StfState, shard: &ShardIdentifier) -> SgxResult<H256> {
Err(status) => return Err(status),
};

debug!("new state hash=0x{}", hex::encode_hex(&state_hash));
debug!("new state with hash=0x{} written to {}", hex::encode_hex(&state_hash), state_path);

io::write(&cyphertext, &state_path)?;
Ok(state_hash.into())
Expand Down Expand Up @@ -106,7 +106,7 @@ fn read(path: &str) -> SgxResult<Vec<u8>> {
};

aes::de_or_encrypt(&mut bytes)?;
debug!("buffer decrypted = {:?}", bytes);
trace!("buffer decrypted = {:?}", bytes);

Ok(bytes)
}
Expand Down
32 changes: 24 additions & 8 deletions worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ mod ipfs;
mod tests;
mod ws_server;

/// how many blocks will be synced before storing the chain db to disk
const BLOCK_SYNC_BATCH_SIZE: u32 = 1000;

fn main() {
// Setup logging
env_logger::init();
Expand Down Expand Up @@ -475,7 +478,10 @@ pub fn sync_chain_relay(
.get_signed_block(Some(head.block.header.parent_hash))
.unwrap();
blocks_to_sync.push(head.clone());
debug!("Syncing Block: {:?}", head.block)

if head.block.header.number % BLOCK_SYNC_BATCH_SIZE == 0 {
println!("Remaining blocks to fetch until last synced header: {:?}", head.block.header.number - last_synced_head.number)
}
}
blocks_to_sync.reverse();
debug!(
Expand All @@ -486,13 +492,23 @@ pub fn sync_chain_relay(
let tee_accountid = enclave_account(eid);
let tee_nonce = get_nonce(&api, &tee_accountid);

let xts = enclave_sync_chain_relay(eid, blocks_to_sync, tee_nonce).unwrap();

let extrinsics: Vec<Vec<u8>> = Decode::decode(&mut xts.as_slice()).unwrap();
info!(
"Sync chain relay: Enclave wants to send {} extrinsics",
extrinsics.len()
);
// only feed BLOCK_SYNC_BATCH_SIZE blocks at a time into the enclave to save enclave state regularly
let mut i = blocks_to_sync[0].block.header.number as usize;
for chunk in blocks_to_sync.chunks(BLOCK_SYNC_BATCH_SIZE as usize) {
let tee_nonce = get_nonce(&api, &tee_accountid);
let xts = enclave_sync_chain_relay(eid, chunk.to_vec(), tee_nonce).unwrap();
let extrinsics: Vec<Vec<u8>> = Decode::decode(&mut xts.as_slice()).unwrap();

if !extrinsics.is_empty() {
println!(
"Sync chain relay: Enclave wants to send {} extrinsics",
extrinsics.len()
);
}
for xt in extrinsics.into_iter() {
api.send_extrinsic(hex_encode(xt), XtStatus::InBlock)
.unwrap();
}

for xt in extrinsics.into_iter() {
api.send_extrinsic(hex_encode(xt), XtStatus::InBlock)
Expand Down