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 12, 2022
1 parent ec6fbab commit bd39d4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
25 changes: 11 additions & 14 deletions core-primitives/stf-state-handler/src/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,18 @@ pub mod sgx {

let state_path = state_file_path(shard_identifier, state_id);
trace!("loading state from: {:?}", state_path);
let state_vec = self.read(&state_path)?;

// state is now decrypted!
let state: StfStateType = match state_vec.len() {
0 => {
debug!("state at {:?} is empty. will initialize it.", state_path);
Stf::init_state().state
},
n => {
debug!("State loaded from {:?} with size {}B, deserializing...", state_path, n);
StfStateType::decode(&mut state_vec.as_slice())?
},
};
let state_encoded = self.read(&state_path)?;

// State is now decrypted.
debug!(
"State loaded from {:?} with size {}B, deserializing...",
state_path,
state_encoded.len()
);
let state = StfStateType::decode(&mut state_encoded.as_slice())?;

trace!("state decoded successfully");
// add empty state-diff
// Add empty state-diff.
let state_with_diff = StfState { state, state_diff: Default::default() };
trace!("New state created: {:?}", state_with_diff);
Ok(state_with_diff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ mod tests {

#[test]
fn initialize_with_shard_creates_empty_directory() {
let shard = ShardIdentifier::random();
let shard = ShardIdentifier::from([2u8; 32]);
let state_file_io = create_in_memory_state_file_io(&[shard]);

assert!(state_file_io.list_state_ids_for_shard(&shard).unwrap().is_empty());
assert!(state_file_io.list_state_ids_for_shard(&ShardIdentifier::random()).is_err());
assert!(state_file_io
.list_state_ids_for_shard(&ShardIdentifier::from([3u8; 32]))
.is_err());
}

#[test]
Expand Down

0 comments on commit bd39d4a

Please sign in to comment.