Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
  • Loading branch information
dima74 committed Oct 1, 2024
1 parent 3264ff2 commit eb45eca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crates/iroha_core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ impl Executor {
}
Self::UserProvided(loaded_executor) => {
let wasm_cache = WasmCache::change_lifetime(wasm_cache);
let mut runtime =
wasm_cache.create_runtime_cached(state_transaction, &loaded_executor.module)?;
let mut runtime = wasm_cache
.take_or_create_cached_runtime(state_transaction, &loaded_executor.module)?;
let result = runtime.execute_executor_validate_transaction(
state_transaction,
authority,
transaction,
)?;
wasm_cache.save_cached_runtime(runtime);
wasm_cache.put_cached_runtime(runtime);
result
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/iroha_core/src/smartcontracts/wasm/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ impl<'world, 'block, 'state> WasmCache<'world, 'block, 'state> {
if let Some(cache) = wasm_cache.cache.as_ref() {
assert!(cache.store.data().is_none());
}
// SAFETY: since we have ensured that `cache.store.data()` is `None`,
// the lifetime parameters we are transmuting are not used by any references.
unsafe { std::mem::transmute::<&mut WasmCache, &mut WasmCache>(wasm_cache) }
}

/// Returns cached saved runtime, or creates a new one.
pub fn create_runtime_cached(
pub fn take_or_create_cached_runtime(
&mut self,
state_transaction: &StateTransaction<'_, '_>,
module: &Module,
Expand Down Expand Up @@ -69,7 +71,7 @@ impl<'world, 'block, 'state> WasmCache<'world, 'block, 'state> {
}

/// Saves runtime to be reused later.
pub fn save_cached_runtime(
pub fn put_cached_runtime(
&mut self,
runtime: RuntimeFull<ValidateTransaction<'world, 'block, 'state>>,
) {
Expand Down

0 comments on commit eb45eca

Please sign in to comment.