Skip to content

Commit

Permalink
clean up chain relay sync logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain Brenzikofer committed Jun 21, 2020
1 parent 518cefc commit 7f2c6be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,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 @@ -43,21 +43,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 @@ -68,7 +68,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 @@ -77,7 +77,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 @@ -110,7 +110,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
9 changes: 6 additions & 3 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 @@ -494,17 +497,17 @@ pub fn sync_chain_relay(
.unwrap();
blocks_to_sync.push(head.clone());

if head.block.header.number % 100 == 0 {
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();

let tee_accountid = enclave_account(eid);

// only feed 100 blocks at a time into the enclave to save enclave state regularly
// 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(100) {
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();
Expand Down

0 comments on commit 7f2c6be

Please sign in to comment.