Skip to content

Commit

Permalink
More PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Müller committed Apr 11, 2022
1 parent 28e7ba3 commit b3ec74e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
10 changes: 5 additions & 5 deletions core-primitives/stf-state-handler/src/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub mod sgx {
use sgx_tcrypto::rsgx_sha256_slice;
use std::path::Path;

/// SGX state file I/O
/// SGX state file I/O.
pub struct SgxStateFileIo<StateKey> {
state_key: StateKey,
}
Expand Down Expand Up @@ -200,8 +200,8 @@ pub mod sgx {
self.write(shard_identifier, state_id, state)
}

/// Writes the state (without the state diff) encrypted into the enclave storage
/// Returns the hash of the saved state (independent of the diff!)
/// Writes the state (without the state diff) encrypted into the enclave storage.
/// Returns the hash of the saved state (independent of the diff!).
fn write(
&self,
shard_identifier: &ShardIdentifier,
Expand All @@ -211,7 +211,7 @@ pub mod sgx {
let state_path = state_file_path(shard_identifier, state_id);
trace!("writing state to: {:?}", state_path);

// only save the state, the state diff is pruned
// Only save the state, the state diff is pruned.
let cyphertext = self.encrypt(state.state.encode())?;

let state_hash = rsgx_sha256_slice(&cyphertext)?;
Expand Down Expand Up @@ -257,7 +257,7 @@ pub mod sgx {
}

/// Remove a shard directory with all of its content.
pub fn remove_shard_dir(shard: &ShardIdentifier) {
pub fn purge_shard_dir(shard: &ShardIdentifier) {
let shard_dir_path = shard_path(shard);
if let Err(e) = std::fs::remove_dir_all(&shard_dir_path) {
error!("Failed to remove shard directory {:?}: {:?}", shard_dir_path, e);
Expand Down
4 changes: 2 additions & 2 deletions core-primitives/stf-state-handler/src/state_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use std::vec::Vec;

/// Implementation of the `HandleState` trait.
///
/// It's concurrency wrapper around a state snapshot repository, which handles
/// access to any shards and state files. The state handler ensure we have thread-safe
/// It's a concurrency wrapper around a state snapshot repository, which handles
/// access to any shards and state files. The state handler ensures we have thread-safe
/// concurrent access to that repository.
pub struct StateHandler<Repository> {
state_snapshot_repository: RwLock<Repository>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,15 @@ where
) -> Vec<StateSnapshotMetaData<HashType>> {
state_ids
.into_iter()
.flat_map(|state_id| {
self.file_io
.compute_hash(shard, state_id)
.map_err(|e| {
warn!(
.flat_map(|state_id| match self.file_io.compute_hash(shard, state_id) {
Ok(hash) => Some(StateSnapshotMetaData::new(hash, state_id)),
Err(e) => {
warn!(
"Failed to compute hash for state snapshot with id {}: {:?}, ignoring snapshot as a result",
state_id, e
);
})
.ok()
.map(|h| StateSnapshotMetaData::new(h, state_id))
None
},
})
.collect()
}
Expand Down
6 changes: 3 additions & 3 deletions core-primitives/stf-state-handler/src/test/sgx_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::{
error::{Error, Result},
file_io::{
init_shard, remove_shard_dir, sgx::SgxStateFileIo, shard_exists, shard_path, StateFileIo,
init_shard, purge_shard_dir, sgx::SgxStateFileIo, shard_exists, shard_path, StateFileIo,
},
handle_state::HandleState,
query_shard_state::QueryShardState,
Expand Down Expand Up @@ -57,7 +57,7 @@ impl ShardDirectoryHandle {

impl Drop for ShardDirectoryHandle {
fn drop(&mut self) {
remove_shard_dir(&self.shard)
purge_shard_dir(&self.shard)
}
}

Expand Down Expand Up @@ -320,7 +320,7 @@ fn given_hello_world_state() -> StfState {

fn given_initialized_shard(shard: &ShardIdentifier) -> Result<()> {
if shard_exists(&shard) {
remove_shard_dir(shard);
purge_shard_dir(shard);
}
init_shard(&shard)
}
Expand Down
4 changes: 2 additions & 2 deletions service/src/tests/ecalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::tests::commons::test_trusted_getter_signed;
use codec::Encode;
use itp_enclave_api::{enclave_base::EnclaveBase, EnclaveResult};
use itp_stf_state_handler::file_io::remove_shard_dir;
use itp_stf_state_handler::file_io::purge_shard_dir;
use log::*;
use sp_core::hash::H256;
use sp_keyring::AccountKeyring;
Expand All @@ -34,7 +34,7 @@ pub fn get_state_works<E: EnclaveBase>(enclave_api: &E) -> EnclaveResult<()> {

assert!(!res.is_empty());

remove_shard_dir(&shard);
purge_shard_dir(&shard);

Ok(())
}

0 comments on commit b3ec74e

Please sign in to comment.